qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] qtest: Add assertion that required environment


From: John Snow
Subject: Re: [Qemu-devel] [PATCH] qtest: Add assertion that required environment variable is set
Date: Wed, 01 Apr 2015 17:06:47 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0



On 04/01/2015 02:00 PM, Ed Maste wrote:
Signed-off-by: Ed Maste <address@hidden>
---
  tests/libqtest.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 12d65bd..54550a8 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -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:

Reviewed-by: John Snow <address@hidden>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]