summaryrefslogtreecommitdiff
path: root/src/tests/gpu/test_spectool.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-09 20:27:04 +0100
committerskal <pascal.massimino@gmail.com>2026-02-09 20:27:04 +0100
commiteff8d43479e7704df65fae2a80eefa787213f502 (patch)
tree76f2fb8fe8d3db2c15179449df2cf12f7f54e0bf /src/tests/gpu/test_spectool.cc
parent12378b1b7e9091ba59895b4360b2fa959180a56a (diff)
refactor: Reorganize tests into subsystem subdirectories
Restructured test suite for better organization and targeted testing: **Structure:** - src/tests/audio/ - 15 audio system tests - src/tests/gpu/ - 12 GPU/shader tests - src/tests/3d/ - 6 3D rendering tests - src/tests/assets/ - 2 asset system tests - src/tests/util/ - 3 utility tests - src/tests/common/ - 3 shared test helpers - src/tests/scripts/ - 2 bash test scripts (moved conceptually, not physically) **CMake changes:** - Updated add_demo_test macro to accept LABEL parameter - Applied CTest labels to all 36 tests for subsystem filtering - Updated all test file paths in CMakeLists.txt - Fixed common helper paths (webgpu_test_fixture, etc.) - Added custom targets for subsystem testing: - run_audio_tests, run_gpu_tests, run_3d_tests - run_assets_tests, run_util_tests, run_all_tests **Include path updates:** - Fixed relative includes in GPU tests to reference ../common/ **Documentation:** - Updated doc/HOWTO.md with subsystem test commands - Updated doc/CONTRIBUTING.md with new test organization - Updated scripts/check_all.sh to reflect new structure **Verification:** - All 36 tests passing (100%) - ctest -L <subsystem> filters work correctly - make run_<subsystem>_tests targets functional - scripts/check_all.sh passes Backward compatible: make test and ctest continue to work unchanged. handoff(Gemini): Test reorganization complete. 36/36 tests passing.
Diffstat (limited to 'src/tests/gpu/test_spectool.cc')
-rw-r--r--src/tests/gpu/test_spectool.cc69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/tests/gpu/test_spectool.cc b/src/tests/gpu/test_spectool.cc
new file mode 100644
index 0000000..984322a
--- /dev/null
+++ b/src/tests/gpu/test_spectool.cc
@@ -0,0 +1,69 @@
+// This file is part of the 64k demo project.
+// It performs an end-to-end test of the spectool's analysis capability.
+// Generates a test WAV, analyzes it, and verifies the resulting .spec file.
+
+#include "audio/audio.h"
+#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "miniaudio.h"
+
+// struct SpecHeader { ... } -> now in audio.h
+
+void generate_test_wav(const char* path, int duration_seconds) {
+ ma_encoder_config config =
+ ma_encoder_config_init(ma_encoding_format_wav, ma_format_f32, 1, 32000);
+ ma_encoder encoder;
+
+ if (ma_encoder_init_file(path, &config, &encoder) != MA_SUCCESS) {
+ printf("Failed to create test WAV file.\n");
+ exit(1);
+ }
+
+ int num_frames = 32000 * duration_seconds;
+ for (int i = 0; i < num_frames; ++i) {
+ float sample = 0.5f * sinf(2.0f * 3.14159f * 440.0f * i / 32000.0f);
+ ma_encoder_write_pcm_frames(&encoder, &sample, 1, NULL);
+ }
+
+ ma_encoder_uninit(&encoder);
+}
+
+int main() {
+ const char* test_wav = "test_input.wav";
+ const char* test_spec = "test_output.spec";
+
+ printf("Generating test WAV...\n");
+ generate_test_wav(test_wav, 1);
+
+ printf("Running spectool analyze...\n");
+ char command[256];
+ snprintf(command, sizeof(command), "./spectool analyze %s %s", test_wav,
+ test_spec);
+ int ret = system(command);
+ assert(ret == 0);
+
+ printf("Verifying .spec file...\n");
+ FILE* f = fopen(test_spec, "rb");
+ assert(f != NULL);
+
+ SpecHeader header;
+ size_t read = fread(&header, sizeof(SpecHeader), 1, f);
+ assert(read == 1);
+ assert(strncmp(header.magic, "SPEC", 4) == 0);
+ assert(header.version == 1);
+ assert(header.dct_size == 512);
+ assert(header.num_frames > 0);
+
+ fclose(f);
+ printf("Spectool E2E test PASSED\n");
+
+ // Clean up
+ remove(test_wav);
+ remove(test_spec);
+
+ return 0;
+}