From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org, ivanren@tencent.com, peterx@redhat.com,
richardw.yang@linux.intel.com, yury-kotov@yandex-team.ru,
quintela@redhat.com
Subject: [Qemu-devel] [PULL 07/12] tests/libqtest: Allow setting expected exit status
Date: Thu, 12 Sep 2019 14:50:01 +0100 [thread overview]
Message-ID: <20190912135006.14820-8-dgilbert@redhat.com> (raw)
In-Reply-To: <20190912135006.14820-1-dgilbert@redhat.com>
From: Yury Kotov <yury-kotov@yandex-team.ru>
Add qtest_set_expected_status function to set expected exit status of
child process. By default expected exit status is 0.
Signed-off-by: Yury Kotov <yury-kotov@yandex-team.ru>
Message-Id: <20190903162246.18524-3-yury-kotov@yandex-team.ru>
Acked-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
tests/libqtest.c | 36 +++++++++++++++++++++---------------
tests/libqtest.h | 9 +++++++++
2 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 0a6b91737e..4a7556462d 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -41,6 +41,7 @@ struct QTestState
int qmp_fd;
pid_t qemu_pid; /* our child QEMU process */
int wstatus;
+ int expected_status;
bool big_endian;
bool irq_level[MAX_IRQ];
GString *rx;
@@ -111,6 +112,11 @@ bool qtest_probe_child(QTestState *s)
return false;
}
+void qtest_set_expected_status(QTestState *s, int status)
+{
+ s->expected_status = status;
+}
+
static void kill_qemu(QTestState *s)
{
pid_t pid = s->qemu_pid;
@@ -124,24 +130,23 @@ static void kill_qemu(QTestState *s)
}
/*
- * We expect qemu to exit with status 0; anything else is
+ * Check whether qemu exited with expected exit status; 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) && WEXITSTATUS(wstatus) != s->expected_status) {
+ fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
+ "process but encountered exit status %d (expected %d)\n",
+ __FILE__, __LINE__, WEXITSTATUS(wstatus), s->expected_status);
+ abort();
+ } 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();
}
}
@@ -246,6 +251,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
g_test_message("starting QEMU: %s", command);
s->wstatus = 0;
+ s->expected_status = 0;
s->qemu_pid = fork();
if (s->qemu_pid == 0) {
setenv("QEMU_AUDIO_DRV", "none", true);
diff --git a/tests/libqtest.h b/tests/libqtest.h
index c8cffe5d68..a177e502d9 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -708,4 +708,13 @@ void qmp_assert_error_class(QDict *rsp, const char *class);
*/
bool qtest_probe_child(QTestState *s);
+/**
+ * qtest_set_expected_status:
+ * @s: QTestState instance to operate on.
+ * @status: an expected exit status.
+ *
+ * Set expected exit status of the child.
+ */
+void qtest_set_expected_status(QTestState *s, int status);
+
#endif
--
2.21.0
next prev parent reply other threads:[~2019-09-12 14:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-12 13:49 [Qemu-devel] [PULL 00/12] migration queue Dr. David Alan Gilbert (git)
2019-09-12 13:49 ` [Qemu-devel] [PULL 01/12] migration: multifd_send_thread always post p->sem_sync when error happen Dr. David Alan Gilbert (git)
2019-09-12 13:49 ` [Qemu-devel] [PULL 02/12] migration: cleanup check on ops in savevm.handlers iterations Dr. David Alan Gilbert (git)
2019-09-12 13:49 ` [Qemu-devel] [PULL 03/12] hw/net/vmxnet3: Fix leftover unregister_savevm Dr. David Alan Gilbert (git)
2019-09-12 13:49 ` [Qemu-devel] [PULL 04/12] migration: register_savevm_live doesn't need dev Dr. David Alan Gilbert (git)
2019-09-12 13:49 ` [Qemu-devel] [PULL 05/12] qemu-file: Rework old qemu_fflush comment Dr. David Alan Gilbert (git)
2019-09-12 13:50 ` [Qemu-devel] [PULL 06/12] migration: Add validate-uuid capability Dr. David Alan Gilbert (git)
2019-09-12 13:50 ` Dr. David Alan Gilbert (git) [this message]
2019-09-12 13:50 ` [Qemu-devel] [PULL 08/12] tests/migration: Add a test for " Dr. David Alan Gilbert (git)
2019-09-12 13:50 ` [Qemu-devel] [PULL 09/12] migration: Fix postcopy bw for recovery Dr. David Alan Gilbert (git)
2019-09-12 13:50 ` [Qemu-devel] [PULL 10/12] migration/qemu-file: remove check on writev_buffer in qemu_put_compression_data Dr. David Alan Gilbert (git)
2019-09-12 13:50 ` [Qemu-devel] [PULL 11/12] migration/qemu-file: fix potential buf waste for extra buf_index adjustment Dr. David Alan Gilbert (git)
2019-09-12 13:50 ` [Qemu-devel] [PULL 12/12] migration: fix one typo in comment of function migration_total_bytes() Dr. David Alan Gilbert (git)
2019-09-13 14:44 ` [Qemu-devel] [PULL 00/12] migration queue Peter Maydell
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=20190912135006.14820-8-dgilbert@redhat.com \
--to=dgilbert@redhat.com \
--cc=ivanren@tencent.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=richardw.yang@linux.intel.com \
--cc=yury-kotov@yandex-team.ru \
/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).