Files
voice-cat/tests/CMakeLists.txt
Talon bad9c7533a
Some checks failed
Build Linux Binaries / linux/amd64 (push) Has been cancelled
Build Linux Binaries / linux/arm64 (push) Has been cancelled
feat(audio): real noise suppression via vendored RNNoise (send + receive)
The two-sided NR plumbing (RemoteStream::recv_ns + the per-listener
vc_set_remote_stream noise_reduction toggle) was wired but inert:
ApmProcessor::create() returned a no-op passthrough, because the
originally-planned webrtc-audio-processing has no working Windows/macOS
build. Drop in RNNoise as the real backend behind the same ApmProcessor
interface, lighting up both NR paths.

- Vendor RNNoise (BSD-3 + CC0) at third_party/rnnoise/ — the vcpkg port
  is !windows !arm, so it can't cover our primary targets. Shrunk int8
  model (78MB -> 11.7MB via upstream scripts/shrink_model.sh), built as a
  standalone C static lib with no RTCD (portable scalar path on x86,
  auto-NEON on arm64) under -DDISABLE_DEBUG_FLOAT. Model is baked in
  (rnnoise_create(NULL)); no runtime file.
- New RnnoiseProcessor (core/src/audio/apm_processor.cpp) selected by
  ApmProcessor::create() when VOICECAT_HAS_NS. Mono/48kHz/480-sample;
  our clock is fixed 48kHz and Opus frame sizes are multiples of 480, so
  no resampling. RT-safe: allocates at construction, lock-free in the
  capture/playback callbacks.
- Receive-side: lit up via the factory; gated to mono streams (a stereo
  stream is a screen-audio share, not voice).
- Send-side (new): vc_set_input_noise_reduction(client, enable) ABI +
  vc_client::mic_ns_, run before input gain/VAD in on_capture_frame. A
  stereo mic is downmixed to mono ONLY when NR is on — with NR off a
  stereo mic keeps full stereo (never collapse mic quality unasked).
- Enable C as a project language for the vendored lib.
- New noise_suppression test: white noise through ApmProcessor::create()
  drops ~99.9% RMS. ctest --preset dev green, 28/28. windows-client DLL
  builds clean with vc_set_input_noise_reduction exported, system-only deps.
- Docs synced: voice.md §10, tech-stack.md §1/§5, third_party/README.md,
  vcpkg.json note, PROGRESS.md, CLAUDE.md.

Client on/off UI toggles (Windows/macOS/iOS) are the remaining follow-up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 13:30:54 +02:00

241 lines
15 KiB
CMake

