Revision 5:6a279da6fdd7

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 TestInputExtremes.o TestMultipleRuns.o TestOutputs.o
5
OBJECTS		:= vamp-plugin-tester.o Tester.o Test.o TestStaticData.o TestInputExtremes.o TestMultipleRuns.o TestOutputs.o TestDefaults.o
6 6

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

  
TestDefaults.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 "TestDefaults.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<TestDefaultProgram>
51
TestDefaultProgram::m_registrar("E1 Inconsistent default program");
52

  
53
Tester::TestRegistrar<TestDefaultParameters>
54
TestDefaultParameters::m_registrar("E2 Inconsistent default parameters");
55

  
56
static const size_t _step = 1000;
57

  
58
Test::Results
59
TestDefaultProgram::test(string key)
60
{
61
    Plugin::FeatureSet f[2];
62
    int rate = 44100;
63
    Results r;
64
    float **data = 0;
65
    size_t channels = 0;
66
    size_t count = 100;
67

  
68
    for (int run = 0; run < 2; ++run) {
69
        auto_ptr<Plugin> p(load(key, rate));
70
	if (p->getPrograms().empty()) return r;
71
	if (run == 1) {
72
            p->selectProgram(p->getCurrentProgram());
73
        }
74
        if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
75
        if (!data) data = createTestAudio(channels, _step, count);
76
        for (size_t i = 0; i < count; ++i) {
77
            float *ptr[channels];
78
            size_t idx = i * _step;
79
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
80
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
81
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
82
            appendFeatures(f[run], fs);
83
        }
84
        Plugin::FeatureSet fs = p->getRemainingFeatures();
85
        appendFeatures(f[run], fs);
86
    }
87
    if (data) destroyTestAudio(data, channels);
88

  
89
    if (!(f[0] == f[1])) {
90
        r.push_back(warning("Explicitly setting current program to its supposed current value changes the results"));
91
    } else {
92
        r.push_back(success());
93
    }
94

  
95
    return r;
96
}
97

  
98
Test::Results
99
TestDefaultParameters::test(string key)
100
{
101
    Plugin::FeatureSet f[2];
102
    int rate = 44100;
103
    Results r;
104
    float **data = 0;
105
    size_t channels = 0;
106
    size_t count = 100;
107

  
108
    for (int run = 0; run < 2; ++run) {
109
        auto_ptr<Plugin> p(load(key, rate));
110
	if (p->getParameterDescriptors().empty()) return r;
111
	if (run == 1) {
112
            Plugin::ParameterList pl = p->getParameterDescriptors();
113
            for (int i = 0; i < (int)pl.size(); ++i) {
114
                if (p->getParameter(pl[i].identifier) != pl[i].defaultValue) {
115
                    r.push_back(error("Not all parameters have their default values when queried directly after construction"));
116
                }
117
                p->setParameter(pl[i].identifier, pl[i].defaultValue);
118
            }
119
        }
120
        if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
121
        if (!data) data = createTestAudio(channels, _step, count);
122
        for (size_t i = 0; i < count; ++i) {
123
            float *ptr[channels];
124
            size_t idx = i * _step;
125
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
126
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
127
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
128
            appendFeatures(f[run], fs);
129
        }
130
        Plugin::FeatureSet fs = p->getRemainingFeatures();
131
        appendFeatures(f[run], fs);
132
    }
133
    if (data) destroyTestAudio(data, channels);
134

  
135
    if (!(f[0] == f[1])) {
136
        r.push_back(warning("Explicitly setting parameters to their supposed default values changes the results"));
137
    } else {
138
        r.push_back(success());
139
    }
140

  
141
    return r;
142
}
TestDefaults.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_DEFAULTS_H_
41
#define _TEST_DEFAULTS_H_
42

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

  
46
class TestDefaultProgram : public Test
47
{
48
public:
49
    TestDefaultProgram() : Test() { }
50
    Results test(std::string key);
51
    
52
protected:
53
    static Tester::TestRegistrar<TestDefaultProgram> m_registrar;
54
};
55

  
56
class TestDefaultParameters : public Test
57
{
58
public:
59
    TestDefaultParameters() : Test() { }
60
    Results test(std::string key);
61
    
62
protected:
63
    static Tester::TestRegistrar<TestDefaultParameters> m_registrar;
64
};
65

  
66

  
67
#endif
TestMultipleRuns.cpp
56 56
Tester::TestRegistrar<TestInterleavedRuns>
57 57
TestInterleavedRuns::m_registrar("D3 Simultaneous interleaved runs in a single thread");
58 58

  
59
Tester::TestRegistrar<TestDifferentStartTimes>
60
TestDifferentStartTimes::m_registrar("D4 Consecutive runs with different start times");
61

  
59 62
static const size_t _step = 1000;
60 63

  
61 64
Test::Results
......
180 183

  
181 184
    return r;
