Skip to content

test/cmocka: Add util/deque.h characterization test - #1548

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

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

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Refs #1546 (step 3, part 1 of 2: the characterization; the Rust equivalent in obs-util follows in its own PR)

What and why

The obs-output delay port (#1546) has to push to, peek and pop output->delay_data, a C struct deque that obs-output.c also owns and frees. So obs-util needs a Rust equivalent of the header-inline libobs/util/deque.h, as it has for darray.h. The testing policy says a header-inline unit gets a layout test, a 1:1 Tier 1 port of its C test and Tier 3 parity against oracle wrappers. deque.h has no C test, so Tier 1 would have nothing to port. This PR adds the characterization test first, as test_util_uint64 did for util_uint64.h. It contains no Rust and does not change libobs.

New test test_deque (tests.d/ fragment, all platforms, plus the Cargo C-test manifest rust/obs-build/manifests/c-tests-linux.json). It links libobs only for bmalloc / brealloc / bfree. 16 cases:

  • Layout: struct deque is five pointer-sized words (data, size, start_pos, end_pos, capacity, in that order) with pointer alignment.
  • Growth rule: the first push allocates exactly its size. After that the capacity doubles, or becomes the new size when that is larger (4 → 8 → 16 → 35; 3 → 10).
  • Wraparound: a push at end_pos == capacity goes to position 0, and a push that does not fit before the end is split across it.
  • Growth on wrapped data: growth and deque_reserve move the bytes from start_pos to the old end up to the new end. The wrapped head stays at 0. An unwrapped deque with a start_pos offset is not moved, even when the push would have wrapped before growth.
  • Both ends: push_front (into an empty deque, at start_pos 0, split, and into a full wrapped deque), push_back_zero / push_front_zero, peek_back / pop_back, and peek_front / pop_front, with and without a destination buffer.
  • Indexing, place and upsize: deque_data indexing, which wraps and returns NULL from size on. deque_place within the data, past its end and across a gap (deque_upsize zero-fills the gap, growing and moving the tail first), and deque_upsize no-ops.
  • Reset and memory: popping to empty resets both positions to 0 and keeps the buffer. A deque makes one bmalloc allocation however much it grows, and deque_free releases it and zeroes the struct. Freeing a deque that never allocated is fine.
  • The delay pattern: 16-byte records pushed at the back and peeked and popped at the front over 64 rounds. That is 127 pushes and 96 pops, through growth from 16 to 1024 bytes and 36 rounds ending wrapped. Every record stays in push order at the position deque_data gives.

Characterized, not endorsed: a full, unwrapped deque, or one popped from the back by exactly end_pos bytes, has end_pos == capacity, not 0. Every function handles that value, so this is not a bug, but the Rust equivalent has to keep it, since C code reads the same struct.

The functions are static inline, so the test exercises the C header in both libobs builds and cannot see a Rust equivalent. In the follow-up PR, Tier 3 parity against oracle_* wrappers of these inlines checks the Rust side.

RED → GREEN

  • No RED commit: this is a characterization test of unchanged C, and it passes on master's header. Commit: 19a7ff584 test/cmocka: Add util/deque.h characterization test.
  • Local, two build trees (ENABLE_RUST_LIBOBS=OFF and ON, full builds). Each runs the full ctest suite against libobs and against libobs-with-rust, headless (private Xvfb, private D-Bus, fresh HOME):
Lane libobs libobs-with-rust Exported symbols
C (ENABLE_RUST_LIBOBS=OFF) 334/334 334/334 IDENTICAL (1766, same as master)
Rust (ENABLE_RUST_LIBOBS=ON) 334/334 334/334 IDENTICAL (1766)
  • Nothing was skipped or not run in any of the four runs, and the export lists are identical across the two lanes. test_deque passes 16/16 in all four.
  • The test also passes 16/16 under AddressSanitizer and UndefinedBehaviorSanitizer.
  • Deliberate-break check, on a copy of the header placed first on the include path (the header in the tree is unchanged):
    • the growth rule changed from capacity * 2 to capacity * 2 + 1: 6 of 16 cases fail;
    • the deque_push_back wraparound changed from new_end_pos -= capacity to new_end_pos -= capacity - 1: 6 of 16 fail;
    • with the header restored, 16/16 pass.
  • ci/local_gate.py:
    • --lane lint (clang-format, gersemi, rustfmt, clippy -D warnings, Dylints, ifdef ratchet, test-binary cap): passed.
    • --lane cross: passed.
    • --lane cross-release: passed.
    • --lane rust-test (soldr cargo test --workspace --locked, plus a --no-run link for x86_64-pc-windows-gnu): passed, 1634 tests, none failed. The obs-util harness passes 671/671. No Rust test binary was added.
  • Real app: not applicable (no behavior change).

Windows/macOS: not built there. The test is portable C with no host conditionals and links only OBS::libobs and cmocka. It uses no assert_in_range, so it builds on cmocka 1.x and 2.x.

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 PR is the characterization; RED and GREEN are the follow-up)
  • 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)

@rdoupe
rdoupe requested a review from zackees as a code owner October 20, 2026 19:08
util/deque.h is header-inline and has no C test, so a Rust equivalent
in obs-util would have nothing for Tier 1 to port and Tier 2 would only
be its layout test. The obs-output delay port (obs-rust#1546) needs that Rust
equivalent to push, peek and pop the C deque obs-output.c owns, so
this pins the current C behaviour first, as test_util_uint64 did for
util_uint64.h.

test_deque (16 cases, all platforms, plus the Cargo C-test manifest)
covers the struct layout; the growth rule (the first push allocates
its size, then the capacity doubles, or becomes the new size when that
is larger); where pushes go when they wrap past the end; how growth
and reserve move the wrapped tail to the new end and leave an
unwrapped offset in place; push and pop at both ends, the zero-fill
pushes, place and upsize, deque_data indexing; the reset to position 0
when the deque empties; the bmalloc accounting (one allocation, freed
by deque_free); and a fixed-size record FIFO through growth and
wraparound, the pattern of the delay queue. Characterized, not
endorsed: a full unwrapped deque, or one popped back by exactly
end_pos bytes, has end_pos equal to the capacity, not 0.

The functions are static inline, so the test exercises the C header in
both libobs builds; the Rust equivalent will be checked against oracle
wrappers of them. No change to libobs.

Refs obs-rust#1546
@zackees
zackees force-pushed the test/deque-characterization branch from 19a7ff5 to 5cb9c0f Compare October 20, 2026 19:12
@zackees
zackees enabled auto-merge October 20, 2026 19:12
@zackees

zackees commented Oct 20, 2026

Copy link
Copy Markdown
Member

Coordinator: rebased onto master. The only conflict was c-tests-linux.json, where #1547's test_output_delay entry landed at the same spot; kept both entries. Auto-merge on.

@zackees
zackees added this pull request to the merge queue Oct 20, 2026
Merged via the queue into obs-rust:master with commit 88060d9 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