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