qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 2/3] tests: add qtest_set_exit_status()


From: Marc-André Lureau
Subject: [Qemu-devel] [PATCH 2/3] tests: add qtest_set_exit_status()
Date: Mon, 8 Jul 2019 11:24:36 +0400

Modify the behaviour of qtest_quit() to check against the expected
exit status value. The default remains 0.

Signed-off-by: Marc-André Lureau <address@hidden>
---
 tests/libqtest.c | 41 ++++++++++++++++++++++-------------------
 tests/libqtest.h |  9 +++++++++
 2 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 3c5c3f49d8..d722de6da8 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -46,6 +46,7 @@ struct QTestState
     bool big_endian;
     bool irq_level[MAX_IRQ];
     GString *rx;
+    int exit_status;
 };
 
 static GHookList abrt_hooks;
@@ -125,27 +126,29 @@ static void kill_qemu(QTestState *s)
         assert(pid == s->qemu_pid);
     }
 
-    /*
-     * We expect qemu to exit with status 0; anything else is
-     * fishy and should be logged with as much detail as possible.
-     */
     wstatus = s->wstatus;
-    if (wstatus) {
-        if (WIFEXITED(wstatus)) {
-            fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
-                    "process but encountered exit status %d\n",
-                    __FILE__, __LINE__, WEXITSTATUS(wstatus));
-        } else if (WIFSIGNALED(wstatus)) {
-            int sig = WTERMSIG(wstatus);
-            const char *signame = strsignal(sig) ?: "unknown ???";
-            const char *dump = WCOREDUMP(wstatus) ? " (core dumped)" : "";
-
-            fprintf(stderr, "%s:%d: kill_qemu() detected QEMU death "
-                    "from signal %d (%s)%s\n",
-                    __FILE__, __LINE__, sig, signame, dump);
+    if (WIFEXITED(wstatus)) {
+        if (WEXITSTATUS(wstatus) == s->exit_status) {
+            return;
         }
-        abort();
+        fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
+                "process but encountered exit status %d\n",
+                __FILE__, __LINE__, WEXITSTATUS(wstatus));
+    } else if (WIFSIGNALED(wstatus)) {
+        int sig = WTERMSIG(wstatus);
+        const char *signame = strsignal(sig) ?: "unknown ???";
+        const char *dump = WCOREDUMP(wstatus) ? " (core dumped)" : "";
+
+        fprintf(stderr, "%s:%d: kill_qemu() detected QEMU death "
+                "from signal %d (%s)%s\n",
+                __FILE__, __LINE__, sig, signame, dump);
     }
+    abort();
+}
+
+void qtest_set_exit_status(QTestState *s, int status)
+{
+    s->exit_status = status;
 }
 
 static void kill_qemu_hook_func(void *s)
@@ -215,7 +218,7 @@ QTestState *qtest_init_without_qmp_handshake(const char 
*extra_args)
     gchar *command;
     const char *qemu_binary = qtest_qemu_binary();
 
-    s = g_new(QTestState, 1);
+    s = g_new0(QTestState, 1);
 
     socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
     qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
diff --git a/tests/libqtest.h b/tests/libqtest.h
index cadf1d4a03..aa54225c0e 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -84,6 +84,15 @@ QTestState *qtest_init_with_serial(const char *extra_args, 
int *sock_fd);
  */
 void qtest_quit(QTestState *s);
 
+/**
+ * qtest_set_exit_status:
+ * @s: #QTestState instance to operate on.
+ * @status: the expected exit status
+ *
+ * Set the expected exit status when calling qtest_quit().
+ */
+void qtest_set_exit_status(QTestState *s, int status);
+
 /**
  * qtest_qmp_fds:
  * @s: #QTestState instance to operate on.
-- 
2.22.0.214.g8dca754b1e




reply via email to

[Prev in Thread] Current Thread [Next in Thread]