annotate vamp-plugin-tester.cpp @ 39:07144cdcbedf

Introduce logic for running only a single test (not yet wired up to command line interface)
author Chris Cannam
date Mon, 28 Jul 2014 11:11:59 +0100
parents a835f9cf3a3d
children 649f32c7eb41
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.
Chris@32 7 Copyright 2009-2012 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"
Chris@32 58 "Copyright 2009-2012 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
Chris@39 121 std::string single = "";
Chris@39 122
cannam@8 123 Test::Options opts = Test::NoOption;
cannam@8 124 if (nondeterministic) opts |= Test::NonDeterministic;
cannam@8 125 if (verbose) opts |= Test::Verbose;
Chris@39 126 if (single != "") opts |= Test::SingleTest;
cannam@8 127
cannam@25 128 if (all) {
cannam@0 129 bool good = true;
cannam@0 130 Vamp::HostExt::PluginLoader::PluginKeyList keys =
cannam@0 131 Vamp::HostExt::PluginLoader::getInstance()->listPlugins();
Chris@33 132 if (keys.size() == 0) {
Chris@33 133 cout << name << ": NOTE: No plugins found!" << endl;
Chris@33 134 cout << name << ": (No libraries in search path, or no descriptors in library)" << endl;
Chris@37 135 return 2;
Chris@33 136 }
cannam@4 137 int notes = 0, warnings = 0, errors = 0;
cannam@0 138 for (int i = 0; i < (int)keys.size(); ++i) {
cannam@3 139 cout << "Testing plugin: " << keys[i] << endl;
Chris@39 140 Tester tester(keys[i], opts, single);
cannam@4 141 if (tester.test(notes, warnings, errors)) {
cannam@3 142 cout << name << ": All tests succeeded for this plugin" << endl;
cannam@0 143 } else {
cannam@3 144 cout << name << ": Some tests failed for this plugin" << endl;
cannam@0 145 good = false;
cannam@0 146 }
cannam@3 147 cout << endl;
cannam@0 148 }
cannam@0 149 if (good) {
cannam@4 150 cout << name << ": All tests succeeded";
cannam@4 151 if (warnings > 0) {
cannam@4 152 cout << ", with " << warnings << " warning(s)";
cannam@4 153 if (notes > 0) {
cannam@4 154 cout << " and " << notes << " other note(s)";
cannam@4 155 }
cannam@4 156 } else if (notes > 0) {
cannam@4 157 cout << ", with " << notes << " note(s)";
cannam@4 158 }
cannam@4 159 cout << endl;
cannam@0 160 return 0;
cannam@0 161 } else {
cannam@3 162 cout << name << ": Some tests failed" << endl;
cannam@0 163 return 1;
cannam@0 164 }
cannam@0 165 } else {
cannam@8 166 string key = argument;
Chris@39 167 Tester tester(key, opts, single);
cannam@4 168 int notes = 0, warnings = 0, errors = 0;
cannam@4 169 if (tester.test(notes, warnings, errors)) {
cannam@4 170 cout << name << ": All tests succeeded";
cannam@4 171 if (warnings > 0) {
cannam@4 172 cout << ", with " << warnings << " warning(s)";
cannam@4 173 if (notes > 0) {
cannam@4 174 cout << " and " << notes << " other note(s)";
cannam@4 175 }
cannam@4 176 } else if (notes > 0) {
cannam@4 177 cout << ", with " << notes << " note(s)";
cannam@4 178 }
cannam@4 179 cout << endl;
cannam@0 180 return 0;
cannam@0 181 } else {
cannam@3 182 cout << name << ": Some tests failed" << endl;
cannam@0 183 return 1;
cannam@0 184 }
cannam@0 185 }
cannam@0 186 }
cannam@0 187