comparison vamp-plugin-tester.cpp @ 40:649f32c7eb41

Add single-test arg, as well as list-tests and version
author Chris Cannam
date Mon, 28 Jul 2014 11:41:37 +0100
parents 07144cdcbedf
children f1e8e14e9c96
comparison
equal deleted inserted replaced
39:07144cdcbedf 40:649f32c7eb41
48 48
49 #include "Tester.h" 49 #include "Tester.h"
50 50
51 using namespace std; 51 using namespace std;
52 52
53 static const std::string VERSION="1.1";
54
53 void usage(const char *name) 55 void usage(const char *name)
54 { 56 {
55 cerr << "\n" 57 cerr << "\n"
56 << name << ": A Vamp plugin host that tests plugins for common errors.\n" 58 << 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" 59 "Chris Cannam, Centre for Digital Music, Queen Mary, University of London.\n"
58 "Copyright 2009-2012 QMUL.\n" 60 "Copyright 2009-2012 QMUL.\n"
59 "Freely redistributable; published under a BSD-style license.\n\n" 61 "Freely redistributable; published under a BSD-style license.\n\n"
60 "Usage:\n" 62 "Usage:\n"
61 " " << name << " [-nv] <pluginbasename>:<plugin>\n" 63 " " << name << " [-nv] [-t <test>] <pluginbasename>:<plugin>\n"
62 " " << name << " [-nv] -a\n\n" 64 " " << name << " [-nv] [-t <test>] -a\n"
65 " " << name << " -l\n\n"
63 "Example:\n" 66 "Example:\n"
64 " " << name << " vamp-example-plugins:amplitudefollower\n\n" 67 " " << name << " vamp-example-plugins:amplitudefollower\n\n"
65 "Options:\n" 68 "Options:\n"
66 " -a, --all Test all plugins found in Vamp path\n\n" 69 " -a, --all Test all plugins found in Vamp path\n\n"
67 " -n, --nondeterministic Plugins may be nondeterministic: print a note\n" 70 " -n, --nondeterministic Plugins may be nondeterministic: print a note\n"
68 " instead of an error if results differ between runs\n\n" 71 " instead of an error if results differ between runs\n\n"
69 " -v, --verbose Show returned features each time a note, warning,\n" 72 " -v, --verbose Show returned features each time a note, warning,\n"
70 " or error arises from feature data\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"
71 "\nIf you have access to a runtime memory checker, you may find it especially\n" 78 "\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" 79 "helpful to run this tester under it and watch for errors thus provoked.\n"
73 << endl; 80 << endl;
74 exit(2); 81 exit(2);
75 } 82 }
85 if (!name || !*name) name = argv[0]; 92 if (!name || !*name) name = argv[0];
86 93
87 bool nondeterministic = false; 94 bool nondeterministic = false;
88 bool verbose = false; 95 bool verbose = false;
89 bool all = false; 96 bool all = false;
90 string argument; 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
91 for (int i = 1; i < argc; ++i) { 102 for (int i = 1; i < argc; ++i) {
92 if (!argv[i]) break; 103 if (!argv[i]) break;
93 if (argv[i][0] == '-') { 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 }
94 if (!strcmp(argv[i], "-v") || 111 if (!strcmp(argv[i], "-v") ||
95 !strcmp(argv[i], "--verbose")) { 112 !strcmp(argv[i], "--verbose")) {
96 verbose = true; 113 verbose = true;
97 continue; 114 continue;
98 } 115 }
104 if (!strcmp(argv[i], "-a") || 121 if (!strcmp(argv[i], "-a") ||
105 !strcmp(argv[i], "--all")) { 122 !strcmp(argv[i], "--all")) {
106 all = true; 123 all = true;
107 continue; 124 continue;
108 } 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 }
109 usage(name); 145 usage(name);
110 } else { 146 } else {
111 if (argument != "") usage(name); 147 if (plugin != "") usage(name);
112 else argument = argv[i]; 148 else plugin = argv[i];
113 } 149 }
150 }
151
152 if (list) {
153 if (all || nondeterministic || (single != "") || (plugin != "")) {
154 usage(name);
155 }
156 Tester::listTests();
157 return 0;
114 } 158 }
115 159
116 if (argument == "" && !all) usage(name); 160 if (plugin == "" && !all) usage(name);
117 if (argument != "" && all) usage(name); 161 if (plugin != "" && all) usage(name);
118 162
119 cerr << name << ": Running..." << endl; 163 cerr << name << ": Running..." << endl;
120
121 std::string single = "";
122 164
123 Test::Options opts = Test::NoOption; 165 Test::Options opts = Test::NoOption;
124 if (nondeterministic) opts |= Test::NonDeterministic; 166 if (nondeterministic) opts |= Test::NonDeterministic;
125 if (verbose) opts |= Test::Verbose; 167 if (verbose) opts |= Test::Verbose;
126 if (single != "") opts |= Test::SingleTest; 168 if (single != "") opts |= Test::SingleTest;
161 } else { 203 } else {
162 cout << name << ": Some tests failed" << endl; 204 cout << name << ": Some tests failed" << endl;
163 return 1; 205 return 1;
164 } 206 }
165 } else { 207 } else {
166 string key = argument; 208 Tester tester(plugin, opts, single);
167 Tester tester(key, opts, single);
168 int notes = 0, warnings = 0, errors = 0; 209 int notes = 0, warnings = 0, errors = 0;
169 if (tester.test(notes, warnings, errors)) { 210 if (tester.test(notes, warnings, errors)) {
170 cout << name << ": All tests succeeded"; 211 cout << name << ": All tests succeeded";
171 if (warnings > 0) { 212 if (warnings > 0) {
172 cout << ", with " << warnings << " warning(s)"; 213 cout << ", with " << warnings << " warning(s)";