[Qemu-devel] [PATCH] tests/libqtest: Print error instead of aborting when env variable is missing

Thomas Huth posted 1 patch 6 years, 11 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1495238065-15846-1-git-send-email-thuth@redhat.com
Test checkpatch passed
Test docker passed
Test s390x passed
There is a newer version of this series
tests/libqtest.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[Qemu-devel] [PATCH] tests/libqtest: Print error instead of aborting when env variable is missing
Posted by Thomas Huth 6 years, 11 months ago
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.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/libqtest.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 84ecbd2..f0fd682 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -160,7 +160,11 @@ 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, "The environment variable QTEST_QEMU_BINARY has to be "
+                        "set before running the test.\n");
+        exit(1);
+    }
 
     s = g_malloc(sizeof(*s));
 
-- 
1.8.3.1