# Tests use plain asserts + exit codes (no framework dep needed).
# Behavior tests — not just "it compiles" — are how milestones are judged (AGENTS.md).
add_executable(test_smoke test_smoke.cpp)
target_link_libraries(test_smoke PRIVATE voicecat::voicecat)
target_compile_features(test_smoke PRIVATE cxx_std_20)
add_test(NAME smoke COMMAND test_smoke)
# frame_codec has no third-party deps; runs under both skeleton and dev.
# Needs core/src on the include path to reach internal headers (protocol/, session/, etc.).
add_executable(test_frame_codec test_frame_codec.cpp)
target_link_libraries(test_frame_codec PRIVATE voicecat::voicecat)
target_compile_features(test_frame_codec PRIVATE cxx_std_20)
target_include_directories(test_frame_codec PRIVATE ${CMAKE_SOURCE_DIR}/core/src)
add_test(NAME frame_codec COMMAND test_frame_codec)
if(VOICECAT_USE_VCPKG_DEPS)
set(VC_TEST_INTERNAL_INCLUDES
${CMAKE_SOURCE_DIR}/core/src
${CMAKE_SOURCE_DIR}/server/src
${CMAKE_BINARY_DIR}/core/generated) # protobuf-generated headers
add_executable(test_envelope test_envelope.cpp)
target_link_libraries(test_envelope PRIVATE voicecat::voicecat)
target_compile_features(test_envelope PRIVATE cxx_std_20)
target_include_directories(test_envelope PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME envelope COMMAND test_envelope)
add_executable(test_tls_loopback test_tls_loopback.cpp)
target_link_libraries(test_tls_loopback PRIVATE voicecat::voicecat)
target_compile_features(test_tls_loopback PRIVATE cxx_std_20)
target_include_directories(test_tls_loopback PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME tls_loopback COMMAND test_tls_loopback)
# Links voicecat::server (which pulls in voicecat::voicecat + all deps transitively).
add_executable(test_m1_integration test_m1_integration.cpp)
target_link_libraries(test_m1_integration PRIVATE voicecat::server)
target_compile_features(test_m1_integration PRIVATE cxx_std_20)
target_include_directories(test_m1_integration PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME m1_integration COMMAND test_m1_integration)
set_tests_properties(m1_integration PROPERTIES TIMEOUT 60)
# ── M2 unit tests ──────────────────────────────────────────────────────────
add_executable(test_voice_frame test_voice_frame.cpp)
target_link_libraries(test_voice_frame PRIVATE voicecat::voicecat)
target_compile_features(test_voice_frame PRIVATE cxx_std_20)
target_include_directories(test_voice_frame PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME voice_frame COMMAND test_voice_frame)
add_executable(test_media_aead test_media_aead.cpp)
target_link_libraries(test_media_aead PRIVATE voicecat::voicecat)
target_compile_features(test_media_aead PRIVATE cxx_std_20)
target_include_directories(test_media_aead PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME media_aead COMMAND test_media_aead)
add_executable(test_opus_codec test_opus_codec.cpp)
target_link_libraries(test_opus_codec PRIVATE voicecat::voicecat)
target_compile_features(test_opus_codec PRIVATE cxx_std_20)
target_include_directories(test_opus_codec PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME opus_codec COMMAND test_opus_codec)
# PLC cap: after ~2s of pure PLC (no real packets), the mixer emits silence instead of
# comfort noise — bounds the eternal-hiss failure mode (defense-in-depth for the
# disconnect/LEFT fix). White-box AudioEngine test, no server needed.
add_executable(test_plc_cap test_plc_cap.cpp)
target_link_libraries(test_plc_cap PRIVATE voicecat::voicecat)
target_compile_features(test_plc_cap PRIVATE cxx_std_20)
target_include_directories(test_plc_cap PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME plc_cap COMMAND test_plc_cap)
# Jitter-buffer bounded depth: across many talkspurt/silence cycles with a compressed sender
# timeline + reordered stragglers, playout latency must stay bounded (no backward drift /
# ratchet). White-box AudioEngine test, no server needed.
add_executable(test_jitter_depth test_jitter_depth.cpp)
target_link_libraries(test_jitter_depth PRIVATE voicecat::voicecat)
target_compile_features(test_jitter_depth PRIVATE cxx_std_20)
target_include_directories(test_jitter_depth PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME jitter_depth COMMAND test_jitter_depth)
# External playback (iOS VPIO): the mixer-timer thread drives decode+mix with NO hardware
# device and delivers the final mix to the mixed-output sink. White-box AudioEngine test.
add_executable(test_external_playback test_external_playback.cpp)
target_link_libraries(test_external_playback PRIVATE voicecat::voicecat)
target_compile_features(test_external_playback PRIVATE cxx_std_20)
target_include_directories(test_external_playback PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME external_playback COMMAND test_external_playback)
# M2 exit criterion: two headless clients relay encrypted Opus frames via the SFU.
add_executable(test_m2_voice test_m2_voice.cpp)
target_link_libraries(test_m2_voice PRIVATE voicecat::server)
target_compile_features(test_m2_voice PRIVATE cxx_std_20)
target_include_directories(test_m2_voice PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME m2_voice COMMAND test_m2_voice)
set_tests_properties(m2_voice PROPERTIES TIMEOUT 120)
# Same exit criterion, but through the real C ABI (vc_client), not raw sockets —
# proves stream_start/stop/UDP-binding in core/src/core/client.cpp actually work.
add_executable(test_voice_client_abi test_voice_client_abi.cpp)
target_link_libraries(test_voice_client_abi PRIVATE voicecat::server)
target_compile_features(test_voice_client_abi PRIVATE cxx_std_20)
target_include_directories(test_voice_client_abi PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME voice_client_abi COMMAND test_voice_client_abi)
set_tests_properties(voice_client_abi PROPERTIES TIMEOUT 60)
# M3 exit criterion: multi-stream (mic + desktop audio), independent per-stream
# gain/mute/NS, per-channel Opus configurability, talk indicators -- all through the
# real C ABI (vc_client), not raw sockets.
add_executable(test_m3_multistream test_m3_multistream.cpp)
target_link_libraries(test_m3_multistream PRIVATE voicecat::server)
target_compile_features(test_m3_multistream PRIVATE cxx_std_20)
target_include_directories(test_m3_multistream PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME m3_multistream COMMAND test_m3_multistream)
set_tests_properties(m3_multistream PROPERTIES TIMEOUT 60)
# Post-M3 follow-up: device enumeration, VAD/PTT input gate, true stereo playback mixing —
# the items PROGRESS.md's M3 section explicitly carried forward as out of scope.
add_executable(test_vad_ptt_devices test_vad_ptt_devices.cpp)
target_link_libraries(test_vad_ptt_devices PRIVATE voicecat::server)
target_compile_features(test_vad_ptt_devices PRIVATE cxx_std_20)
target_include_directories(test_vad_ptt_devices PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME vad_ptt_devices COMMAND test_vad_ptt_devices)
set_tests_properties(vad_ptt_devices PROPERTIES TIMEOUT 60)
# M4: channel/user/stream snapshot getters (vc_list_channels/vc_list_users/
# vc_list_user_streams) — through the real C ABI against a real in-process server.
add_executable(test_channel_user_list_abi test_channel_user_list_abi.cpp)
target_link_libraries(test_channel_user_list_abi PRIVATE voicecat::server)
target_compile_features(test_channel_user_list_abi PRIVATE cxx_std_20)
target_include_directories(test_channel_user_list_abi PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME channel_user_list_abi COMMAND test_channel_user_list_abi)
set_tests_properties(channel_user_list_abi PROPERTIES TIMEOUT 60)
# M4: TOFU server-identity gate (VC_EVENT_SERVER_IDENTITY / vc_confirm_server_identity /
# vc_get_server_identity_display) — real TLS handshakes against real in-process servers.
add_executable(test_tofu_flow test_tofu_flow.cpp)
target_link_libraries(test_tofu_flow PRIVATE voicecat::server)
target_compile_features(test_tofu_flow PRIVATE cxx_std_20)
target_include_directories(test_tofu_flow PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME tofu_flow COMMAND test_tofu_flow)
set_tests_properties(tofu_flow PROPERTIES TIMEOUT 90)
# M5 Phase 1: permission enforcement + SetPermissionRequest + channel create.
add_executable(test_m5_permissions test_m5_permissions.cpp)
target_link_libraries(test_m5_permissions PRIVATE voicecat::server)
target_compile_features(test_m5_permissions PRIVATE cxx_std_20)
target_include_directories(test_m5_permissions PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME m5_permissions COMMAND test_m5_permissions)
set_tests_properties(m5_permissions PROPERTIES TIMEOUT 60)
# M5 Phase 2: kick/ban/move/server-mute.
add_executable(test_m5_kick_ban_move_mute test_m5_kick_ban_move_mute.cpp)
target_link_libraries(test_m5_kick_ban_move_mute PRIVATE voicecat::server)
target_compile_features(test_m5_kick_ban_move_mute PRIVATE cxx_std_20)
target_include_directories(test_m5_kick_ban_move_mute PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME m5_kick_ban_move_mute COMMAND test_m5_kick_ban_move_mute)
set_tests_properties(m5_kick_ban_move_mute PROPERTIES TIMEOUT 90)
# M5 Phase 3: in-app admin account management.
add_executable(test_m5_admin_accounts test_m5_admin_accounts.cpp)
target_link_libraries(test_m5_admin_accounts PRIVATE voicecat::server)
target_compile_features(test_m5_admin_accounts PRIVATE cxx_std_20)
target_include_directories(test_m5_admin_accounts PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME m5_admin_accounts COMMAND test_m5_admin_accounts)
set_tests_properties(m5_admin_accounts PROPERTIES TIMEOUT 90)
# M5 Phase 4: channel CRUD & password enforcement.
add_executable(test_m5_channel_crud test_m5_channel_crud.cpp)
target_link_libraries(test_m5_channel_crud PRIVATE voicecat::server)
target_compile_features(test_m5_channel_crud PRIVATE cxx_std_20)
target_include_directories(test_m5_channel_crud PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME m5_channel_crud COMMAND test_m5_channel_crud)
set_tests_properties(m5_channel_crud PROPERTIES TIMEOUT 90)
# Disconnect/timeout: server broadcasts UserEvent::LEFT on TCP drop (no more ghost
# users or eternal PLC hiss on peers). Also covers the keepalive/reaper paths added
# alongside the LEFT-broadcast fix.
add_executable(test_disconnect_left test_disconnect_left.cpp)
target_link_libraries(test_disconnect_left PRIVATE voicecat::server)
target_compile_features(test_disconnect_left PRIVATE cxx_std_20)
target_include_directories(test_disconnect_left PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME disconnect_left COMMAND test_disconnect_left)
set_tests_properties(disconnect_left PROPERTIES TIMEOUT 90)
# Reaper: half-open connections (no TCP EOF) are dropped after the configurable timeout,
# peers get UserEvent::LEFT, the stale client gets disconnected. Uses a 2s timeout for
# fast test turnaround (production default is 45s).
add_executable(test_reaper_timeout test_reaper_timeout.cpp)
target_link_libraries(test_reaper_timeout PRIVATE voicecat::server)
target_compile_features(test_reaper_timeout PRIVATE cxx_std_20)
target_include_directories(test_reaper_timeout PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME reaper_timeout COMMAND test_reaper_timeout)
set_tests_properties(reaper_timeout PROPERTIES TIMEOUT 30)
# DRED toggle: per-channel dred flag round-trips through protocol; encoder initialises
# with DRED; PCM injection through DRED-enabled encode path runs without crash.
add_executable(test_dred_toggle test_dred_toggle.cpp)
target_link_libraries(test_dred_toggle PRIVATE voicecat::server)
target_compile_features(test_dred_toggle PRIVATE cxx_std_20)
target_include_directories(test_dred_toggle PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME dred_toggle COMMAND test_dred_toggle)
set_tests_properties(dred_toggle PROPERTIES TIMEOUT 60)
# External PCM feed/tap API:
# test_feed_pcm_round_trip — vc_stream_feed_pcm (mono), verified via pcm_sink.
# test_feed_pcm_stereo — vc_stream_feed_pcm (stereo, Music Room), L != R assertion.
# test_pcm_sink — vc_set_pcm_sink metadata (user_id / stream_id / sr) + disable.
add_executable(test_external_pcm test_external_pcm.cpp)
target_link_libraries(test_external_pcm PRIVATE voicecat::server)
target_compile_features(test_external_pcm PRIVATE cxx_std_20)
target_include_directories(test_external_pcm PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME external_pcm COMMAND test_external_pcm)
set_tests_properties(external_pcm PROPERTIES TIMEOUT 90)
# Non-20ms channel frame_ms: the fixed 48k/20ms engine clock is reframed to the channel's
# Opus window before encoding. 40ms (accumulate) and 10ms (split) feed->sink round trips.
add_executable(test_frame_ms_reframe test_frame_ms_reframe.cpp)
target_link_libraries(test_frame_ms_reframe PRIVATE voicecat::server)
target_compile_features(test_frame_ms_reframe PRIVATE cxx_std_20)
target_include_directories(test_frame_ms_reframe PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME frame_ms_reframe COMMAND test_frame_ms_reframe)
set_tests_properties(frame_ms_reframe PROPERTIES TIMEOUT 90)
# Per-channel sample_rate as an Opus bandwidth cap (OPUS_SET_MAX_BANDWIDTH): a 7 kHz tone is
# attenuated on an 8 kHz (narrowband) channel vs a 48 kHz (full-band) channel.
add_executable(test_channel_samplerate test_channel_samplerate.cpp)
target_link_libraries(test_channel_samplerate PRIVATE voicecat::server)
target_compile_features(test_channel_samplerate PRIVATE cxx_std_20)
target_include_directories(test_channel_samplerate PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME channel_samplerate COMMAND test_channel_samplerate)
set_tests_properties(channel_samplerate PROPERTIES TIMEOUT 90)
# Noise suppression: the RNNoise backend behind ApmProcessor actually denoises (docs/voice.md
# §10-11). Links core only; reaches the internal audio/ headers for ApmProcessor::create().
add_executable(test_noise_suppression test_noise_suppression.cpp)
target_link_libraries(test_noise_suppression PRIVATE voicecat::voicecat)
target_compile_features(test_noise_suppression PRIVATE cxx_std_20)
target_include_directories(test_noise_suppression PRIVATE ${VC_TEST_INTERNAL_INCLUDES})
add_test(NAME noise_suppression COMMAND test_noise_suppression)
endif()