Skip to content

util: Move os_nstime_to_timespec into platform-time.c - #1506

Closed
rdoupe wants to merge 1 commit into
obs-rust:masterfrom
rdoupe:refactor/platform-time-move
Closed

rdoupe wants to merge 1 commit into
obs-rust:masterfrom
rdoupe:refactor/platform-time-move

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Refs #262 (slice 6, time).

What and why

Behavior-neutral extraction before the Rust port, as the testing policy asks for a partial-file port: os_nstime_to_timespec, its static init_timespec_offset and the timespec_offset static move verbatim from libobs/util/platform.c.h into libobs/util/platform-time.c.h. No Rust, no signature, header or behavior change.

  • Build: the new file joins the existing libobs.platform unity group and libobs-platform.pch.h.
  • Oracle: rust/obs-c-oracle/oracle/platform.c includes it too (os_nstime_to_timespec was already renamed oracle_os_nstime_to_timespec there), so the oracle still runs the real C.
  • Ifdef ratchet: the moved code has no host conditionals.

New characterization test test_platform_time (tests.d/ fragment, plus the Cargo C-test manifest). No test called os_nstime_to_timespec before. The base is taken on the first call and can't be read back, but its wall-minus-monotonic difference can: the group setup converts a timestamp read just before the first call, which is at or below the base, so that result is exact. Every case then predicts its result from that difference, so nothing depends on how much time passes. The one exception is the bounds check that the first call takes the base. Cases:

  • the first call takes the base, within the clock readings around it, and later calls keep it;
  • NULL storage returns NULL and leaves the base as it was; the old storage contents don't matter;
  • every timestamp across the window that holds the base (one of them equal to it);
  • above the base: sub-second steps, exact seconds, the nanosecond carry;
  • below the base: the borrow and no-borrow branches, down to 0;
  • large timestamps, up to UINT64_MAX.

One case is characterized, not endorsed: above the base, a result that lands on a whole second comes back as tv_nsec == 1000000000 with tv_sec one second short. The carry is nsecs > nsecs_per_sec where >= was meant. It is filed as #1505. The port keeps it, and the fix goes in its own PR.

RED → GREEN

  • No RED commit: this is a move plus a characterization test, which passes on the moved code. It passes on master's code too, and on the v0.1.0-beta.20261018 release's libobs.so.30, both the C one and the obs-studio-rust/ one.
  • Local, two build trees (ENABLE_RUST_LIBOBS=OFF and ON). Each runs the cmocka tests against libobs and against libobs-with-rust:
Lane libobs libobs-with-rust Exported symbols
C (ENABLE_RUST_LIBOBS=OFF) 318/319 ¹ 319/319 IDENTICAL (1766)
Rust (ENABLE_RUST_LIBOBS=ON) 319/319 319/319 IDENTICAL (1766)

¹ test_pulse_monitor_device (PipeWire default sink) failed once under -j6; it passes 3/3 on its own in all four. 7 frontend tests (test_config_migration_*, test_virtual_cam_shutdown) were not built in these trees: I built only the cmocka-tests target. Nothing was skipped.

  • test_platform_time: 9/9 in all four, and 20 repeated runs in each.
  • ./lint (ci/local_gate.py --lane lint): passed (121 s)
  • Real app: not applicable (no behavior change).

Windows/macOS: PR CI scopes this Linux-only. The stacked port PR touches rust/obs-util/src/platform/, so its CI runs the Windows and macOS Rust and Tier 2 lanes, which build plain libobs with this moved file and run test_platform_time there.

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
  • 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)

Behavior-neutral extraction before the Rust port: os_nstime_to_timespec,
its static init_timespec_offset and the timespec_offset static move
verbatim from libobs/util/platform.c.h into libobs/util/platform-time.c.h,
in the same libobs.platform unity group and precompiled header. The
oracle compiles both files. No host conditionals move.

test_platform_time characterizes os_nstime_to_timespec, which no test
called. The base pair is taken on the first call and cannot be read
back, but its wall-minus-monotonic difference can: the group setup
converts a timestamp read just before the first call, which is at or
below the base, so every case predicts its result exactly. It covers
the first call taking the base, NULL storage, timestamps around, above
and below the base, the nanosecond carry and borrow, and timestamps up
to UINT64_MAX. One case is characterized, not endorsed: above the base,
a result on a whole second comes back as tv_nsec == 1000000000 with
tv_sec one short (the carry is `>` where `>=` was meant).

Refs obs-rust#262
@rdoupe
rdoupe requested a review from zackees as a code owner October 20, 2026 06:30
@rdoupe rdoupe mentioned this pull request Oct 20, 2026
6 of 7 tasks
@zackees
zackees enabled auto-merge October 20, 2026 06:42
@zackees
zackees added this pull request to the merge queue Oct 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 20, 2026
@zackees

zackees commented Oct 20, 2026

Copy link
Copy Markdown
Member

Coordinator: closing as landed. Its move commit went into master with the stacked port #1507 (merged 07:08Z), which then ported the moved C. Merging this now would put the C back that #1507 removed, so there is nothing left to merge.

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