To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / Tester.cpp @ 5:6a279da6fdd7

History | View | Annotate | Download (6.29 KB)

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 <vamp-hostsdk/PluginHostAdapter.h>
41
#include <vamp-hostsdk/PluginInputDomainAdapter.h>
42
#include <vamp-hostsdk/PluginLoader.h>
43

    
44
#include <iostream>
45

    
46
#include <cstring>
47
#include <cstdlib>
48
#include <cmath>
49
#include <set>
50

    
51
#include "Tester.h"
52

    
53
using Vamp::Plugin;
54
using Vamp::PluginHostAdapter;
55
using Vamp::RealTime;
56
using Vamp::HostExt::PluginLoader;
57
using Vamp::HostExt::PluginWrapper;
58
using Vamp::HostExt::PluginInputDomainAdapter;
59

    
60
using namespace std;
61

    
62
Tester::Tester(std::string key) :
63
    m_key(key)
64
{
65
}
66

    
67
Tester::~Tester()
68
{
69
}
70

    
71
Tester::Registry &
72
Tester::registry()
73
{
74
    static Registry r;
75
    return r;
76
}
77

    
78
bool
79
Tester::test(int &notes, int &warnings, int &errors)
80
{
81
    /*
82
      
83
      Things I would like to see tested:
84

85
      * Identifiers for parameters, outputs, or plugin itself contain
86
        illegal characters - DONE
87

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

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

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

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

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

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

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

103
      * Plugin returns different results if another instance is
104
        constructed and run "interleaved" with it (from same thread) - DONE
105
 
106
      * Plugin's returned timestamps do not change as expected when
107
        run with a different base timestamp for input (though there
108
        could be legitimate reasons for this) - DONE
109

110
      * Plugin produces different results on second run, after reset
111
        called - DONE
112

113
      * Initial value of a parameter on plugin construction differs
114
        from its default value (i.e. plugin produces different
115
        results depending on whether parameter is set explicitly by
116
        host to default value or not)
117
        
118
      * If a plugin reports any programs, selecting default program
119
        explicitly changes results (as for default parameters)
120

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

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

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

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

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

137
      * Constructor takes a long time to run.  A fuzzy concept, but
138
        suggests that some work should have been deferred to
139
        initialise().  Warning only
140

141
      Well, that's quite a lot of tests already.  What else?
142

143
    */
144

    
145
    bool good = true;
146

    
147
    try {
148
        for (Registry::const_iterator i = registry().begin();
149
             i != registry().end(); ++i) {
150
            
151
            std::cout << " -- Performing test: " << i->first << std::endl;
152

    
153
            Test *test = i->second->makeTest();
154
            Test::Results results = test->test(m_key);
155
            delete test;
156

    
157
            set<string> printed;
158
            
159
            for (int j = 0; j < (int)results.size(); ++j) {
160
                string message = results[j].message();
161
                if (printed.find(message) != printed.end()) continue;
162
                printed.insert(message);
163
                switch (results[j].code()) {
164
                case Test::Result::Success:
165
                    break;
166
                case Test::Result::Note:
167
                    std::cout << " ** NOTE: " << results[j].message() << std::endl;
168
                    ++notes;
169
                    break;
170
                case Test::Result::Warning:
171
                    std::cout << " ** WARNING: " << results[j].message() << std::endl;
172
                    ++warnings;
173
                    break;
174
                case Test::Result::Error:
175
                    std::cout << " ** ERROR: " << results[j].message() << std::endl;
176
                    ++errors;
177
                    good = false;
178
                    break;
179
                }
180
            }
181
        }
182
    } catch (Test::FailedToLoadPlugin) {
183
        std::cout << "ERROR: Failed to load plugin (key = \"" << m_key
184
                  << "\")" << std::endl;
185
    }
186

    
187
    return good;
188
}
189