annotate TestDefaults.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 28097c1b3de4
children b1bc4d045a4b
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@5 51 Tester::TestRegistrar<TestDefaultProgram>
cannam@5 52 TestDefaultProgram::m_registrar("E1 Inconsistent default program");
cannam@5 53
cannam@5 54 Tester::TestRegistrar<TestDefaultParameters>
cannam@5 55 TestDefaultParameters::m_registrar("E2 Inconsistent default parameters");
cannam@5 56
cannam@5 57 static const size_t _step = 1000;
cannam@5 58
cannam@5 59 Test::Results
cannam@8 60 TestDefaultProgram::test(string key, Options options)
cannam@5 61 {
cannam@5 62 Plugin::FeatureSet f[2];
cannam@5 63 int rate = 44100;
cannam@5 64 Results r;
cannam@5 65 float **data = 0;
cannam@5 66 size_t channels = 0;
cannam@5 67 size_t count = 100;
cannam@5 68
cannam@5 69 for (int run = 0; run < 2; ++run) {
cannam@5 70 auto_ptr<Plugin> p(load(key, rate));
cannam@5 71 if (p->getPrograms().empty()) return r;
cannam@5 72 if (run == 1) {
cannam@5 73 p->selectProgram(p->getCurrentProgram());
cannam@5 74 }
cannam@5 75 if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
cannam@5 76 if (!data) data = createTestAudio(channels, _step, count);
cannam@5 77 for (size_t i = 0; i < count; ++i) {
cannam@5 78 float *ptr[channels];
cannam@5 79 size_t idx = i * _step;
cannam@5 80 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
cannam@5 81 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
cannam@5 82 Plugin::FeatureSet fs = p->process(ptr, timestamp);
cannam@5 83 appendFeatures(f[run], fs);
cannam@5 84 }
cannam@5 85 Plugin::FeatureSet fs = p->getRemainingFeatures();
cannam@5 86 appendFeatures(f[run], fs);
cannam@5 87 }
cannam@5 88 if (data) destroyTestAudio(data, channels);
cannam@5 89
cannam@5 90 if (!(f[0] == f[1])) {
cannam@8 91 string message = "Explicitly setting current program to its supposed current value changes the results";
cannam@8 92 Result res;
cannam@8 93 if (options & NonDeterministic) res = note(message);
cannam@8 94 else res = error(message);
cannam@8 95 if (options & Verbose) dump(res, f[0], f[1]);
cannam@7 96 r.push_back(res);
cannam@5 97 } else {
cannam@5 98 r.push_back(success());
cannam@5 99 }
cannam@5 100
cannam@5 101 return r;
cannam@5 102 }
cannam@5 103
cannam@5 104 Test::Results
cannam@8 105 TestDefaultParameters::test(string key, Options options)
cannam@5 106 {
cannam@5 107 Plugin::FeatureSet f[2];
cannam@5 108 int rate = 44100;
cannam@5 109 Results r;
cannam@5 110 float **data = 0;
cannam@5 111 size_t channels = 0;
cannam@5 112 size_t count = 100;
cannam@5 113
cannam@5 114 for (int run = 0; run < 2; ++run) {
cannam@5 115 auto_ptr<Plugin> p(load(key, rate));
cannam@5 116 if (p->getParameterDescriptors().empty()) return r;
cannam@5 117 if (run == 1) {
cannam@5 118 Plugin::ParameterList pl = p->getParameterDescriptors();
cannam@5 119 for (int i = 0; i < (int)pl.size(); ++i) {
cannam@5 120 if (p->getParameter(pl[i].identifier) != pl[i].defaultValue) {
cannam@23 121 if (options & Verbose) {
cannam@23 122 cout << "Parameter: " << pl[i].identifier << endl;
cannam@23 123 cout << "Expected: " << pl[i].defaultValue << endl;
cannam@23 124 cout << "Actual: " << p->getParameter(pl[i].identifier) << endl;
cannam@23 125 }
cannam@5 126 r.push_back(error("Not all parameters have their default values when queried directly after construction"));
cannam@5 127 }
cannam@5 128 p->setParameter(pl[i].identifier, pl[i].defaultValue);
cannam@5 129 }
cannam@5 130 }
cannam@5 131 if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
cannam@5 132 if (!data) data = createTestAudio(channels, _step, count);
cannam@5 133 for (size_t i = 0; i < count; ++i) {
cannam@5 134 float *ptr[channels];
cannam@5 135 size_t idx = i * _step;
cannam@5 136 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
cannam@5 137 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
cannam@5 138 Plugin::FeatureSet fs = p->process(ptr, timestamp);
cannam@5 139 appendFeatures(f[run], fs);
cannam@5 140 }
cannam@5 141 Plugin::FeatureSet fs = p->getRemainingFeatures();
cannam@5 142 appendFeatures(f[run], fs);
cannam@5 143 }
cannam@5 144 if (data) destroyTestAudio(data, channels);
cannam@5 145
cannam@5 146 if (!(f[0] == f[1])) {
cannam@8 147 string message = "Explicitly setting parameters to their supposed default values changes the results";
cannam@8 148 Result res;
cannam@8 149 if (options & NonDeterministic) res = note(message);
cannam@8 150 else res = error(message);
cannam@8 151 if (options & Verbose) dump(res, f[0], f[1]);
cannam@7 152 r.push_back(res);
cannam@5 153 } else {
cannam@5 154 r.push_back(success());
cannam@5 155 }
cannam@5 156
cannam@5 157 return r;
cannam@5 158 }