From e21f83977669cc31f8e27490e421c1273b02c639 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 13 Sep 2023 12:33:08 +0200 Subject: [PATCH] tests/dbus-runner: Detect nested invocations to skip mocking The test and dist CI jobs run wrap the meson calls in dbus-runner to avoid setting up dbus servers and mocking services for every test but the dbus-runner invocation from meson test didn't actually skip all the setup. This nested mocking also doesn't work because the system bus is assumed to be the host system bus and not a mocked one. Part-of: --- src/tests/mutter_dbusrunner.py | 56 +++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/tests/mutter_dbusrunner.py b/src/tests/mutter_dbusrunner.py index 4025ff719..45407ba0f 100644 --- a/src/tests/mutter_dbusrunner.py +++ b/src/tests/mutter_dbusrunner.py @@ -258,21 +258,22 @@ ret = logind_helpers.open_file_direct(major, minor) return template_path raise FileNotFoundError(f'Couldnt find a {template_name} template') - def wrap_call(self, args): - env = {} - env.update(os.environ) - env['NO_AT_BRIDGE'] = '1' - env['GTK_A11Y'] = 'none' - env['GSETTINGS_BACKEND'] = 'memory' - wrapper = env.get('META_DBUS_RUNNER_WRAPPER') - if wrapper == 'gdb': - args = ['gdb', '-ex', 'r', '-ex', 'bt full', '--args'] + args - elif wrapper: - args = wrapper.split(' ') + args +def wrap_call(args, wrapper): + env = {} + env.update(os.environ) + env['NO_AT_BRIDGE'] = '1' + env['GTK_A11Y'] = 'none' + env['GSETTINGS_BACKEND'] = 'memory' + env['META_DBUS_RUNNER_ACTIVE'] = '1' - p = subprocess.Popen(args, env=env) - return p.wait() + if wrapper == 'gdb': + args = ['gdb', '-ex', 'r', '-ex', 'bt full', '--args'] + args + elif wrapper: + args = wrapper.split(' ') + args + + p = subprocess.Popen(args, env=env) + return p.wait() def meta_run(klass): @@ -287,14 +288,27 @@ def meta_run(klass): if rest[0] == '--': rest.pop(0) - klass.setUpClass(args.kvm, args.launch) - runner = klass() - runner.assertGreater(len(rest), 0) result = 1 - try: - print('Running test case...', file=sys.stderr) - result = runner.wrap_call(rest) - finally: - MutterDBusRunner.tearDownClass() + if os.getenv('META_DBUS_RUNNER_ACTIVE') == None: + klass.setUpClass(args.kvm, args.launch) + runner = klass() + runner.assertGreater(len(rest), 0) + wrapper = os.getenv('META_DBUS_RUNNER_WRAPPER') + + try: + print('Running test case...', file=sys.stderr) + result = wrap_call(rest, wrapper) + finally: + MutterDBusRunner.tearDownClass() + else: + try: + print(('Inside a nested meta-dbus-runner: ' + 'Not re-creating mocked environment.'), + file=sys.stderr) + print('Running test case...', file=sys.stderr) + result = wrap_call(rest, None) + finally: + pass + return result