Skip to content

test: characterize video-frame.c before media-io port - #117

Merged
zackees merged 2 commits into
obs-rust:masterfrom
chriscoveries:char/video-frame-test
Oct 10, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
chriscoveries:char/video-frame-test

Conversation

@chriscoveries

Copy link
Copy Markdown
Contributor

Summary

  • Adds test/cmocka/test_video_frame.c, a characterization test pinning the current C behavior of libobs/media-io/video-frame.c and the static inlines in video-frame.h, ahead of the obs-media-io port (Phase 5).
  • No C test existed for this unit; per testing-policy.md the characterization test lands in its own PR before the port ("characterized, not endorsed").

Coverage

  • video_frame_init: per-plane linesize and data pointer offsets for every video_format across widths {1,3,5,16,47,48,100,640} x heights {1,3,5,16,480}.
  • VIDEO_FORMAT_NONE is pinned as a crash: it produces zero total bytes, so bmalloc(0) trips os_breakpoint()/bcrash() (asserted in a forked child; POSIX).
  • video_frame_copy: equal linesizes (memcpy path), wider destination (line-by-line truncation), narrower destination (extension).
  • video_frame_free/_create/_destroy inlines incl. NULL tolerance.

Validation

  • 7/7 tests pass against ENABLE_RUST_LIBOBS=OFF build of this repo's master (compiled against installed libobs, Linux).

Note on claims

video-frame.c is listed as item 5 of the media-io port order approved on #45 (lane: swilk19, #114). This characterization test is required groundwork regardless of who performs the port.

Refs #45

chriscoveries and others added 2 commits October 10, 2026 15:18
cmocka test pinning the current C behavior of libobs/media-io/
video-frame.c and the static inlines in video-frame.h, ahead of the
obs-media-io port (Phase 5, item 'media-io').

- video_frame_init: per-plane linesize and data-pointer offsets for
  every video_format across widths {1,3,5,16,47,48,100,640} and
  heights {1,3,5,16,480}. VIDEO_FORMAT_NONE is skipped: it allocates
  0 bytes via bmalloc, which trips os_breakpoint()/bcrash() - the
  characterized crash is asserted in a forked child.
- video_frame_copy: equal linesizes (memcpy path), wider dst and
  narrower dst (line-by-line truncation/extension).
- video_frame_free/create/destroy inlines, including NULL tolerance.

Refs #45

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Local-Gate: v1 tree=74741cb20ea0963a8d74f64eb36ef734a7c26e68 secs=349 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791671040,"gate":"rust/all/fmt","host":"linux-x86_64","key":"7a71a5bd655f778761fef7a351357add46260002ede06e4316c89f587555e592","lane":"lint","parents":["135a25105a6b7e09c278a4aa50845a37b22d30bc"],"secs":254,"stamp":"52ff2be802488adc39dd4aeda7eb58ee","tree":"74741cb20ea0963a8d74f64eb36ef734a7c26e68","v":1,"via":"run"}
Ci-Attestation: {"at":1791671040,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"7a71a5bd655f778761fef7a351357add46260002ede06e4316c89f587555e592","lane":"lint","parents":["135a25105a6b7e09c278a4aa50845a37b22d30bc"],"secs":254,"stamp":"2e821f0b6f9f4874dfff96e58c85af14","tree":"74741cb20ea0963a8d74f64eb36ef734a7c26e68","v":1,"via":"run"}
Ci-Attestation: {"at":1791671040,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"90d26fda47a2b2ff428d991b28ab166419a1fd21c4ba99667cd09679b392afb5","lane":"rust-test","parents":["135a25105a6b7e09c278a4aa50845a37b22d30bc"],"secs":57,"stamp":"82955257828f066f28e577c1e8d9cb67","tree":"74741cb20ea0963a8d74f64eb36ef734a7c26e68","v":1,"via":"run"}
Ci-Attestation: {"at":1791671040,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"a7352bd2ebe868d178a3a75779f864c953352cc482768be6b743fd08205803a0","lane":"tier2-linux","parents":["135a25105a6b7e09c278a4aa50845a37b22d30bc"],"secs":37,"stamp":"1afc84c0f1c3369ab82ba4b9c4164ee0","tree":"74741cb20ea0963a8d74f64eb36ef734a7c26e68","v":1,"via":"run"}
@zackees
zackees force-pushed the char/video-frame-test branch from 886fe3e to b1e6c6a Compare October 10, 2026 22:24
@zackees
zackees marked this pull request as ready for review October 10, 2026 22:24
@zackees

zackees commented Oct 10, 2026

Copy link
Copy Markdown
Member

Rebased onto master (old head 886fe3e, replaced with --force-with-lease). The test/cmocka/CMakeLists.txt conflict is resolved by appending the test_video_frame block to master's file. This is a characterization test, so by policy it pins current C behaviour and passes now: test_video_frame passes with the Rust port OFF and ON (46/46). No fail_msg is used. The local gate passes and is stamped. Marked ready.

