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.
|
cannam@0
|
7 Copyright 2009 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 <cstring>
|
cannam@0
|
47 #include <cstdlib>
|
cannam@0
|
48 #include <cmath>
|
cannam@4
|
49 #include <set>
|
cannam@0
|
50
|
cannam@0
|
51 #include "Tester.h"
|
cannam@0
|
52
|
cannam@0
|
53 using Vamp::Plugin;
|
cannam@0
|
54 using Vamp::PluginHostAdapter;
|
cannam@0
|
55 using Vamp::RealTime;
|
cannam@0
|
56 using Vamp::HostExt::PluginLoader;
|
cannam@0
|
57 using Vamp::HostExt::PluginWrapper;
|
cannam@0
|
58 using Vamp::HostExt::PluginInputDomainAdapter;
|
cannam@0
|
59
|
cannam@0
|
60 using namespace std;
|
cannam@0
|
61
|
Chris@39
|
62 Tester::Tester(std::string key, Test::Options options, std::string singleTestId) :
|
cannam@8
|
63 m_key(key),
|
Chris@39
|
64 m_options(options),
|
Chris@39
|
65 m_singleTest(singleTestId)
|
cannam@0
|
66 {
|
cannam@0
|
67 }
|
cannam@0
|
68
|
cannam@0
|
69 Tester::~Tester()
|
cannam@0
|
70 {
|
cannam@0
|
71 }
|
cannam@0
|
72
|
Chris@39
|
73 Tester::NameIndex &
|
Chris@39
|
74 Tester::nameIndex()
|
Chris@39
|
75 {
|
Chris@39
|
76 static NameIndex ix;
|
Chris@39
|
77 return ix;
|
Chris@39
|
78 }
|
Chris@39
|
79
|
cannam@0
|
80 Tester::Registry &
|
cannam@0
|
81 Tester::registry()
|
cannam@0
|
82 {
|
cannam@0
|
83 static Registry r;
|
cannam@0
|
84 return r;
|
cannam@0
|
85 }
|
cannam@0
|
86
|
cannam@0
|
87 bool
|
cannam@4
|
88 Tester::test(int ¬es, int &warnings, int &errors)
|
cannam@0
|
89 {
|
cannam@0
|
90 /*
|
cannam@0
|
91
|
cannam@0
|
92 Things I would like to see tested:
|
cannam@0
|
93
|
cannam@0
|
94 * Identifiers for parameters, outputs, or plugin itself contain
|
cannam@0
|
95 illegal characters - DONE
|
cannam@0
|
96
|
cannam@0
|
97 * Any of the plugin's name, maker etc fields are empty - DONE
|
cannam@0
|
98
|
cannam@1
|
99 * Default value of a parameter is not quantized as specified - DONE
|
cannam@1
|
100
|
cannam@1
|
101 * Parameter minValue >= maxValue, or defaultValue < minValue
|
cannam@1
|
102 or > maxValue - DONE
|
cannam@1
|
103
|
cannam@1
|
104 * Plugin fails when given zero-length or very short input - DONE
|
cannam@1
|
105
|
cannam@1
|
106 * Plugin fails when given "all digital zeros" input - DONE
|
cannam@1
|
107
|
cannam@1
|
108 * Plugin fails when given input that exceeds +/-1 - DONE
|
cannam@1
|
109
|
cannam@1
|
110 * Plugin fails when given "normal" random input (just in case!) - DONE
|
cannam@1
|
111
|
cannam@0
|
112 * Plugin returns different results if another instance is
|
cannam@3
|
113 constructed and run "interleaved" with it (from same thread) - DONE
|
cannam@0
|
114
|
cannam@0
|
115 * Plugin's returned timestamps do not change as expected when
|
cannam@0
|
116 run with a different base timestamp for input (though there
|
cannam@5
|
117 could be legitimate reasons for this) - DONE
|
cannam@0
|
118
|
cannam@0
|
119 * Plugin produces different results on second run, after reset
|
cannam@3
|
120 called - DONE
|
cannam@0
|
121
|
cannam@0
|
122 * Initial value of a parameter on plugin construction differs
|
cannam@0
|
123 from its default value (i.e. plugin produces different
|
cannam@0
|
124 results depending on whether parameter is set explicitly by
|
cannam@6
|
125 host to default value or not) - DONE
|
cannam@0
|
126
|
cannam@0
|
127 * If a plugin reports any programs, selecting default program
|
cannam@6
|
128 explicitly changes results (as for default parameters) - DONE
|
cannam@0
|
129
|
cannam@0
|
130 * Output feature does not hasTimestamp when output type is
|
cannam@5
|
131 VariableSampleRate - DONE
|
cannam@0
|
132
|
cannam@0
|
133 * Output feature hasTimestamp or hasDuration when output type is
|
cannam@5
|
134 OneSamplePerStep (warning only, this is not an error) - DONE
|
cannam@0
|
135
|
cannam@0
|
136 * Plugin returns features whose output numbers do not have
|
cannam@5
|
137 a corresponding record in output descriptor list - DONE
|
cannam@0
|
138
|
cannam@0
|
139 * Plugin fails to return any features on some output (warning
|
cannam@5
|
140 only) - DONE
|
cannam@0
|
141
|
cannam@0
|
142 * Constructor takes a long time to run. A fuzzy concept, but
|
cannam@0
|
143 suggests that some work should have been deferred to
|
cannam@6
|
144 initialise(). Warning only - DONE
|
cannam@6
|
145
|
cannam@6
|
146 * Plugin fails gracelessly when constructed with "weird" sample
|
cannam@6
|
147 rate or initialised with "wrong" step size, block size, or
|
cannam@6
|
148 number of channels
|
cannam@0
|
149
|
cannam@0
|
150 Well, that's quite a lot of tests already. What else?
|
cannam@0
|
151
|
cannam@0
|
152 */
|
cannam@0
|
153
|
cannam@0
|
154 bool good = true;
|
cannam@0
|
155
|
cannam@0
|
156 try {
|
cannam@0
|
157
|
Chris@39
|
158 if (m_options & Test::SingleTest) {
|
cannam@4
|
159
|
Chris@39
|
160 if (registry().find(m_singleTest) != registry().end()) {
|
Chris@39
|
161
|
Chris@39
|
162 good = performTest(m_singleTest, notes, warnings, errors);
|
Chris@39
|
163
|
Chris@39
|
164 } else {
|
Chris@39
|
165
|
Chris@39
|
166 std::cout << " ** ERROR: Unknown single-test id \""
|
Chris@39
|
167 << m_singleTest << "\"" << std::endl;
|
Chris@39
|
168 good = false;
|
Chris@39
|
169 }
|
Chris@39
|
170
|
Chris@39
|
171 } else {
|
Chris@39
|
172
|
Chris@39
|
173 for (Registry::const_iterator i = registry().begin();
|
Chris@39
|
174 i != registry().end(); ++i) {
|
Chris@39
|
175
|
Chris@39
|
176 bool thisGood = performTest(i->first, notes, warnings, errors);
|
Chris@39
|
177 if (!thisGood) good = false;
|
cannam@0
|
178 }
|
cannam@0
|
179 }
|
Chris@39
|
180
|
cannam@0
|
181 } catch (Test::FailedToLoadPlugin) {
|
cannam@17
|
182 std::cout << " ** ERROR: Failed to load plugin (key = \"" << m_key
|
cannam@0
|
183 << "\")" << std::endl;
|
cannam@25
|
184 std::cout << " ** NOTE: Vamp plugin path is: " << std::endl;
|
cannam@25
|
185 std::vector<std::string> pp = PluginHostAdapter::getPluginPath();
|
cannam@25
|
186 for (size_t i = 0; i < pp.size(); ++i) {
|
cannam@25
|
187 std::cout << " " << pp[i] << std::endl;
|
cannam@25
|
188 }
|
cannam@26
|
189 good = false;
|
cannam@0
|
190 }
|
cannam@0
|
191
|
cannam@0
|
192 return good;
|
cannam@0
|
193 }
|
cannam@0
|
194
|
Chris@39
|
195 bool
|
Chris@39
|
196 Tester::performTest(std::string id, int ¬es, int &warnings, int &errors)
|
Chris@39
|
197 {
|
Chris@39
|
198 std::cout << " -- Performing test: "
|
Chris@39
|
199 << id
|
Chris@39
|
200 << " "
|
Chris@39
|
201 << nameIndex()[id]
|
Chris@39
|
202 << std::endl;
|
Chris@39
|
203
|
Chris@39
|
204 Test *test = registry()[id]->makeTest();
|
Chris@39
|
205 Test::Results results = test->test(m_key, m_options);
|
Chris@39
|
206 delete test;
|
Chris@39
|
207
|
Chris@39
|
208 set<string> printed;
|
Chris@39
|
209
|
Chris@39
|
210 bool good = true;
|
Chris@39
|
211
|
Chris@39
|
212 for (int j = 0; j < (int)results.size(); ++j) {
|
Chris@39
|
213 string message = results[j].message();
|
Chris@39
|
214 if (printed.find(message) != printed.end()) continue;
|
Chris@39
|
215 printed.insert(message);
|
Chris@39
|
216 switch (results[j].code()) {
|
Chris@39
|
217 case Test::Result::Success:
|
Chris@39
|
218 break;
|
Chris@39
|
219 case Test::Result::Note:
|
Chris@39
|
220 std::cout << " ** NOTE: " << results[j].message() << std::endl;
|
Chris@39
|
221 ++notes;
|
Chris@39
|
222 break;
|
Chris@39
|
223 case Test::Result::Warning:
|
Chris@39
|
224 std::cout << " ** WARNING: " << results[j].message() << std::endl;
|
Chris@39
|
225 ++warnings;
|
Chris@39
|
226 break;
|
Chris@39
|
227 case Test::Result::Error:
|
Chris@39
|
228 std::cout << " ** ERROR: " << results[j].message() << std::endl;
|
Chris@39
|
229 ++errors;
|
Chris@39
|
230 good = false;
|
Chris@39
|
231 break;
|
Chris@39
|
232 }
|
Chris@39
|
233 }
|
Chris@39
|
234
|
Chris@39
|
235 return good;
|
Chris@39
|
236 }
|
Chris@39
|
237
|