#!/usr/bin/env python3 # SPDX-FileCopyrightText: 2026 Volker Krause # SPDX-License-Identifier: BSD-2-Clause import os import subprocess import sys import time if __name__ == '__main__': if 'KDE_FLATPAK_TEST_COMMAND' not in os.environ: print("No test command specified, skipping.") sys.exit(0) # remove environment variables potentially containing secure tokens # (see similar code in run-ci-build.py) env = os.environ env.pop('KDECI_CACHE_PATH', None) env.pop('KDECI_GITLAB_SERVER', None) env.pop('KDECI_GITLAB_TOKEN', None) env.pop('KDECI_PACKAGE_PROJECT', None) env.pop('KDECI_SECURE_SERVICES_KEY', None) # set up D-Bus and Xvfb print("### Environment setup…") env['DISPLAY'] = ':90' xvfbProcess = subprocess.Popen("Xvfb :90 -ac -screen 0 1600x1200x24+32", stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT, shell=True) time.sleep(5) wmProcess = subprocess.Popen("openbox", stdout=sys.stdout, stderr=sys.stderr, shell=True, env=env) process = subprocess.Popen("dbus-launch", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) process.wait() for variable in process.stdout: line = str(variable, 'utf-8') splitVars = line.split('=', 1) env[splitVars[0]] = splitVars[1].strip() for (key, value) in env.items(): print(f"{key}={value}") print("### Running test…") timeout = os.environ.get('KDE_FLATPAK_TEST_TIMEOUT', 300) returncode = 0 try: testProcess = subprocess.Popen(os.environ['KDE_FLATPAK_TEST_COMMAND'], stdout=sys.stdout, stderr=sys.stderr, shell=True, env=env) testProcess.wait(timeout) print(f"### Test finished with exit code {testProcess.returncode}!") returncode = testProcess.returncode except subprocess.TimeoutExpired: print(f"### Test failed to finish within {timeout} seconds!") testProcess.terminate() returncode = -1 wmProcess.terminate() xvfbProcess.terminate() sys.exit(returncode)