[libvirt] [PATCH] qemufirmwaretest: Produce better message on error

Michal Privoznik posted 1 patch 5 years, 1 month ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/18a42da8846a73f082d3c6aa4853e0133a83b7ea.1553587288.git.mprivozn@redhat.com
tests/qemufirmwaretest.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
[libvirt] [PATCH] qemufirmwaretest: Produce better message on error
Posted by Michal Privoznik 5 years, 1 month ago
If qemuFirmwareFetchConfigs() returned more or less 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>
---
 tests/qemufirmwaretest.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/tests/qemufirmwaretest.c b/tests/qemufirmwaretest.c
index 340344ebba..2b5cbf649b 100644
--- a/tests/qemufirmwaretest.c
+++ b/tests/qemufirmwaretest.c
@@ -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;
         }
     }
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemufirmwaretest: Produce better message on error
Posted by Andrea Bolognani 5 years, 1 month ago
On Tue, 2019-03-26 at 09:02 +0100, Michal Privoznik wrote:
> If qemuFirmwareFetchConfigs() returned more or less paths than

https://66.media.tumblr.com/c9eb5611a9f9c6a5cb7be6d5365afdf9/tumblr_ouaw1xYO8u1ruwssto2_500.gif

> 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>
> ---
>  tests/qemufirmwaretest.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)

Reviewed-by: Andrea Bolognani <abologna@redhat.com>

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list