Add misc unit tests + harden the WAV chunk walk

Fills small coverage gaps:
- shared_memory_test: SharedMemory create-or-open aliasing, move (steal + empty
  the source, no double-free), reset, open-missing.
- wav_test: malformed input -- truncation, bad magic, missing data chunk,
  over-long data size (clamps), odd-sized chunk (word-align skip), and a corrupt
  ~4 GB chunk_size. The reader gains an advance guard so that last case can't wrap
  pos on a 32-bit size_t (x86) or spin the walk; it stops cleanly.
- tool_paths_test: deployed_artifact_path resolution -- next-to-exe, one-dir-up,
  and the not-found fallback -- with real marker files.
- audio_ring_test: an overrun-at-the-seam case (write head near the end: a
  wrapping push that fits vs. an over-capacity wrapping push dropped whole),
  exercising the wrap split + overrun together, not just at offset 0.

The injector bitness check isn't added as a unit test: is_wow64_process is
file-local and the real WOW64 path needs a 32-bit target, so it stays
inspection-covered (and exercised by the x86 injection path).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-24 02:05:35 +02:00
parent 9cc69d1dcd
commit 2802fbddf6
7 changed files with 393 additions and 3 deletions

View File

@@ -89,6 +89,22 @@ target_include_directories(protocol_test PRIVATE ${CMAKE_SOURCE_DIR}/hook/src)
target_link_libraries(protocol_test PRIVATE coop_common)
add_test(NAME protocol_test COMMAND protocol_test)
# Unit test for the SharedMemory RAII wrapper (create-or-open aliasing, move, reset, open-missing).
add_executable(shared_memory_test shared_memory_test.cpp)
target_link_libraries(shared_memory_test PRIVATE coop_common)
add_test(NAME shared_memory_test COMMAND shared_memory_test)
# Unit test for the WAV reader's robustness on malformed input (truncation, bad magic, missing/
# over-long/odd/corrupt chunks). Header-only.
add_executable(wav_test wav_test.cpp)
target_link_libraries(wav_test PRIVATE coop_common)
add_test(NAME wav_test COMMAND wav_test)
# Unit test for deployed-artifact path resolution (next-to-exe vs one-dir-up vs not-found fallback).
add_executable(tool_paths_test tool_paths_test.cpp)
target_link_libraries(tool_paths_test PRIVATE coop_common)
add_test(NAME tool_paths_test COMMAND tool_paths_test)
# Unit test for the audio mixer math (decode/sum/soft-clip/encode). Header-only.
add_executable(audio_mix_test audio_mix_test.cpp)
target_include_directories(audio_mix_test PRIVATE ${CMAKE_SOURCE_DIR}/host/src)
@@ -336,6 +352,9 @@ coop_output_subdir(tests
mkb_ring_test
log_ring_test
protocol_test
shared_memory_test
wav_test
tool_paths_test
mkb_map_test
audio_mix_test
tone_analysis_test