qtest: Add assertion that required environment variable is set
PATCH 1/1 qtest: Add assertion that required environment variable is set
--- tests/libqtest.c | 1 + 1 file changed, 1 insertion(+)
tests/libqtest.c +1 -0
@@ -453,6 +453,7 @@ void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...)const char *qtest_get_arch (void ) {const char *qemu =getenv ("QTEST_QEMU_BINARY" ); +g_assert (qemu !=NULL );const char *end =strrchr (qemu,'/' );return end +strlen ("/qemu-system-" );
Signature · 1 line
2.2.2
Quoted 11 lines · Ed Maste
Signed-off-by Ed Maste <[email protected]>--- tests/libqtest.c | 1 + 1 file changed, 1 insertion(+)tests/libqtest.c +0
-0
tests/libqtest.c void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...) · line 459
Quoted 7 lines
tests/libqtest.c +1
-0@@ -453,6 +453,7 @@ void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...)const char *qtest_get_arch (void ) {const char *qemu =getenv ("QTEST_QEMU_BINARY" ); +g_assert (qemu !=NULL );const char *end =strrchr (qemu,'/' );return end +strlen ("/qemu-system-" );
This one has annoyed me in the past, too.
I wonder if it would be even nicer to add an fprintf to give the user a nice message explaining exactly what went wrong, though -- since this particular error is only going to happen when a user is invoking the test manually.
Maybe:
if (qemu == NULL) {
fprintf(stderr, "...");
g_assert_not_reached();
}
Though that does read a little strangely. ("Here's a nice error message for something we are asserting will never happen.")
Well, either way, it's better than segfaulting, so:
Quoted 8 lines · John Snow
if (qemu == NULL) {
fprintf(stderr, "...");
g_assert_not_reached();
}Though that does read a little strangely. ("Here's a nice error message for something we are asserting will never happen.")
Just "exit(1);" then. :)
Good idea, this is annoying.
Paolo
Quoted 9 lines · Paolo Bonzini
Quoted 6 lines · John Snow
if (qemu == NULL) {
fprintf(stderr, "...");
g_assert_not_reached();
}
Quoted 6 lines
Quoted 2 lines
Though that does read a little strangely. ("Here's a nice error message for something we are asserting will never happen.")
Just "exit(1);" then. :)
Good idea, this is annoying.
Also irritating is the way it silently requires the binary to have a name in the shape it was expecting, which can catch you out if you were trying to set it to a wrapper shell script that invokes valgrind or something...
-- PMM
Quoted 13 lines · Peter Maydell
Quoted 12 lines · Paolo Bonzini
Quoted 8 lines · John Snow
if (qemu == NULL) {
fprintf(stderr, "...");
g_assert_not_reached();
}Though that does read a little strangely. ("Here's a nice error message for something we are asserting will never happen.")
Just "exit(1);" then. :)
Quoted 7 lines
Quoted 1 line
Good idea, this is annoying.
Also irritating is the way it silently requires the binary to have a name in the shape it was expecting, which can catch you out if you were trying to set it to a wrapper shell script that invokes valgrind or something...
I don't really have enough context to propose a good user-facing message with a tip for manually executing this, so hopefully someone else can provide one. I just noticed one other instance that already had an assertion on getenv("QTEST_QEMU_BINARY") being non-null.
-Ed
Quoted 11 lines · Ed Maste
Quoted 5 lines · Peter Maydell
Also irritating is the way it silently requires the binary to have a name in the shape it was expecting, which can catch you out if you were trying to set it to a wrapper shell script that invokes valgrind or something...
I don't really have enough context to propose a good user-facing message with a tip for manually executing this, so hopefully someone else can provide one. I just noticed one other instance that already had an assertion on
getenv("QTEST_QEMU_BINARY")being non-null.
Yes, that was just me venting about something that caught me out in the past rather than review comment on this patch :-) Sorry for any confusion.
-- PMM
Quoted 13 lines · Peter Maydell
Quoted 11 lines · Ed Maste
Quoted 5 lines · Peter Maydell
Also irritating is the way it silently requires the binary to have a name in the shape it was expecting, which can catch you out if you were trying to set it to a wrapper shell script that invokes valgrind or something...
I don't really have enough context to propose a good user-facing message with a tip for manually executing this, so hopefully someone else can provide one. I just noticed one other instance that already had an assertion on
getenv("QTEST_QEMU_BINARY")being non-null.
Quoted 6 lines
Yes, that was just me venting about something that caught me out in the past rather than review comment on this patch :-) Sorry for any confusion.
-- PMM
I'll pull this into ide-next for 2.4 -- I have some ahci-test things to submit anyway.
I'll touch up the user facing error messages in a later patch and hit a few of the startup assertions all at once.
Thanks.
--js