From 17cc5a009c77317a120f606bcba0c31a01bd7ee1 Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 10 Sep 2026 22:04:45 +0200 Subject: [PATCH] tests: removed hardcoded paths, tests with slimmable models --- tools/test/test_get_dsp.cpp | 50 ++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/tools/test/test_get_dsp.cpp b/tools/test/test_get_dsp.cpp index 538f70c0..79e784c5 100644 --- a/tools/test/test_get_dsp.cpp +++ b/tools/test/test_get_dsp.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -14,6 +15,7 @@ #include "NAM/get_dsp.h" #include "NAM/registry.h" +#include "NAM/slimmable.h" namespace test_get_dsp { @@ -236,27 +238,51 @@ void process_buffers(nam::DSP* dsp, int num_buffers, int buffer_size) } } -void test_load_and_process_nam_files() +std::vector example_nam_files() { - // Test loading and processing three different .nam files - // Paths are relative to root directory where tests run (./build/tools/run_tests) - const std::vector nam_files = {"example_models/wavenet.nam", "example_models/lstm.nam", - "example_models/wavenet_condition_dsp.nam", - "example_models/wavenet_a2_feature_test.nam"}; + // Paths are relative to the repo root, where CI runs ./build/tools/run_tests + const std::filesystem::path dir("example_models"); + assert(std::filesystem::is_directory(dir)); + std::vector nam_files; + for (const auto& entry : std::filesystem::directory_iterator(dir)) + { + if (entry.is_regular_file() && entry.path().extension() == ".nam") + nam_files.push_back(entry.path()); + } + std::sort(nam_files.begin(), nam_files.end()); + assert(!nam_files.empty()); + return nam_files; +} + +void test_load_and_process_nam_files() +{ + // Smoke-test every shipped .nam: load via the public get_dsp() path, Reset, process + // a few blocks, and (when applicable) exercise SlimmableModel. This is intentionally + // architecture-agnostic so a new example file is covered without editing a hardcoded list. const int num_buffers = 3; const int buffer_size = 64; + nam::DspLoadOptions options; + options.prewarm = false; - for (const auto& nam_file : nam_files) + for (const auto& model_path : example_nam_files()) { - std::filesystem::path model_path(nam_file); - - // Load the model - std::unique_ptr dsp = nam::get_dsp(model_path); + nam::dspData returned_config; + std::unique_ptr dsp = nam::get_dsp(model_path, returned_config, options); assert(dsp != nullptr); - // Process buffers through the model + auto* slimmable = dynamic_cast(dsp.get()); + std::cout << " smoke " << model_path.generic_string() << " architecture=" << returned_config.architecture + << " in=" << dsp->NumInputChannels() << " out=" << dsp->NumOutputChannels() + << " slimmable=" << (slimmable != nullptr ? "yes" : "no") << std::endl; + process_buffers(dsp.get(), num_buffers, buffer_size); + + if (slimmable != nullptr) + { + slimmable->SetSlimmableSize(0.5); + process_buffers(dsp.get(), num_buffers, buffer_size); + } } }