annotate TestDefaults.cpp @ 34:a2d9aed55a2a

Check that a reset call does not change parameter values
author Chris Cannam
date Mon, 16 Dec 2013 13:28:28 +0000
parents b1bc4d045a4b
children 7d4c98c696a5
rev   line source
cannam@5 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@5 2
cannam@5 3 /*
cannam@5 4 Vamp Plugin Tester
cannam@5 5 Chris Cannam, cannam@all-day-breakfast.com
cannam@5 6 Centre for Digital Music, Queen Mary, University of London.
cannam@5 7 Copyright 2009 QMUL.
cannam@5 8
cannam@5 9 This program loads a Vamp plugin and tests its susceptibility to a
cannam@5 10 number of common pitfalls, including handling of extremes of input
cannam@5 11 data. If you can think of any additional useful tests that are
cannam@5 12 easily added, please send them to me.
cannam@5 13
cannam@5 14 Permission is hereby granted, free of charge, to any person
cannam@5 15 obtaining a copy of this software and associated documentation
cannam@5 16 files (the "Software"), to deal in the Software without
cannam@5 17 restriction, including without limitation the rights to use, copy,
cannam@5 18 modify, merge, publish, distribute, sublicense, and/or sell copies
cannam@5 19 of the Software, and to permit persons to whom the Software is
cannam@5 20 furnished to do so, subject to the following conditions:
cannam@5 21
cannam@5 22 The above copyright notice and this permission notice shall be
cannam@5 23 included in all copies or substantial portions of the Software.
cannam@5 24
cannam@5 25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@5 26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@5 27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cannam@5 28 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
cannam@5 29 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@5 30 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@5 31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@5 32
cannam@5 33 Except as contained in this notice, the names of the Centre for
cannam@5 34 Digital Music; Queen Mary, University of London; and Chris Cannam
cannam@5 35 shall not be used in advertising or otherwise to promote the sale,
cannam@5 36 use or other dealings in this Software without prior written
cannam@5 37 authorization.
cannam@5 38 */
cannam@5 39
cannam@5 40 #include "TestDefaults.h"
cannam@5 41
cannam@5 42 #include <vamp-hostsdk/Plugin.h>
cannam@5 43 using namespace Vamp;
cannam@5 44
cannam@5 45 #include <memory>
cannam@5 46 using namespace std;
cannam@5 47
cannam@5 48 #include <cmath>
cannam@6 49 #include <time.h>
cannam@5 50
cannam@28 51 #ifndef __GNUC__
cannam@28 52 #include <alloca.h>
cannam@28 53 #endif
cannam@28 54
cannam@5 55 Tester::TestRegistrar<TestDefaultProgram>
cannam@5 56 TestDefaultProgram::m_registrar("E1 Inconsistent default program");
cannam@5 57
cannam@5 58 Tester::TestRegistrar<TestDefaultParameters>
cannam@5 59 TestDefaultParameters::m_registrar("E2 Inconsistent default parameters");
cannam@5 60
Chris@34 61 Tester::TestRegistrar<TestParametersOnReset>
Chris@34 62 TestParametersOnReset::m_registrar("E3 Parameter retention through reset");
Chris@34 63
cannam@5 64 static const size_t _step = 1000;
cannam@5 65
cannam@5 66 Test::Results
cannam@8 67 TestDefaultProgram::test(string key, Options options)
cannam@5 68 {
cannam@5 69 Plugin::FeatureSet f[2];
cannam@5 70 int rate = 44100;
cannam@5 71 Results r;
cannam@5 72 float **data = 0;
cannam@5 73 size_t channels = 0;
cannam@5 74 size_t count = 100;
cannam@5 75
cannam@5 76 for (int run = 0; run < 2; ++run) {
cannam@5 77 auto_ptr<Plugin> p(load(key, rate));
cannam@5 78 if (p->getPrograms().empty()) return r;
cannam@5 79 if (run == 1) {
cannam@5 80 p->selectProgram(p->getCurrentProgram());
cannam@5 81 }
cannam@5 82 if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
cannam@5 83 if (!data) data = createTestAudio(channels, _step, count);
cannam@5 84 for (size_t i = 0; i < count; ++i) {
cannam@28 85 #ifdef __GNUC__
cannam@5 86 float *ptr[channels];
cannam@28 87 #else
cannam@28 88 float **ptr = (float **)alloca(channels * sizeof(float));
cannam@28 89 #endif
cannam@5 90 size_t idx = i * _step;
cannam@5 91 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
cannam@5 92 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
cannam@5 93 Plugin::FeatureSet fs = p->process(ptr, timestamp);
cannam@5 94 appendFeatures(f[run], fs);
cannam@5 95 }
cannam@5 96 Plugin::FeatureSet fs = p->getRemainingFeatures();
cannam@5 97 appendFeatures(f[run], fs);
cannam@5 98 }
cannam@5 99 if (data) destroyTestAudio(data, channels);
cannam@5 100
cannam@5 101 if (!(f[0] == f[1])) {
cannam@8 102 string message = "Explicitly setting current program to its supposed current value changes the results";
cannam@8 103 Result res;
cannam@8 104 if (options & NonDeterministic) res = note(message);
cannam@8 105 else res = error(message);
cannam@8 106 if (options & Verbose) dump(res, f[0], f[1]);
cannam@7 107 r.push_back(res);
cannam@5 108 } else {
cannam@5 109 r.push_back(success());
cannam@5 110 }
cannam@5 111
cannam@5 112 return r;
cannam@5 113 }
cannam@5 114
cannam@5 115 Test::Results
cannam@8 116 TestDefaultParameters::test(string key, Options options)
cannam@5 117 {
cannam@5 118 Plugin::FeatureSet f[2];
cannam@5 119 int rate = 44100;
cannam@5 120 Results r;
cannam@5 121 float **data = 0;
cannam@5 122 size_t channels = 0;
cannam@5 123 size_t count = 100;
cannam@5 124
cannam@5 125 for (int run = 0; run < 2; ++run) {
cannam@5 126 auto_ptr<Plugin> p(load(key, rate));
cannam@5 127 if (p->getParameterDescriptors().empty()) return r;
cannam@5 128 if (run == 1) {
cannam@5 129 Plugin::ParameterList pl = p->getParameterDescriptors();
cannam@5 130 for (int i = 0; i < (int)pl.size(); ++i) {
cannam@5 131 if (p->getParameter(pl[i].identifier) != pl[i].defaultValue) {
cannam@23 132 if (options & Verbose) {
cannam@23 133 cout << "Parameter: " << pl[i].identifier << endl;
cannam@23 134 cout << "Expected: " << pl[i].defaultValue << endl;
cannam@23 135 cout << "Actual: " << p->getParameter(pl[i].identifier) << endl;
cannam@23 136 }
cannam@5 137 r.push_back(error("Not all parameters have their default values when queried directly after construction"));
cannam@5 138 }
cannam@5 139 p->setParameter(pl[i].identifier, pl[i].defaultValue);
cannam@5 140 }
cannam@5 141 }
cannam@5 142 if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
cannam@5 143 if (!data) data = createTestAudio(channels, _step, count);
cannam@5 144 for (size_t i = 0; i < count; ++i) {
cannam@28 145 #ifdef __GNUC__
cannam@5 146 float *ptr[channels];
cannam@28 147 #else
cannam@28 148 float **ptr = (float **)alloca(channels * sizeof(float));
cannam@28 149 #endif
cannam@5 150 size_t idx = i * _step;
cannam@5 151 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
cannam@5 152 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
cannam@5 153 Plugin::FeatureSet fs = p->process(ptr, timestamp);
cannam@5 154 appendFeatures(f[run], fs);
cannam@5 155 }
cannam@5 156 Plugin::FeatureSet fs = p->getRemainingFeatures();
cannam@5 157 appendFeatures(f[run], fs);
cannam@5 158 }
cannam@5 159 if (data) destroyTestAudio(data, channels);
cannam@5 160
cannam@5 161 if (!(f[0] == f[1])) {
cannam@8 162 string message = "Explicitly setting parameters to their supposed default values changes the results";
cannam@8 163 Result res;
cannam@8 164 if (options & NonDeterministic) res = note(message);
cannam@8 165 else res = error(message);
cannam@8 166 if (options & Verbose) dump(res, f[0], f[1]);
cannam@7 167 r.push_back(res);
cannam@5 168 } else {
cannam@5 169 r.push_back(success());
cannam@5 170 }
cannam@5 171
cannam@5 172 return r;
cannam@5 173 }
Chris@34 174
Chris@34 175 Test::Results
Chris@34 176 TestParametersOnReset::test(string key, Options options)
Chris@34 177 {
Chris@34 178 Plugin::FeatureSet f[2];
Chris@34 179 int rate = 44100;
Chris@34 180 Results r;
Chris@34 181 float **data = 0;
Chris@34 182 size_t channels = 0;
Chris@34 183 size_t count = 100;
Chris@34 184
Chris@34 185 for (int run = 0; run < 2; ++run) {
Chris@34 186 auto_ptr<Plugin> p(load(key, rate));
Chris@34 187 if (p->getParameterDescriptors().empty()) return r;
Chris@34 188
Chris@34 189 // Set all parameters to non-default values
Chris@34 190 Plugin::ParameterList pl = p->getParameterDescriptors();
Chris@34 191 for (int i = 0; i < (int)pl.size(); ++i) {
Chris@34 192 if (pl[i].defaultValue == pl[i].minValue) {
Chris@34 193 p->setParameter(pl[i].identifier, pl[i].maxValue);
Chris@34 194 } else {
Chris@34 195 p->setParameter(pl[i].identifier, pl[i].minValue);
Chris@34 196 }
Chris@34 197 }
Chris@34 198
Chris@34 199 if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
Chris@34 200
Chris@34 201 // First run: construct, set params, init, process
Chris@34 202 // Second run: construct, set params, init, reset, process
Chris@34 203 // We expect these to produce the same results
Chris@34 204 if (run == 1) p->reset();
Chris@34 205
Chris@34 206 if (!data) data = createTestAudio(channels, _step, count);
Chris@34 207 for (size_t i = 0; i < count; ++i) {
Chris@34 208 #ifdef __GNUC__
Chris@34 209 float *ptr[channels];
Chris@34 210 #else
Chris@34 211 float **ptr = (float **)alloca(channels * sizeof(float));
Chris@34 212 #endif
Chris@34 213 size_t idx = i * _step;
Chris@34 214 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
Chris@34 215 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
Chris@34 216 Plugin::FeatureSet fs = p->process(ptr, timestamp);
Chris@34 217 appendFeatures(f[run], fs);
Chris@34 218 }
Chris@34 219 Plugin::FeatureSet fs = p->getRemainingFeatures();
Chris@34 220 appendFeatures(f[run], fs);
Chris@34 221 }
Chris@34 222 if (data) destroyTestAudio(data, channels);
Chris@34 223
Chris@34 224 if (!(f[0] == f[1])) {
Chris@34 225 string message = "Call to reset after setting parameters, but before processing, changes the results (parameter values not retained through reset?)";
Chris@34 226 Result res;
Chris@34 227 if (options & NonDeterministic) res = note(message);
Chris@34 228 else res = error(message);
Chris@34 229 if (options & Verbose) dump(res, f[0], f[1]);
Chris@34 230 r.push_back(res);
Chris@34 231 } else {
Chris@34 232 r.push_back(success());
Chris@34 233 }
Chris@34 234
Chris@34 235 return r;
Chris@34 236 }