Skip to content

obs-c-oracle: Compile platform.c instead of host copies - #1094

Merged
zackees merged 2 commits into
obs-rust:masterfrom
chriscoveries:fix/oracle-real-platform-linear
Oct 17, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
chriscoveries:fix/oracle-real-platform-linear

Conversation

@chriscoveries

Copy link
Copy Markdown
Contributor

Problem

The Rust C oracle used for parity tests had empty breakpoint and OOM stand-ins plus copied platform helpers. Tests could therefore agree with the oracle while the corresponding libobs C path behaved differently. This change addresses the util/platform.c helpers and the breakpoint/OOM test behavior; it does not complete the broader stand-in audit tracked in #145. Refs #145.

Root cause

At tested upstream base fb3910360f8b165c2d8ded0819bc59455fe9b3d8, rust/obs-c-oracle/oracle/test_stubs.c:18-40 defines empty weak os_breakpoint and os_oom handlers. The zero-size and allocation-failure paths in libobs/util/bmem.c:101-134 call these handlers. The weak handlers return without printing the expected marker or raising the SIGTRAP used by libobs; bmem.c then reaches bcrash, so the child still terminates but the RED tests fail because the marker is absent. Hand-copied platform helpers in the oracle can also drift from util/platform.c.

Fix

Compile the real util/platform.c in the oracle with its exports renamed to oracle_*, route oracle calls to those symbols, and remove the copied helpers. Test-only breakpoint and OOM handlers print a marker and abort so forked tests can observe those paths. Windows plain-name forwarders preserve the Rust FFI symbols while calling the renamed C implementations.

For MinGW cross-link builds, which exclude platform-windows.c, link-only stubs provide the remaining oracle symbols that source would otherwise define. The Windows behavioral oracle tests are MSVC-only.

Keeping the helper copies would retain the drift risk; linking unrenamed exports would collide with the Rust implementation in parity tests.

Evidence

Tested base: upstream fb3910360f8b165c2d8ded0819bc59455fe9b3d8.

  • Linear-history RED 03febcf1a076d4e7de873bf5418ac01237b0fda9 (tree identical to tested RED 4c32e7a409af81111daaf4f0ee1b49edc3c3a6fb): fork Pull run 38888966646 failed obs-util --test platform_oracle as intended. Three cases failed because the child did not print the expected marker: oracle_bmalloc_zero_dies_loudly, oracle_brealloc_zero_dies_loudly, and oracle_bmalloc_oom_dies_loudly. Output: test result: FAILED. 2 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.19s. The child still terminated in the bmem.c error path; RED caught the missing marker. The run was cancelled after this focused result to stop unrelated platform builds.
  • Linear-history GREEN 9f2504a3fa8acd561843ef7dad0dbccca5b6e139 (tree identical to tested GREEN 4b8346044defe5dcb97975dfa947533b5a3b48c9): in exact-head fork Pull run 38898555908, platform_oracle.rs reported test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s. The full CI run passed on this exact head (27 jobs succeeded, 0 failed, 3 skipped).
  • The focused oracle stand-in checker passes locally: uv run python -m unittest ci/test_oracle_standins.py (2 tests).
  • git merge-tree --write-tree upstream/master HEAD against upstream 2dae7366609405b552965e428b926dfc61394591 exited successfully and returned ca0f50dc63a8f4474611759041398f4c41e520c5.
  • No local Cargo tests were run; Rust tests use the fork Pull workflow. No OBS runtime run is applicable because this change affects only the test oracle.

Compatibility & risk

No public API or ABI changes. The change is confined to test infrastructure: the C oracle and its helpers, Rust regression tests, and the stand-in drift checker. The fork-based regression tests run on Unix; Pull CI also checks supported platform builds, including the Windows FFI links.

Status

Ready for review.

How this was tested

  • RED → GREEN: obs-util --test platform_oracle fails on linear-history RED 03febcf1a076d4e7de873bf5418ac01237b0fda9 and passes on linear-history GREEN 9f2504a3fa8acd561843ef7dad0dbccca5b6e139; their trees are identical to the commits used for the cited RED/GREEN runs. No local Cargo test was run.
  • Real runs: Not applicable. This changes only the C oracle used by tests and does not change OBS runtime behavior.
  • Fork Pull CI (same workflows as upstream PR CI): run 38898555908 passed on exact linear-history GREEN 9f2504a3fa8acd561843ef7dad0dbccca5b6e139 (27 jobs succeeded, 0 failed, 3 skipped).

