Message ID | 1527174955-160019-1-git-send-email-mst@redhat.com |
---|---|
State | New |
Headers | show |
Series | None | expand |
On 05/24/2018 10:17 AM, Michael S. Tsirkin wrote: > Add more checks on how did QEMU exit. > > Legal ways to exit right now: > - exit(0) or return from main > - kill(SIGTERM) - sent by testing infrastructure Yes, but kill(SIGTERM) causes qemu proper to exit with status 0, because we handle the signal rather than letting it have default behavior or rethrowing it. > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com> > Suggested-by: Thomas Huth <thuth@redhat.com> > --- > > TODO: refactor testing infrastructure to stop > QEMU through QMP as opposed to SIGTERM. > if (pid == s->qemu_pid && WIFSIGNALED(wstatus)) { > + /* Core dump is never OK */ > assert(!WCOREDUMP(wstatus)); > + /* Either exit normally or get killed */ > + assert((WIFEXITED(wstatus) || WIFSIGNALED(wstatus))); Eww. This is true if someone does SIGKILL, but not if someone does SIGTERM. > + /* Exited normally - check exit status. */ > + assert(!WIFEXITED(wstatus) || WEXITSTATUS(wstatus) == 0); This is fine. > + /* Killed - we only ever send SIGTERM. */ > + assert(!WIFSIGNALED(wstatus) || WTERMSIG(wstatus) == SIGTERM); But this is bogus. Sending SIGTERM does NOT cause WIFSIGNALED(); you'd be hard-pressed to get qemu to exit with WTERMSIG(wstatus) == SIGTERM.
diff --git a/tests/libqtest.c b/tests/libqtest.c index f869854..2470f57 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -110,7 +110,14 @@ static void kill_qemu(QTestState *s) pid = waitpid(s->qemu_pid, &wstatus, 0); if (pid == s->qemu_pid && WIFSIGNALED(wstatus)) { + /* Core dump is never OK */ assert(!WCOREDUMP(wstatus)); + /* Either exit normally or get killed */ + assert((WIFEXITED(wstatus) || WIFSIGNALED(wstatus))); + /* Exited normally - check exit status. */ + assert(!WIFEXITED(wstatus) || WEXITSTATUS(wstatus) == 0); + /* Killed - we only ever send SIGTERM. */ + assert(!WIFSIGNALED(wstatus) || WTERMSIG(wstatus) == SIGTERM); } } }
Add more checks on how did QEMU exit. Legal ways to exit right now: - exit(0) or return from main - kill(SIGTERM) - sent by testing infrastructure Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Suggested-by: Thomas Huth <thuth@redhat.com> --- TODO: refactor testing infrastructure to stop QEMU through QMP as opposed to SIGTERM. tests/libqtest.c | 7 +++++++ 1 file changed, 7 insertions(+)