annotate Test.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@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 Fuzz 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 "Test.h"
cannam@0 41
cannam@0 42 #include <vamp-hostsdk/PluginLoader.h>
cannam@0 43
cannam@0 44 using namespace Vamp;
cannam@0 45 using namespace Vamp::HostExt;
cannam@0 46
cannam@20 47 #include <math.h>
cannam@1 48
cannam@0 49 Test::Test() { }
cannam@0 50 Test::~Test() { }
cannam@0 51
cannam@0 52 Plugin *
cannam@0 53 Test::load(std::string key, float rate)
cannam@0 54 {
cannam@23 55 Plugin *p = PluginLoader::getInstance()->loadPlugin
cannam@0 56 (key, rate, PluginLoader::ADAPT_ALL);
cannam@23 57 if (!p) throw FailedToLoadPlugin();
cannam@23 58 return p;
cannam@0 59 }
cannam@0 60
cannam@1 61 float **
cannam@1 62 Test::createBlock(size_t channels, size_t blocksize)
cannam@1 63 {
cannam@1 64 float **b = new float *[channels];
cannam@1 65 for (size_t c = 0; c < channels; ++c) {
cannam@1 66 b[c] = new float[blocksize];
cannam@1 67 }
cannam@1 68 return b;
cannam@1 69 }
cannam@1 70
cannam@1 71 void
cannam@1 72 Test::destroyBlock(float **blocks, size_t channels)
cannam@1 73 {
cannam@1 74 for (size_t c = 0; c < channels; ++c) {
cannam@1 75 delete[] blocks[c];
cannam@1 76 }
cannam@1 77 delete[] blocks;
cannam@1 78 }
cannam@1 79
cannam@3 80 float **
cannam@3 81 Test::createTestAudio(size_t channels, size_t blocksize, size_t blocks)
cannam@3 82 {
cannam@3 83 float **b = new float *[channels];
cannam@3 84 for (size_t c = 0; c < channels; ++c) {
cannam@3 85 b[c] = new float[blocksize * blocks];
cannam@3 86 for (int i = 0; i < int(blocksize * blocks); ++i) {
cannam@3 87 b[c][i] = sinf(float(i) / 10.f);
cannam@3 88 if (i == 5005 || i == 20002) {
cannam@3 89 b[c][i-2] = 0;
cannam@3 90 b[c][i-1] = -1;
cannam@3 91 b[c][i] = 1;
cannam@3 92 }
cannam@3 93 }
cannam@3 94 }
cannam@3 95 return b;
cannam@3 96 }
cannam@3 97
cannam@3 98 void
cannam@3 99 Test::destroyTestAudio(float **b, size_t channels)
cannam@3 100 {
cannam@3 101 for (size_t c = 0; c < channels; ++c) {
cannam@3 102 delete[] b[c];
cannam@3 103 }
cannam@3 104 delete[] b;
cannam@3 105 }
cannam@3 106
cannam@1 107 bool
cannam@1 108 Test::initDefaults(Plugin *p, size_t &channels, size_t &step, size_t &block,
cannam@1 109 Results &r)
cannam@1 110 {
cannam@1 111 channels = p->getMinChannelCount();
cannam@1 112 block = p->getPreferredBlockSize();
cannam@1 113 step = p->getPreferredStepSize();
cannam@1 114 if (block == 0) block = 1024;
cannam@1 115 if (step == 0) {
cannam@1 116 if (p->getInputDomain() == Plugin::FrequencyDomain) step = block/2;
cannam@1 117 else step = block;
cannam@1 118 }
cannam@1 119 if (!p->initialise(channels, step, block)) {
cannam@1 120 r.push_back(error("initialisation with default values failed"));
cannam@1 121 return false;
cannam@1 122 }
cannam@1 123 return true;
cannam@1 124 }
cannam@1 125
cannam@3 126 bool
cannam@3 127 Test::initAdapted(Plugin *p, size_t &channels, size_t step, size_t block,
cannam@3 128 Results &r)
cannam@3 129 {
cannam@3 130 channels = p->getMinChannelCount();
cannam@3 131 if (!p->initialise(channels, step, block)) {
cannam@3 132 r.push_back(error("initialisation failed"));
cannam@3 133 return false;
cannam@3 134 }
cannam@3 135 return true;
cannam@3 136 }
cannam@3 137
cannam@0 138 void
cannam@0 139 Test::appendFeatures(Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
cannam@0 140 {
cannam@0 141 for (Plugin::FeatureSet::const_iterator i = b.begin(); i != b.end(); ++i) {
cannam@0 142 int output = i->first;
cannam@0 143 const Plugin::FeatureList &fl = i->second;
cannam@0 144 Plugin::FeatureList &target = a[output];
cannam@0 145 for (Plugin::FeatureList::const_iterator j = fl.begin(); j != fl.end(); ++j) {
cannam@0 146 target.push_back(*j);
cannam@0 147 }
cannam@0 148 }
cannam@0 149 }
cannam@0 150
cannam@0 151 bool
cannam@1 152 Test::allFeaturesValid(const Plugin::FeatureSet &b)
cannam@1 153 {
cannam@1 154 for (Plugin::FeatureSet::const_iterator i = b.begin(); i != b.end(); ++i) {
cannam@1 155 for (int j = 0; j < (int)i->second.size(); ++j) {
cannam@1 156 if (i->second[j].values.empty()) continue;
cannam@1 157 for (int k = 0; k < (int)i->second[j].values.size(); ++k) {
cannam@1 158 if (isnan(i->second[j].values[k]) ||
cannam@1 159 isinf(i->second[j].values[k])) {
cannam@1 160 return false;
cannam@1 161 }
cannam@1 162 }
cannam@1 163 }
cannam@1 164 }
cannam@1 165 return true;
cannam@1 166 }
cannam@1 167
cannam@3 168 void
cannam@3 169 Test::dump(const Plugin::FeatureSet &fs)
cannam@3 170 {
cannam@3 171 for (Plugin::FeatureSet::const_iterator fsi = fs.begin();
cannam@3 172 fsi != fs.end(); ++fsi) {
cannam@3 173 int output = fsi->first;
cannam@8 174 std::cout << "Output " << output << ":" << std::endl;
cannam@3 175 const Plugin::FeatureList &fl = fsi->second;
cannam@3 176 for (int i = 0; i < (int)fl.size(); ++i) {
cannam@8 177 std::cout << " Feature " << i << ":" << std::endl;
cannam@3 178 const Plugin::Feature &f = fl[i];
cannam@8 179 std::cout << " Timestamp: " << (f.hasTimestamp ? "(none)" : f.timestamp.toText()) << std::endl;
cannam@8 180 std::cout << " Duration: " << (f.hasDuration ? "(none)" : f.duration.toText()) << std::endl;
cannam@8 181 std::cout << " Label: " << (f.label == "" ? "(none)" : f.label) << std::endl;
cannam@8 182 std::cout << " Value: " << (f.values.empty() ? "(none)" : "");
cannam@3 183 for (int j = 0; j < (int)f.values.size(); ++j) {
cannam@8 184 std::cout << f.values[j] << " ";
cannam@3 185 }
cannam@8 186 std::cout << std::endl;
cannam@3 187 }
cannam@3 188 }
cannam@3 189 }
cannam@3 190
cannam@3 191 void
cannam@3 192 Test::dump(const Result &r,
cannam@3 193 const Plugin::FeatureSet &a,
cannam@3 194 const Plugin::FeatureSet &b)
cannam@3 195 {
cannam@8 196 std::cout << r.message() << std::endl;
cannam@8 197 std::cout << "\nFirst result set:" << std::endl;
cannam@3 198 dump(a);
cannam@8 199 std::cout << "\nSecond result set:" << std::endl;
cannam@3 200 dump(b);
cannam@8 201 std::cout << std::endl;
cannam@3 202 }
cannam@3 203
cannam@1 204 bool
cannam@0 205 operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
cannam@0 206 {
cannam@0 207 if (a.size() != b.size()) return false;
cannam@0 208 for (Plugin::FeatureSet::const_iterator ai = a.begin();
cannam@0 209 ai != a.end(); ++ai) {
cannam@0 210 int output = ai->first;
cannam@0 211 Plugin::FeatureSet::const_iterator bi = b.find(output);
cannam@0 212 if (bi == b.end()) return false;
cannam@0 213 if (!(ai->second == bi->second)) return false;
cannam@0 214 }
cannam@0 215 return true;
cannam@0 216 }
cannam@0 217
cannam@0 218 bool
cannam@0 219 operator==(const Plugin::FeatureList &a, const Plugin::FeatureList &b)
cannam@0 220 {
cannam@0 221 if (a.size() != b.size()) return false;
cannam@0 222 for (int i = 0; i < (int)a.size(); ++i) {
cannam@0 223 if (!(a[i] == b[i])) return false;
cannam@0 224 }
cannam@0 225 return true;
cannam@0 226 }
cannam@0 227
cannam@0 228 bool
cannam@0 229 operator==(const Plugin::Feature &a, const Plugin::Feature &b)
cannam@0 230 {
cannam@0 231 if (a.hasTimestamp != b.hasTimestamp) return false;
cannam@0 232 if (a.hasTimestamp && (a.timestamp != b.timestamp)) return false;
cannam@0 233 if (a.hasDuration != b.hasDuration) return false;
cannam@0 234 if (a.hasDuration && (a.duration != b.duration)) return false;
cannam@0 235 if (a.values != b.values) return false;
cannam@0 236 if (a.label != b.label) return false;
cannam@0 237 return true;
cannam@0 238 }
cannam@0 239