Repository navigation
test/cmocka: Characterize the util/darray.h operations the interleaver uses - #1596
Merged
Merged
Conversation
…r uses The output interleaver port (obs-rust#1594) has to insert into, erase ranges from, pop the front of and append zeroed items to darrays that C in obs-output.c also owns and frees, so the Rust equivalent of the header-inline util/darray.h in obs-util needs those operations with the C semantics. The testing policy has Tier 1 port the unit's C test 1:1, but test_darray covers only da_push_back_array, so this pins the current C behaviour first, as test_deque did for util/deque.h. test_darray_ops (14 cases, all platforms, plus the Cargo C-test manifest) covers the struct darray layout and the DARRAY union; da_insert at the front, middle and end, into a zeroed array, and through growth (the ensure_capacity rule, including from a reserve that is not a power of two), on a multi-word element; da_erase and da_erase_range from the front, middle and end, a range of one, and the whole array; da_pop_front; da_push_back_new (the GCC and Clang macro, and the darray_push_back_new function other compilers use) returning the zeroed new last item after growth and on a reused slot; that removal never shrinks or frees the buffer; the bmalloc accounting; and the interleaver's resort and packet-time patterns. Characterized, not endorsed: removal leaves the old values in the slots past the new num. 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. Every call satisfies the header's asserts, so the results do not depend on NDEBUG. No change to libobs. Refs obs-rust#1594
zackees
force-pushed
the
test/darray-ops-characterization
branch
from
October 21, 2026 02:12
f2f2a3d to
f7661f7
Compare
zackees
enabled auto-merge
October 21, 2026 02:12
Member
|
Coordinator: rebased onto master. The only conflict was |
6 of 7 tasks
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 21, 2026
…1600) * obs-util: Add Tier 1 tests for the darray.h interleaver operations The interleaver port (obs-rust#1594) uses the C darrays that obs-output.c resets and frees (interleaved_packets, encoder_packet_times[] and keyframe_group_tracking) in place, so obs-util's darray equivalent needs the inline operations it uses and does not have yet: insert, erase range, pop front and push back new (the function and the GCC/Clang macro, which do the same steps). obs-rust#1596 characterized them in test_darray_ops. This adds those functions with todo!() bodies, to the raw API that runs on a struct darray with bmem memory (plus darray_push_back, which insert at num calls) and to the safe DArray, and Tier 1: every test_darray_ops case ported 1:1 under the same names on the raw API, as the C test runs the header, including the "characterized, not endorsed" stale slots past num after removal. The bnum_allocs() cases run in their own process. New edge cases: insert at num into a full array, into a reserved empty one and with an odd item size, growth copying the stale tail, push back new zeroing only the new item, pop front on an empty array, the precondition panics (where C asserts), and the same operations on the safe core. 30 of 31 fail with "not yet implemented"; layout passes, as it checks the existing struct mirror. Refs obs-rust#1594 * obs-util: Add the darray.h operations the interleaver uses The interleaver port (obs-rust#1594) uses interleaved_packets, encoder_packet_times[] and keyframe_group_tracking in place: C darrays that obs-output.c resets and frees. darray.h is header-inline, so nothing swaps; the Rust equivalent is a library the port calls, and the struct darray layout is the contract. - obs_util::ffi::darray: darray_insert, darray_erase_range, darray_pop_front and darray_push_back_new (the function, and the GCC/Clang da_push_back_new macro, which does the same steps), plus darray_push_back, which insert at num calls. They follow the header step by step on a struct darray with bmem memory, so C and Rust can hand one array back and forth: num grows before the capacity check, growth copies the whole old capacity, removal moves the tail down and leaves the old values past num (characterized, not endorsed), and only the new item of push back new is zeroed. An index or range the header asserts on panics; pop front on an empty array is a no-op, as the C body checks num after its assert. - obs_util::darray::DArray: the same four operations on the safe core. - Oracle: oracle_* wrappers of the five inline functions, and oracle_da_push_back_new, the macro on a typed DARRAY for 1, 4, 12 and 16-byte items. - Tier 3: darray_ops_match_c now covers every Rust function on twin arrays (and the safe core for one-byte items), comparing num, capacity, the null-ness of the buffer, the return values and every determined byte, including the stale slots past num. darray_mixed_in_place_matches_c hands one array to Rust or C at random against a C-only twin; interleaver_patterns_match_c runs the test_darray_ops packet-time and resort patterns that way, and bmem_accounting_matches_c checks the bnum_allocs() deltas of a hand-off in both directions, in its own process. - rust/README.md: the darray row. No intentional differences. Refs obs-rust#1594
6 of 7 tasks
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 21, 2026
* libobs: Add Tier 1 tests for the output interleaver port RED for the port of libobs/obs-output-interleave.c.h, the encoded packet interleaver, to obs-output's new interleave module. The pure parts work on a slice of packets (a PacketView trait): the first and last packet of a track, the start index, the premature prune, the insertion position, the offset arithmetic, the streamable count and the catch-up rule, the discard count, the caption timing and the packet-time lookup. The functions named after the C ones are generic over the output (InterleaveOutput): its fields, the queue and the other darrays, the locks, the encoders and the libobs calls the C file makes, so the C ABI shim can run them on the real struct obs_output through the hidden accessors of obs-rust#1599, and the tests on a model. Every function is a todo!() stub. The first thirty cases mirror test_output_interleave 1:1 (same names, same assertions, in order) on a model output that records what the C test's stubs record: each sent packet with whether interleaved_mutex was held, each packet callback call with its packet time and whether pkt_callbacks_mutex was held, each add_caption call with whether the track's caption mutex was held, and every held copy until it is released. The other 23 pin the edges: the dts_usec and encoder duration truncation, the first and last packet of a track, the start index and the premature prune without audio, the duration lookups stopping at the missing track, the insertion position at equal times, the opposing-type test without video encoders, the catch-up boundaries, the discard count, the caption timing at equal times, the first matching packet time, single-encoder and foreign group entries, one lock per packet and none when inactive, a delayed waiting packet released after the unlock, a packet time offset after the start, an audio packet's time going to the same-numbered array, one pir per callback, and a start without video encoders. They are a module of obs-tests-core, so no new test binary (ci/test_binary_cap.py: 8 of 8). soldr cargo test -p obs-data --test obs-tests-core output::interleave:: fails 53 of 53 with "not yet implemented". Refs obs-rust#1594 * libobs: Port the output interleaver to obs-output libobs/obs-output-interleave.c.h moves to obs_output::interleave. It is the encoded packet callback of an output with video and audio: interleave_packets queues the encoders' packets, starts every track together at timestamp 0 and sends the packets in dts order, with their encoder timing, captions and the encoder group keyframe check. interleave_packets, get_encoder_index and free_packets are declared in obs-internal.h without EXPORT; obs-output.c calls them, and passes interleave_packets to the encoders by name, so the Rust symbol replaces the C one the encoder later compares against. The pure parts work on a slice of packets (PacketView): the first and last packet of a track, the start index, the premature prune, the insertion position, the offset arithmetic, the streamable count and the catch-up rule, the discard count, the caption timing and the packet-time lookup. The functions named after the C ones are generic over the output (InterleaveOutput), as the delay core is over DelayOutput, and take interleaved_mutex, pkt_callbacks_mutex and the caption mutex exactly where the C does. The nine behaviours test_output_interleave marks "characterized, not endorsed" are kept, among them the late-audio keyframe drop, the last-track prune difference, the truncating encoder duration, the track-0-only start index, the non-keyframe start, the waiting non-keyframe discard, priming audio at offset 0 and the early return that does not release a delayed packet. The shim never reads struct obs_output or struct obs_encoder: it goes through the hidden accessors and wrappers of obs-rust#1599, and reads and writes each field where the C does. interleaved_packets, encoder_packet_times[] and keyframe_group_tracking stay the C darrays obs-output.c resets and frees; they are changed in place with obs_util::ffi::darray (obs-rust#1596, obs-rust#1600). Queued packets are libobs's reference-counted copies or the delay's. The clock is read once per packet callback, as in C; the *_with_clock entry point and the statics module (the C file's static functions on a live output) are Rust-mangled and are what the parity test drives. The file leaves libobs.core-output for its own group, libobs.ported-output-interleave, whose PCH is obs-internal.h alone, so the oracle and test_output_interleave compile it without the core. The three symbols go in rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt. The exported symbol sets are unchanged. Tier 3 (oracle/output_interleave.c) compares the layouts of the keyframe group entry, the packet callback, the caption text, the darray and the three accessor structs, the values the file uses, thirteen characterization scenarios, and 1024 random runs of up to 80 steps over one to two video and audio encoders: packets with random tracks, keyframes, running timestamps and packet times, changes of active, the delay, the batch limit, the captions, add_caption, the callbacks and the encoder group, restarts, get_encoder_index, and the static functions where their C preconditions hold. After every step it compares the return value, every recorded call and whether each lock was held, the log line, the held copies, the caller's packet, every queued packet, packet time and group entry, the darray capacities and every interleaver field. Both sides go through the same accessor and libobs stand-ins. The oracle builds the file with NDEBUG, as libobs is built: darray_pop_front asserts when a video packet without a packet time is discarded, then does nothing, as the Rust darray does. No intentional differences. test_output_interleave compiles the C into itself and is unchanged. Fixes obs-rust#1594
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 #1594 (step 3, part 1 of 2: the characterization; the Rust darray operations in
obs-utilfollow in their own PR)What and why
The interleaver port (#1594, step 4) works on darrays that
obs-output.calso owns and frees:interleaved_packets,encoder_packet_times[]andkeyframe_group_tracking. It needs the C semantics, in place on a C-owned darray, of the operationsobs-output-interleave.c.hcalls:da_insert,da_erase_range,da_pop_front,da_push_back_new,da_eraseandda_free. The Rust equivalent ofutil/darray.hinobs-utilhasfree,reserve,ensure_capacity,clear,resize,push_back_array,eraseandpop_back. Insert, erase range, pop front and push back new are missing.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.
test_darrayhas one case, which covers onlyda_push_back_array, so Tier 1 would have nothing to port for the new operations. This PR adds the characterization test first, as #1548 (test_deque) did forutil/deque.h. It contains no Rust and does not change libobs.test_darrayis unchanged.New test
test_darray_ops(tests.d/fragment, all platforms, plus the Cargo C-test manifestrust/obs-build/manifests/c-tests-linux.json). It links libobs only forbmalloc/bfree. 14 cases:struct darrayis three pointer-sized words (array,num,capacity, in that order) with pointer alignment, and theDARRAY(type)union's typed fields alias.da.da_insertat the front, middle and end (idx == numtakes the push-back path), into an array zeroed withmemsetthe wayresort_interleaved_packetsdoes it, and on a 16-byte record. Growth follows thedarray_ensure_capacityrule: the first allocation takes the new size, then the capacity doubles, or becomes the new size when that is larger (1 → 2 → 4 → 8 → 16; 3 → 6 from a reserve). A middle insert into a full array grows it and keeps every item.da_eraseat the front, middle and end, down to empty.da_erase_rangefrom the front (asdiscard_to_idxdoes), the middle and the end, a range of one (thedarray_erasepath) and the whole array (onlynumchanges).da_pop_frontdown to empty.da_push_back_newreturns the new last item, zeroed, after any growth and on a reused slot. With GCC and Clang it is a macro of its own, so thedarray_push_back_newfunction that other compilers use is called directly as well.da_freereleases it and zeroes the struct, and freeing an array that never allocated is fine..daout,memsetthe owner, insert every old item in sorted position, free the old buffer) and the packet-time arrays (records appended withda_push_back_new, the oldest dropped withda_pop_front, a matching one erased from the middle), over 40 rounds.Characterized, not endorsed: removal moves the tail down and lowers
num, but the slots past the newnumkeep their old values. Nothing may read them. The test pins this only so that the Rust equivalent, which works in place on the same C buffer, is known to leave the same bytes.Every call meets the header's asserts (
idx <= num,end > start, a non-empty array forpop_front), so the results do not depend onNDEBUG. The functions arestatic 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
f2f2a3da6test/cmocka: Characterize the util/darray.h operations the interleaver uses.ENABLE_RUST_LIBOBS=OFFandON). In each,test_darray_ops,test_darrayandtest_dequeran againstlibobsand againstlibobs-with-rust(loaded in its place), headless:ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)test_darray(1/1) andtest_deque(16/16) also pass in all four runs, and the export lists are identical across the two lanes and both libraries.libobs/util/placed first on the include path (the header in the tree is unchanged):darray_insertwriting the new item atidx + 1instead ofidx: 4 of 14 cases fail;darray_erase_rangeloweringnumbycount - 1: 3 of 14 fail;darray_pop_fronterasing the last item instead of the first: 3 of 14 fail;darray_push_back_newwithout itsmemset: 1 of 14 fails, and the same for the GCC/Clangda_push_back_newmacro;capacity * 2tocapacity * 2 + 1: 9 of 14 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, 1732 tests, none failed, 1 ignored. 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