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 Fuzz Tester
|
cannam@0
|
5 Chris Cannam, cannam@all-day-breakfast.com
|
cannam@0
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@42
|
7 Copyright 2009-2014 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 "Test.h"
|
cannam@0
|
41
|
cannam@0
|
42 #include <vamp-hostsdk/PluginLoader.h>
|
cannam@0
|
43
|
cannam@0
|
44 using namespace Vamp;
|
cannam@0
|
45 using namespace Vamp::HostExt;
|
cannam@0
|
46
|
cannam@20
|
47 #include <math.h>
|
cannam@1
|
48
|
cannam@28
|
49 #ifdef __SUNPRO_CC
|
cannam@28
|
50 #include <ieeefp.h>
|
cannam@28
|
51 #define isinf(x) (!finite(x))
|
cannam@28
|
52 #endif
|
cannam@28
|
53
|
cannam@0
|
54 Test::Test() { }
|
cannam@0
|
55 Test::~Test() { }
|
cannam@0
|
56
|
Chris@52
|
57 using std::cerr;
|
Chris@52
|
58 using std::cout;
|
Chris@52
|
59 using std::endl;
|
Chris@52
|
60 using std::string;
|
Chris@52
|
61
|
cannam@0
|
62 Plugin *
|
Chris@52
|
63 Test::load(string key, float rate)
|
cannam@0
|
64 {
|
cannam@23
|
65 Plugin *p = PluginLoader::getInstance()->loadPlugin
|
cannam@0
|
66 (key, rate, PluginLoader::ADAPT_ALL);
|
cannam@23
|
67 if (!p) throw FailedToLoadPlugin();
|
cannam@23
|
68 return p;
|
cannam@0
|
69 }
|
cannam@0
|
70
|
cannam@1
|
71 float **
|
cannam@1
|
72 Test::createBlock(size_t channels, size_t blocksize)
|
cannam@1
|
73 {
|
cannam@1
|
74 float **b = new float *[channels];
|
cannam@1
|
75 for (size_t c = 0; c < channels; ++c) {
|
cannam@1
|
76 b[c] = new float[blocksize];
|
cannam@1
|
77 }
|
cannam@1
|
78 return b;
|
cannam@1
|
79 }
|
cannam@1
|
80
|
cannam@1
|
81 void
|
cannam@1
|
82 Test::destroyBlock(float **blocks, size_t channels)
|
cannam@1
|
83 {
|
cannam@1
|
84 for (size_t c = 0; c < channels; ++c) {
|
cannam@1
|
85 delete[] blocks[c];
|
cannam@1
|
86 }
|
cannam@1
|
87 delete[] blocks;
|
cannam@1
|
88 }
|
cannam@1
|
89
|
cannam@3
|
90 float **
|
cannam@3
|
91 Test::createTestAudio(size_t channels, size_t blocksize, size_t blocks)
|
cannam@3
|
92 {
|
cannam@3
|
93 float **b = new float *[channels];
|
cannam@3
|
94 for (size_t c = 0; c < channels; ++c) {
|
cannam@3
|
95 b[c] = new float[blocksize * blocks];
|
cannam@3
|
96 for (int i = 0; i < int(blocksize * blocks); ++i) {
|
cannam@3
|
97 b[c][i] = sinf(float(i) / 10.f);
|
cannam@3
|
98 if (i == 5005 || i == 20002) {
|
cannam@3
|
99 b[c][i-2] = 0;
|
cannam@3
|
100 b[c][i-1] = -1;
|
cannam@3
|
101 b[c][i] = 1;
|
cannam@3
|
102 }
|
cannam@3
|
103 }
|
cannam@3
|
104 }
|
cannam@3
|
105 return b;
|
cannam@3
|
106 }
|
cannam@3
|
107
|
cannam@3
|
108 void
|
cannam@3
|
109 Test::destroyTestAudio(float **b, size_t channels)
|
cannam@3
|
110 {
|
cannam@3
|
111 for (size_t c = 0; c < channels; ++c) {
|
cannam@3
|
112 delete[] b[c];
|
cannam@3
|
113 }
|
cannam@3
|
114 delete[] b;
|
cannam@3
|
115 }
|
cannam@3
|
116
|
cannam@1
|
117 bool
|
cannam@1
|
118 Test::initDefaults(Plugin *p, size_t &channels, size_t &step, size_t &block,
|
cannam@1
|
119 Results &r)
|
cannam@1
|
120 {
|
cannam@1
|
121 channels = p->getMinChannelCount();
|
cannam@1
|
122 block = p->getPreferredBlockSize();
|
cannam@1
|
123 step = p->getPreferredStepSize();
|
cannam@1
|
124 if (block == 0) block = 1024;
|
cannam@1
|
125 if (step == 0) {
|
cannam@1
|
126 if (p->getInputDomain() == Plugin::FrequencyDomain) step = block/2;
|
cannam@1
|
127 else step = block;
|
cannam@1
|
128 }
|
cannam@1
|
129 if (!p->initialise(channels, step, block)) {
|
cannam@1
|
130 r.push_back(error("initialisation with default values failed"));
|
cannam@1
|
131 return false;
|
cannam@1
|
132 }
|
cannam@1
|
133 return true;
|
cannam@1
|
134 }
|
cannam@1
|
135
|
cannam@3
|
136 bool
|
cannam@3
|
137 Test::initAdapted(Plugin *p, size_t &channels, size_t step, size_t block,
|
cannam@3
|
138 Results &r)
|
cannam@3
|
139 {
|
cannam@3
|
140 channels = p->getMinChannelCount();
|
cannam@3
|
141 if (!p->initialise(channels, step, block)) {
|
cannam@3
|
142 r.push_back(error("initialisation failed"));
|
cannam@3
|
143 return false;
|
cannam@3
|
144 }
|
cannam@3
|
145 return true;
|
cannam@3
|
146 }
|
cannam@3
|
147
|
cannam@0
|
148 void
|
cannam@0
|
149 Test::appendFeatures(Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
|
cannam@0
|
150 {
|
cannam@0
|
151 for (Plugin::FeatureSet::const_iterator i = b.begin(); i != b.end(); ++i) {
|
cannam@0
|
152 int output = i->first;
|
cannam@0
|
153 const Plugin::FeatureList &fl = i->second;
|
cannam@0
|
154 Plugin::FeatureList &target = a[output];
|
cannam@0
|
155 for (Plugin::FeatureList::const_iterator j = fl.begin(); j != fl.end(); ++j) {
|
cannam@0
|
156 target.push_back(*j);
|
cannam@0
|
157 }
|
cannam@0
|
158 }
|
cannam@0
|
159 }
|
cannam@0
|
160
|
cannam@0
|
161 bool
|
cannam@1
|
162 Test::allFeaturesValid(const Plugin::FeatureSet &b)
|
cannam@1
|
163 {
|
cannam@1
|
164 for (Plugin::FeatureSet::const_iterator i = b.begin(); i != b.end(); ++i) {
|
cannam@1
|
165 for (int j = 0; j < (int)i->second.size(); ++j) {
|
cannam@1
|
166 if (i->second[j].values.empty()) continue;
|
cannam@1
|
167 for (int k = 0; k < (int)i->second[j].values.size(); ++k) {
|
cannam@1
|
168 if (isnan(i->second[j].values[k]) ||
|
cannam@1
|
169 isinf(i->second[j].values[k])) {
|
cannam@1
|
170 return false;
|
cannam@1
|
171 }
|
cannam@1
|
172 }
|
cannam@1
|
173 }
|
cannam@1
|
174 }
|
cannam@1
|
175 return true;
|
cannam@1
|
176 }
|
cannam@1
|
177
|
Chris@53
|
178 bool
|
Chris@53
|
179 Test::containsTimestamps(const Plugin::FeatureSet &b)
|
Chris@53
|
180 {
|
Chris@53
|
181 for (Plugin::FeatureSet::const_iterator i = b.begin(); i != b.end(); ++i) {
|
Chris@53
|
182 for (int j = 0; j < (int)i->second.size(); ++j) {
|
Chris@53
|
183 if (i->second[j].values.empty()) continue;
|
Chris@53
|
184 for (int k = 0; k < (int)i->second[j].values.size(); ++k) {
|
Chris@53
|
185 if (i->second[j].hasTimestamp) {
|
Chris@53
|
186 return true;
|
Chris@53
|
187 }
|
Chris@53
|
188 }
|
Chris@53
|
189 }
|
Chris@53
|
190 }
|
Chris@53
|
191 return false;
|
Chris@53
|
192 }
|
Chris@53
|
193
|
cannam@3
|
194 void
|
Chris@61
|
195 Test::dumpFeature(const Plugin::Feature &f, bool showValues,
|
Chris@61
|
196 const Plugin::Feature *other)
|
Chris@52
|
197 {
|
Chris@52
|
198 cout << " Timestamp: " << (!f.hasTimestamp ? "(none)" : f.timestamp.toText()) << endl;
|
Chris@52
|
199 cout << " Duration: " << (!f.hasDuration ? "(none)" : f.duration.toText()) << endl;
|
Chris@52
|
200 cout << " Label: " << (f.label == "" ? "(none)" : f.label) << endl;
|
Chris@52
|
201 if (showValues) {
|
Chris@52
|
202 cout << " Values (" << f.values.size() << "): " << (f.values.empty() ? "(none)" : "");
|
Chris@61
|
203 int n = f.values.size();
|
Chris@61
|
204 if (!other) {
|
Chris@61
|
205 for (int j = 0; j < n; ++j) {
|
Chris@61
|
206 cout << f.values[j] << " ";
|
Chris@61
|
207 }
|
Chris@61
|
208 } else {
|
Chris@61
|
209 int samecount = 0;
|
Chris@61
|
210 int diffcount = 0;
|
Chris@61
|
211 for (int j = 0; j <= n; ++j) {
|
Chris@61
|
212 if (j < n && f.values[j] == other->values[j]) {
|
Chris@61
|
213 ++samecount;
|
Chris@61
|
214 } else {
|
Chris@61
|
215 if (samecount > 0) {
|
Chris@61
|
216 cout << "(" << samecount << " identical) ";
|
Chris@61
|
217 }
|
Chris@61
|
218 samecount = 0;
|
Chris@61
|
219 if (j < n) {
|
Chris@61
|
220 ++diffcount;
|
Chris@61
|
221 if (diffcount > 20 && j + 10 < n) {
|
Chris@61
|
222 cout << "(remaining " << n - j << " values elided)";
|
Chris@61
|
223 break;
|
Chris@61
|
224 } else {
|
Chris@61
|
225 cout << f.values[j] << " [diff "
|
Chris@61
|
226 << f.values[j] - other->values[j] << "] ";
|
Chris@61
|
227 }
|
Chris@61
|
228 }
|
Chris@61
|
229 }
|
Chris@61
|
230 }
|
Chris@52
|
231 }
|
Chris@52
|
232 cout << endl;
|
Chris@52
|
233 } else {
|
Chris@52
|
234 cout << " Values (" << f.values.size() << "): (elided)" << endl;
|
Chris@52
|
235 }
|
Chris@52
|
236 }
|
Chris@52
|
237
|
Chris@52
|
238 void
|
Chris@52
|
239 Test::dump(const Plugin::FeatureSet &fs, bool showValues)
|
cannam@3
|
240 {
|
cannam@3
|
241 for (Plugin::FeatureSet::const_iterator fsi = fs.begin();
|
cannam@3
|
242 fsi != fs.end(); ++fsi) {
|
cannam@3
|
243 int output = fsi->first;
|
Chris@52
|
244 cout << "Output " << output << ":" << endl;
|
cannam@3
|
245 const Plugin::FeatureList &fl = fsi->second;
|
cannam@3
|
246 for (int i = 0; i < (int)fl.size(); ++i) {
|
Chris@52
|
247 cout << " Feature " << i << ":" << endl;
|
cannam@3
|
248 const Plugin::Feature &f = fl[i];
|
Chris@52
|
249 dumpFeature(f, showValues);
|
cannam@3
|
250 }
|
cannam@3
|
251 }
|
cannam@3
|
252 }
|
cannam@3
|
253
|
cannam@3
|
254 void
|
Chris@52
|
255 Test::dumpTwo(const Result &r,
|
Chris@52
|
256 const Plugin::FeatureSet &a,
|
Chris@52
|
257 const Plugin::FeatureSet &b)
|
cannam@3
|
258 {
|
cannam@8
|
259 std::cout << r.message() << std::endl;
|
cannam@8
|
260 std::cout << "\nFirst result set:" << std::endl;
|
Chris@52
|
261 dump(a, false);
|
cannam@8
|
262 std::cout << "\nSecond result set:" << std::endl;
|
Chris@52
|
263 dump(b, false);
|
cannam@8
|
264 std::cout << std::endl;
|
cannam@3
|
265 }
|
cannam@3
|
266
|
Chris@52
|
267 void
|
Chris@52
|
268 Test::dumpDiff(const Result &r,
|
Chris@52
|
269 const Plugin::FeatureSet &a,
|
Chris@52
|
270 const Plugin::FeatureSet &b)
|
Chris@52
|
271 {
|
Chris@52
|
272 cout << r.message() << endl;
|
Chris@52
|
273 cout << "\nDifferences follow:" << endl;
|
Chris@52
|
274 if (a.size() != b.size()) {
|
Chris@52
|
275 cout << "*** First result set has features on " << a.size()
|
Chris@52
|
276 << " output(s), second has features on " << b.size()
|
Chris@52
|
277 << endl;
|
Chris@52
|
278 return;
|
Chris@52
|
279 }
|
Chris@52
|
280 Plugin::FeatureSet::const_iterator ai = a.begin();
|
Chris@52
|
281 Plugin::FeatureSet::const_iterator bi = b.begin();
|
Chris@52
|
282 while (ai != a.end()) {
|
Chris@52
|
283 if (ai->first != bi->first) {
|
Chris@52
|
284 cout << "\n*** Output number mismatch: first result set says "
|
Chris@52
|
285 << ai->first << " where second says " << bi->first
|
Chris@52
|
286 << endl;
|
Chris@52
|
287 } else {
|
Chris@52
|
288 cout << "\nOutput " << ai->first << ":" << endl;
|
Chris@52
|
289 if (ai->second.size() != bi->second.size()) {
|
Chris@52
|
290 cout << "*** First result set has " << ai->second.size()
|
Chris@52
|
291 << " feature(s) on this output, second has "
|
Chris@52
|
292 << bi->second.size() << endl;
|
Chris@52
|
293 } else {
|
Chris@52
|
294 int fno = 0;
|
Chris@52
|
295 int diffcount = 0;
|
Chris@52
|
296 Plugin::FeatureList::const_iterator afi = ai->second.begin();
|
Chris@52
|
297 Plugin::FeatureList::const_iterator bfi = bi->second.begin();
|
Chris@52
|
298 while (afi != ai->second.end()) {
|
Chris@52
|
299 if (!(*afi == *bfi)) {
|
Chris@52
|
300 if (diffcount == 0) {
|
Chris@61
|
301 bool differInValues =
|
Chris@61
|
302 (afi->values.size() == bfi->values.size() &&
|
Chris@61
|
303 afi->values != bfi->values);
|
Chris@52
|
304 if (afi->hasTimestamp != bfi->hasTimestamp) {
|
Chris@52
|
305 cout << "*** Feature " << fno << " differs in presence of timestamp (" << afi->hasTimestamp << " vs " << bfi->hasTimestamp << ")" << endl;
|
Chris@52
|
306 }
|
Chris@52
|
307 if (afi->hasTimestamp && (afi->timestamp != bfi->timestamp)) {
|
Chris@52
|
308 cout << "*** Feature " << fno << " differs in timestamp (" << afi->timestamp << " vs " << bfi->timestamp << " )" << endl;
|
Chris@52
|
309 }
|
Chris@52
|
310 if (afi->hasDuration != bfi->hasDuration) {
|
Chris@52
|
311 cout << "*** Feature " << fno << " differs in presence of duration (" << afi->hasDuration << " vs " << bfi->hasDuration << ")" << endl;
|
Chris@52
|
312 }
|
Chris@52
|
313 if (afi->hasDuration && (afi->duration != bfi->duration)) {
|
Chris@52
|
314 cout << "*** Feature " << fno << " differs in duration (" << afi->duration << " vs " << bfi->duration << " )" << endl;
|
Chris@52
|
315 }
|
Chris@52
|
316 if (afi->label != bfi->label) {
|
Chris@52
|
317 cout << "*** Feature " << fno << " differs in label" << endl;
|
Chris@52
|
318 }
|
Chris@61
|
319 if (afi->values.size() != bfi->values.size()) {
|
Chris@61
|
320 cout << "*** Feature " << fno << " differs in number of values (" << afi->values.size() << " vs " << bfi->values.size() << ")" << endl;
|
Chris@61
|
321 }
|
Chris@52
|
322 if (differInValues) {
|
Chris@52
|
323 cout << "*** Feature " << fno << " differs in values" << endl;
|
Chris@52
|
324 }
|
Chris@52
|
325 cout << " First output:" << endl;
|
Chris@52
|
326 dumpFeature(*afi, differInValues);
|
Chris@52
|
327 cout << " Second output:" << endl;
|
Chris@61
|
328 dumpFeature(*bfi, differInValues, &(*afi));
|
Chris@52
|
329 }
|
Chris@52
|
330 ++diffcount;
|
Chris@52
|
331 }
|
Chris@52
|
332 ++fno;
|
Chris@52
|
333 ++afi;
|
Chris@52
|
334 ++bfi;
|
Chris@52
|
335 }
|
Chris@52
|
336 if (diffcount > 1) {
|
Chris@52
|
337 cout << diffcount-1 << " subsequent differing feature(s) elided" << endl;
|
Chris@52
|
338 }
|
Chris@52
|
339 }
|
Chris@52
|
340 }
|
Chris@52
|
341 ++ai;
|
Chris@52
|
342 ++bi;
|
Chris@52
|
343 }
|
Chris@52
|
344 cout << endl;
|
Chris@52
|
345 }
|
Chris@52
|
346
|
cannam@1
|
347 bool
|
cannam@0
|
348 operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
|
cannam@0
|
349 {
|
cannam@0
|
350 if (a.size() != b.size()) return false;
|
cannam@0
|
351 for (Plugin::FeatureSet::const_iterator ai = a.begin();
|
cannam@0
|
352 ai != a.end(); ++ai) {
|
cannam@0
|
353 int output = ai->first;
|
cannam@0
|
354 Plugin::FeatureSet::const_iterator bi = b.find(output);
|
cannam@0
|
355 if (bi == b.end()) return false;
|
cannam@0
|
356 if (!(ai->second == bi->second)) return false;
|
cannam@0
|
357 }
|
cannam@0
|
358 return true;
|
cannam@0
|
359 }
|
cannam@0
|
360
|
cannam@0
|
361 bool
|
cannam@0
|
362 operator==(const Plugin::FeatureList &a, const Plugin::FeatureList &b)
|
cannam@0
|
363 {
|
cannam@0
|
364 if (a.size() != b.size()) return false;
|
cannam@0
|
365 for (int i = 0; i < (int)a.size(); ++i) {
|
cannam@0
|
366 if (!(a[i] == b[i])) return false;
|
cannam@0
|
367 }
|
cannam@0
|
368 return true;
|
cannam@0
|
369 }
|
cannam@0
|
370
|
cannam@0
|
371 bool
|
cannam@0
|
372 operator==(const Plugin::Feature &a, const Plugin::Feature &b)
|
cannam@0
|
373 {
|
cannam@0
|
374 if (a.hasTimestamp != b.hasTimestamp) return false;
|
cannam@0
|
375 if (a.hasTimestamp && (a.timestamp != b.timestamp)) return false;
|
cannam@0
|
376 if (a.hasDuration != b.hasDuration) return false;
|
cannam@0
|
377 if (a.hasDuration && (a.duration != b.duration)) return false;
|
cannam@0
|
378 if (a.values != b.values) return false;
|
cannam@0
|
379 if (a.label != b.label) return false;
|
cannam@0
|
380 return true;
|
cannam@0
|
381 }
|
cannam@0
|
382
|