[glib: 3/7] tests: fix spawn-multithreaded on win32
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 3/7] tests: fix spawn-multithreaded on win32
- Date: Fri, 4 Mar 2022 16:16:40 +0000 (UTC)
commit 2ebe30e170f612faf9c4a83371033b9b8111b271
Author: Marc-André Lureau <marcandre lureau redhat com>
Date: Fri Jan 21 21:08:12 2022 +0400
tests: fix spawn-multithreaded on win32
Add test-spawn-sleep helper program to sleep on Windows (child-test
removed in commit 241b9f41b, probably breaking the test)
(fwiw, Windows has a timeout command nowadays, but it conflicts with
msys2 timeout which has different usage)
Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>
glib/tests/meson.build | 10 ++++++++++
glib/tests/spawn-multithreaded.c | 14 ++++++++------
glib/tests/test-spawn-sleep.c | 32 ++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 6 deletions(-)
---
diff --git a/glib/tests/meson.build b/glib/tests/meson.build
index 9150f3f44..dc6b095d8 100644
--- a/glib/tests/meson.build
+++ b/glib/tests/meson.build
@@ -267,6 +267,16 @@ executable('test-spawn-echo', 'test-spawn-echo.c',
install: installed_tests_enabled,
)
+if host_machine.system() == 'windows'
+ # test-spawn-sleep helper binary required by the spawn tests above
+ executable('test-spawn-sleep', 'test-spawn-sleep.c',
+ c_args : test_cargs,
+ dependencies : test_deps,
+ install_dir: installed_tests_execdir,
+ install: installed_tests_enabled,
+ )
+endif
+
executable('testing-helper', 'testing-helper.c',
c_args : test_cargs,
dependencies : test_deps,
diff --git a/glib/tests/spawn-multithreaded.c b/glib/tests/spawn-multithreaded.c
index fc0bf9c6e..c73a23433 100644
--- a/glib/tests/spawn-multithreaded.c
+++ b/glib/tests/spawn-multithreaded.c
@@ -31,6 +31,7 @@
#include <sys/types.h>
static char *echo_prog_path;
+static char *sleep_prog_path;
#ifdef G_OS_UNIX
#include <unistd.h>
@@ -43,10 +44,6 @@ static char *echo_prog_path;
static GMainLoop *global_main_loop;
static guint alive;
-#ifdef G_OS_WIN32
-static char *argv0;
-#endif
-
static GPid
get_a_child (gint ttl)
{
@@ -61,9 +58,9 @@ get_a_child (gint ttl)
si.cb = sizeof (&si);
memset (&pi, 0, sizeof (pi));
- cmdline = g_strdup_printf ("child-test -c%d", ttl);
+ cmdline = g_strdup_printf ("%s %d", sleep_prog_path, ttl);
- if (!CreateProcess (argv0, cmdline, NULL, NULL,
+ if (!CreateProcess (NULL, cmdline, NULL, NULL,
FALSE, 0, NULL, NULL, &si, &pi))
g_error ("CreateProcess failed: %s",
g_win32_error_message (GetLastError ()));
@@ -384,9 +381,13 @@ main (int argc,
dirname = g_path_get_dirname (argv[0]);
echo_prog_path = g_build_filename (dirname, "test-spawn-echo" EXEEXT, NULL);
+ sleep_prog_path = g_build_filename (dirname, "test-spawn-sleep" EXEEXT, NULL);
g_free (dirname);
g_assert (g_file_test (echo_prog_path, G_FILE_TEST_EXISTS));
+#ifdef G_OS_WIN32
+ g_assert (g_file_test (sleep_prog_path, G_FILE_TEST_EXISTS));
+#endif
g_test_add_func ("/gthread/spawn-childs", test_spawn_childs);
g_test_add_func ("/gthread/spawn-childs-threads", test_spawn_childs_threads);
@@ -396,6 +397,7 @@ main (int argc,
ret = g_test_run();
g_free (echo_prog_path);
+ g_free (sleep_prog_path);
return ret;
}
diff --git a/glib/tests/test-spawn-sleep.c b/glib/tests/test-spawn-sleep.c
new file mode 100644
index 000000000..34dfd5bd9
--- /dev/null
+++ b/glib/tests/test-spawn-sleep.c
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2022 Red Hat, Inc.
+ *
+ * This work is provided "as is"; redistribution and modification
+ * in whole or in part, in any medium, physical or electronic is
+ * permitted without restriction.
+ *
+ * This work is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * In no event shall the authors or contributors be liable for any
+ * direct, indirect, incidental, special, exemplary, or consequential
+ * damages (including, but not limited to, procurement of substitute
+ * goods or services; loss of use, data, or profits; or business
+ * interruption) however caused and on any theory of liability, whether
+ * in contract, strict liability, or tort (including negligence or
+ * otherwise) arising in any way out of the use of this software, even
+ * if advised of the possibility of such damage.
+ */
+#include "config.h"
+
+#include <stdlib.h>
+#include "glib.h"
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_usleep (atoi (argv[1]) * G_USEC_PER_SEC);
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]