[glib/wip/3v1n0/support-can-fail-tests] fixup! meson: Support tests that can fail under certain conditions
- From: Marco Trevisan <marcotrevi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/3v1n0/support-can-fail-tests] fixup! meson: Support tests that can fail under certain conditions
- Date: Wed, 19 Oct 2022 21:35:59 +0000 (UTC)
commit 8db4f45231d3879c936903c1691005ac1caa2e9a
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Wed Oct 19 23:26:27 2022 +0200
fixup! meson: Support tests that can fail under certain conditions
gio/tests/meson.build | 53 ++++++++++-------------------------------------
glib/tests/meson.build | 52 ++++++++--------------------------------------
gmodule/tests/meson.build | 28 +++++++------------------
gobject/tests/meson.build | 50 +++++++-------------------------------------
meson.build | 6 +++---
tests/run-flaky-test.py | 21 +++++++++++++++++++
6 files changed, 59 insertions(+), 151 deletions(-)
---
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index daaa7fb2aa..938e7b2210 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -916,27 +916,13 @@ foreach test_name, extra_args : gio_tests
local_test_env = test_env
if extra_args.get('can_fail', false)
- if have_sh
- depends += [exe]
- args = [
- '-c',
- 'timeout -k @0@ "@1@" "$@" || exit 77'.format(timeout, exe.full_path()),
- '--',
- args
- ]
- exe = sh_program
- timeout = -1
- elif cmd_exe_program.found()
- depends += [exe]
- args = [
- '/c',
- '"@0@" "@1@" || exit 77'.format(exe.full_path(), ' '.join(args)),
- ]
- exe = cmd_exe_program
- else
- warning('Test @0@ cannot be ran reliably, skipping it'.format(test_name))
- continue
- endif
+ depends += [exe]
+ args = [
+ timeout,
+ args
+ ]
+ exe = flaky_test_runner
+ timeout = -1
endif
foreach var, value : extra_args.get('env', {})
@@ -973,27 +959,10 @@ foreach test_name, extra_args : python_tests
timeout = test_timeout
if extra_args.get('can_fail', false)
- if have_sh
- depends += [exe]
- args = [
- '-c',
- 'timeout -k @0@ "@1@" "$@" || exit 77'.format(timeout, exe.full_path()),
- '--',
- args
- ]
- exe = sh_program
- timeout = -1
- elif cmd_exe_program.found()
- depends += [exe]
- args = [
- '/c',
- '"@0@" "@1@" || exit 77'.format(exe.full_path(), ' '.join(args)),
- ]
- exe = cmd_exe_program
- else
- warning('Test @0@ cannot be ran reliably, skipping it'.format(test_name))
- continue
- endif
+ depends += [exe]
+ args = [ timeout.to_string(), exe, args ]
+ exe = flaky_test_runner
+ timeout = -1
endif
test(
diff --git a/glib/tests/meson.build b/glib/tests/meson.build
index 3405512852..f5b429b201 100644
--- a/glib/tests/meson.build
+++ b/glib/tests/meson.build
@@ -48,7 +48,7 @@ glib_tests = {
'keyfile' : {},
'list' : {},
'logging' : {},
- 'macros' : {},
+ 'macros' : {'can_fail': true},
'mainloop' : {},
'mappedfile' : {},
'mapping' : {},
@@ -301,27 +301,10 @@ foreach test_name, extra_args : glib_tests
timeout = suite.contains('slow') ? test_timeout_slow : test_timeout
if extra_args.get('can_fail', false)
- if have_sh
- depends += [exe]
- args = [
- '-c',
- 'timeout -k @0@ "@1@" "$@" || exit 77'.format(timeout, exe.full_path()),
- '--',
- args
- ]
- exe = sh_program
- timeout = -1
- elif cmd_exe_program.found()
- depends += [exe]
- args = [
- '/c',
- '"@0@" "@1@" || exit 77'.format(exe.full_path(), ' '.join(args)),
- ]
- exe = cmd_exe_program
- else
- warning('Test @0@ cannot be ran reliably, skipping it'.format(test_name))
- continue
- endif
+ depends += [exe]
+ args = [ timeout.to_string(), exe, args ]
+ exe = flaky_test_runner
+ timeout = -1
endif
test(test_name, exe,
@@ -363,27 +346,10 @@ foreach test_name, extra_args : python_tests
timeout = test_timeout
if extra_args.get('can_fail', false)
- if have_sh
- depends += [exe]
- args = [
- '-c',
- 'timeout -k @0@ "@1@" "$@" || exit 77'.format(timeout, exe.full_path()),
- '--',
- args
- ]
- exe = sh_program
- timeout = -1
- elif cmd_exe_program.found()
- depends += [exe]
- args = [
- '/c',
- '"@0@" "@1@" || exit 77'.format(exe.full_path(), ' '.join(args)),
- ]
- exe = cmd_exe_program
- else
- warning('Test @0@ cannot be ran reliably, skipping it'.format(test_name))
- continue
- endif
+ depends += [exe]
+ args = [ timeout.to_string(), exe, args ]
+ exe = flaky_test_runner
+ timeout = -1
endif
test(
diff --git a/gmodule/tests/meson.build b/gmodule/tests/meson.build
index b2e34b296e..95f36a1eec 100644
--- a/gmodule/tests/meson.build
+++ b/gmodule/tests/meson.build
@@ -99,27 +99,13 @@ foreach test_name, extra_args : gmodule_tests
timeout = suite.contains('slow') ? test_timeout_slow : test_timeout
if extra_args.get('can_fail', false)
- if have_sh
- depends += [exe]
- args = [
- '-c',
- 'timeout -k @0@ "@1@" "$@" || exit 77'.format(timeout, exe.full_path()),
- '--',
- args
- ]
- exe = sh_program
- timeout = -1
- elif cmd_exe_program.found()
- depends += [exe]
- args = [
- '/c',
- '"@0@" "@1@" || exit 77'.format(exe.full_path(), ' '.join(args)),
- ]
- exe = cmd_exe_program
- else
- warning('Test @0@ cannot be ran reliably, skipping it'.format(test_name))
- continue
- endif
+ depends += [exe]
+ args = [
+ timeout,
+ args
+ ]
+ exe = flaky_test_runner
+ timeout = -1
endif
test(test_name, exe,
diff --git a/gobject/tests/meson.build b/gobject/tests/meson.build
index 86ddce9a76..750cb16794 100644
--- a/gobject/tests/meson.build
+++ b/gobject/tests/meson.build
@@ -177,27 +177,10 @@ foreach test_name, extra_args : gobject_tests
endif
if extra_args.get('can_fail', false)
- if have_sh
- depends += [exe]
- args = [
- '-c',
- 'timeout -k @0@ "@1@" "$@" || exit 77'.format(timeout, exe.full_path()),
- '--',
- args
- ]
- exe = sh_program
- timeout = -1
- elif cmd_exe_program.found()
- depends += [exe]
- args = [
- '/c',
- '"@0@" "@1@" || exit 77'.format(exe.full_path(), ' '.join(args)),
- ]
- exe = cmd_exe_program
- else
- warning('Test @0@ cannot be ran reliably, skipping it'.format(test_name))
- continue
- endif
+ depends += [exe]
+ args = [ timeout.to_string(), exe, args ]
+ exe = flaky_test_runner
+ timeout = -1
endif
test(test_name, exe,
@@ -215,27 +198,10 @@ foreach test_name, extra_args : python_tests
timeout = test_timeout
if extra_args.get('can_fail', false)
- if have_sh
- depends += [exe]
- args = [
- '-c',
- 'timeout -k @0@ "@1@" "$@" || exit 77'.format(timeout, exe.full_path()),
- '--',
- args
- ]
- exe = sh_program
- timeout = -1
- elif cmd_exe_program.found()
- depends += [exe]
- args = [
- '/c',
- '"@0@" "@1@" || exit 77'.format(exe.full_path(), ' '.join(args)),
- ]
- exe = cmd_exe_program
- else
- warning('Test @0@ cannot be ran reliably, skipping it'.format(test_name))
- continue
- endif
+ depends += [exe]
+ args = [ timeout.to_string(), exe, args ]
+ exe = flaky_test_runner
+ timeout = -1
endif
test(
diff --git a/meson.build b/meson.build
index 9e597f254a..9396e291d8 100644
--- a/meson.build
+++ b/meson.build
@@ -2243,9 +2243,7 @@ endif
# Determine which user environment-dependent files that we want to install
have_bash = find_program('bash', required : false).found() # For completion scripts
bash_comp_dep = dependency('bash-completion', version: '>=2.0', required: false)
-sh_program = find_program('sh', required : false) # For glib-gettextize
-cmd_exe_program = find_program('cmd.exe', required : false)
-have_sh = sh_program.found()
+have_sh = find_program('sh', required : false).found() # For glib-gettextize
# Some installed tests require a custom environment
env_program = find_program('env', required: installed_tests_enabled)
@@ -2339,6 +2337,8 @@ common_test_env = [
]
test_timeout = 60
test_timeout_slow = 180
+flaky_test_runner = find_program('tests' / 'run-flaky-test.py',
+ required : get_option('tests'))
pkg = import('pkgconfig')
windows = import('windows')
diff --git a/tests/run-flaky-test.py b/tests/run-flaky-test.py
new file mode 100755
index 0000000000..4db60398bd
--- /dev/null
+++ b/tests/run-flaky-test.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+
+import subprocess
+import sys
+
+if len(sys.argv) < 3:
+ print("Missing arguments <timeout> <program> [ args... ]")
+ sys.exit(1)
+
+timeout = int(sys.argv[1])
+cmd = sys.argv[2:]
+
+try:
+ p = subprocess.run(cmd, timeout=timeout)
+ p.check_returncode()
+except subprocess.TimeoutExpired:
+ print(f'Timeout of {timeout} expired for {" ".join(cmd)}')
+ sys.exit(77)
+except subprocess.CalledProcessError:
+ sys.exit(77)
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]