From 9702ea06ced9585a705c41186f814700bc859dcd Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 7 Feb 2026 10:01:03 +0100 Subject: test(gpu): Add automatic validation for effect test coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: When new effects are added to demo_effects.h, developers might forget to update test_demo_effects.cc, leading to untested code. Solution: Added compile-time constants and runtime assertions to enforce test coverage: 1. Added EXPECTED_POST_PROCESS_COUNT = 8 2. Added EXPECTED_SCENE_COUNT = 6 3. Runtime validation in each test function 4. Fails with clear error message if counts don't match Error message when validation fails: ✗ COVERAGE ERROR: Expected N effects, but only tested M! ✗ Did you add a new effect without updating the test? ✗ Update EXPECTED_*_COUNT in test_demo_effects.cc Updated CONTRIBUTING.md with mandatory test update requirement: - Added step 3 to "Adding a New Visual Effect" workflow - Clear instructions on updating effect counts - Verification command examples This ensures no effect can be added without corresponding test coverage. Tested validation by intentionally breaking count - error caught correctly. --- doc/CONTRIBUTING.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/CONTRIBUTING.md b/doc/CONTRIBUTING.md index 4b85e9f..7d206a5 100644 --- a/doc/CONTRIBUTING.md +++ b/doc/CONTRIBUTING.md @@ -255,7 +255,18 @@ Make sure everything is reflected in clang-format. - Implement `compute()` if you need GPU-side physics or state updates. - Implement `render()` to record WebGPU draw commands. 2. **Register**: Add an `EFFECT` entry to `assets/demo.seq` specifying the class name, start/end times, and any constructor arguments. -3. **Verify**: Build with `DEMO_ALL_OPTIONS=ON` and use `--seek` to test your effect at its specific timestamp. +3. **Update Tests** (REQUIRED): Add your effect to `src/tests/test_demo_effects.cc`: + - Add effect to the appropriate test list (`test_post_process_effects()` or `test_scene_effects()`) + - Increment `EXPECTED_POST_PROCESS_COUNT` or `EXPECTED_SCENE_COUNT` at the top of the file + - If your effect requires `Renderer3D` with full shader setup, add it to the `requires_3d` check + - The test will fail with a clear error message if you forget this step +4. **Verify**: Build with `DEMO_ALL_OPTIONS=ON` and run tests: + ```bash + cmake -S . -B build -DDEMO_BUILD_TESTS=ON + cmake --build build --target test_demo_effects + cd build && ./test_demo_effects + ``` + Then test your effect at its specific timestamp with `--seek`. ### Audio Subsystem Initialization -- cgit v1.2.3