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 @ 37:a835f9cf3a3d
History | View | Annotate | Download (6.7 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 |
void usage(const char *name) |
| 54 |
{
|
| 55 |
cerr << "\n"
|
| 56 |
<< name << ": A Vamp plugin host that tests plugins for common errors.\n"
|
| 57 |
"Chris Cannam, Centre for Digital Music, Queen Mary, University of London.\n"
|
| 58 |
"Copyright 2009-2012 QMUL.\n"
|
| 59 |
"Freely redistributable; published under a BSD-style license.\n\n"
|
| 60 |
"Usage:\n"
|
| 61 |
" " << name << " [-nv] <pluginbasename>:<plugin>\n" |
| 62 |
" " << name << " [-nv] -a\n\n" |
| 63 |
"Example:\n"
|
| 64 |
" " << name << " vamp-example-plugins:amplitudefollower\n\n" |
| 65 |
"Options:\n"
|
| 66 |
" -a, --all Test all plugins found in Vamp path\n\n"
|
| 67 |
" -n, --nondeterministic Plugins may be nondeterministic: print a note\n"
|
| 68 |
" instead of an error if results differ between runs\n\n"
|
| 69 |
" -v, --verbose Show returned features each time a note, warning,\n"
|
| 70 |
" or error arises from feature data\n"
|
| 71 |
"\nIf you have access to a runtime memory checker, you may find it especially\n"
|
| 72 |
"helpful to run this tester under it and watch for errors thus provoked.\n"
|
| 73 |
<< endl; |
| 74 |
exit(2);
|
| 75 |
} |
| 76 |
|
| 77 |
int main(int argc, char **argv) |
| 78 |
{
|
| 79 |
char *scooter = argv[0]; |
| 80 |
char *name = 0; |
| 81 |
while (scooter && *scooter) {
|
| 82 |
if (*scooter == '/' || *scooter == '\\') name = ++scooter; |
| 83 |
else ++scooter;
|
| 84 |
} |
| 85 |
if (!name || !*name) name = argv[0]; |
| 86 |
|
| 87 |
bool nondeterministic = false; |
| 88 |
bool verbose = false; |
| 89 |
bool all = false; |
| 90 |
string argument;
|
| 91 |
for (int i = 1; i < argc; ++i) { |
| 92 |
if (!argv[i]) break; |
| 93 |
if (argv[i][0] == '-') { |
| 94 |
if (!strcmp(argv[i], "-v") || |
| 95 |
!strcmp(argv[i], "--verbose")) {
|
| 96 |
verbose = true;
|
| 97 |
continue;
|
| 98 |
} |
| 99 |
if (!strcmp(argv[i], "-n") || |
| 100 |
!strcmp(argv[i], "--nondeterministic")) {
|
| 101 |
nondeterministic = true;
|
| 102 |
continue;
|
| 103 |
} |
| 104 |
if (!strcmp(argv[i], "-a") || |
| 105 |
!strcmp(argv[i], "--all")) {
|
| 106 |
all = true;
|
| 107 |
continue;
|
| 108 |
} |
| 109 |
usage(name); |
| 110 |
} else {
|
| 111 |
if (argument != "") usage(name); |
| 112 |
else argument = argv[i];
|
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
if (argument == "" && !all) usage(name); |
| 117 |
if (argument != "" && all) usage(name); |
| 118 |
|
| 119 |
cerr << name << ": Running..." << endl;
|
| 120 |
|
| 121 |
Test::Options opts = Test::NoOption; |
| 122 |
if (nondeterministic) opts |= Test::NonDeterministic;
|
| 123 |
if (verbose) opts |= Test::Verbose;
|
| 124 |
|
| 125 |
if (all) {
|
| 126 |
bool good = true; |
| 127 |
Vamp::HostExt::PluginLoader::PluginKeyList keys = |
| 128 |
Vamp::HostExt::PluginLoader::getInstance()->listPlugins(); |
| 129 |
if (keys.size() == 0) { |
| 130 |
cout << name << ": NOTE: No plugins found!" << endl;
|
| 131 |
cout << name << ": (No libraries in search path, or no descriptors in library)" << endl;
|
| 132 |
return 2; |
| 133 |
} |
| 134 |
int notes = 0, warnings = 0, errors = 0; |
| 135 |
for (int i = 0; i < (int)keys.size(); ++i) { |
| 136 |
cout << "Testing plugin: " << keys[i] << endl;
|
| 137 |
Tester tester(keys[i], opts); |
| 138 |
if (tester.test(notes, warnings, errors)) {
|
| 139 |
cout << name << ": All tests succeeded for this plugin" << endl;
|
| 140 |
} else {
|
| 141 |
cout << name << ": Some tests failed for this plugin" << endl;
|
| 142 |
good = false;
|
| 143 |
} |
| 144 |
cout << endl; |
| 145 |
} |
| 146 |
if (good) {
|
| 147 |
cout << name << ": All tests succeeded";
|
| 148 |
if (warnings > 0) { |
| 149 |
cout << ", with " << warnings << " warning(s)"; |
| 150 |
if (notes > 0) { |
| 151 |
cout << " and " << notes << " other note(s)"; |
| 152 |
} |
| 153 |
} else if (notes > 0) { |
| 154 |
cout << ", with " << notes << " note(s)"; |
| 155 |
} |
| 156 |
cout << endl; |
| 157 |
return 0; |
| 158 |
} else {
|
| 159 |
cout << name << ": Some tests failed" << endl;
|
| 160 |
return 1; |
| 161 |
} |
| 162 |
} else {
|
| 163 |
string key = argument;
|
| 164 |
Tester tester(key, opts); |
| 165 |
int notes = 0, warnings = 0, errors = 0; |
| 166 |
if (tester.test(notes, warnings, errors)) {
|
| 167 |
cout << name << ": All tests succeeded";
|
| 168 |
if (warnings > 0) { |
| 169 |
cout << ", with " << warnings << " warning(s)"; |
| 170 |
if (notes > 0) { |
| 171 |
cout << " and " << notes << " other note(s)"; |
| 172 |
} |
| 173 |
} else if (notes > 0) { |
| 174 |
cout << ", with " << notes << " note(s)"; |
| 175 |
} |
| 176 |
cout << endl; |
| 177 |
return 0; |
| 178 |
} else {
|
| 179 |
cout << name << ": Some tests failed" << endl;
|
| 180 |
return 1; |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
|