To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / vamp-plugin-tester.cpp @ 40:649f32c7eb41
History | View | Annotate | Download (8.21 KB)
| 1 |
/* -*- 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 |
Copyright 2009-2012 QMUL.
|
| 8 |
|
| 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 |
#include <cstring> |
| 48 |
|
| 49 |
#include "Tester.h" |
| 50 |
|
| 51 |
using namespace std; |
| 52 |
|
| 53 |
static const std::string VERSION="1.1"; |
| 54 |
|
| 55 |
void usage(const char *name) |
| 56 |
{
|
| 57 |
cerr << "\n"
|
| 58 |
<< name << ": A Vamp plugin host that tests plugins for common errors.\n"
|
| 59 |
"Chris Cannam, Centre for Digital Music, Queen Mary, University of London.\n"
|
| 60 |
"Copyright 2009-2012 QMUL.\n"
|
| 61 |
"Freely redistributable; published under a BSD-style license.\n\n"
|
| 62 |
"Usage:\n"
|
| 63 |
" " << name << " [-nv] [-t <test>] <pluginbasename>:<plugin>\n" |
| 64 |
" " << name << " [-nv] [-t <test>] -a\n" |
| 65 |
" " << name << " -l\n\n" |
| 66 |
"Example:\n"
|
| 67 |
" " << name << " vamp-example-plugins:amplitudefollower\n\n" |
| 68 |
"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 |
" 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 |
"\nIf you have access to a runtime memory checker, you may find it especially\n"
|
| 79 |
"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 |
|
| 94 |
bool nondeterministic = false; |
| 95 |
bool verbose = false; |
| 96 |
bool all = false; |
| 97 |
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 |
for (int i = 1; i < argc; ++i) { |
| 103 |
if (!argv[i]) break; |
| 104 |
if (argv[i][0] == '-') { |
| 105 |
if (!strcmp(argv[i], "-vn") || |
| 106 |
!strcmp(argv[i], "-nv")) {
|
| 107 |
verbose = true;
|
| 108 |
nondeterministic = true;
|
| 109 |
continue;
|
| 110 |
} |
| 111 |
if (!strcmp(argv[i], "-v") || |
| 112 |
!strcmp(argv[i], "--verbose")) {
|
| 113 |
verbose = true;
|
| 114 |
continue;
|
| 115 |
} |
| 116 |
if (!strcmp(argv[i], "-n") || |
| 117 |
!strcmp(argv[i], "--nondeterministic")) {
|
| 118 |
nondeterministic = true;
|
| 119 |
continue;
|
| 120 |
} |
| 121 |
if (!strcmp(argv[i], "-a") || |
| 122 |
!strcmp(argv[i], "--all")) {
|
| 123 |
all = true;
|
| 124 |
continue;
|
| 125 |
} |
| 126 |
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 |
usage(name); |
| 146 |
} else {
|
| 147 |
if (plugin != "") usage(name); |
| 148 |
else plugin = argv[i];
|
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
if (list) {
|
| 153 |
if (all || nondeterministic || (single != "") || (plugin != "")) { |
| 154 |
usage(name); |
| 155 |
} |
| 156 |
Tester::listTests(); |
| 157 |
return 0; |
| 158 |
} |
| 159 |
|
| 160 |
if (plugin == "" && !all) usage(name); |
| 161 |
if (plugin != "" && all) usage(name); |
| 162 |
|
| 163 |
cerr << name << ": Running..." << endl;
|
| 164 |
|
| 165 |
Test::Options opts = Test::NoOption; |
| 166 |
if (nondeterministic) opts |= Test::NonDeterministic;
|
| 167 |
if (verbose) opts |= Test::Verbose;
|
| 168 |
if (single != "") opts |= Test::SingleTest; |
| 169 |
|
| 170 |
if (all) {
|
| 171 |
bool good = true; |
| 172 |
Vamp::HostExt::PluginLoader::PluginKeyList keys = |
| 173 |
Vamp::HostExt::PluginLoader::getInstance()->listPlugins(); |
| 174 |
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 |
return 2; |
| 178 |
} |
| 179 |
int notes = 0, warnings = 0, errors = 0; |
| 180 |
for (int i = 0; i < (int)keys.size(); ++i) { |
| 181 |
cout << "Testing plugin: " << keys[i] << endl;
|
| 182 |
Tester tester(keys[i], opts, single); |
| 183 |
if (tester.test(notes, warnings, errors)) {
|
| 184 |
cout << name << ": All tests succeeded for this plugin" << endl;
|
| 185 |
} else {
|
| 186 |
cout << name << ": Some tests failed for this plugin" << endl;
|
| 187 |
good = false;
|
| 188 |
} |
| 189 |
cout << endl; |
| 190 |
} |
| 191 |
if (good) {
|
| 192 |
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 |
return 0; |
| 203 |
} else {
|
| 204 |
cout << name << ": Some tests failed" << endl;
|
| 205 |
return 1; |
| 206 |
} |
| 207 |
} else {
|
| 208 |
Tester tester(plugin, opts, single); |
| 209 |
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 |
return 0; |
| 222 |
} else {
|
| 223 |
cout << name << ": Some tests failed" << endl;
|
| 224 |
return 1; |
| 225 |
} |
| 226 |
} |
| 227 |
} |
| 228 |
|