[glib/wip/3v1n0/support-can-fail-tests: 1/2] fixup! meson: Support tests that can fail under certain conditions




commit cf47dfcc2e476732c7ea68e7d14d9e3cfd6149cf
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    | 50 +++++++-------------------------------------
 gmodule/tests/meson.build | 28 +++++++------------------
 gobject/tests/meson.build | 50 +++++++-------------------------------------
 meson.build               |  6 +++---
 tests/run-flaky-test.py   | 21 +++++++++++++++++++
 6 files changed, 58 insertions(+), 150 deletions(-)
---
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index daaa7fb2aa..3b303884dd 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..30f77ca6f6 100644
--- a/glib/tests/meson.build
+++ b/glib/tests/meson.build
@@ -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..4577f9b93f 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]