41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
# Copyright (c) 2026 Storm Dragon
|
|
# Authors: Storm Dragon, Angus Kola
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Launch native tests with disposable runtime sockets and private D-Bus."""
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
|
|
def run_private_session(command, *, env, **kwargs):
|
|
"""Keep activated services away from the desktop's runtime sockets."""
|
|
if not command or command[0] not in ("dbus-run-session", "xvfb-run"):
|
|
raise ValueError("Start the private session with xvfb-run or dbus-run-session")
|
|
if "dbus-run-session" not in command:
|
|
raise ValueError("A private session requires dbus-run-session")
|
|
if "xvfb-run" in command and command.index("xvfb-run") > command.index("dbus-run-session"):
|
|
raise ValueError("Start Xvfb before D-Bus so activated services inherit the private display")
|
|
|
|
# Keep this path short: AT-SPI falls back from named sockets if its
|
|
# generated socket path is 100 bytes or longer.
|
|
with tempfile.TemporaryDirectory(prefix="cth-run-", dir="/tmp") as runtimeDir:
|
|
sessionEnv = dict(env, XDG_RUNTIME_DIR=runtimeDir)
|
|
for name in ("DBUS_SESSION_BUS_ADDRESS", "DBUS_STARTER_ADDRESS", "DBUS_STARTER_BUS_TYPE",
|
|
"AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY"):
|
|
sessionEnv.pop(name, None)
|
|
return subprocess.run(command, env=sessionEnv, **kwargs)
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) < 2:
|
|
sys.exit("Usage: native_test_session.py COMMAND [ARG ...]")
|
|
result = run_private_session(
|
|
["xvfb-run", "-a", "dbus-run-session", "--", *sys.argv[1:]], env=os.environ)
|
|
return result.returncode
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|