Skip to content

test: Characterize Linux sleep inhibition before its port - #1503

Closed
rdoupe wants to merge 1 commit into
obs-rust:masterfrom
rdoupe:test/characterize-inhibit-sleep
Closed

rdoupe wants to merge 1 commit into
obs-rust:masterfrom
rdoupe:test/characterize-inhibit-sleep

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Refs #1500

What and why

Characterization before the port of libobs/util/platform-nix-inhibit.c.h (Linux and FreeBSD os_inhibit_sleep_*). No Rust and no production code in this change. The port may not edit these tests.

The first platform-nix port (#403) dropped the portal and session D-Bus inhibitors without a failing test (#453). These tests pin every path of the file, so the port cannot do that again.

test_inhibit_sleep (new) covers the path with no session D-Bus. The bus address points at a socket that does not exist, and PATH holds only a fake xdg-screensaver, so the user's session is never touched.

Case Pinned behavior
null_info_is_rejected set_active(NULL, …) returns false; destroy(NULL) does nothing
no_bus_falls_back_to_xdg_screensaver create still returns an inhibitor. set_active returns true only when the state changes. Deactivating joins at once
repeated_activate_deactivate 50 cycles, each start and join in time
destroy_while_active_joins destroy deactivates first and joins the thread
destroy_inactive create then destroy, never activated
null_and_odd_reasons NULL, empty, 4 KiB, non-ASCII and control-character reasons. NULL is characterized, not endorsed
reason_is_copied the caller's string can be freed after create
two_inhibitors_are_independent separate state and thread per inhibitor

In every case the fake xdg-screensaver never runs: the thread waits the full 30 s before its first reset.

test_inhibit_sleep_dbus gets 7 new cases on its private bus. The 3 old cases are unchanged.

Case Pinned behavior
test_portal_preferred_over_screensaver with a portal and org.freedesktop.ScreenSaver both up, only the portal is used
test_portal_repeated_set_active only a change reaches the portal; each cycle makes a new request and closes it
test_portal_destroy_while_active destroy closes the portal request
test_screensaver_repeated_set_active 5 cycles give 5 Inhibit and 5 UnInhibit calls, with the service's cookie
test_screensaver_destroy_while_active destroy releases the inhibit once
test_screensaver_reason_is_copied the service gets the reason as it was at create, byte for byte (empty, non-ASCII, 1 KiB)
test_empty_bus_falls_back a bus with neither service: the fallback is used and neither service gets a call

Without dbus-daemon, test_inhibit_sleep_dbus used to call skip() in each case. cmocka counts that as a pass, so a Tier 2 image with no dbus-daemon would have passed it without running anything. It now exits 77, which ctest reports as Skipped (SKIP_RETURN_CODE), and rust/tools/linux-validate/check-skips.sh fails a skipped test_inhibit_sleep*. ci/test_tier2_skips.py has a case for that.

Not pinned:

  • the Flatpak branch. Create returns NULL when there is no portal and /.flatpak-info exists, and a test cannot create that file at the root of the file system;
  • a NULL reason with a portal or D-Bus inhibitor, which reaches g_variant_new_string(NULL).

RED → GREEN

  • Characterization only. Both tests pass on master (13e73b115) unchanged. Headless; the D-Bus cases run on their own private bus (GTestDBus).
Build test_inhibit_sleep test_inhibit_sleep_dbus
C lane (ENABLE_RUST_LIBOBS=OFF) 8/8 10/10
Rust lane, libobs (OFF) 8/8 10/10
Rust lane, libobs-with-rust (ON, loaded from libobs-with-rust/) 8/8 10/10
  • ctest -R '^test_inhibit_sleep' --repeat until-fail:5 passed in all three.
  • With no dbus-daemon on PATH, ctest reports test_inhibit_sleep_dbus ... Skipped, and test_inhibit_sleep still passes.
  • uv run ci/local_gate.py --lane lint: ok. uv run python -m unittest ci/test_tier2_skips.py: 3/3.
  • Real app: not applicable (no behavior change).

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: 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: none
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not applicable, no port here

Pins os_inhibit_sleep_* in libobs/util/platform-nix-inhibit.c on Linux
and FreeBSD before the Rust port, so the port cannot drop a path the way
the first platform-nix port dropped the portal and D-Bus inhibitors.
No Rust and no production code change.

test_inhibit_sleep (new) covers the path with no session D-Bus: the bus
address points at a missing socket and PATH holds only a fake
xdg-screensaver, so the user's session is never touched. It pins a NULL
inhibitor, set_active returning true only on a change, 50
activate/deactivate cycles, destroy while active joining the thread at
once, NULL, empty, long and non-ASCII reasons, and two independent
inhibitors. The first reset waits the full 30 s, so the fake never runs.

test_inhibit_sleep_dbus gains seven cases on its private bus: the
portal is used and the session screensaver is not when both exist,
repeated set_active on the portal and on org.freedesktop.ScreenSaver
reaches the service once per change, destroy while active releases the
inhibit, the reason is copied at create byte for byte, and an empty bus
falls back without calling either service.

Without dbus-daemon it used to skip every case, which cmocka reports as
a pass, so a Tier 2 image without dbus would have passed it silently.
It now exits 77 (SKIP_RETURN_CODE), and check-skips.sh refuses a skipped
test_inhibit_sleep* in Tier 2.

Not pinned: the Flatpak branch (needs /.flatpak-info at the root) and a
NULL reason with a portal or D-Bus inhibitor (reaches
g_variant_new_string(NULL)).

Refs obs-rust#1500
@rdoupe
rdoupe requested a review from zackees as a code owner October 20, 2026 06:28
@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 characterization commit went into master with the stacked port #1504 (merged 07:08Z); the tree of this PR has no remaining diff against master.

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