* Marc-André Lureau (marcandre.lur...@redhat.com) wrote: > Modify the behaviour of qtest_quit() to check against the expected > exit status value. The default remains 0. > > Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com>
This looks similar to the one in the current pending migration pull by Yury Kotov: 'tests/libqtest: Allow setting expected exit status' Dave > --- > 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 0a6b91737e..1f7910e583 100644 > --- a/tests/libqtest.c > +++ b/tests/libqtest.c > @@ -44,6 +44,7 @@ struct QTestState > bool big_endian; > bool irq_level[MAX_IRQ]; > GString *rx; > + int exit_status; > }; > > static GHookList abrt_hooks; > @@ -123,27 +124,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_expect_exit_status(QTestState *s, int status) > +{ > + s->exit_status = status; > } > > static void kill_qemu_hook_func(void *s) > @@ -213,7 +216,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 c8cffe5d68..d41229d7fd 100644 > --- a/tests/libqtest.h > +++ b/tests/libqtest.h > @@ -82,6 +82,15 @@ QTestState *qtest_init_with_serial(const char *extra_args, > int *sock_fd); > */ > void qtest_quit(QTestState *s); > > +/** > + * qtest_expect_exit_status: > + * @s: #QTestState instance to operate on. > + * @status: the expected exit status > + * > + * Set the expected exit status when calling qtest_quit(). > + */ > +void qtest_expect_exit_status(QTestState *s, int status); > + > /** > * qtest_qmp_fds: > * @s: #QTestState instance to operate on. > -- > 2.23.0 > -- Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK