annotate vamp-plugin-tester.cpp @ 26:eff1772ba397 vamp-plugin-tester-v1.0-erroneous

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