Rust processor tests
Test real audio, lifecycle, the C ABI, allocations and parity between runtimes.
The soundor SDK includes a pure-Rust test harness. It runs your actual
processor without a plugin host, a browser, or the rendering engine. gen creates a starter crate when lib/Cargo.toml is absent, including a
processor integration test alongside lib/src/processor.rs.
Run the crate
Generate the config contract first:
pnpm gen
cargo check --manifest-path lib/Cargo.toml
cargo test --manifest-path lib/Cargo.toml
cargo clippy --all-targets --manifest-path lib/Cargo.toml -- -D warnings
cargo fmt --check --manifest-path lib/Cargo.tomlThe template's pnpm test:rust runs generation and Cargo tests together. Commit
lib/Cargo.lock so CI resolves the same third-party dependencies. There is
no compilation in npm postinstall.
Audio and lifecycle
In a unit test in lib/src/processor.rs, for a processor with a gain parameter:
#[cfg(test)]
mod tests {
use super::PluginProcessor;
use soundor::testing::{Status, TestProcessor};
#[test]
fn gain_and_reprepare() {
let mut processor = TestProcessor::<PluginProcessor>::new()
.sample_rate(48_000.0)
.block_size(64)
.channels(1)
.parameter("gain", 0.5)
.build();
assert_eq!(processor.process(&[vec![1.0, -1.0, 0.0]])[0], [0.5, -0.5, 0.0]);
assert_eq!(processor.reset(), Status::Ok);
assert_eq!(processor.prepare(44_100.0, 256), Status::Ok);
assert_eq!(processor.process(&[vec![0.5]])[0], [0.25]);
}
}build() constructs and prepares the processor; dropping the harness destroys
it. process divides input into blocks no larger than prepared. channels,
layout, and named_layout choose layouts declared by your config.
parameters_mut exposes typed values; set_parameter checks a plain value by
ID. transport_mut supplies transport snapshots. state_mut is the
ctx.state the processor reads (audio: true fields), the config's defaults
to start with: change it as the plugin's state would, and the next block sees
it (processor.state_mut().pattern.set(&[60, 67]), false when longer than its
maxLength). process_buses and try_process_buses exercise sidechains and
multiple outputs.
Test unity and zero gain, negative samples, silence, mono and stereo, irregular and empty blocks, repeated blocks, changed parameters, sample-rate changes, reset and separate instances. Add tests of state particular to your DSP, such as clearing a delay line on reset. Parameter smoothing means a changed value may take time to settle; include that transition in expected audio.
Count allocations
Install the SDK allocator in the test binary, outside the test function:
#[cfg(test)]
#[global_allocator]
static ALLOCATOR: soundor::testing::CountingAllocator = soundor::testing::CountingAllocator;After processor.process(...), assert processor.allocations() == 0.
The count covers allocator calls on the processing thread during the processor
call, including reallocations and frees. The harness's input/output vectors
are outside that interval. count_allocations can measure reset or another
specific operation. A test without the counting allocator fails instead of
silently claiming that no allocation occurred.
Exercise the largest expected buffers, automation, bypass, and conditional DSP
paths. The repository also counts C++ operator new calls in the engine's processor
bridge;
AddressSanitizer owns those operators in sanitizer builds, so its allocation
counter is disabled there. Rust allocator tests run separately. These counts
do not detect arbitrary C allocations, every aligned allocation, blocking calls,
page faults, or scheduler delays. Review callback code and dependencies; passing
counts do not establish a hard real-time guarantee.
Test adapters as well as DSP
soundor::testing::NativeProcessor accepts the function table returned by
__soundor_exports::exports() (the internal module generated by soundor::export!)
and calls the actual C ABI. It supports
raw descriptors for testing invalid lengths, layouts and lifecycle transitions.
This complements a pure-Rust test; it does not load a plugin. The SDK's
tests/ffi.rs shows buffer boundaries, null descriptors, ABI versions, panic
containment, independent instances and destruction.
To exercise the plugin itself, build the VST3 and use the VST3 host or end-to-end tools to feed it real samples. In this repository:
pnpm --filter @soundor/vst3-runtime test:pluginThat test checks the Rust gain through the actual plugin, mono/stereo layout negotiation, different block sizes and parameter changes. Settled gain samples match the float32 reference exactly, treating signed zero as equal.
WebAssembly and cross-runtime parity
The Web runtime tests compile a real Rust fixture to WASM, instantiate it, prepare it, write samples into linear memory, call its exports and check the output. They cover parameters, mono/stereo, irregular blocks, reset, independent instances and failures. The Chromium suite runs that same module through an actual AudioWorklet in an OfflineAudioContext, including posted parameter changes, published values, panics and stale contracts:
pnpm --filter @soundor/web-runtime test
pnpm --filter @soundor/web-runtime test:browserSoundor's end-to-end suite (tests/e2e/e2e/vst3/parity.test.ts) compares its
plugin's real VST3 output with its WASM build, given identical seeded input,
parameters, audio state and block sizes. Run it with
pnpm --filter soundor-e2e test:vst3 after installing the WASM target.
Transcendental functions can differ across native and WASM math libraries, so
a DSP that uses them needs a tolerance (an absolute sample error below 1e-6
is well under what a 24-bit converter resolves). Use tolerances appropriate to
your DSP and also assert that the signal is nonzero so silence cannot pass as
parity.
These layers each exercise their own boundary. A native WasmHandle unit test
alone is not a WASM test, and invoking a worklet class in Node alone is not a
browser AudioWorklet test. Keep both fast DSP tests and actual runtime tests.
The controller
A crate that exports a controller tests it with
soundor::testing::TestController, which runs the controller as a runtime
runs it (its stores, control queue, worker and dispatch) on a TestHost that
stands in for the runtime's parameters, state, History and presets.
TestController::for_processor(&processor) shares a TestProcessor's
resources, so what the controller publishes is what the next process()
reads. See Testing in the controller guide.