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
Anything else is illegal. Include explicit asserts on bad behaviour encountered to make debugging easier. Signed-off-by: Michael S. Tsirkin <m...@redhat.com> --- Changes from v2: - bugfix - assert returned pid - rework complex asserts for clarity Changes from v1: - drop SIGTERM as suggested by Eric tests/libqtest.c | 5 +++++ tests/libqtest.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index f869854..36ca859 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -109,9 +109,19 @@ static void kill_qemu(QTestState *s) kill(s->qemu_pid, SIGTERM); pid = waitpid(s->qemu_pid, &wstatus, 0); - if (pid == s->qemu_pid && WIFSIGNALED(wstatus)) { + /* waitpid returns child PID on success */ + assert(pid == s->qemu_pid); + + /* If exited on signal - check the reason: core dump is never OK */ + if (WIFSIGNALED(wstatus)) { assert(!WCOREDUMP(wstatus)); } + /* If exited normally - check exit status */ + if (WIFEXITED(wstatus)) { + assert(!WEXITSTATUS(wstatus)); + } + /* Valid ways to exit: right now only return from main or exit */ + assert(WIFEXITED(wstatus)); } } -- MST