@zackees
zackees merged commit faaca71 into obs-rust:master Oct 10, 2026
20 checks passed
zackees pushed a commit to swilk19/obs-studio that referenced this pull request Oct 11, 2026
Tier 1, Tier 2 layout and Tier 3 parity tests for video_frame_init,
video_frame_copy and the video-frame.h inlines, against a todo!() core.
test/cmocka/test_video_frame.c (obs-rust#117) is the existing C test, so there
is no characterization commit. Tier 1 ports it 1:1, including its
expected_linesizes / expected_heights model, and adds edge cases: the
V210 ALIGN-by-48 quirk (1 -> 16, 47 and 48 -> 80, 1280 stays 1280), u32
wraps (width * 4, HALF(UINT32_MAX) = 0, the u32 linesize * rows copy
length), and a plane after a skipped one landing on plane 0.

Only video_frame_init and video_frame_copy get C symbols, listed in
rust-exports.d/obs-media-io-video_frame.txt.
video_frame_get_linesizes and video_frame_get_plane_heights have no
header declaration and no caller outside video-frame.c, so they are
safe-core functions only. ffi::video_frame mirrors struct video_frame.
It also has plain-Rust video_frame_free / _create / _destroy for later
ports that handle a struct video_frame. The C inlines stay compiled into
their callers (header-inline rule). A format outside enum video_format
takes the C switches' default, VIDEO_FORMAT_NONE.

video_frame_init still reaches bmalloc(0), which crashes, for
VIDEO_FORMAT_NONE, an unknown format and a zero width or height, as
test_video_frame.c's frame_init_none expects. The safe VideoFrame::new
panics there.

The oracle (oracle/video_frame.c) renames the four non-static functions
and wraps the inlines in oracle_* functions. Its bmalloc and bfree are
libobs's, which under cargo test is the Rust bmem port. Parity sweeps
every enumerator and out-of-range values over widths and heights at each
rounding step and u32 wrap for the linesizes and heights. It compares
frame shapes (linesizes, and plane offsets from data[0]) from init and
create, and checks free and destroy. Copies run into separate
canary-filled destinations, with equal, wider, narrower and zero
linesizes, and every byte is compared. Proptest adds arbitrary formats
and sizes. The exclusions are the C crashes and UB: bmalloc(0), layouts
too large to allocate, and copies past a plane or between overlapping
planes.

RED: 19 of the 20 Tier 1 tests fail on todo!(). The parity binary aborts
at its first todo!() inside an extern "C" shim. The layout test passes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees pushed a commit to swilk19/obs-studio that referenced this pull request Oct 11, 2026
Tier 1, Tier 2 layout and Tier 3 parity tests for video_frame_init,
video_frame_copy and the video-frame.h inlines, against a todo!() core.
test/cmocka/test_video_frame.c (obs-rust#117) is the existing C test, so there
is no characterization commit. Tier 1 ports it 1:1, including its
expected_linesizes / expected_heights model, and adds edge cases: the
V210 ALIGN-by-48 quirk (1 -> 16, 47 and 48 -> 80, 1280 stays 1280), u32
wraps (width * 4, HALF(UINT32_MAX) = 0, the u32 linesize * rows copy
length), and a plane after a skipped one landing on plane 0.

Only video_frame_init and video_frame_copy get C symbols, listed in
rust-exports.d/obs-media-io-video_frame.txt.
video_frame_get_linesizes and video_frame_get_plane_heights have no
header declaration and no caller outside video-frame.c, so they are
safe-core functions only. ffi::video_frame mirrors struct video_frame.
It also has plain-Rust video_frame_free / _create / _destroy for later
ports that handle a struct video_frame. The C inlines stay compiled into
their callers (header-inline rule). A format outside enum video_format
takes the C switches' default, VIDEO_FORMAT_NONE.

video_frame_init still reaches bmalloc(0), which crashes, for
VIDEO_FORMAT_NONE, an unknown format and a zero width or height, as
test_video_frame.c's frame_init_none expects. The safe VideoFrame::new
panics there.

The oracle (oracle/video_frame.c) renames the four non-static functions
and wraps the inlines in oracle_* functions. Its bmalloc and bfree are
libobs's, which under cargo test is the Rust bmem port. Parity sweeps
every enumerator and out-of-range values over widths and heights at each
rounding step and u32 wrap for the linesizes and heights. It compares
frame shapes (linesizes, and plane offsets from data[0]) from init and
create, and checks free and destroy. Copies run into separate
canary-filled destinations, with equal, wider, narrower and zero
linesizes, and every byte is compared. Proptest adds arbitrary formats
and sizes. The exclusions are the C crashes and UB: bmalloc(0), layouts
too large to allocate, and copies past a plane or between overlapping
planes.

RED: 19 of the 20 Tier 1 tests fail on todo!(). The parity binary aborts
at its first todo!() inside an extern "C" shim. The layout test passes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chriscoveries
chriscoveries deleted the char/video-frame-test branch October 11, 2026 02:18
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