-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathPluginTests.cpp
More file actions
237 lines (190 loc) · 8.44 KB
/
PluginTests.cpp
File metadata and controls
237 lines (190 loc) · 8.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*==============================================================================
Copyright 2018 by Tracktion Corporation.
For more information visit www.tracktion.com
You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
pluginval IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================*/
#include "PluginTests.h"
#include "TestUtilities.h"
#include <random>
#include <cassert>
juce::String getDisplayString (RealtimeCheck rtc)
{
if (rtc == RealtimeCheck::disabled)
return "Disabled (don't check for real-time safety)";
if (rtc == RealtimeCheck::enabled)
return "Enabled (check for real-time safety in all process calls)";
if (rtc == RealtimeCheck::relaxed)
return "Relaxed (check for real-time safety in all but the first process call)";
assert(false);
return {};
}
namespace
{
/** Deletes a plugin asyncronously on the message thread */
void deletePluginAsync (std::unique_ptr<juce::AudioPluginInstance> pluginInstance)
{
juce::WaitableEvent completionEvent;
struct AsyncDeleter : public juce::CallbackMessage
{
AsyncDeleter (std::unique_ptr<juce::AudioPluginInstance> api, juce::WaitableEvent& we)
: instance (std::move (api)), event (we)
{}
void messageCallback() override
{
instance.reset();
juce::Thread::sleep (150); // Pause a few ms to let the plugin clean up after itself
event.signal();
}
std::unique_ptr<juce::AudioPluginInstance> instance;
juce::WaitableEvent& event;
};
(new AsyncDeleter (std::move (pluginInstance), completionEvent))->post();
completionEvent.wait();
}
}
PluginTests::PluginTests (const juce::String& fileOrIdentifier, Options opts)
: juce::UnitTest ("pluginval"),
fileOrID (fileOrIdentifier),
options (opts)
{
jassert (fileOrIdentifier.isNotEmpty());
jassert (juce::isPositiveAndNotGreaterThan (options.strictnessLevel, 10));
#if JUCE_VERSION >= 0x08000B
juce::addDefaultFormatsToManager (formatManager);
#else
formatManager.addDefaultFormats();
#endif
}
PluginTests::PluginTests (const juce::PluginDescription& desc, Options opts)
: PluginTests (juce::String(), opts)
{
typesFound.add (new juce::PluginDescription (desc));
}
juce::String PluginTests::getFileOrID() const
{
if (fileOrID.isNotEmpty())
return fileOrID;
if (auto first = typesFound.getFirst())
return first->createIdentifierString();
return {};
}
void PluginTests::logVerboseMessage (const juce::String& message)
{
// We still need to send an empty message or the test may timeout
logMessage (options.verbose ? message : juce::String());
}
void PluginTests::resetTimeout()
{
logMessage (juce::String());
}
void PluginTests::runTest()
{
// This has to be called on a background thread to keep the message thread free
jassert (! juce::MessageManager::existsAndIsCurrentThread());
logMessage ("Validation started");
logVerboseMessage ("\t" + juce::Time::getCurrentTime().toString (true, true) + "\n");
logMessage ("Strictness level: " + juce::String (options.strictnessLevel));
if (fileOrID.isNotEmpty())
{
beginTest ("Scan for plugins located in: " + fileOrID);
juce::WaitableEvent completionEvent;
juce::MessageManager::callAsync ([&, this]() mutable
{
knownPluginList.scanAndAddDragAndDroppedFiles (formatManager, juce::StringArray (fileOrID), typesFound);
completionEvent.signal();
});
completionEvent.wait();
logMessage ("Num plugins found: " + juce::String (typesFound.size()));
expect (! typesFound.isEmpty(),
"No types found. This usually means the plugin binary is missing or damaged, "
"an incompatible format or that it is an AU that isn't found by macOS so can't be created.");
if (typesFound.isEmpty())
if (! juce::File (fileOrID).exists())
logMessage (juce::String ("There was no plugin file found at: XYYX").replace ("XYYX", fileOrID));
}
for (auto pd : typesFound)
testType (*pd);
}
std::unique_ptr<juce::AudioPluginInstance> PluginTests::testOpenPlugin (const juce::PluginDescription& pd)
{
juce::String errorMessage;
auto instance = std::unique_ptr<juce::AudioPluginInstance> (formatManager.createPluginInstance (pd, 44100.0, 512, errorMessage));
expectEquals (errorMessage, juce::String());
expect (instance != nullptr, "Unable to create juce::AudioPluginInstance");
return instance;
}
void PluginTests::testType (const juce::PluginDescription& pd)
{
StopwatchTimer totalTimer;
logMessage ("\nTesting plugin: " + pd.createIdentifierString());
logMessage (pd.manufacturerName + ": " + pd.name + " v" + pd.version);
{
beginTest ("Open plugin (cold)");
StopwatchTimer sw;
deletePluginAsync (testOpenPlugin (pd));
logVerboseMessage ("\nTime taken to open plugin (cold): " + sw.getDescription());
}
{
beginTest ("Open plugin (warm)");
StopwatchTimer sw;
if (auto instance = testOpenPlugin (pd))
{
logVerboseMessage ("\nTime taken to open plugin (warm): " + sw.getDescription());
logMessage (juce::String ("Running tests 123 times").replace ("123",juce::String (options.numRepeats)));
// This sleep is here to allow time for plugin async initialisation as in most cases
// plugins will be added to tracks and then be played a little time later. This sleep
// allows time for this initialisation for tests otherwise they might complete without
// actually having processed anything.
// The exception to this is if the plugin is being rendered there's likely to be no gap
// between construction, initialisation and processing. For this case, plugins should
// check AudioProcessor::isNonRealtime and force initialisation if rendering.
juce::Thread::sleep (150);
auto r = getRandom();
for (int testRun = 0; testRun < options.numRepeats; ++testRun)
{
if (options.numRepeats > 1)
logMessage ("\nTest run: " + juce::String (testRun + 1));
juce::Array<PluginTest*> testsToRun = PluginTest::getAllTests();
if (options.randomiseTestOrder)
{
std::mt19937 random (static_cast<unsigned int> (r.nextInt()));
std::shuffle (testsToRun.begin(), testsToRun.end(), random);
}
for (auto t : testsToRun)
{
if (options.strictnessLevel < t->strictnessLevel
|| (! options.withGUI && t->requiresGUI()))
continue;
if (options.disabledTests.contains (t->name))
{
logMessage ("\nINFO: \"" + t->name + "\" is disabled.");
continue;
}
StopwatchTimer sw2;
beginTest (t->name);
if (t->needsToRunOnMessageThread())
{
juce::WaitableEvent completionEvent;
juce::MessageManager::callAsync ([&, this]() mutable
{
t->runTest (*this, *instance);
completionEvent.signal();
});
completionEvent.wait();
}
else
{
t->runTest (*this, *instance);
}
logVerboseMessage ("\nTime taken to run test: " + sw2.getDescription());
}
}
deletePluginAsync (std::move (instance));
}
}
logVerboseMessage ("\nTime taken to run all tests: " + totalTimer.getDescription());
}