To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / vamp-plugin-tester.cpp @ 8:3019cb6b538d

History | View | Annotate | Download (6.2 KB)

1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2

    
3
/*
4
    Vamp Plugin Tester
5
    Chris Cannam, cannam@all-day-breakfast.com
6
    Centre for Digital Music, Queen Mary, University of London.
7
    Copyright 2009 QMUL.
8

9
    This program loads a Vamp plugin and tests its susceptibility to a
10
    number of common pitfalls, including handling of extremes of input
11
    data.  If you can think of any additional useful tests that are
12
    easily added, please send them to me.
13
  
14
    Permission is hereby granted, free of charge, to any person
15
    obtaining a copy of this software and associated documentation
16
    files (the "Software"), to deal in the Software without
17
    restriction, including without limitation the rights to use, copy,
18
    modify, merge, publish, distribute, sublicense, and/or sell copies
19
    of the Software, and to permit persons to whom the Software is
20
    furnished to do so, subject to the following conditions:
21

22
    The above copyright notice and this permission notice shall be
23
    included in all copies or substantial portions of the Software.
24

25
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
29
    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
30
    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32

33
    Except as contained in this notice, the names of the Centre for
34
    Digital Music; Queen Mary, University of London; and Chris Cannam
35
    shall not be used in advertising or otherwise to promote the sale,
36
    use or other dealings in this Software without prior written
37
    authorization.
38
*/
39

    
40
#include <vamp-hostsdk/PluginHostAdapter.h>
41
#include <vamp-hostsdk/PluginInputDomainAdapter.h>
42
#include <vamp-hostsdk/PluginLoader.h>
43

    
44
#include <iostream>
45

    
46
#include <cstdlib>
47
#include <cstring>
48

    
49
#include "Tester.h"
50

    
51
using namespace std;
52

    
53
void usage(const char *name)
54
{
55
    cerr << "\n"
56
         << name << ": A Vamp plugin host that tests plugins for some likely errors.\n"
57
        "Chris Cannam, Centre for Digital Music, Queen Mary, University of London.\n"
58
        "Copyright 2009 QMUL.\n"
59
        "Freely redistributable; published under a BSD-style license.\n\n"
60
        "Usage:\n"
61
        "  " << name << " [-n] [-v] [<pluginbasename>:<plugin>]\n\n"
62
        "Example:\n"
63
        "  " << name << " vamp-example-plugins:amplitudefollower\n\n"
64
        "With an argument, tests one plugin; without, tests all plugins in Vamp path.\n"
65
        "\nOptions:\n"
66
        "  --nondeterministic, -n    Plugins may be nondeterministic: print a note\n"
67
        "                            instead of an error if results differ between runs\n"
68
        "  --verbose, -v             Show returned features each time a note, warning,\n"
69
        "                            or error arises from feature data\n"
70
        "\nIf you have access to a runtime memory checker, you may find it especially\n"
71
        "helpful to run this tester under it and watch for errors thus provoked.\n"
72
         << endl;
73
    exit(2);
74
}
75

    
76
int main(int argc, char **argv)
77
{
78
    char *scooter = argv[0];
79
    char *name = 0;
80
    while (scooter && *scooter) {
81
        if (*scooter == '/' || *scooter == '\\') name = ++scooter;
82
        else ++scooter;
83
    }
84
    if (!name || !*name) name = argv[0];
85

    
86
    bool nondeterministic = false;
87
    bool verbose = false;
88
    string argument;
89
    for (int i = 1; i < argc; ++i) {
90
        if (!argv[i]) break;
91
        if (argv[i][0] == '-') {
92
            if (!strcmp(argv[i], "-v") ||
93
                !strcmp(argv[i], "--verbose")) {
94
                verbose = 1;
95
                continue;
96
            }
97
            if (!strcmp(argv[i], "-n") ||
98
                !strcmp(argv[i], "--nondeterministic")) {
99
                nondeterministic = 1;
100
                continue;
101
            }
102
            usage(name);
103
        } else {
104
            if (argument != "") usage(name);
105
            else argument = argv[i];
106
        }
107
    }
108
    
109
    cerr << name << ": Running..." << endl;
110

    
111
    Test::Options opts = Test::NoOption;
112
    if (nondeterministic) opts |= Test::NonDeterministic;
113
    if (verbose) opts |= Test::Verbose;
114

    
115
    if (argument == "") {
116
        bool good = true;
117
        Vamp::HostExt::PluginLoader::PluginKeyList keys =
118
            Vamp::HostExt::PluginLoader::getInstance()->listPlugins();
119
        int notes = 0, warnings = 0, errors = 0;
120
        for (int i = 0; i < (int)keys.size(); ++i) {
121
            cout << "Testing plugin: " << keys[i] << endl;
122
            Tester tester(keys[i], opts);
123
            if (tester.test(notes, warnings, errors)) {
124
                cout << name << ": All tests succeeded for this plugin" << endl;
125
            } else {
126
                cout << name << ": Some tests failed for this plugin" << endl;
127
                good = false;
128
            }
129
            cout << endl;
130
        }
131
        if (good) {
132
            cout << name << ": All tests succeeded";
133
            if (warnings > 0) {
134
                cout << ", with " << warnings << " warning(s)";
135
                if (notes > 0) {
136
                    cout << " and " << notes << " other note(s)";
137
                }
138
            } else if (notes > 0) {
139
                cout << ", with " << notes << " note(s)";
140
            }
141
            cout << endl;
142
            return 0;
143
        } else {
144
            cout << name << ": Some tests failed" << endl;
145
            return 1;
146
        }   
147
    } else {
148
        string key = argument;
149
        Tester tester(key, opts);
150
        int notes = 0, warnings = 0, errors = 0;
151
        if (tester.test(notes, warnings, errors)) {
152
            cout << name << ": All tests succeeded";
153
            if (warnings > 0) {
154
                cout << ", with " << warnings << " warning(s)";
155
                if (notes > 0) {
156
                    cout << " and " << notes << " other note(s)";
157
                }
158
            } else if (notes > 0) {
159
                cout << ", with " << notes << " note(s)";
160
            }
161
            cout << endl;
162
            return 0;
163
        } else {
164
            cout << name << ": Some tests failed" << endl;
165
            return 1;
166
        }
167
    }
168
}
169