Skip to content

Commit

Permalink
tests/py: Check x-d-p exit code and add ASAN suppression
Browse files Browse the repository at this point in the history
This makes sure that the portal frontend exited cleanly. This includes
no memory leaks detected by ASAN and for that to work we need our
suppression file.
  • Loading branch information
swick committed Oct 28, 2024
1 parent 2a74332 commit 54fbfd4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import os
import subprocess
import time
import signal

DBusGMainLoop(set_as_default=True)

Expand Down Expand Up @@ -425,10 +426,9 @@ def start_xdp(self):
"""

portal_dir = Path(os.getenv("G_TEST_BUILDDIR", "tests")) / "portals" / "test"

if not portal_dir.exists():
raise FileNotFoundError(
f"{portal_dir} does not exist, try running from meson build dir or setting G_TEST_SRCDIR"
f"{portal_dir} does not exist, try running from meson build dir or setting G_TEST_BUILDDIR"
)

env = os.environ.copy()
Expand All @@ -437,6 +437,16 @@ def start_xdp(self):
env["XDG_CURRENT_DESKTOP"] = "test"
env["XDG_DESKTOP_PORTAL_TEST_APP_ID"] = self.app_id

asan_suppression = (
Path(os.getenv("G_TEST_SRCDIR", "tests")) / "asan.suppression"
)
if not asan_suppression.exists():
raise FileNotFoundError(
f"{asan_suppression} does not exist, try running from meson build dir or setting G_TEST_SRCDIR"
)

env["LSAN_OPTIONS"] = f"suppressions={asan_suppression}"

self.start_dbus_monitor()
self.start_portal_frontend(env)
self.start_permission_store(env)
Expand Down Expand Up @@ -527,8 +537,10 @@ def tear_down(self):
self.dbus_monitor.wait()

if self.portal_frontend:
self.portal_frontend.terminate()
self.portal_frontend.wait()
# give it a chance to shut down cleanly
self.portal_frontend.send_signal(signal.SIGHUP)
returncode = self.portal_frontend.wait()
assert returncode == 0

if self.permission_store:
self.permission_store.terminate()
Expand Down
5 changes: 5 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ if enable_pytest

pytest_args = ['--verbose', '--log-level=DEBUG']

pytest_env = environment()
pytest_env.set('G_TEST_SRCDIR', meson.current_source_dir())
pytest_env.set('G_TEST_BUILDDIR', meson.current_build_dir())

# pytest xdist is nice because it significantly speeds up our
# test process, but it's not required
if pymod.find_installation('python3', modules: ['xdist'], required: false).found()
Expand Down Expand Up @@ -323,6 +327,7 @@ if enable_pytest
'pytest/@0@'.format(testname),
pytest,
args: pytest_args + ['-k', testname],
env: pytest_env,
suite: ['pytest'],
timeout: 120,
)
Expand Down

0 comments on commit 54fbfd4

Please sign in to comment.