qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, ehabkost@redhat.com, mst@redhat.com
Subject: [Qemu-devel] [RFC PATCH] tests: use g_test_trap_fork for glib between 2.16 and 2.38
Date: Tue, 16 Sep 2014 17:43:24 +0200	[thread overview]
Message-ID: <1410882204-9836-1-git-send-email-pbonzini@redhat.com> (raw)

Glib recently introduced a robust way to run tests in a subprocess,
which is used in test-qdev-global-props.  However, we would like
to have the same tests run with older versions of glib, and the
older fork-based mechanisms works well enough.

This still requires:

- bumping the minimum required version from 2.12 to 2.16.  I suggest
bumping to the currently required version for Windows, which is 2.20
(released March 2009).

- disabling the test on Windows, since it does not have fork

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/Makefile                 |  2 +-
 tests/test-qdev-global-props.c | 63 +++++++++++++++++++++++++++---------------
 2 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/tests/Makefile b/tests/Makefile
index d5db97b..7f125e8 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -58,7 +58,7 @@ check-unit-y += tests/test-int128$(EXESUF)
 # all code tested by test-int128 is inside int128.h
 gcov-files-test-int128-y =
 check-unit-y += tests/test-bitops$(EXESUF)
-check-unit-y += tests/test-qdev-global-props$(EXESUF)
+check-unit-$(CONFIG_POSIX) += tests/test-qdev-global-props$(EXESUF)
 check-unit-y += tests/check-qom-interface$(EXESUF)
 gcov-files-check-qom-interface-y = qom/object.c
 check-unit-$(CONFIG_POSIX) += tests/test-vmstate$(EXESUF)
diff --git a/tests/test-qdev-global-props.c b/tests/test-qdev-global-props.c
index 0be9835..8e4b270 100644
--- a/tests/test-qdev-global-props.c
+++ b/tests/test-qdev-global-props.c
@@ -29,6 +29,27 @@
 #include "qom/object.h"
 #include "qapi/visitor.h"
 
+/* Use the older fork() mechanism if the newer, more robust subprocess tests
+ * are not available.
+ */
+#if GLIB_CHECK_VERSION(2, 38, 0)
+# define TEST_ADD_FUNC_SUBPROCESS(name, func) do {               \
+        g_test_add_func(name "/subprocess", func##_subprocess); \
+        g_test_add_func(name, func);                            \
+    } while (0)
+# define TEST_TRAP_SUBPROCESS(name, func)                        \
+    g_test_trap_subprocess(name, 0, 0)
+#else
+# define TEST_ADD_FUNC_SUBPROCESS(name, func) \
+    g_test_add_func(name, func)
+# define TEST_TRAP_SUBPROCESS(name, func) do {                                                \
+        if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) { \
+            func();                                                                          \
+            exit(0);                                                                         \
+        }                                                                                    \
+    } while(0)
+#endif
+
 
 #define TYPE_STATIC_PROPS "static_prop_type"
 #define STATIC_TYPE(obj) \
@@ -77,7 +98,8 @@ static void test_static_prop_subprocess(void)
 
 static void test_static_prop(void)
 {
-    g_test_trap_subprocess("/qdev/properties/static/default/subprocess", 0, 0);
+    TEST_TRAP_SUBPROCESS("/qdev/properties/static/default/subprocess",
+                         test_static_prop_subprocess);
     g_test_trap_assert_passed();
     g_test_trap_assert_stderr("");
     g_test_trap_assert_stdout("");
@@ -103,7 +125,8 @@ static void test_static_globalprop_subprocess(void)
 
 static void test_static_globalprop(void)
 {
-    g_test_trap_subprocess("/qdev/properties/static/global/subprocess", 0, 0);
+    TEST_TRAP_SUBPROCESS("/qdev/properties/static/global/subprocess",
+                         test_static_globalprop_subprocess);
     g_test_trap_assert_passed();
     g_test_trap_assert_stderr("");
     g_test_trap_assert_stdout("");
@@ -235,7 +258,8 @@ static void test_dynamic_globalprop_subprocess(void)
 
 static void test_dynamic_globalprop(void)
 {
-    g_test_trap_subprocess("/qdev/properties/dynamic/global/subprocess", 0, 0);
+    TEST_TRAP_SUBPROCESS("/qdev/properties/dynamic/global/subprocess",
+                         test_dynamic_globalprop_subprocess);
     g_test_trap_assert_passed();
     g_test_trap_assert_stderr_unmatched("*prop1*");
     g_test_trap_assert_stderr_unmatched("*prop2*");
@@ -280,7 +304,8 @@ static void test_dynamic_globalprop_nouser_subprocess(void)
 
 static void test_dynamic_globalprop_nouser(void)
 {
-    g_test_trap_subprocess("/qdev/properties/dynamic/global/nouser/subprocess", 0, 0);
+    TEST_TRAP_SUBPROCESS("/qdev/properties/dynamic/global/nouser/subprocess",
+                         test_dynamic_globalprop_nouser_subprocess);
     g_test_trap_assert_passed();
     g_test_trap_assert_stderr("");
     g_test_trap_assert_stdout("");
@@ -297,25 +322,17 @@ int main(int argc, char **argv)
     type_register_static(&nohotplug_type);
     type_register_static(&nondevice_type);
 
-    g_test_add_func("/qdev/properties/static/default/subprocess",
-                    test_static_prop_subprocess);
-    g_test_add_func("/qdev/properties/static/default",
-                    test_static_prop);
-
-    g_test_add_func("/qdev/properties/static/global/subprocess",
-                    test_static_globalprop_subprocess);
-    g_test_add_func("/qdev/properties/static/global",
-                    test_static_globalprop);
-
-    g_test_add_func("/qdev/properties/dynamic/global/subprocess",
-                    test_dynamic_globalprop_subprocess);
-    g_test_add_func("/qdev/properties/dynamic/global",
-                    test_dynamic_globalprop);
-
-    g_test_add_func("/qdev/properties/dynamic/global/nouser/subprocess",
-                    test_dynamic_globalprop_nouser_subprocess);
-    g_test_add_func("/qdev/properties/dynamic/global/nouser",
-                    test_dynamic_globalprop_nouser);
+    TEST_ADD_FUNC_SUBPROCESS("/qdev/properties/static/default",
+                             test_static_prop);
+
+    TEST_ADD_FUNC_SUBPROCESS("/qdev/properties/static/global",
+                             test_static_globalprop);
+
+    TEST_ADD_FUNC_SUBPROCESS("/qdev/properties/dynamic/global",
+                             test_dynamic_globalprop);
+
+    TEST_ADD_FUNC_SUBPROCESS("/qdev/properties/dynamic/global/nouser",
+                             test_dynamic_globalprop_nouser);
 
     g_test_run();
 
-- 
2.1.0

             reply	other threads:[~2014-09-16 15:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-16 15:43 Paolo Bonzini [this message]
2014-09-16 16:18 ` [Qemu-devel] [RFC PATCH] tests: use g_test_trap_fork for glib between 2.16 and 2.38 Michael S. Tsirkin
2014-09-16 16:20 ` Peter Maydell
2014-09-16 16:23   ` Paolo Bonzini
2014-09-16 16:28     ` Peter Maydell
2014-09-16 16:33       ` Paolo Bonzini
2014-09-16 16:45         ` Peter Maydell
2014-09-16 16:57           ` Michael S. Tsirkin
2014-09-16 17:23             ` Peter Maydell
2014-09-16 17:54               ` Michael S. Tsirkin
2014-09-16 16:43       ` Michael S. Tsirkin
2014-09-16 16:42     ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1410882204-9836-1-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).