Skip to content

test: characterize audio-io.c before media-io port - #120

Merged
zackees merged 3 commits into
obs-rust:masterfrom
chriscoveries:char/audio-io-test
Oct 11, 2026
Merged

zackees merged 3 commits into
obs-rust:masterfrom
chriscoveries:char/audio-io-test

Conversation

@chriscoveries

@chriscoveries chriscoveries commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Phase 5 ports libobs/media-io/ to Rust, but media-io/audio-io.c had no test at all
— not even a characterization test. There is nothing to port against, so the first
Rust-portable unit of that directory cannot be verified. Refs #45.

Root cause

No test_audio_io.c exists, and media-io/audio-io.c is not covered by any test
target. Per docs/rust-port/testing-policy.md a port is only validated once the
original C behavior is characterized first — "characterized, not endorsed".

Fix

Adds test/cmocka/test_audio_io.c, pinning the current C behavior of
audio_output_open/close/connect/disconnect/active and the getters. No production
code changes.

Pins:

  • open(): AUDIO_OUTPUT_INVALIDPARAM for unset format/name/rate/speakers, no
    thread spawned, *audio untouched. Getters mirror audio_output_info
    (interleaved float stereo → 1 plane / 2 ch / 8 B; planar 16-bit 5.1 → 6 planes /
    6 ch / 2 B).
  • connect(): NULL/zero conversion fields fall back to the output info; a duplicate
    (callback, param) is refused while the same callback with a different param
    registers a second input; out-of-range mix index or NULL audio returns false.
  • active() tracks registered mix inputs through connect/disconnect.
  • The input thread starts at open() and invokes the callback on the audio clock.
  • Characterized crashes — pinned in a forked child, "characterized, not
    endorsed": unguarded NULL getters, and audio_output_open with no obs core running,
    where the spawned thread dereferences obs->name_store on entry.

Alternatives considered, rejected: porting first and characterizing after (the policy
requires the C behavior pinned before a port, otherwise a ported bug becomes the
specification); a hand-rolled harness instead of cmocka (loses signal handling for the
characterized-crash pins).

Evidence

  • Fork CI (self-hosted x86-64 Linux: lint, Rust Tiers 1–3, Docker Tier 2 OFF/ON) passed at 94251a45c: https://github.com/chriscoveries/obsrust-fork/actions/runs/38108904258. test_audio_io passes with the Rust port OFF and ON.
  • That CI container has no display, so the obs-core-dependent pins skip there and only the env-independent pins run. The display-dependent pins (input thread, connect/active on a live output) need xvfb-run or a desktop session. Under xvfb-run in the same Tier 2 container on x86-64 Linux, 20 runs each with the Rust port OFF and ON came out identical: 7 pass, 1 skip, 0 fail per run, no flake. The skip is open_crashes_without_obs_core, which needs the obs core absent. input_thread_runs takes about 230–320 ms, well inside its 3 s timeout
  • The crash pins run in forked children with cmocka's handlers reset, POSIX only.

Compatibility & risk

  • C API/ABI: none — a test target only, no production file touched.
  • Behavior: none. Nothing in the shipped binary changes.
  • Platforms: 4/8 need a display on Linux (the audio clock needs the obs core) and skip in a headless container. A 5th, open_crashes_without_obs_core, needs the obs core absent and skips when one is present. The crash pins are POSIX-only.

Status

Ready for review. Since the rebase (thanks @zackees), two small test-only commits:

  • silent_output tolerates a NULL param, since connect() accepts one and the callback still runs on the audio thread.
  • The input-thread test now waits on an os_event signalled by the callback (3 s timeout) instead of a sleep poll, and frees that event only after audio_output_close() has joined the thread.

The crash pins depend on fork/signal handling; if your CI hosts need an opt-out flag for them, say so and I'll add one.


Thank you to the obs-rust maintainers and contributors for building this project in the open. In the American spirit of free expression and individual independence, and with the principle of judging contributions on their merit alone, this PR is a small piece of what independent people can build when they come together.

@zackees

zackees commented Oct 10, 2026

Copy link
Copy Markdown
Member

Rebased onto master (old head b2891a4, replaced with --force-with-lease). The test/cmocka/CMakeLists.txt conflict is resolved by appending the test_audio_io block to master's file. As a characterization test it pins current C behaviour: test_audio_io passes with the Rust port OFF and ON (47/47). No fail_msg is used. The local gate passes and is stamped. Mark it ready when you're happy.

@zackees
zackees force-pushed the char/audio-io-test branch from b2891a4 to 325a49d Compare October 10, 2026 22:45
zackees pushed a commit to swilk19/obs-studio that referenced this pull request Oct 11, 2026
Pins the header-inline helpers before the Rust port: get_audio_channels
for every enum speaker_layout value, get_audio_bytes_per_channel and
is_audio_planar for every enum audio_format value, get_audio_planes for
every format and layout pair, get_audio_size and get_total_audio_size
(including TOTAL_AUDIO_SIZE), and the audio_frames_to_ns and
ns_to_audio_frames conversions.