182 185
}
186

  
187
Test::Results
188
TestDifferentStartTimes::test(string key)
189
{
190
    Plugin::FeatureSet f[2];
191
    int rate = 44100;
192
    Results r;
193
    float **data = 0;
194
    size_t channels = 0;
195
    size_t count = 100;
196

  
197
    for (int run = 0; run < 2; ++run) {
198
        auto_ptr<Plugin> p(load(key, rate));
199
        if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
200
        if (!data) data = createTestAudio(channels, _step, count);
201
        for (size_t i = 0; i < count; ++i) {
202
            float *ptr[channels];
203
            size_t idx = i * _step;
204
            for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
205
            RealTime timestamp = RealTime::frame2RealTime(idx, rate);
206
            if (run == 1) timestamp = timestamp + RealTime::fromSeconds(10);
207
            Plugin::FeatureSet fs = p->process(ptr, timestamp);
208
            appendFeatures(f[run], fs);
209
        }
210
        Plugin::FeatureSet fs = p->getRemainingFeatures();
211
        appendFeatures(f[run], fs);
212
    }
213
    if (data) destroyTestAudio(data, channels);
214

  
215
    if (f[0] == f[1]) {
216
        r.push_back(warning("Consecutive runs with different starting timestamps produce the same result"));
217
    } else {
218
        r.push_back(success());
219
    }
220

  
221
    return r;
222
}
TestMultipleRuns.h
73 73
    static Tester::TestRegistrar<TestInterleavedRuns> m_registrar;
74 74
};
75 75

  
76
class TestDifferentStartTimes : public Test
77
{
78
public:
79
    TestDifferentStartTimes() : Test() { }
80
    Results test(std::string key);
81
    
82
protected:
83
    static Tester::TestRegistrar<TestDifferentStartTimes> m_registrar;
84
};
85

  
76 86
#endif
TestOutputs.cpp
85 85

  
86 86
    std::set<int> used;
87 87
    Plugin::OutputList outputs = p->getOutputDescriptors();
88
    for (Plugin::FeatureSet::const_iterator i = fs.begin();
89
         i != fs.end(); ++i) {
88
    for (Plugin::FeatureSet::const_iterator i = f.begin();
89
         i != f.end(); ++i) {
90 90
        int o = i->first;
91 91
        used.insert(o);
92 92
        if (o < 0 || o >= (int)outputs.size()) {
......
133 133
    if (data) destroyTestAudio(data, channels);
134 134

  
135 135
    Plugin::OutputList outputs = p->getOutputDescriptors();
136
    for (Plugin::FeatureSet::const_iterator i = fs.begin();
137
         i != fs.end(); ++i) {
136
    for (Plugin::FeatureSet::const_iterator i = f.begin();
137
         i != f.end(); ++i) {
138 138
        const Plugin::OutputDescriptor &o = outputs[i->first];
139 139
        const Plugin::FeatureList &fl = i->second;
140 140
        for (int j = 0; j < (int)fl.size(); ++j) {
141
            const Plugin::Feature &f = fl[j];
141
            const Plugin::Feature &fe = fl[j];
142 142
            switch (o.sampleType) {
143 143
            case Plugin::OutputDescriptor::OneSamplePerStep:
144
                if (f.hasTimestamp) {
144
                if (fe.hasTimestamp) {
145 145
                    r.push_back(note("Plugin returns features with timestamps on OneSamplePerStep output"));
146 146
                }
147
                if (f.hasDuration) {
147
                if (fe.hasDuration) {
148 148
                    r.push_back(note("Plugin returns features with durations on OneSamplePerStep output"));
149 149
                }
150 150
                break;
151 151
            case Plugin::OutputDescriptor::FixedSampleRate:
152 152
                break;
153 153
            case Plugin::OutputDescriptor::VariableSampleRate:
154
                if (!f.hasTimestamp) {
154
                if (!fe.hasTimestamp) {
155 155
                    r.push_back(error("Plugin returns features with no timestamps on VariableSampleRate output"));
156 156
                }
157 157
                break;
Tester.cpp
105 105
 
106 106
      * Plugin's returned timestamps do not change as expected when
107 107
        run with a different base timestamp for input (though there
108
        could be legitimate reasons for this)
108
        could be legitimate reasons for this) - DONE
109 109

  
110 110
      * Plugin produces different results on second run, after reset
111 111
        called - DONE
......
119 119
        explicitly changes results (as for default parameters)
120 120

  
121 121
      * Output feature does not hasTimestamp when output type is
122
        VariableSampleRate
122
        VariableSampleRate - DONE
123 123

  
124 124
      * Output feature hasTimestamp or hasDuration when output type is
125
        OneSamplePerStep (warning only, this is not an error)
125
        OneSamplePerStep (warning only, this is not an error) - DONE
126 126

  
127 127
      * Plugin fails gracelessly when constructed with "weird" sample
128 128
        rate or initialised with "wrong" step size, block size, or
129 129
        number of channels
130 130

  
131 131
      * Plugin returns features whose output numbers do not have
132
        a corresponding record in output descriptor list
132
        a corresponding record in output descriptor list - DONE
133 133

  
134 134
      * Plugin fails to return any features on some output (warning
135
        only)
135
        only) - DONE
136 136

  
137 137
      * Constructor takes a long time to run.  A fuzzy concept, but
138 138
        suggests that some work should have been deferred to

Also available in: Unified diff