Revision 1:d7ef749300ed

View differences:

Makefile
2 2
LDFLAGS 	+= -lvamp-hostsdk -ldl
3 3
CXXFLAGS	+= -Wall -Wextra
4 4

  
5
OBJECTS		:= vamp-plugin-tester.o Tester.o Test.o TestStaticData.o
5
OBJECTS		:= vamp-plugin-tester.o Tester.o Test.o TestStaticData.o TestInputExtremes.o
6 6

  
7 7
vamp-plugin-tester:	$(OBJECTS)
8 8

  
......
18 18
# DO NOT DELETE
19 19

  
20 20
Test.o: Test.h
21
TestInputExtremes.o: TestInputExtremes.h
21 22
TestStaticData.o: TestStaticData.h Test.h Tester.h
22 23
Tester.o: Tester.h Test.h
23 24
vamp-plugin-tester.o: Tester.h Test.h
Test.cpp
44 44
using namespace Vamp;
45 45
using namespace Vamp::HostExt;
46 46

  
47
#include <cmath>
48

  
47 49
Test::Test() { }
48 50
Test::~Test() { }
49 51

  
......
54 56
        (key, rate, PluginLoader::ADAPT_ALL);
55 57
}
56 58

  
59
float **
60
Test::createBlock(size_t channels, size_t blocksize)
61
{
62
    float **b = new float *[channels];
63
    for (size_t c = 0; c < channels; ++c) {
64
        b[c] = new float[blocksize];
65
    }
66
    return b;
67
}
68

  
69
void
70
Test::destroyBlock(float **blocks, size_t channels)
71
{
72
    for (size_t c = 0; c < channels; ++c) {
73
        delete[] blocks[c];
74
    }
75
    delete[] blocks;
76
}
77

  
78
bool
79
Test::initDefaults(Plugin *p, size_t &channels, size_t &step, size_t &block,
80
                   Results &r)
