[PATCH spice-server 28/33] test-display-base: Port to Windows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use GLib function to launch and wait process exit.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 server/tests/regression-test.py  |  4 ++--
 server/tests/test-display-base.c | 37 +++++++++++++++-----------------
 2 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/server/tests/regression-test.py b/server/tests/regression-test.py
index 5aad1a7b..81eaecf1 100755
--- a/server/tests/regression-test.py
+++ b/server/tests/regression-test.py
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 from subprocess import PIPE, Popen
-import Image
-import ImageChops
+from PIL import Image
+from PIL import ImageChops
 
 
 def spicy_screenshot():
diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
index 868521bc..ecf40e4a 100644
--- a/server/tests/test-display-base.c
+++ b/server/tests/test-display-base.c
@@ -91,17 +91,19 @@ static int has_automated_tests = 0; //automated test flag
 // between multiple threads so use a mutex
 static pthread_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-__attribute__((noreturn))
-static void sigchld_handler(SPICE_GNUC_UNUSED int signal_num) // wait for the child process and exit
+// wait for the child process and exit
+static void child_exited(GPid pid, gint status, gpointer user_data)
 {
-    int status;
-    wait(&status);
+    g_spawn_close_pid(pid);
     exit(0);
 }
 
 static void regression_test(void)
 {
-    pid_t pid;
+    GPid pid;
+    GError *error = NULL;
+    gboolean retval;
+    gchar **argv;
 
     if (--rects != 0) {
         return;
@@ -113,17 +115,17 @@ static void regression_test(void)
         return;
     }
 
-    pid = fork();
-    if (pid == 0) {
-        char buf[PATH_MAX];
-        char *argv[] = { NULL };
-        char *envp[] = {buf, NULL};
+    argv = g_strsplit("./regression-test.py", " ", -1);
+    retval = g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH|G_SPAWN_DO_NOT_REAP_CHILD,
+                           NULL, NULL, &pid, &error);
+    g_strfreev(argv);
+    g_assert(retval);
 
-        snprintf(buf, sizeof(buf), "PATH=%s", getenv("PATH"));
-        execve("regression-test.py", argv, envp);
-    } else if (pid > 0) {
-        return;
-    }
+    GSource *source = g_child_watch_source_new(pid);
+    g_source_set_callback(source, (GSourceFunc)(void*)child_exited, NULL, NULL);
+    guint id = g_source_attach(source, basic_event_loop_get_context());
+    g_assert(id != 0);
+    g_source_unref(source);
 }
 
 static void set_cmd(QXLCommandExt *ext, uint32_t type, QXLPHYSICAL data)
@@ -969,11 +971,6 @@ void test_destroy(Test *test)
 
 static void init_automated(void)
 {
-    struct sigaction sa;
-
-    memset(&sa, 0, sizeof sa);
-    sa.sa_handler = &sigchld_handler;
-    sigaction(SIGCHLD, &sa, NULL);
 }
 
 static __attribute__((noreturn))
-- 
2.17.2

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]