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 / vamp-plugin-tester.cpp @ 32:054ccdae5ed7

History | View | Annotate | Download (6.48 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-2012 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 <cstdlib>
47
#include <cstring>
48

    
49
#include "Tester.h"
50

    
51
using namespace std;
52

    
53
void usage(const char *name)
54
{
55
    cerr << "\n"
56
         << name << ": A Vamp plugin host that tests plugins for common errors.\n"
57
        "Chris Cannam, Centre for Digital Music, Queen Mary, University of London.\n"
58
        "Copyright 2009-2012 QMUL.\n"
59
        "Freely redistributable; published under a BSD-style license.\n\n"
60
        "Usage:\n"
61
        "  " << name << " [-nv] <pluginbasename>:<plugin>\n"
62
        "  " << name << " [-nv] -a\n\n"
63
        "Example:\n"
64
        "  " << name << " vamp-example-plugins:amplitudefollower\n\n"
65
        "Options:\n"
66
        "  -a, --all                 Test all plugins found in Vamp path\n\n"
67
        "  -n, --nondeterministic    Plugins may be nondeterministic: print a note\n"
68
        "                            instead of an error if results differ between runs\n\n"
69
        "  -v, --verbose             Show returned features each time a note, warning,\n"
70
        "                            or error arises from feature data\n"
71
        "\nIf you have access to a runtime memory checker, you may find it especially\n"
72
        "helpful to run this tester under it and watch for errors thus provoked.\n"
73
         << endl;
74
    exit(2);
75
}
76

    
77
int main(int argc, char **argv)
78
{
79
    char *scooter = argv[0];
80
    char *name = 0;
81
    while (scooter && *scooter) {
82
        if (*scooter == '/' || *scooter == '\\') name = ++scooter;
83
        else ++scooter;
84
    }
85
    if (!name || !*name) name = argv[0];
86

    
87
    bool nondeterministic = false;
88
    bool verbose = false;
89
    bool all = false;
90
    string argument;
91
    for (int i = 1; i < argc; ++i) {
92
        if (!argv[i]) break;
93
        if (argv[i][0] == '-') {
94
            if (!strcmp(argv[i], "-v") ||
95
                !strcmp(argv[i], "--verbose")) {
96
                verbose = true;
97
                continue;
98
            }
99
            if (!strcmp(argv[i], "-n") ||
100
                !strcmp(argv[i], "--nondeterministic")) {
101
                nondeterministic = true;
102
                continue;
103
            }
104
            if (!strcmp(argv[i], "-a") ||
105
                !strcmp(argv[i], "--all")) {
106
                all = true;
107
                continue;
108
            }
109
            usage(name);
110
        } else {
111
            if (argument != "") usage(name);
112
            else argument = argv[i];
113
        }
114
    }
115
    
116
    if (argument == "" && !all) usage(name);
117
    if (argument != "" &&  all) usage(name);
118

    
119
    cerr << name << ": Running..." << endl;
120

    
121
    Test::Options opts = Test::NoOption;
122
    if (nondeterministic) opts |= Test::NonDeterministic;
123
    if (verbose) opts |= Test::Verbose;
124

    
125
    if (all) {
126
        bool good = true;
127
        Vamp::HostExt::PluginLoader::PluginKeyList keys =
128
            Vamp::HostExt::PluginLoader::getInstance()->listPlugins();
129
        int notes = 0, warnings = 0, errors = 0;
130
        for (int i = 0; i < (int)keys.size(); ++i) {
131
            cout << "Testing plugin: " << keys[i] << endl;
132
            Tester tester(keys[i], opts);
133
            if (tester.test(notes, warnings, errors)) {
134
                cout << name << ": All tests succeeded for this plugin" << endl;
135
            } else {
136
                cout << name << ": Some tests failed for this plugin" << endl;
137
                good = false;
138
            }
139
            cout << endl;
140
        }
141
        if (good) {
142
            cout << name << ": All tests succeeded";
143
            if (warnings > 0) {
144
                cout << ", with " << warnings << " warning(s)";
145
                if (notes > 0) {
146
                    cout << " and " << notes << " other note(s)";
147
                }
148
            } else if (notes > 0) {
149
                cout << ", with " << notes << " note(s)";
150
            }
151
            cout << endl;
152
            return 0;
153
        } else {
154
            cout << name << ": Some tests failed" << endl;
155
            return 1;
156
        }   
157
    } else {
158
        string key = argument;
159
        Tester tester(key, opts);
160
        int notes = 0, warnings = 0, errors = 0;
161
        if (tester.test(notes, warnings, errors)) {
162
            cout << name << ": All tests succeeded";
163
            if (warnings > 0) {
164
                cout << ", with " << warnings << " warning(s)";
165
                if (notes > 0) {
166
                    cout << " and " << notes << " other note(s)";
167
                }
168
            } else if (notes > 0) {
169
                cout << ", with " << notes << " note(s)";
170
            }
171
            cout << endl;
172
            return 0;
173
        } else {
174
            cout << name << ": Some tests failed" << endl;
175
            return 1;
176
        }
177
    }
178
}
179