Thank you to the obs-rust maintainers and contributors for building this project in the open. In the American spirit of free expression and individual independence, and with the principle of judging contributions on their merit alone, this PR is a small piece of what independent people can build when they come together.

@zackees
zackees added this pull request to the merge queue Oct 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 16, 2026
@zackees

zackees commented Oct 16, 2026

Copy link
Copy Markdown
Member

Merge queue triage: the queue dropped this PR at 19:53 UTC. Format 🔍 / checks failed in ci/test_binary_cap.py with obs-util: 9 integration-test binaries (cap 8), and the workspace cap of 22 was also exceeded.

Your branch is not at fault. #978 merged at 17:32, after this PR's CI ran. It groups each crate's tests/*.rs into category binaries and caps their number. This PR adds rust/obs-util/tests/platform_oracle.rs as a new top-level test, so on current master it becomes a 9th binary.

Fix: rebase onto origin/master, move the file to rust/obs-util/tests/platform/platform_oracle.rs, and add mod platform_oracle; to rust/obs-util/tests/platform/main.rs beside pipe_parity and the other platform tests. uv run ci/test_binary_cap.py --report should then show obs-util at 8. Push the change and I'll put the PR back in the queue once CI is green.

@zackees
zackees added this pull request to the merge queue Oct 17, 2026
@zackees
zackees removed this pull request from the merge queue due to a manual request Oct 17, 2026
@zackees
zackees force-pushed the fix/oracle-real-platform-linear branch from 9f2504a to e5f4b89 Compare October 17, 2026 01:56
@zackees

zackees commented Oct 17, 2026

Copy link
Copy Markdown
Member

Maintainer push: I've made the binary-cap fix on your branch so this can merge. I rebased onto master (472cc09f7) and, in the RED commit, moved rust/obs-util/tests/platform_oracle.rs to rust/obs-util/tests/platform/platform_oracle.rs and added mod platform_oracle; to tests/platform/main.rs. Nothing else changed, and both commits still have you as author. Old head 9f2504a3f, new head e5f4b89b7.

Checked locally:

  • ci/test_binary_cap.py: OK, obs-util is at 8 and the workspace total is 22, both at their caps.
  • soldr cargo test -p obs-util --test platform: 80 passed, including the 5 platform_oracle cases. They fork, and they run fine alongside the rest of the binary.
  • ./lint: OK.

I'll queue it once CI is green.

@zackees
zackees added this pull request to the merge queue Oct 17, 2026
@zackees
zackees force-pushed the fix/oracle-real-platform-linear branch from e5f4b89 to b1b857c Compare October 17, 2026 02:44
@zackees

zackees commented Oct 17, 2026

Copy link
Copy Markdown
Member

Second maintainer push: the merge queue failed this PR in Fast Gate with oracle/platform.c:104:10: fatal error: util/platform.c: No such file or directory. #1147 (f96e0daa1) renamed libobs's implementation files to *.c.h, so util/platform.c is now util/platform.c.h, and master's other oracle files already include the .c.h names.

I rebased onto master (08c5f4fe1) and changed the include in oracle/platform.c to util/platform.c.h, plus the two names in obs-c-oracle/src/lib.rs's doc comment. Both changes went into your GREEN commit; the RED commit is unchanged apart from the rebase. New head b1b857c0d.

Checked locally: soldr cargo test -p obs-util passes every test binary (platform 80/80), cargo test -p obs-c-oracle OK, ci/test_oracle_standins.py + ci/test_binary_cap.py OK, ./lint OK. I'll queue it once CI is green.

@zackees
zackees removed this pull request from the merge queue due to a manual request Oct 17, 2026
@zackees zackees closed this Oct 17, 2026
@zackees zackees reopened this Oct 17, 2026
@zackees

zackees commented Oct 17, 2026

Copy link
Copy Markdown
Member

Part one of the speed up refactor has gone in. C code is amalgamated and relies on one single PCH

Part two, going in now, is rust optimization:

  • unit test amalgamation
  • artifact caching

You are going to have to rebase, but it's worth it!

