[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 24/25] tests/libqtest: Improve kill_qemu()
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 24/25] tests/libqtest: Improve kill_qemu() |
Date: |
Thu, 16 Aug 2018 10:37:00 +0200 |
From: Eric Blake <address@hidden>
In kill_qemu() we have an assert that checks that the QEMU process
didn't dump core:
assert(!WCOREDUMP(wstatus));
Unfortunately the WCOREDUMP macro here means the resulting message
is not very easy to comprehend on at least some systems:
ahci-test: tests/libqtest.c:113: kill_qemu: Assertion `!(((__extension__
(((union { __typeof(wstatus) __in; int __i; }) { .__in = (wstatus) }).__i))) &
0x80)' failed.
and it doesn't identify what signal the process took. What's more,
WCOREDUMP is not reliable - in some cases, setrlimit() coupled with
kernel dump settings can result in the flag not being set. It's
better to log ALL death by signal, instead of caring whether a core
dump was attempted (although once we know a signal happened, also
mentioning if a core dump is present can be helpful).
Furthermore, we are NOT detecting EINTR (while EINTR shouldn't be
happening if we didn't install signal handlers, it's still better
to always be robust).
Finally, even non-signal death with a non-zero status is suspicious,
since qemu's SIGINT handler is supposed to result in exit(0).
Instead of using a raw assert, print the information in an
easier to understand way:
/i386/ahci/sanity: tests/libqtest.c:129: kill_qemu() detected QEMU death from
signal 11 (Segmentation fault) (core dumped)
(Of course, the really useful information would be why the QEMU
process dumped core in the first place, but we don't have that
by the time the test program has picked up the exit status.)
Suggested-by: Peter Maydell <address@hidden>
Signed-off-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
[Core dump reporting and commit message tweaked]
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
---
tests/libqtest.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 3706f30aa2..b703fca26d 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -107,10 +107,28 @@ static void kill_qemu(QTestState *s)
pid_t pid;
kill(s->qemu_pid, SIGTERM);
- pid = waitpid(s->qemu_pid, &wstatus, 0);
+ TFR(pid = waitpid(s->qemu_pid, &wstatus, 0));
- if (pid == s->qemu_pid && WIFSIGNALED(wstatus)) {
- assert(!WCOREDUMP(wstatus));
+ 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.
+ */
+ 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);
+ }
+ abort();
}
}
}
--
2.17.1
- [Qemu-devel] [PULL 09/25] test-qobject-input-visitor: Avoid format string ambiguity, (continued)
- [Qemu-devel] [PULL 09/25] test-qobject-input-visitor: Avoid format string ambiguity, Markus Armbruster, 2018/08/16
- [Qemu-devel] [PULL 20/25] migration-test: Clean up string interpolation into QMP, part 3, Markus Armbruster, 2018/08/16
- [Qemu-devel] [PULL 13/25] cpu-plug-test: Don't pass integers as strings to device_add, Markus Armbruster, 2018/08/16
- [Qemu-devel] [PULL 11/25] tests: Pass literal format strings directly to qmp_FOO(), Markus Armbruster, 2018/08/16
- [Qemu-devel] [PULL 15/25] migration-test: Make wait_command() return the "return" member, Markus Armbruster, 2018/08/16
- [Qemu-devel] [PULL 19/25] migration-test: Clean up string interpolation into QMP, part 2, Markus Armbruster, 2018/08/16
- [Qemu-devel] [PULL 16/25] tests: New helper qtest_qmp_receive_success(), Markus Armbruster, 2018/08/16
- [Qemu-devel] [PULL 21/25] libqtest: Enable compile-time format string checking, Markus Armbruster, 2018/08/16
- [Qemu-devel] [PULL 12/25] tests: Clean up string interpolation into QMP input (simple cases), Markus Armbruster, 2018/08/16
- [Qemu-devel] [PULL 14/25] tests: Clean up string interpolation around qtest_qmp_device_add(), Markus Armbruster, 2018/08/16
- [Qemu-devel] [PULL 24/25] tests/libqtest: Improve kill_qemu(),
Markus Armbruster <=
- Re: [Qemu-devel] [PULL 00/25] Testing patches for 2018-08-16, Peter Maydell, 2018/08/16