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

@@ -126,6 +126,47 @@ int main()
check(h->overruns.load() == 1, "overruns not bumped on success");
}
// --- Seam interaction: with the write head near the end, a wrapping push fits while an
// over-capacity wrapping push is dropped whole (the overrun + wrap split happening together). ---
{
const std::uint32_t cap = 512;
std::vector<std::uint8_t> storage;
AudioRingHeader* h = make_ring(storage, cap);
// Advance the write head near the end so subsequent writes wrap the buffer seam.
std::vector<std::uint8_t> pre(400, 0x55);
check(audio_ring_push(*h, pre.data(), 400, 1), "seam: prime to advance the write head");
std::vector<std::uint8_t> sink(400, 0);
check(audio_ring_pop(*h, sink.data(), 400) == 400, "seam: drain it (head now near the end)");
check(audio_ring_available(*h) == 0, "seam: empty again, write head near the seam");
// A 200-byte push now splits across the seam; it fits, so the data must survive the split.
std::vector<std::uint8_t> wrap(200);
for (std::uint32_t i = 0; i < 200; ++i)
{
wrap[i] = static_cast<std::uint8_t>(i);
}
check(audio_ring_push(*h, wrap.data(), 200, 1), "seam: a wrapping push that fits is accepted");
check(audio_ring_available(*h) == 200, "seam: 200 bytes present after the wrapping push");
// A 400-byte push would also wrap but can't fit (free = 312) -> dropped whole, overruns++.
const std::uint64_t before = h->overruns.load();
std::vector<std::uint8_t> big(400, 0xEE);
check(!audio_ring_push(*h, big.data(), 400, 1), "seam: an over-capacity wrapping push is rejected whole");
check(h->overruns.load() == before + 1, "seam: overrun counted");
check(audio_ring_available(*h) == 200, "seam: rejected wrapping push left the ring untouched");
// Pop the wrapped payload back and verify integrity across the seam.
std::vector<std::uint8_t> out(200, 0);
check(audio_ring_pop(*h, out.data(), 200) == 200, "seam: pop the wrapped payload");
bool ok = true;
for (std::uint32_t i = 0; i < 200; ++i)
{
ok = ok && out[i] == static_cast<std::uint8_t>(i);
}
check(ok, "seam: wrapping push/pop preserved data across the buffer seam");
}
std::printf(g_failures == 0 ? "AUDIO RING TEST PASS\n" : "AUDIO RING TEST FAILED (%d)\n", g_failures);
return g_failures == 0 ? 0 : 1;
}