]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
tests/libqtest: Print error instead of aborting when env variable is missing
authorThomas Huth <thuth@redhat.com>
Mon, 22 May 2017 15:40:54 +0000 (17:40 +0200)
committerMichael Tokarev <mjt@tls.msk.ru>
Sun, 4 Jun 2017 15:42:55 +0000 (18:42 +0300)
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>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
tests/libqtest.c

index 84ecbd2bd8f3e22a763b859697335d00a8d9e1ed..4a5492a603c2ba0ce74813af7108d0c84e3787e4 100644 (file)
@@ -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));