]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemufirmwaretest: Produce better message on error
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 26 Mar 2019 07:57:33 +0000 (08:57 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 26 Mar 2019 15:43:48 +0000 (16:43 +0100)
If qemuFirmwareFetchConfigs() returned more or fewer paths than
expected all that we see is the following error message:

  Expected 5 paths, got 7

While it is technically correct (the best kind of correct), we
can do better:

  Unexpected path (i=0). Expected /some/path got /some/other/path

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
tests/qemufirmwaretest.c

index 340344ebbae26aa438a9c839f2e390863ad29772..2b5cbf649bbd32319081b72461592cc236cd1ab1 100644 (file)
@@ -66,6 +66,7 @@ testFWPrecedence(const void *opaque ATTRIBUTE_UNUSED)
         PREFIX "/share/qemu/firmware/61-ovmf.json",
         PREFIX "/share/qemu/firmware/70-aavmf.json",
     };
+    const size_t nexpected = ARRAY_CARDINALITY(expected);
 
     if (VIR_STRDUP(fakehome, abs_srcdir "/qemufirmwaredata/home/user/.config") < 0)
         return -1;
@@ -81,17 +82,15 @@ testFWPrecedence(const void *opaque ATTRIBUTE_UNUSED)
     }
 
     nfwList = virStringListLength((const char **)fwList);
-    if (nfwList != ARRAY_CARDINALITY(expected)) {
-        fprintf(stderr, "Expected %zu paths, got %zu\n",
-                ARRAY_CARDINALITY(expected), nfwList);
-        return -1;
-    }
 
-    for (i = 0; i < ARRAY_CARDINALITY(expected); i++) {
-        if (STRNEQ_NULLABLE(expected[i], fwList[i])) {
+    for (i = 0; i < MAX(nfwList, nexpected); i++) {
+        const char *e = i < nexpected ? expected[i] : NULL;
+        const char *f = i < nfwList ? fwList[i] : NULL;
+
+        if (STRNEQ_NULLABLE(e, f)) {
             fprintf(stderr,
                     "Unexpected path (i=%zu). Expected %s got %s \n",
-                    i, expected[i], NULLSTR(fwList[i]));
+                    i, NULLSTR(e), NULLSTR(f));
             return -1;
         }
     }