cannam@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@0
|
2
|
cannam@0
|
3 /*
|
cannam@0
|
4 Vamp Plugin Tester
|
cannam@0
|
5 Chris Cannam, cannam@all-day-breakfast.com
|
cannam@0
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@59
|
7 Copyright 2009-2015 QMUL.
|
cannam@0
|
8
|
cannam@0
|
9 This program loads a Vamp plugin and tests its susceptibility to a
|
cannam@0
|
10 number of common pitfalls, including handling of extremes of input
|
cannam@0
|
11 data. If you can think of any additional useful tests that are
|
cannam@0
|
12 easily added, please send them to me.
|
cannam@0
|
13
|
cannam@0
|
14 Permission is hereby granted, free of charge, to any person
|
cannam@0
|
15 obtaining a copy of this software and associated documentation
|
cannam@0
|
16 files (the "Software"), to deal in the Software without
|
cannam@0
|
17 restriction, including without limitation the rights to use, copy,
|
cannam@0
|
18 modify, merge, publish, distribute, sublicense, and/or sell copies
|
cannam@0
|
19 of the Software, and to permit persons to whom the Software is
|
cannam@0
|
20 furnished to do so, subject to the following conditions:
|
cannam@0
|
21
|
cannam@0
|
22 The above copyright notice and this permission notice shall be
|
cannam@0
|
23 included in all copies or substantial portions of the Software.
|
cannam@0
|
24
|
cannam@0
|
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
cannam@0
|
26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
cannam@0
|
27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
cannam@0
|
28 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
cannam@0
|
29 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
cannam@0
|
30 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
cannam@0
|
31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
cannam@0
|
32
|
cannam@0
|
33 Except as contained in this notice, the names of the Centre for
|
cannam@0
|
34 Digital Music; Queen Mary, University of London; and Chris Cannam
|
cannam@0
|
35 shall not be used in advertising or otherwise to promote the sale,
|
cannam@0
|
36 use or other dealings in this Software without prior written
|
cannam@0
|
37 authorization.
|
cannam@0
|
38 */
|
cannam@0
|
39
|
cannam@0
|
40 #include <vamp-hostsdk/PluginHostAdapter.h>
|
cannam@0
|
41 #include <vamp-hostsdk/PluginInputDomainAdapter.h>
|
cannam@0
|
42 #include <vamp-hostsdk/PluginLoader.h>
|
cannam@0
|
43
|
cannam@0
|
44 #include <iostream>
|
cannam@0
|
45
|
cannam@0
|
46 #include <cstdlib>
|
cannam@8
|
47 #include <cstring>
|
cannam@0
|
48
|
cannam@0
|
49 #include "Tester.h"
|
cannam@0
|
50
|
cannam@0
|
51 using namespace std;
|
cannam@0
|
52
|
Chris@40
|
53 static const std::string VERSION="1.1";
|
Chris@40
|
54
|
cannam@0
|
55 void usage(const char *name)
|
cannam@0
|
56 {
|
cannam@0
|
57 cerr << "\n"
|
cannam@9
|
58 << name << ": A Vamp plugin host that tests plugins for common errors.\n"
|
cannam@0
|
59 "Chris Cannam, Centre for Digital Music, Queen Mary, University of London.\n"
|
Chris@59
|
60 "Copyright 2009-2015 QMUL.\n"
|
cannam@0
|
61 "Freely redistributable; published under a BSD-style license.\n\n"
|
cannam@0
|
62 "Usage:\n"
|
Chris@40
|
63 " " << name << " [-nv] [-t <test>] <pluginbasename>:<plugin>\n"
|
Chris@40
|
64 " " << name << " [-nv] [-t <test>] -a\n"
|
Chris@40
|
65 " " << name << " -l\n\n"
|
cannam@0
|
66 "Example:\n"
|
cannam@0
|
67 " " << name << " vamp-example-plugins:amplitudefollower\n\n"
|
cannam@25
|
68 "Options:\n"
|
cannam@25
|
69 " -a, --all Test all plugins found in Vamp path\n\n"
|
cannam@25
|
70 " -n, --nondeterministic Plugins may be nondeterministic: print a note\n"
|
cannam@25
|
71 " instead of an error if results differ between runs\n\n"
|
cannam@25
|
72 " -v, --verbose Show returned features each time a note, warning,\n"
|
Chris@40
|
73 " or error arises from feature data\n\n"
|
Chris@40
|
74 " -t, --test <test> Run only a single test, not the full test suite.\n"
|
Chris@40
|
75 " Identify the test by its id, e.g. A3\n\n"
|
Chris@40
|
76 " -l, --list-tests List tests by id and name\n\n"
|
Chris@40
|
77 " --version Display the version of " << name << "\n"
|
cannam@8
|
78 "\nIf you have access to a runtime memory checker, you may find it especially\n"
|
cannam@0
|
79 "helpful to run this tester under it and watch for errors thus provoked.\n"
|
cannam@0
|
80 << endl;
|
cannam@0
|
81 exit(2);
|
cannam@0
|
82 }
|
cannam@0
|
83
|
cannam@0
|
84 int main(int argc, char **argv)
|
cannam@0
|
85 {
|
cannam@0
|
86 char *scooter = argv[0];
|
cannam@0
|
87 char *name = 0;
|
cannam@0
|
88 while (scooter && *scooter) {
|
cannam@0
|
89 if (*scooter == '/' || *scooter == '\\') name = ++scooter;
|
cannam@0
|
90 else ++scooter;
|
cannam@0
|
91 }
|
cannam@0
|
92 if (!name || !*name) name = argv[0];
|
cannam@8
|
93
|
cannam@8
|
94 bool nondeterministic = false;
|
cannam@8
|
95 bool verbose = false;
|
cannam@25
|
96 bool all = false;
|
Chris@40
|
97 bool list = false;
|
Chris@40
|
98 string plugin;
|
Chris@40
|
99 string single;
|
Chris@40
|
100
|
Chris@40
|
101 // Would be better to use getopt, but let's avoid the dependency for now
|
cannam@8
|
102 for (int i = 1; i < argc; ++i) {
|
cannam@8
|
103 if (!argv[i]) break;
|
cannam@8
|
104 if (argv[i][0] == '-') {
|
Chris@40
|
105 if (!strcmp(argv[i], "-vn") ||
|
Chris@40
|
106 !strcmp(argv[i], "-nv")) {
|
Chris@40
|
107 verbose = true;
|
Chris@40
|
108 nondeterministic = true;
|
Chris@40
|
109 continue;
|
Chris@40
|
110 }
|
cannam@8
|
111 if (!strcmp(argv[i], "-v") ||
|
cannam@8
|
112 !strcmp(argv[i], "--verbose")) {
|
cannam@25
|
113 verbose = true;
|
cannam@8
|
114 continue;
|
cannam@8
|
115 }
|
cannam@8
|
116 if (!strcmp(argv[i], "-n") ||
|
cannam@8
|
117 !strcmp(argv[i], "--nondeterministic")) {
|
cannam@25
|
118 nondeterministic = true;
|
cannam@25
|
119 continue;
|
cannam@25
|
120 }
|
cannam@25
|
121 if (!strcmp(argv[i], "-a") ||
|
cannam@25
|
122 !strcmp(argv[i], "--all")) {
|
cannam@25
|
123 all = true;
|
cannam@8
|
124 continue;
|
cannam@8
|
125 }
|
Chris@40
|
126 if (!strcmp(argv[i], "-l") ||
|
Chris@40
|
127 !strcmp(argv[i], "--list-tests")) {
|
Chris@40
|
128 list = true;
|
Chris@40
|
129 continue;
|
Chris@40
|
130 }
|
Chris@40
|
131 if (!strcmp(argv[i], "-t") ||
|
Chris@40
|
132 !strcmp(argv[i], "--test")) {
|
Chris@40
|
133 if (i + 1 < argc) {
|
Chris@40
|
134 single = argv[i+1];
|
Chris@40
|
135 ++i;
|
Chris@40
|
136 } else {
|
Chris@40
|
137 usage(name);
|
Chris@40
|
138 }
|
Chris@40
|
139 continue;
|
Chris@40
|
140 }
|
Chris@40
|
141 if (!strcmp(argv[i], "--version")) {
|
Chris@40
|
142 cout << "v" << VERSION << endl;
|
Chris@40
|
143 return 0;
|
Chris@40
|
144 }
|
cannam@8
|
145 usage(name);
|
cannam@8
|
146 } else {
|
Chris@40
|
147 if (plugin != "") usage(name);
|
Chris@40
|
148 else plugin = argv[i];
|
cannam@8
|
149 }
|
cannam@8
|
150 }
|
Chris@40
|
151
|
Chris@40
|
152 if (list) {
|
Chris@40
|
153 if (all || nondeterministic || (single != "") || (plugin != "")) {
|
Chris@40
|
154 usage(name);
|
Chris@40
|
155 }
|
Chris@40
|
156 Tester::listTests();
|
Chris@40
|
157 return 0;
|
Chris@40
|
158 }
|
cannam@0
|
159
|
Chris@40
|
160 if (plugin == "" && !all) usage(name);
|
Chris@40
|
161 if (plugin != "" && all) usage(name);
|
cannam@25
|
162
|
cannam@0
|
163 cerr << name << ": Running..." << endl;
|
cannam@0
|
164
|
cannam@8
|
165 Test::Options opts = Test::NoOption;
|
cannam@8
|
166 if (nondeterministic) opts |= Test::NonDeterministic;
|
cannam@8
|
167 if (verbose) opts |= Test::Verbose;
|
Chris@39
|
168 if (single != "") opts |= Test::SingleTest;
|
cannam@8
|
169
|
cannam@25
|
170 if (all) {
|
cannam@0
|
171 bool good = true;
|
cannam@0
|
172 Vamp::HostExt::PluginLoader::PluginKeyList keys =
|
cannam@0
|
173 Vamp::HostExt::PluginLoader::getInstance()->listPlugins();
|
Chris@33
|
174 if (keys.size() == 0) {
|
Chris@33
|
175 cout << name << ": NOTE: No plugins found!" << endl;
|
Chris@33
|
176 cout << name << ": (No libraries in search path, or no descriptors in library)" << endl;
|
Chris@37
|
177 return 2;
|
Chris@33
|
178 }
|
cannam@4
|
179 int notes = 0, warnings = 0, errors = 0;
|
cannam@0
|
180 for (int i = 0; i < (int)keys.size(); ++i) {
|
cannam@3
|
181 cout << "Testing plugin: " << keys[i] << endl;
|
Chris@39
|
182 Tester tester(keys[i], opts, single);
|
cannam@4
|
183 if (tester.test(notes, warnings, errors)) {
|
cannam@3
|
184 cout << name << ": All tests succeeded for this plugin" << endl;
|
cannam@0
|
185 } else {
|
cannam@3
|
186 cout << name << ": Some tests failed for this plugin" << endl;
|
cannam@0
|
187 good = false;
|
cannam@0
|
188 }
|
cannam@3
|
189 cout << endl;
|
cannam@0
|
190 }
|
cannam@0
|
191 if (good) {
|
cannam@4
|
192 cout << name << ": All tests succeeded";
|
cannam@4
|
193 if (warnings > 0) {
|
cannam@4
|
194 cout << ", with " << warnings << " warning(s)";
|
cannam@4
|
195 if (notes > 0) {
|
cannam@4
|
196 cout << " and " << notes << " other note(s)";
|
cannam@4
|
197 }
|
cannam@4
|
198 } else if (notes > 0) {
|
cannam@4
|
199 cout << ", with " << notes << " note(s)";
|
cannam@4
|
200 }
|
cannam@4
|
201 cout << endl;
|
cannam@0
|
202 return 0;
|
cannam@0
|
203 } else {
|
cannam@3
|
204 cout << name << ": Some tests failed" << endl;
|
cannam@0
|
205 return 1;
|
cannam@0
|
206 }
|
cannam@0
|
207 } else {
|
Chris@40
|
208 Tester tester(plugin, opts, single);
|
cannam@4
|
209 int notes = 0, warnings = 0, errors = 0;
|
cannam@4
|
210 if (tester.test(notes, warnings, errors)) {
|
cannam@4
|
211 cout << name << ": All tests succeeded";
|
cannam@4
|
212 if (warnings > 0) {
|
cannam@4
|
213 cout << ", with " << warnings << " warning(s)";
|
cannam@4
|
214 if (notes > 0) {
|
cannam@4
|
215 cout << " and " << notes << " other note(s)";
|
cannam@4
|
216 }
|
cannam@4
|
217 } else if (notes > 0) {
|
cannam@4
|
218 cout << ", with " << notes << " note(s)";
|
cannam@4
|
219 }
|
cannam@4
|
220 cout << endl;
|
cannam@0
|
221 return 0;
|
cannam@0
|
222 } else {
|
cannam@3
|
223 cout << name << ": Some tests failed" << endl;
|
cannam@0
|
224 return 1;
|
cannam@0
|
225 }
|
cannam@0
|
226 }
|
cannam@0
|
227 }
|
cannam@0
|
228
|