Skip to content

test: Characterize the output stream delay - #1547

Merged
zackees merged 1 commit into
obs-rust:masterfrom
rdoupe:test/output-delay-characterization
Oct 20, 2026
Merged

zackees merged 1 commit into
obs-rust:masterfrom
rdoupe:test/output-delay-characterization

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Refs #1546 (PR 1 of the plan: the characterization; the accessor and the port follow)

What and why

libobs/obs-output-delay.c.h, the stream delay, has no C test. This PR adds test/cmocka/test_output_delay.c, which pins what the C does now before the Rust port. From then on it is an unchanged Tier 2 check, and Tier 1 ports its assertions 1:1. No Rust, and no change to libobs, to a public header or to an existing test.

  • How it runs. process_delay() and the delay start, stop and cleanup are not exported, so the test compiles the file into itself, as test_scene_blend and test_hotkey_load do. That means it characterizes the C source only, and Tier 3 will be the proof of the swap (as with libobs: Port the Wayland hotkey key state to obs-hotkey #1516).
    • The output is a zeroed struct obs_output; only the fields the file reads are set up.
    • The obs-output.c functions the file calls are recording stubs: actual start and stop, can_begin_data_capture, initialize_encoders and begin_data_capture. So are the delay callback and the starting / stopping signals.
    • os_gettime_ns() is renamed to a test clock, so no case depends on real time or sleeps.
    • Held packets are released with libobs's obs_encoder_packet_release(). obs_encoder_packet_create_instance() is hidden, so the test has a copy of it. Teardown checks bnum_allocs(), so a packet the delay fails to release fails the test.
    • No libobs core and no display, so it runs on every platform.
  • Registration. A tests.d/test_output_delay.cmake fragment, with the same include and link lines as test_scene_blend, plus the Cargo C-test manifest entry. cmocka executables are C compatibility tests, outside the Rust test-binary budget; no Rust harness is added.
  • The 20 cases:
    • setter and getters: the seconds and flags are stored as given and do not touch the running delay. A raw output is refused with a warning. NULL returns 0. The active delay is reported in whole seconds, truncated;
    • packets are held for the delay and released oldest first once more than the delay has passed (equal is still held). One call releases every packet that is due but never the one it just queued. The data is copied, and the packet time is copied or NULL;
    • a due packet is released without delivery unless the delay is both active and capturing, checked when it leaves the queue;
    • delay_start runs, in order, the data capture check, sets starting, initializes the encoders, then begins capture, with no signal of its own. It queues the real start and takes a restart reference. A failed check or encoder initialization queues nothing and clears starting again;
    • a restart while the delay runs skips the checks, queues the start, takes a reference and signals starting;
    • queued start and stop entries run after the delay whatever the delay state, the start before the packets behind it. The stop is not forced and carries the time it was asked for. stopping is signalled at once;
    • cleanup releases every entry without running it, sets the active delay to 0 and drops the restart references. The other delay fields are left alone;
    • preserve on disconnect: while reconnecting, nothing leaves the queue, captured or not, and the delay grows to the age of the oldest entry. Without preserve, due packets keep leaving (and are dropped once capture has ended). Preserve is read from the running flags (delay_cur_flags), not the setting, and only its bit counts;
    • every stub, callback and signal is called with the delay mutex released.

Characterized, not endorsed (comments in the test):

  • obs_output_get_delay() and obs_output_get_active_delay() log a NULL output under the setter's name (obs_output_set_delay: Null 'output' parameter);
  • obs_output_get_active_delay() casts to uint32_t, so it wraps past UINT32_MAX seconds;
  • with an active delay of 0 (what cleanup leaves), a packet is still held until a later call, because 0 > 0 is false;
  • the elapsed time is an unsigned difference, so a clock that goes backwards releases a packet at once (os_gettime_ns() is monotonic, so this is not reached in practice);
  • after a preserved reconnect the grown delay never shrinks back to the delay that was set;
  • when obs_output_begin_data_capture() fails, delay_start cleans up the delay but leaves starting set, unlike the failed encoder initialization path. Before that call, delay_start has just checked obs_output_can_begin_data_capture(), so this needs the output's state to change in between. No bug filed.

RED → GREEN

  • No RED commit: this is a characterization test, and it passes on the current C. The C file is still in libobs-with-rust until the port.
  • test_output_delay: 20/20, run 3 times against each of libobs and libobs-with-rust in both lanes, all passing. It also passes 20/20 when built with ASan and UBSan (leak detection on).
  • Mutation check of the new test: 23 of 23 mutants of obs-output-delay.c.h fail it. The mutants were:
    • >= for > in the pop;
    • one pop per call instead of the loop;
    • no delay growth; preserve without the reconnecting check; the setting's flags instead of the running ones;
    • delivery without the capturing check;
    • a stop with the pop time, or forced;
    • packet time never valid;
    • no reset of the restart references or of the active delay in cleanup;
    • starting not cleared on failed encoder initialization;
    • no restart reference; no starting or stopping signal;
    • no cleanup on failed capture;
    • rounding instead of truncation in the getter;
    • flags not stored; no raw-output check;
    • a dropped packet, or a cleaned-up packet, not released;
    • no stop queued;
    • the callback run with the mutex held.
  • Local, two build trees (ENABLE_RUST_LIBOBS=OFF and ON), headless (private Xvfb, private D-Bus, fresh HOME). Each runs the full cmocka suite against libobs and against libobs-with-rust:
Lane libobs libobs-with-rust Exported symbols
C (ENABLE_RUST_LIBOBS=OFF) 334/334 334/334 IDENTICAL (1766)
Rust (ENABLE_RUST_LIBOBS=ON) 334/334 334/334 IDENTICAL (1766)

None of the four runs skipped or failed to run a test. The export lists are also identical across the two lanes. test_output_delay passes in all four runs.

  • uv run ci/local_gate.py --lane lint: passed (45 s). clang-format 22.1.3 and gersemi 0.25.0 are clean on the new files.
  • Real app: not applicable (no behaviour change).

Windows/macOS: not built there. The test is portable C with no host conditionals. It builds against libobs.pch.h with the same includes and libraries as test_scene_blend. It defines the functions it stubs, as test_hotkey_load does with its compiled-in file.

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (this is the characterization; the port follows)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): not applicable
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not applicable (no port here)

The stream delay in libobs/obs-output-delay.c has no C test. Before its
Rust port, test_output_delay pins what the C does now, so the port keeps
it as an unchanged Tier 2 check and Tier 1 ports its assertions 1:1.

process_delay() and the delay start, stop and cleanup are not exported,
so the test compiles the file into itself with a zeroed struct obs_output,
recording stubs for the obs-output.c functions it calls, and a test clock
in place of os_gettime_ns(). No libobs core, display or real time.

20 cases: the setter and getters (raw outputs, NULL, whole seconds);
packets held for the delay and released oldest first once more than the
delay has passed, all due packets per call, copied with their packet
time; packets dropped when the delay is not capturing; delay_start's
order of checks, `starting` and restart references, and the restart
while a delay runs; queued start and stop running after the delay, the
stop with the time it was asked for; cleanup releasing everything
without running it; and preserve on disconnect, which holds every packet
while reconnecting and grows the delay by the outage. Callbacks run with
the delay mutex released. Odd cases are marked "characterized, not
endorsed".

Refs obs-rust#1546
@rdoupe
rdoupe requested a review from zackees as a code owner October 20, 2026 18:18
@zackees
zackees added this pull request to the merge queue Oct 20, 2026
Merged via the queue into obs-rust:master with commit 86aa89e Oct 20, 2026
23 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