Values outside the enums are characterized: an unknown layout,
including 7 (the gap before SPEAKERS_7POINT1 = 8), has 0 channels, and
an unknown format has 0 bytes per channel and is interleaved, so it has
one plane. Planar sizes ignore the layout, even an unknown one.

The conversions truncate, so a frames -> ns -> frames round trip can
lose a frame. ns_to_audio_frames takes a sample rate of 0 (it is the
multiplier) and returns 0. The large-value cases are inputs where both
util_mul_div64 paths agree; the per-platform differences and division
by zero stay with test_util_uint64.c.

Nothing is swapped, so the test passes with ENABLE_RUST_LIBOBS OFF and
ON alike. It is separate from the audio-io.c characterization in obs-rust#120
(test_audio_io.c), which needs a running obs core.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chriscoveries

Copy link
Copy Markdown
Contributor Author

Thanks for the rebase, @zackees, and sorry it sat waiting on us. Two small test-only commits since then:

  • silent_output tolerates a NULL param. connect() accepts one, and the callback still runs on the audio thread for that input.
  • input_thread_runs now waits on an event signalled by the input callback (3 s timeout) instead of a sleep poll, and frees the event only after audio_output_close() has joined the thread.

CI on our runners passed at 94251a4 (https://github.com/chriscoveries/obsrust-fork/actions/runs/38108904258). Under xvfb-run, 20 runs each with the Rust port OFF and ON gave 7 pass / 1 skip / 0 fail every time. I've updated the description to match and marked it ready.

@chriscoveries
chriscoveries marked this pull request as ready for review October 11, 2026 04:15
chriscoveries and others added 3 commits October 10, 2026 21:24
cmocka test pinning the current C behavior of libobs/media-io/
audio-io.c ahead of the obs-media-io port (Phase 5). audio-io.c is the
smallest media-io unit not already claimed by an open port order.

- open(): AUDIO_OUTPUT_INVALIDPARAM for unset format/name/rate/speakers
  (no thread spawned, *audio untouched); getters mirror audio_output_info
  (interleaved float stereo: 1 plane / 2 ch / 8-byte block; planar
  16-bit 5.1: 6 planes / 6 ch / 2-byte block).
- connect(): NULL/zero conversion fields fall back to the output info;
  duplicate (callback, param) on one mix is refused while the same
  callback with a different param registers a second input; out-of-range
  mix index and NULL audio return false.
- active(): tracks registered mix inputs through connect/disconnect.
- Thread model: open() spawns the input thread immediately and the
  callback fires on the audio clock.
- Characterized crashes (not endorsed): the unguarded NULL getters and,
  with no obs core running, audio_output_open itself die by signal
  (the spawned thread dereferences obs->name_store on entry) - each
  pinned in a forked child with cmocka's signal handlers reset.

The behavioral pins need a running obs core (obs_startup), which needs
a display on Linux; they skip in the headless gate and run under
xvfb-run.

Refs #45

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Local-Gate: v1 tree=f3d2e26bde1bcfec8370af8c615fa43998fc9ae9 secs=350 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791672334,"gate":"rust/all/fmt","host":"linux-x86_64","key":"f06beafdad8c0e6401d54ec504cdbb4c6ff8cc9c99298d7770b1042156188009","lane":"lint","parents":["b3cc16f7cbb177da70d2d0997a15d111f7dee3ec"],"secs":199,"stamp":"68289f5197c34c3b485811e11aef0a06","tree":"f3d2e26bde1bcfec8370af8c615fa43998fc9ae9","v":1,"via":"run"}
Ci-Attestation: {"at":1791672334,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"f06beafdad8c0e6401d54ec504cdbb4c6ff8cc9c99298d7770b1042156188009","lane":"lint","parents":["b3cc16f7cbb177da70d2d0997a15d111f7dee3ec"],"secs":199,"stamp":"ea4878636b524b67d0b5a5c00246cd9b","tree":"f3d2e26bde1bcfec8370af8c615fa43998fc9ae9","v":1,"via":"run"}
Ci-Attestation: {"at":1791672334,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"9b440df8274dd21e1d86abf9f72adc95f209321fa7b3613730625747620dda42","lane":"rust-test","parents":["b3cc16f7cbb177da70d2d0997a15d111f7dee3ec"],"secs":78,"stamp":"9a81bd835884cc8f59413b7b65a44cac","tree":"f3d2e26bde1bcfec8370af8c615fa43998fc9ae9","v":1,"via":"run"}
Ci-Attestation: {"at":1791672334,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"b6e993eabe33d303d6a813f6a7b6c6c5edf09ddebf517c252f712b9d95b33f63","lane":"tier2-linux","parents":["b3cc16f7cbb177da70d2d0997a15d111f7dee3ec"],"secs":71,"stamp":"8e4d35b0e6cf8b077f8de1178e0f2bfa","tree":"f3d2e26bde1bcfec8370af8c615fa43998fc9ae9","v":1,"via":"run"}
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Local-Gate: v1 tree=18904b28bd85ff6ff08ce80f10dae94dda139a76 secs=38 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791675132,"gate":"rust/all/fmt","host":"linux-x86_64","key":"ba65b923f501ad750e65692f42aaa0a23a3021236d6ae0efd3f1c94918d7cee1","lane":"lint","parents":["325a49d29d0d9051e6b473e980fad71b822c6f87"],"secs":5,"stamp":"db7e536db53a4bb710d35628331746f3","tree":"18904b28bd85ff6ff08ce80f10dae94dda139a76","v":1,"via":"run"}
Ci-Attestation: {"at":1791675132,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"ba65b923f501ad750e65692f42aaa0a23a3021236d6ae0efd3f1c94918d7cee1","lane":"lint","parents":["325a49d29d0d9051e6b473e980fad71b822c6f87"],"secs":5,"stamp":"62b64d1aa0d162a22ecf50075452742a","tree":"18904b28bd85ff6ff08ce80f10dae94dda139a76","v":1,"via":"run"}
Ci-Attestation: {"at":1791675132,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"8ab76ba0fdab0ca2f07ef85c35d69bdce29faac588a2f8d7b312b2cd664d174e","lane":"rust-test","parents":["325a49d29d0d9051e6b473e980fad71b822c6f87"],"secs":21,"stamp":"eb5d4333df52d26eb3ebf743f506d30b","tree":"18904b28bd85ff6ff08ce80f10dae94dda139a76","v":1,"via":"run"}
Ci-Attestation: {"at":1791675132,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"ee43101ce8b5a6c42ef660cf7f6f55c3532aaadab25c2ee4811df6d285c824a2","lane":"tier2-linux","parents":["325a49d29d0d9051e6b473e980fad71b822c6f87"],"secs":12,"stamp":"2fa187fac20ed6705d15911748c303f8","tree":"18904b28bd85ff6ff08ce80f10dae94dda139a76","v":1,"via":"run"}
The input callback signals g_input_event from the audio thread, so
destroying it before audio_output_close() could race a late signal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XFvTpgDN6Zh3USjgworNmT
Local-Gate: v1 tree=c4b764f6d8aa71c39e58671c953d64aa1fb41caf secs=62 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791692794,"gate":"rust/all/fmt","host":"linux-x86_64","key":"b7026c063f951c53a9d4ed45ca3c8974bd7c92ddf4320444a488f40238a5f9a1","lane":"lint","parents":["fad9f73502e5917c3bf91b2ea96ad8acb093ef1d"],"secs":14,"stamp":"bbf8ac2c04ea813a254211e50b9cb57d","tree":"c4b764f6d8aa71c39e58671c953d64aa1fb41caf","v":1,"via":"run"}
Ci-Attestation: {"at":1791692794,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"b7026c063f951c53a9d4ed45ca3c8974bd7c92ddf4320444a488f40238a5f9a1","lane":"lint","parents":["fad9f73502e5917c3bf91b2ea96ad8acb093ef1d"],"secs":14,"stamp":"8683db975511caac7301b6107c277f76","tree":"c4b764f6d8aa71c39e58671c953d64aa1fb41caf","v":1,"via":"run"}
Ci-Attestation: {"at":1791692794,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"515c1a621978d2e8cd35efcb9530a01d3b26eca9e5615b6dc02b99cd8b09a7e3","lane":"rust-test","parents":["fad9f73502e5917c3bf91b2ea96ad8acb093ef1d"],"secs":31,"stamp":"45108c7b930820a3ecd87f5b62ba17ce","tree":"c4b764f6d8aa71c39e58671c953d64aa1fb41caf","v":1,"via":"run"}
Ci-Attestation: {"at":1791692794,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"8869ee39dcde8b028bca3040629b682d2541aae6981a1527e58b33cf13566102","lane":"tier2-linux","parents":["fad9f73502e5917c3bf91b2ea96ad8acb093ef1d"],"secs":17,"stamp":"06c66dacab9b3abfac084c0a51d7b313","tree":"c4b764f6d8aa71c39e58671c953d64aa1fb41caf","v":1,"via":"run"}
@zackees

zackees commented Oct 11, 2026

Copy link
Copy Markdown
Member

Verified locally, rebased onto master and stamped. The new head is 2f2da96aa.

  • While rebasing, I moved the CMake block from test/cmocka/CMakeLists.txt into test/cmocka/tests.d/test_audio_io.cmake. That's the layout from infra: Split shared registration lists into per-unit fragments #168, and it keeps ports from conflicting.
  • This is a characterization test, so it should pass against the C. Tier 2 passed 58 of 58 with ENABLE_RUST_LIBOBS OFF and 58 of 58 with it ON. Since it runs the audio thread, I also ran --repeat until-fail:20 -R test_audio_io in both modes, and every repeat passed.
  • Local gate: lint, rust-test and tier2-linux all passed.

Merging once CI is green.

@zackees
zackees force-pushed the char/audio-io-test branch from 94251a4 to 2f2da96 Compare October 11, 2026 04:26
@zackees
zackees merged commit c5a2a1a into obs-rust:master Oct 11, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants