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>
This commit is contained in:
Marc-André Lureau 2022-01-21 21:08:12 +04:00
parent 8bb73c2a74
commit 2ebe30e170
3 changed files with 50 additions and 6 deletions

View File

@ -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,

View File

@ -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;
}

View File

@ -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;
}