tests/libqtest: Improve kill_qemu() assert
PATCH 1/1 tests/libqtest: Improve kill_qemu() assert
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.
Instead of using a raw assert, print the information in an easier to understand way:
/i386/ahci/sanity: libqtest.c: kill_qemu() tried to terminate QEMU process but it dumped core with signal 11
ahci-test: tests/libqtest.c:118: kill_qemu: Assertion `0' failed.
Aborted (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.)
---
In particular, the travis test config that enables gprof seems to (a) run into this every so often and (b) have the really unhelpful assertion text quoted above:
https://travis-ci.org/qemu/qemu/jobs/406192798
Maybe for 3.0 since it's only test code.
tests/libqtest.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tests/libqtest.c +7 -1
@@ -110,7 +110,13 @@ static void kill_qemu(QTestState *s) pid =waitpid (s->qemu_pid, &wstatus,0 );if (pid == s->qemu_pid &&WIFSIGNALED (wstatus)) { -assert (!WCOREDUMP (wstatus)); +if (WCOREDUMP (wstatus)) { +fprintf (stderr, +"libqtest.c: kill_qemu() tried to terminate QEMU " +"process but it dumped core with signal %d\n" , +WTERMSIG (wstatus)); +assert (0 ); + } } } }
Signature · 1 line
2.17.1
Quoted 7 lines · Peter Maydell
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:
Quoted 8 lines
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.
Instead of using a raw assert, print the information in an easier to understand way:
/i386/ahci/sanity:
libqtest.c:kill_qemu()tried to terminate QEMU process but it dumped core with signal 11
Less cryptic, indeed.
Quoted 1 line
ahci-test:
tests/libqtest.c:118:kill_qemu: Assertion `0' failed.
This file:line is not very relevant, ...
Quoted 23 lines
Aborted (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.)
Signed-off-by Peter Maydell <[email protected]>---
In particular, the travis test config that enables gprof seems to (a) run into this every so often and (b) have the really unhelpful assertion text quoted above:
https://travis-ci.org/qemu/qemu/jobs/406192798Maybe for 3.0 since it's only test code.
tests/libqtest.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)tests/libqtest.c +0
-0
tests/libqtest.c static void kill_qemu(QTestState *s) · line 118
Quoted 10 lines
tests/libqtest.c +6
-1@@ -110,7 +110,13 @@ static void kill_qemu(QTestState *s) pid =waitpid (s->qemu_pid, &wstatus,0 );if (pid == s->qemu_pid &&WIFSIGNALED (wstatus)) { -assert (!WCOREDUMP (wstatus)); +if (WCOREDUMP (wstatus)) { +fprintf (stderr, +"libqtest.c: kill_qemu() tried to terminate QEMU " +"process but it dumped core with signal %d\n" , +WTERMSIG (wstatus)); +assert (0 );
... what about directly using abort() here?
tests/libqtest.c static void kill_qemu(QTestState *s) · line 122
Quoted 5 lines
tests/libqtest.c +1
-0+ } } } }
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Peter Maydell
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:
Quoted 8 lines
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.
Instead of using a raw assert, print the information in an easier to understand way:
/i386/ahci/sanity:
libqtest.c:kill_qemu()tried to terminate QEMU process but it dumped core with signal 11
Quoted 7 lines
Less cryptic, indeed.
Quoted 1 line
ahci-test:
tests/libqtest.c:118:kill_qemu: Assertion `0' failed.This file:line is not very relevant, ...
... what about directly using
abort()here?
I did actually start with that, but decided I'd rather have the file-and-line in there to direct people more quickly to the immediate point where we asserted.
thanks
-- PMM
Quoted 22 lines · Peter Maydell
Quoted 21 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Peter Maydell
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:
Quoted 8 lines
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.
Instead of using a raw assert, print the information in an easier to understand way:
/i386/ahci/sanity:
libqtest.c:kill_qemu()tried to terminate QEMU process but it dumped core with signal 11Less cryptic, indeed.
Quoted 1 line
ahci-test:
tests/libqtest.c:118:kill_qemu: Assertion `0' failed.
Quoted 7 lines
Quoted 3 lines
This file:line is not very relevant, ...
... what about directly using
abort()here?I did actually start with that, but decided I'd rather have the file-and-line in there to direct people more quickly to the immediate point where we asserted.
You already print the file, just include the line. Perhaps
fprintf(stderr,
"%s:%d: kill_qemu tried to terminate QEMU "
"process but it dumped core with signal %s\n",
__FILE__, __LINE__, strsignal(WTERMSIG(wstatus)));
abort();Not that I expect the signal to ever be anything other than 11, and that being one of the handful that are consistent across pretty much all unix systems. But still.
r~
PS: The bike shed should be blue.
Quoted 7 lines · Richard Henderson
You already print the file, just include the line. Perhaps
fprintf(stderr, "%s:%d: kill_qemu tried to terminate QEMU " "process but it dumped core with signal %s\n", __FILE__, __LINE__, strsignal(WTERMSIG(wstatus))); abort();
I wasn't convinced that strsignal() would be available on all the host OSes we build on (we don't currently use it outside linux-user/), and I definitely didn't think that it merited a configure test for its presence just for a test error message :-)
thanks
-- PMM
Quoted 10 lines · Peter Maydell
Quoted 7 lines · Richard Henderson
You already print the file, just include the line. Perhaps
fprintf(stderr, "%s:%d: kill_qemu tried to terminate QEMU " "process but it dumped core with signal %s\n", __FILE__, __LINE__, strsignal(WTERMSIG(wstatus))); abort();
Quoted 5 lines
I wasn't convinced that
strsignal()would be available on all the host OSes we build on (we don't currently use it outside linux-user/), and I definitely didn't think that it merited a configure test for its presence just for a test error message :-)
Hmm. It has been in _GNU_SOURCE since the dawn of time and in POSIX since 2008.
For non-linux, I peeked at the OpenBSD man page, which says
The strsignal() function first appeared in AT&T System V Release 4 UNIX and was reimplemented for NetBSD 1.0.
That suggests all of the extant BSDs should have it.
MinGW has had the function since 2008.
What other hosts do we support?
r~
Quoted 22 lines · Richard Henderson
Quoted 10 lines · Peter Maydell
Quoted 7 lines · Richard Henderson
You already print the file, just include the line. Perhaps
fprintf(stderr, "%s:%d: kill_qemu tried to terminate QEMU " "process but it dumped core with signal %s\n", __FILE__, __LINE__, strsignal(WTERMSIG(wstatus))); abort();Quoted 5 lines
I wasn't convinced that
strsignal()would be available on all the host OSes we build on (we don't currently use it outside linux-user/), and I definitely didn't think that it merited a configure test for its presence just for a test error message :-)Hmm. It has been in
_GNU_SOURCEsince the dawn of time and in POSIX since 2008.For non-linux, I peeked at the OpenBSD man page, which says
Quoted 8 lines
The
strsignal()function first appeared in AT&T System V Release 4 UNIX and was reimplemented for NetBSD 1.0.That suggests all of the extant BSDs should have it.
MinGW has had the function since 2008.
What other hosts do we support?
OSX, but that's I think OK as it inherits it from BSD. The configure script also has support for Solaris-variants and Haiku...
thanks
-- PMM
Quoted 7 lines · Peter Maydell
Quoted 7 lines
For non-linux, I peeked at the OpenBSD man page, which says
The
strsignal()function first appeared in AT&T System V Release 4 UNIX and was reimplemented for NetBSD 1.0.That suggests all of the extant BSDs should have it.
Quoted 7 lines
Quoted 3 lines
MinGW has had the function since 2008.
What other hosts do we support?
OSX, but that's I think OK as it inherits it from BSD. The configure script also has support for Solaris-variants and Haiku...
Solaris derives from SVR4, and so should have had it since the beginning of time; certainly OpenSolaris does:
http://repo.or.cz/opensolaris.git/blob/HEAD:/usr/src/head/string.h#l94
Haiku has it as well:
https://git.haiku-os.org/haiku/tree/headers/posix/string.h#n75
r~
Quoted 18 lines · Peter Maydell
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.
Instead of using a raw assert, print the information in an easier to understand way:
/i386/ahci/sanity:
libqtest.c:kill_qemu()tried to terminate QEMU process but it dumped core with signal 11
ahci-test:tests/libqtest.c:118:kill_qemu: Assertion `0' failed.
Aborted (core dumped)
Quoted 5 lines
(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.)
Signed-off-by Peter Maydell <[email protected]>
Up to you whether to apply in 3.0.
Quoted 32 lines
---
In particular, the travis test config that enables gprof seems to (a) run into this every so often and (b) have the really unhelpful assertion text quoted above:
https://travis-ci.org/qemu/qemu/jobs/406192798Maybe for 3.0 since it's only test code.
tests/libqtest.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)tests/libqtest.c +7
-1@@ -110,7 +110,13 @@ static void kill_qemu(QTestState *s) pid =waitpid (s->qemu_pid, &wstatus,0 );if (pid == s->qemu_pid &&WIFSIGNALED (wstatus)) { -assert (!WCOREDUMP (wstatus)); +if (WCOREDUMP (wstatus)) { +fprintf (stderr, +"libqtest.c: kill_qemu() tried to terminate QEMU " +"process but it dumped core with signal %d\n" , +WTERMSIG (wstatus)); +assert (0 ); + } } } }Signature · 1 line
2.17.1
Quoted 40 lines · Peter Maydell
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.
Instead of using a raw assert, print the information in an easier to understand way:
/i386/ahci/sanity:
libqtest.c:kill_qemu()tried to terminate QEMU process but it dumped core with signal 11
ahci-test:tests/libqtest.c:118:kill_qemu: Assertion `0' failed.
Aborted (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.)
Signed-off-by Peter Maydell <[email protected]>---
In particular, the travis test config that enables gprof seems to (a) run into this every so often and (b) have the really unhelpful assertion text quoted above:
https://travis-ci.org/qemu/qemu/jobs/406192798Maybe for 3.0 since it's only test code.
tests/libqtest.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)tests/libqtest.c +0
-0@@ -110,7 +110,13 @@ static void kill_qemu(QTestState *s) pid =waitpid (s->qemu_pid, &wstatus,0 );
tests/libqtest.c static void kill_qemu(QTestState *s) · line 119
Quoted 10 lines
tests/libqtest.c +7
-1if (pid == s->qemu_pid &&WIFSIGNALED (wstatus)) { -assert (!WCOREDUMP (wstatus)); +if (WCOREDUMP (wstatus)) { +fprintf (stderr, +"libqtest.c: kill_qemu() tried to terminate QEMU " +"process but it dumped core with signal %d\n" , +WTERMSIG (wstatus)); +assert (0 ); + }
I had something similar but I added a:
+ if (WCOREDUMP(wstatus)) {
+ fprintf(stderr, "Child QEMU (%s) dumped core\n", getenv("QTEST_QEMU_BINARY"));
+ abort();
+ }
So I could tell which QEMU was the one that was crashing. As you are asserting you can drop the filename/function stuff or use __file__ and __func__ instead. Anyway it is an improvement on what we have now so:
tests/libqtest.c static void kill_qemu(QTestState *s) · line 122
Quoted 3 lines
tests/libqtest.c +0
-0} } }
--
Alex Bennée