render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
7a3408
From 9480c80c70b43a9a81aebabb9bebfbfb3154cc81 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <9480c80c70b43a9a81aebabb9bebfbfb3154cc81@dist-git>
7a3408
From: Andrea Bolognani <abologna@redhat.com>
7a3408
Date: Tue, 11 Aug 2015 17:15:59 +0200
7a3408
Subject: [PATCH] tests: Improve result handling in cpuTestGuestData()
7a3408
7a3408
A test is considered successful if the obtained result matches
7a3408
the expected result: if that's not the case, whether because a
7a3408
test that was expected to succeed failed or because a test that
7a3408
was supposed to fail succeeded, then something's not right and
7a3408
we want the user to know about this.
7a3408
7a3408
On the other hand, if a failure that's unrelated to the bits
7a3408
we're testing occurs, then the user should be notified even if
7a3408
the test was expected to fail.
7a3408
7a3408
Use different values to tell these two situations apart.
7a3408
7a3408
Fix a test case that was wrongly expected to fail as well.
7a3408
7a3408
(cherry picked from commit e5ef51a4c02dd1b61673a6c9771a0cdc0fad343f)
7a3408
7a3408
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1250977
7a3408
7a3408
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 tests/cputest.c | 32 ++++++++++++++++++++++++--------
7a3408
 1 file changed, 24 insertions(+), 8 deletions(-)
7a3408
7a3408
diff --git a/tests/cputest.c b/tests/cputest.c
7a3408
index 06b3f12..93f9d2e 100644
7a3408
--- a/tests/cputest.c
7a3408
+++ b/tests/cputest.c
7a3408
@@ -247,7 +247,7 @@ static int
7a3408
 cpuTestGuestData(const void *arg)
7a3408
 {
7a3408
     const struct data *data = arg;
7a3408
-    int ret = -1;
7a3408
+    int ret = -2;
7a3408
     virCPUDefPtr host = NULL;
7a3408
     virCPUDefPtr cpu = NULL;
7a3408
     virCPUDefPtr guest = NULL;
7a3408
@@ -262,8 +262,10 @@ cpuTestGuestData(const void *arg)
7a3408
 
7a3408
     cmpResult = cpuGuestData(host, cpu, &guestData, NULL);
7a3408
     if (cmpResult == VIR_CPU_COMPARE_ERROR ||
7a3408
-        cmpResult == VIR_CPU_COMPARE_INCOMPATIBLE)
7a3408
+        cmpResult == VIR_CPU_COMPARE_INCOMPATIBLE) {
7a3408
+        ret = -1;
7a3408
         goto cleanup;
7a3408
+    }
7a3408
 
7a3408
     if (VIR_ALLOC(guest) < 0)
7a3408
         goto cleanup;
7a3408
@@ -274,10 +276,7 @@ cpuTestGuestData(const void *arg)
7a3408
     guest->fallback = cpu->fallback;
7a3408
     if (cpuDecode(guest, guestData, data->models,
7a3408
                   data->nmodels, data->preferred) < 0) {
7a3408
-        if (data->result < 0) {
7a3408
-            virResetLastError();
7a3408
-            ret = 0;
7a3408
-        }
7a3408
+        ret = -1;
7a3408
         goto cleanup;
7a3408
     }
7a3408
 
7a3408
@@ -294,7 +293,10 @@ cpuTestGuestData(const void *arg)
7a3408
     }
7a3408
     result = virBufferContentAndReset(&buf;;
7a3408
 
7a3408
-    ret = cpuTestCompareXML(data->arch, guest, result, false);
7a3408
+    if (cpuTestCompareXML(data->arch, guest, result, false) < 0)
7a3408
+        goto cleanup;
7a3408
+
7a3408
+    ret = 0;
7a3408
 
7a3408
  cleanup:
7a3408
     VIR_FREE(result);
7a3408
@@ -302,6 +304,20 @@ cpuTestGuestData(const void *arg)
7a3408
     virCPUDefFree(host);
7a3408
     virCPUDefFree(cpu);
7a3408
     virCPUDefFree(guest);
7a3408
+
7a3408
+    if (ret == data->result) {
7a3408
+        /* We got the result we expected, whether it was
7a3408
+         * a success or a failure */
7a3408
+        virResetLastError();
7a3408
+        ret = 0;
7a3408
+    } else {
7a3408
+        VIR_TEST_VERBOSE("\nExpected result %d, got %d\n",
7a3408
+                         data->result, ret);
7a3408
+        /* Pad to line up with test name ... in virTestRun */
7a3408
+        VIR_TEST_VERBOSE("%74s", "... ");
7a3408
+        ret = -1;
7a3408
+    }
7a3408
+
7a3408
     return ret;
7a3408
 }
7a3408
 
7a3408
@@ -646,7 +662,7 @@ mymain(void)
7a3408
                       NULL, "Haswell-noTSX", 0);
7a3408
 
7a3408
     DO_TEST_GUESTDATA("ppc64", "host", "guest", ppc_models, NULL, 0);
7a3408
-    DO_TEST_GUESTDATA("ppc64", "host", "guest-nofallback", ppc_models, "POWER7_v2.1", -1);
7a3408
+    DO_TEST_GUESTDATA("ppc64", "host", "guest-nofallback", ppc_models, "POWER7_v2.1", 0);
7a3408
 
7a3408
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
7a3408
 }
7a3408
-- 
7a3408
2.5.0
7a3408