qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] tests/libqtest: Print error instead of aborting when env variable is missing
@ 2017-05-22 15:40 Thomas Huth
  2017-05-22 15:58 ` no-reply
  2017-05-23 14:40 ` Michael Tokarev
  0 siblings, 2 replies; 7+ messages in thread
From: Thomas Huth @ 2017-05-22 15:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Markus Armbruster, Eric Blake, qemu-trivial

When you currently try to run a test directly from the command line
without setting the QTEST_QEMU_BINARY environment variable first,
you are presented with an unhelpful assertion message like this:

 ERROR:tests/libqtest.c:163:qtest_init_without_qmp_handshake:
 assertion failed: (qemu_binary != NULL)
 Aborted (core dumped)

Let's replace the assert() with a more user friendly error message
instead.

Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 v2:
 - Changed the error message text according to Markus' suggestion

 tests/libqtest.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 84ecbd2..4a5492a 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -160,7 +160,10 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     const char *qemu_binary;
 
     qemu_binary = getenv("QTEST_QEMU_BINARY");
-    g_assert(qemu_binary != NULL);
+    if (!qemu_binary) {
+        fprintf(stderr, "Environment variable QTEST_QEMU_BINARY required\n");
+        exit(1);
+    }
 
     s = g_malloc(sizeof(*s));
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-05-23 20:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-22 15:40 [Qemu-devel] [PATCH v2] tests/libqtest: Print error instead of aborting when env variable is missing Thomas Huth
2017-05-22 15:58 ` no-reply
2017-05-23  7:25   ` Thomas Huth
2017-05-23  7:59     ` Samuel Thibault
2017-05-23 17:19     ` John Snow
2017-05-23 20:35     ` Michael Roth
2017-05-23 14:40 ` Michael Tokarev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).