@zackees
zackees force-pushed the fix/oracle-real-platform-linear branch from aabf644 to fb63a70 Compare October 17, 2026 03:45
@zackees

zackees commented Oct 17, 2026

Copy link
Copy Markdown
Member

Third maintainer push, correcting my first one. Moving platform_oracle.rs into the platform binary was a mistake. Its cases call libc::fork(), and a raw fork copies every fd in the process, including the pipes pipe_parity::process::dead_pipe_write_survives_concurrent_spawns is testing on another thread. A forked child keeps the pipe's read end open, so a write to the dead child succeeds. Fast Gate on aabf64439 failed with exactly that: 1 of 3000 writes reached a dead child through a leaked fd. Your original standalone binary didn't have this problem; my move caused it.

In the RED commit I moved it to rust/obs-util/tests/profiler/platform_oracle.rs, with a comment in profiler/main.rs saying why. That binary doesn't spawn processes or use pipes, and it doesn't read bnum_allocs, so the forks don't affect anything there. The count is unchanged: obs-util 8, workspace 22. The GREEN commit is unchanged. New head fb63a7001.

Checked locally: --test platform 75/75 on five runs in a row, --test profiler 24/24 (the 5 moved cases included), test_binary_cap + test_oracle_standins OK, ./lint OK. The earlier getcwd() failed failure was a separate, pre-existing race between two existing platform tests (added to #1133).

@zackees
zackees added this pull request to the merge queue Oct 17, 2026
Merged via the queue into obs-rust:master with commit 911980f Oct 17, 2026
25 of 26 checks passed
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 24, 2026
Since obs-rust#1094 the dstr-libc oracle took os_utf8_to_wcs_ptr and
os_mbs_to_utf8_ptr from oracle/platform.c, which allocates with
oracle_bmalloc, while dstr-libc.c frees the wide string with bfree and
keeps the UTF-8 string as a dstr's array, both obs-util's allocator.
Every oracle_dstr_to_upper/to_lower freed an oracle_bmalloc block with
bfree: the counters drift apart (-4 / +4 after util's dstr/to_upper
benches in --test mode) and the two allocators are only compatible by
accident. Define the two helpers in oracle/dstr_libc.c as their
util/platform-conversions.c.h bodies around oracle/platform.c's
conversions, allocating with bmalloc. A full port_comparison --test run
now completes.

Fixes obs-rust#2154
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 24, 2026
…#2159)

* obs-c-oracle: Check each port_comparison module frees its fixtures

util's bmem/count pair compares obs-util's bnum_allocs() with the C
bmem oracle's counter, so any earlier module whose fixtures allocate
through the shared bmalloc and don't free it fails that pair instead
(obs-rust#2154: 16 vs 0 on a full run). comparisons() now runs each module
through module(), which checks both counters are where they were before
the module ran, so a leak names its module. On master it fails at
source_profiler: 16 Rust-side allocations live.

The module list becomes a sorted modules![...] list, one per line, and
ci/test_sorted_shared_lists.py reads it there.

Refs obs-rust#2154

* obs-c-oracle: Free the source profiler bench's sources

source_profiler's bench made its 16 C sources with
oracle_sp_source_new(), a bzalloc through obs-util's shared bmalloc, and
left them live. They were the 16 Rust-side allocations that made util's
bmem/count pair (16 vs 0) panic on a full port_comparison run. Free them
with oracle_sp_source_free() after the closing oracle_sp_reset(), which
has already dropped the profiler's entries for them.

Refs obs-rust#2154

* obs-c-oracle: Allocate dstr-libc's conversions with the libobs bmalloc

Since obs-rust#1094 the dstr-libc oracle took os_utf8_to_wcs_ptr and
os_mbs_to_utf8_ptr from oracle/platform.c, which allocates with
oracle_bmalloc, while dstr-libc.c frees the wide string with bfree and
keeps the UTF-8 string as a dstr's array, both obs-util's allocator.
Every oracle_dstr_to_upper/to_lower freed an oracle_bmalloc block with
bfree: the counters drift apart (-4 / +4 after util's dstr/to_upper
benches in --test mode) and the two allocators are only compatible by
accident. Define the two helpers in oracle/dstr_libc.c as their
util/platform-conversions.c.h bodies around oracle/platform.c's
conversions, allocating with bmalloc. A full port_comparison --test run
now completes.

Fixes obs-rust#2154
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