Repository navigation
test/cmocka: Add util/deque.h characterization test - #1548
Merged
Merged
Conversation
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
force-pushed
the
test/deque-characterization
branch
from
October 20, 2026 19:12
19a7ff5 to
5cb9c0f
Compare
zackees
enabled auto-merge
October 20, 2026 19:12
Member
|
Coordinator: rebased onto master. The only conflict was |
This was referenced Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #1546 (step 3, part 1 of 2: the characterization; the Rust equivalent in
obs-utilfollows in its own PR)What and why
The obs-output delay port (#1546) has to push to, peek and pop
output->delay_data, a Cstruct dequethatobs-output.calso owns and frees. Soobs-utilneeds a Rust equivalent of the header-inlinelibobs/util/deque.h, as it has fordarray.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.hhas no C test, so Tier 1 would have nothing to port. This PR adds the characterization test first, astest_util_uint64did forutil_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 manifestrust/obs-build/manifests/c-tests-linux.json). It links libobs only forbmalloc/brealloc/bfree. 16 cases:struct dequeis five pointer-sized words (data,size,start_pos,end_pos,capacity, in that order) with pointer alignment.end_pos == capacitygoes to position 0, and a push that does not fit before the end is split across it.deque_reservemove the bytes fromstart_posto the old end up to the new end. The wrapped head stays at 0. An unwrapped deque with astart_posoffset is not moved, even when the push would have wrapped before growth.push_front(into an empty deque, atstart_pos0, split, and into a full wrapped deque),push_back_zero/push_front_zero,peek_back/pop_back, andpeek_front/pop_front, with and without a destination buffer.deque_dataindexing, which wraps and returns NULL fromsizeon.deque_placewithin the data, past its end and across a gap (deque_upsizezero-fills the gap, growing and moving the tail first), anddeque_upsizeno-ops.deque_freereleases it and zeroes the struct. Freeing a deque that never allocated is fine.deque_datagives.Characterized, not endorsed: a full, unwrapped deque, or one popped from the back by exactly
end_posbytes, hasend_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 againstoracle_*wrappers of these inlines checks the Rust side.RED → GREEN
19a7ff584test/cmocka: Add util/deque.h characterization test.ENABLE_RUST_LIBOBS=OFFandON, full builds). Each runs the full ctest suite againstlibobsand againstlibobs-with-rust, headless (private Xvfb, private D-Bus, fresh HOME):ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)test_dequepasses 16/16 in all four.capacity * 2tocapacity * 2 + 1: 6 of 16 cases fail;deque_push_backwraparound changed fromnew_end_pos -= capacitytonew_end_pos -= capacity - 1: 6 of 16 fail;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-runlink forx86_64-pc-windows-gnu): passed, 1634 tests, none failed. The obs-util harness passes 671/671. No Rust test binary was added.Windows/macOS: not built there. The test is portable C with no host conditionals and links only
OBS::libobsand cmocka. It uses noassert_in_range, so it builds on cmocka 1.x and 2.x.Checklist
masterdocs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable