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 @ 59:6732dd5e7139

History | View | Annotate | Download (8.21 KB)

1 0:f89128a316e7 cannam
/* -*- 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 59:6732dd5e7139 Chris
    Copyright 2009-2015 QMUL.
8 0:f89128a316e7 cannam

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 8:3019cb6b538d cannam
#include <cstring>
48 0:f89128a316e7 cannam
49
#include "Tester.h"
50
51
using namespace std;
52
53 40:649f32c7eb41 Chris
static const std::string VERSION="1.1";
54
55 0:f89128a316e7 cannam
void usage(const char *name)
56
{
57
    cerr << "\n"
58 9:7cc55187f5db cannam
         << name << ": A Vamp plugin host that tests plugins for common errors.\n"
59 0:f89128a316e7 cannam
        "Chris Cannam, Centre for Digital Music, Queen Mary, University of London.\n"
60 59:6732dd5e7139 Chris
        "Copyright 2009-2015 QMUL.\n"
61 0:f89128a316e7 cannam
        "Freely redistributable; published under a BSD-style license.\n\n"
62
        "Usage:\n"
63 40:649f32c7eb41 Chris
        "  " << name << " [-nv] [-t <test>] <pluginbasename>:<plugin>\n"
64
        "  " << name << " [-nv] [-t <test>] -a\n"
65
        "  " << name << " -l\n\n"
66 0:f89128a316e7 cannam
        "Example:\n"
67
        "  " << name << " vamp-example-plugins:amplitudefollower\n\n"
68 25:612333efd521 cannam
        "Options:\n"
69
        "  -a, --all                 Test all plugins found in Vamp path\n\n"
70
        "  -n, --nondeterministic    Plugins may be nondeterministic: print a note\n"
71
        "                            instead of an error if results differ between runs\n\n"
72
        "  -v, --verbose             Show returned features each time a note, warning,\n"
73 40:649f32c7eb41 Chris
        "                            or error arises from feature data\n\n"
74
        "  -t, --test <test>         Run only a single test, not the full test suite.\n"
75
        "                            Identify the test by its id, e.g. A3\n\n"
76
        "  -l, --list-tests          List tests by id and name\n\n"
77
        "  --version                 Display the version of " << name << "\n"
78 8:3019cb6b538d cannam
        "\nIf you have access to a runtime memory checker, you may find it especially\n"
79 0:f89128a316e7 cannam
        "helpful to run this tester under it and watch for errors thus provoked.\n"
80
         << endl;
81
    exit(2);
82
}
83
84
int main(int argc, char **argv)
85
{
86
    char *scooter = argv[0];
87
    char *name = 0;
88
    while (scooter && *scooter) {
89
        if (*scooter == '/' || *scooter == '\\') name = ++scooter;
90
        else ++scooter;
91
    }
92
    if (!name || !*name) name = argv[0];
93 8:3019cb6b538d cannam
94
    bool nondeterministic = false;
95
    bool verbose = false;
96 25:612333efd521 cannam
    bool all = false;
97 40:649f32c7eb41 Chris
    bool list = false;
98
    string plugin;
99
    string single;
100
101
    // Would be better to use getopt, but let's avoid the dependency for now
102 8:3019cb6b538d cannam
    for (int i = 1; i < argc; ++i) {
103
        if (!argv[i]) break;
104
        if (argv[i][0] == '-') {
105 40:649f32c7eb41 Chris
            if (!strcmp(argv[i], "-vn") ||
106
                !strcmp(argv[i], "-nv")) {
107
                verbose = true;
108
                nondeterministic = true;
109
                continue;
110
            }
111 8:3019cb6b538d cannam
            if (!strcmp(argv[i], "-v") ||
112
                !strcmp(argv[i], "--verbose")) {
113 25:612333efd521 cannam
                verbose = true;
114 8:3019cb6b538d cannam
                continue;
115
            }
116
            if (!strcmp(argv[i], "-n") ||
117
                !strcmp(argv[i], "--nondeterministic")) {
118 25:612333efd521 cannam
                nondeterministic = true;
119
                continue;
120
            }
121
            if (!strcmp(argv[i], "-a") ||
122
                !strcmp(argv[i], "--all")) {
123
                all = true;
124 8:3019cb6b538d cannam
                continue;
125
            }
126 40:649f32c7eb41 Chris
            if (!strcmp(argv[i], "-l") ||
127
                !strcmp(argv[i], "--list-tests")) {
128
                list = true;
129
                continue;
130
            }
131
            if (!strcmp(argv[i], "-t") ||
132
                !strcmp(argv[i], "--test")) {
133
                if (i + 1 < argc) {
134
                    single = argv[i+1];
135
                    ++i;
136
                } else {
137
                    usage(name);
138
                }
139
                continue;
140
            }
141
            if (!strcmp(argv[i], "--version")) {
142
                cout << "v" << VERSION << endl;
143
                return 0;
144
            }
145 8:3019cb6b538d cannam
            usage(name);
146
        } else {
147 40:649f32c7eb41 Chris
            if (plugin != "") usage(name);
148
            else plugin = argv[i];
149 8:3019cb6b538d cannam
        }
150
    }
151 40:649f32c7eb41 Chris
152
    if (list) {
153
        if (all || nondeterministic || (single != "") || (plugin != "")) {
154
            usage(name);
155
        }
156
        Tester::listTests();
157
        return 0;
158
    }
159 0:f89128a316e7 cannam
160 40:649f32c7eb41 Chris
    if (plugin == "" && !all) usage(name);
161
    if (plugin != "" &&  all) usage(name);
162 25:612333efd521 cannam
163 0:f89128a316e7 cannam
    cerr << name << ": Running..." << endl;
164
165 8:3019cb6b538d cannam
    Test::Options opts = Test::NoOption;
166
    if (nondeterministic) opts |= Test::NonDeterministic;
167
    if (verbose) opts |= Test::Verbose;
168 39:07144cdcbedf Chris
    if (single != "") opts |= Test::SingleTest;
169 8:3019cb6b538d cannam
170 25:612333efd521 cannam
    if (all) {
171 0:f89128a316e7 cannam
        bool good = true;
172
        Vamp::HostExt::PluginLoader::PluginKeyList keys =
173
            Vamp::HostExt::PluginLoader::getInstance()->listPlugins();
174 33:005ac7a3d827 Chris
        if (keys.size() == 0) {
175
            cout << name << ": NOTE: No plugins found!" << endl;
176
            cout << name << ": (No libraries in search path, or no descriptors in library)" << endl;
177 37:a835f9cf3a3d Chris
            return 2;
178 33:005ac7a3d827 Chris
        }
179 4:d8724c5a6d83 cannam
        int notes = 0, warnings = 0, errors = 0;
180 0:f89128a316e7 cannam
        for (int i = 0; i < (int)keys.size(); ++i) {
181 3:0f65bb22172b cannam
            cout << "Testing plugin: " << keys[i] << endl;
182 39:07144cdcbedf Chris
            Tester tester(keys[i], opts, single);
183 4:d8724c5a6d83 cannam
            if (tester.test(notes, warnings, errors)) {
184 3:0f65bb22172b cannam
                cout << name << ": All tests succeeded for this plugin" << endl;
185 0:f89128a316e7 cannam
            } else {
186 3:0f65bb22172b cannam
                cout << name << ": Some tests failed for this plugin" << endl;
187 0:f89128a316e7 cannam
                good = false;
188
            }
189 3:0f65bb22172b cannam
            cout << endl;
190 0:f89128a316e7 cannam
        }
191
        if (good) {
192 4:d8724c5a6d83 cannam
            cout << name << ": All tests succeeded";
193
            if (warnings > 0) {
194
                cout << ", with " << warnings << " warning(s)";
195
                if (notes > 0) {
196
                    cout << " and " << notes << " other note(s)";
197
                }
198
            } else if (notes > 0) {
199
                cout << ", with " << notes << " note(s)";
200
            }
201
            cout << endl;
202 0:f89128a316e7 cannam
            return 0;
203
        } else {
204 3:0f65bb22172b cannam
            cout << name << ": Some tests failed" << endl;
205 0:f89128a316e7 cannam
            return 1;
206
        }
207
    } else {
208 40:649f32c7eb41 Chris
        Tester tester(plugin, opts, single);
209 4:d8724c5a6d83 cannam
        int notes = 0, warnings = 0, errors = 0;
210
        if (tester.test(notes, warnings, errors)) {
211
            cout << name << ": All tests succeeded";
212
            if (warnings > 0) {
213
                cout << ", with " << warnings << " warning(s)";
214
                if (notes > 0) {
215
                    cout << " and " << notes << " other note(s)";
216
                }
217
            } else if (notes > 0) {
218
                cout << ", with " << notes << " note(s)";
219
            }
220
            cout << endl;
221 0:f89128a316e7 cannam
            return 0;
222
        } else {
223 3:0f65bb22172b cannam
            cout << name << ": Some tests failed" << endl;
224 0:f89128a316e7 cannam
            return 1;
225
        }
226
    }
227
}