81
{
82
    channels = p->getMinChannelCount();
83
    block = p->getPreferredBlockSize();
84
    step = p->getPreferredStepSize();
85
    if (block == 0) block = 1024;
86
    if (step == 0) {
87
        if (p->getInputDomain() == Plugin::FrequencyDomain) step = block/2;
88
        else step = block;
89
    }
90
    if (!p->initialise(channels, step, block)) {
91
        r.push_back(error("initialisation with default values failed"));
92
        return false;
93
    }
94
    return true;
95
}
96

  
57 97
void
58 98
Test::appendFeatures(Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
59 99
{
......
68 108
}
69 109

  
70 110
bool
111
Test::allFeaturesValid(const Plugin::FeatureSet &b)
112
{
113
    for (Plugin::FeatureSet::const_iterator i = b.begin(); i != b.end(); ++i) {
114
        for (int j = 0; j < (int)i->second.size(); ++j) {
115
            if (i->second[j].values.empty()) continue;
116
            for (int k = 0; k < (int)i->second[j].values.size(); ++k) {
117
                if (isnan(i->second[j].values[k]) ||
118
                    isinf(i->second[j].values[k])) {
119
                    return false;
120
                }
121
            }
122
        }
123
    }
124
    return true;
125
}
126

  
127
bool
71 128
operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
72 129
{
73 130
    if (a.size() != b.size()) return false;
Test.h
81 81
    // may throw FailedToLoadPlugin
82 82
    Vamp::Plugin *load(std::string key, float rate = 44100);
83 83

  
84
    float **createBlock(size_t channels, size_t blocksize);
85
    void destroyBlock(float **blocks, size_t channels);
86

  
87
    bool initDefaults(Vamp::Plugin *, size_t &channels,
88
                      size_t &step, size_t &block, Results &r);
89

  
84 90
    void appendFeatures(Vamp::Plugin::FeatureSet &a,
85 91
                        const Vamp::Plugin::FeatureSet &b);
92

  
93
    bool allFeaturesValid(const Vamp::Plugin::FeatureSet &); // i.e. no NaN/inf
86 94
};
87 95

  
88 96
extern bool operator==(const Vamp::Plugin::FeatureSet &a,
TestInputExtremes.cpp
1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2

  
3
/*
4
    Vamp Plugin Tester
5
    Chris Cannam, cannam@all-day-breakfast.com
6
    Centre for Digital Music, Queen Mary, University of London.
7
    Copyright 2009 QMUL.
8

  
9
    This program loads a Vamp plugin and tests its susceptibility to a
10
    number of common pitfalls, including handling of extremes of input
11
    data.  If you can think of any additional useful tests that are
12
    easily added, please send them to me.
13
  
14
    Permission is hereby granted, free of charge, to any person
15
    obtaining a copy of this software and associated documentation
16
    files (the "Software"), to deal in the Software without
17
    restriction, including without limitation the rights to use, copy,
18
    modify, merge, publish, distribute, sublicense, and/or sell copies
19
    of the Software, and to permit persons to whom the Software is
20
    furnished to do so, subject to the following conditions:
21

  
22
    The above copyright notice and this permission notice shall be
23
    included in all copies or substantial portions of the Software.
24

  
25
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
29
    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
30
    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32

  
33
    Except as contained in this notice, the names of the Centre for
34
    Digital Music; Queen Mary, University of London; and Chris Cannam
35
    shall not be used in advertising or otherwise to promote the sale,
36
    use or other dealings in this Software without prior written
37
    authorization.
38
*/
39

  
40
#include "TestInputExtremes.h"
41

  
42
#include <vamp-hostsdk/Plugin.h>
43
using namespace Vamp;
44

  
45
#include <memory>
46
using namespace std;
47

  
48
#include <cmath>
49

  
50
Tester::TestRegistrar<TestNormalInput>
51
TestNormalInput::m_registrar("Normal input");
52

  
53
Tester::TestRegistrar<TestNoInput>
54
TestNoInput::m_registrar("Empty input");
55

  
56
Tester::TestRegistrar<TestShortInput>
57
TestShortInput::m_registrar("Short input");
58

  
59
Tester::TestRegistrar<TestSilentInput>
60
TestSilentInput::m_registrar("Absolutely silent input");
61

  
62
Tester::TestRegistrar<TestTooLoudInput>
63
TestTooLoudInput::m_registrar("Input beyond expected +/-1 range");
64

  
65
Tester::TestRegistrar<TestRandomInput>
66
TestRandomInput::m_registrar("Random input");
67

  
68
Test::Results
69
TestNormalInput::test(string key)
70
{
71
    int rate = 44100;
72
    auto_ptr<Plugin> p(load(key, rate));
73
    Results r;
74
    size_t channels, step, blocksize;
75
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
76
    float **block = createBlock(channels, blocksize);
77
    int idx = 0;
78
    for (int i = 0; i < 200; ++i) {
79
        for (size_t j = 0; j < blocksize; ++j) {
80
            for (size_t c = 0; c < channels; ++c) {
81
                block[c][j] = sinf(float(idx) / 10.f);
82
            }
83
            ++idx;
84
        }
85
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
86
        p->process(block, timestamp);
87
    }
88
    destroyBlock(block, channels);
89
    Plugin::FeatureSet fs = p->getRemainingFeatures();
90
    if (allFeaturesValid(fs)) {
91
        r.push_back(success());
92
    } else {
93
        r.push_back(warning("plugin returned one or more NaN/inf values"));
94
    }
95
    return r;
96
}
97

  
98
Test::Results
99
TestNoInput::test(string key)
100
{
101
    auto_ptr<Plugin> p(load(key));
102
    Results r;
103
    size_t channels, step, block;
104
    if (!initDefaults(p.get(), channels, step, block, r)) return r;
105
    Plugin::FeatureSet fs = p->getRemainingFeatures();
106
    if (allFeaturesValid(fs)) {
107
        r.push_back(success());
108
    } else {
109
        r.push_back(warning("plugin returned one or more NaN/inf values"));
110
    }
111
    return r;
112
}
113

  
114
Test::Results
115
TestShortInput::test(string key)
116
{
117
    int rate = 44100;
118
    auto_ptr<Plugin> p(load(key, rate));
119
    Results r;
120
    size_t channels, step, blocksize;
121
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
122
    float **block = createBlock(channels, blocksize);
123
    int idx = 0;
124
    for (size_t j = 0; j < blocksize; ++j) {
125
        for (size_t c = 0; c < channels; ++c) {
126
            block[c][j] = sinf(float(idx) / 10.f);
127
        }
128
        ++idx;
129
    }
130
    p->process(block, RealTime::zeroTime);
131
    destroyBlock(block, channels);
132
    Plugin::FeatureSet fs = p->getRemainingFeatures();
133
    if (allFeaturesValid(fs)) {
134
        r.push_back(success());
135
    } else {
136
        r.push_back(warning("plugin returned one or more NaN/inf values"));
137
    }
138
    return r;
139
}
140

  
141
Test::Results
142
TestSilentInput::test(string key)
143
{
144
    int rate = 44100;
145
    auto_ptr<Plugin> p(load(key, rate));
146
    Results r;
147
    size_t channels, step, blocksize;
148
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
149
    float **block = createBlock(channels, blocksize);
150
    for (size_t j = 0; j < blocksize; ++j) {
151
        for (size_t c = 0; c < channels; ++c) {
152
            block[c][j] = 0.f;
153
        }
154
    }
155
    for (int i = 0; i < 200; ++i) {
156
        RealTime timestamp = RealTime::frame2RealTime(i * blocksize, rate);
157
        p->process(block, timestamp);
158
    }
159
    destroyBlock(block, channels);
160
    Plugin::FeatureSet fs = p->getRemainingFeatures();
161
    if (allFeaturesValid(fs)) {
162
        r.push_back(success());
163
    } else {
164
        r.push_back(warning("plugin returned one or more NaN/inf values"));
165
    }
166
    return r;
167
}
168

  
169
Test::Results
170
TestTooLoudInput::test(string key)
171
{
172
    int rate = 44100;
173
    auto_ptr<Plugin> p(load(key, rate));
174
    Results r;
175
    size_t channels, step, blocksize;
176
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
177
    float **block = createBlock(channels, blocksize);
178
    int idx = 0;
179
    for (int i = 0; i < 200; ++i) {
180
        for (size_t j = 0; j < blocksize; ++j) {
181
            for (size_t c = 0; c < channels; ++c) {
182
                block[c][j] = 1000.f * sinf(float(idx) / 10.f);
183
            }
184
            ++idx;
185
        }
186
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
187
        p->process(block, timestamp);
188
    }
189
    destroyBlock(block, channels);
190
    Plugin::FeatureSet fs = p->getRemainingFeatures();
191
    if (allFeaturesValid(fs)) {
192
        r.push_back(success());
193
    } else {
194
        r.push_back(warning("plugin returned one or more NaN/inf values"));
195
    }
196
    return r;
197
}
198

  
199
Test::Results
200
TestRandomInput::test(string key)
201
{
202
    int rate = 44100;
203
    auto_ptr<Plugin> p(load(key, rate));
204
    Results r;
205
    size_t channels, step, blocksize;
206
    if (!initDefaults(p.get(), channels, step, blocksize, r)) return r;
207
    float **block = createBlock(channels, blocksize);
208
    int idx = 0;
209
    for (int i = 0; i < 100; ++i) {
210
        for (size_t j = 0; j < blocksize; ++j) {
211
            for (size_t c = 0; c < channels; ++c) {
212
                block[c][j] = float(drand48() * 2.0 - 1.0);
213
            }
214
            ++idx;
215
        }
216
        RealTime timestamp = RealTime::frame2RealTime(idx, rate);
217
        p->process(block, timestamp);
218
    }
219
    destroyBlock(block, channels);
220
    Plugin::FeatureSet fs = p->getRemainingFeatures();
221
    if (allFeaturesValid(fs)) {
222
        r.push_back(success());
223
    } else {
224
        r.push_back(warning("plugin returned one or more NaN/inf values"));
225
    }
226
    return r;
227
}
228

  
TestInputExtremes.h
1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2

  
3
/*
4
    Vamp Plugin Tester
5
    Chris Cannam, cannam@all-day-breakfast.com
6
    Centre for Digital Music, Queen Mary, University of London.
7
    Copyright 2009 QMUL.
8

  
9
    This program loads a Vamp plugin and tests its susceptibility to a
10
    number of common pitfalls, including handling of extremes of input
11
    data.  If you can think of any additional useful tests that are
12
    easily added, please send them to me.
13
  
14
    Permission is hereby granted, free of charge, to any person
15
    obtaining a copy of this software and associated documentation
16
    files (the "Software"), to deal in the Software without
17
    restriction, including without limitation the rights to use, copy,
18
    modify, merge, publish, distribute, sublicense, and/or sell copies
19
    of the Software, and to permit persons to whom the Software is
20
    furnished to do so, subject to the following conditions:
21

  
22
    The above copyright notice and this permission notice shall be
23
    included in all copies or substantial portions of the Software.
24

  
25
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
29
    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
30
    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32

  
33
    Except as contained in this notice, the names of the Centre for
34
    Digital Music; Queen Mary, University of London; and Chris Cannam
35
    shall not be used in advertising or otherwise to promote the sale,
36
    use or other dealings in this Software without prior written
37
    authorization.
38
*/
39

  
40
#ifndef _TEST_INPUT_EXTREMES_H_
41
#define _TEST_INPUT_EXTREMES_H_
42

  
43
#include "Test.h"
44
#include "Tester.h"
45

  
46
#include <string>
47

  
48
#include <vamp-hostsdk/Plugin.h>
49

  
50
class TestNormalInput : public Test
51
{
52
public:
53
    TestNormalInput() : Test() { }
54
    Results test(std::string key);
55

  
56
protected:
57
    static Tester::TestRegistrar<TestNormalInput> m_registrar;
58
};
59

  
60
class TestNoInput : public Test
61
{
62
public:
63
    TestNoInput() : Test() { }
64
    Results test(std::string key);
65

  
66
protected:
67
    static Tester::TestRegistrar<TestNoInput> m_registrar;
68
};
69

  
70
class TestShortInput : public Test
71
{
72
public:
73
    TestShortInput() : Test() { }
74
    Results test(std::string key);
75

  
76
protected:
77
    static Tester::TestRegistrar<TestShortInput> m_registrar;
78
};
79

  
80
class TestSilentInput : public Test
81
{
82
public:
83
    TestSilentInput() : Test() { }
84
    Results test(std::string key);
85

  
86
protected:
87
    static Tester::TestRegistrar<TestSilentInput> m_registrar;
88
};
89

  
90
class TestTooLoudInput : public Test
91
{
92
public:
93
    TestTooLoudInput() : Test() { }
94
    Results test(std::string key);
95

  
96
protected:
97
    static Tester::TestRegistrar<TestTooLoudInput> m_registrar;
98
};
99

  
100
class TestRandomInput : public Test
101
{
102
public:
103
    TestRandomInput() : Test() { }
104
    Results test(std::string key);
105

  
106
protected:
107
    static Tester::TestRegistrar<TestRandomInput> m_registrar;
108
};
109

  
110

  
111
#endif
112

  
Tester.cpp
86 86

  
87 87
      * Any of the plugin's name, maker etc fields are empty - DONE
88 88

  
89
      * Default value of a parameter is not quantized as specified - DONE
90

  
91
      * Parameter minValue >= maxValue, or defaultValue < minValue
92
        or > maxValue - DONE
93

  
94
      * Plugin fails when given zero-length or very short input - DONE
95

  
96
      * Plugin fails when given "all digital zeros" input - DONE
97

  
98
      * Plugin fails when given input that exceeds +/-1 - DONE
99

  
100
      * Plugin fails when given "normal" random input (just in case!) - DONE
101

  
89 102
      * Plugin returns different results if another instance is
90 103
        constructed and run "interleaved" with it (from same thread)
91 104
 
......
93 106
        run with a different base timestamp for input (though there
94 107
        could be legitimate reasons for this)
95 108

  
96
      * Plugin fails when given zero-length or very short input
97

  
98
      * Plugin fails when given "all digital zeros" input
99

  
100
      * Plugin fails when given input that exceeds +/-1
101

  
102
      * Plugin fails when given "normal" random input (just in case!)
103

  
104 109
      * Plugin produces different results on second run, after reset
105 110
        called
106 111

  
......
108 113
        from its default value (i.e. plugin produces different
109 114
        results depending on whether parameter is set explicitly by
110 115
        host to default value or not)
111

  
112
      * Default value of a parameter is not quantized as specified - DONE
113

  
114
      * Parameter minValue >= maxValue, or defaultValue < minValue
115
        or > maxValue - DONE
116 116
        
117 117
      * If a plugin reports any programs, selecting default program
118 118
        explicitly changes results (as for default parameters)

Also available in: Unified diff