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

[libvirt] [PATCH] tests: Produce predictable results in nsstest



Problem is that in the test any status file matching
tests/nssdata/*.status is loaded as it contains IP addresses that
are parsed. However, there's no order specified in which the
files are loaded. Therefore on different systems the order may be
different. This is then producing an unexpected results.
Instead of defining an order in which the files are loaded, make
the code that checks for missing IP addresses (or redundant ones)
cope with unordered list of addresses. The reasoning behind is
that the code doing the parsing is used in real NSS module where
we don't care for ordering.

Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 tests/nsstest.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/tests/nsstest.c b/tests/nsstest.c
index 68f1c60..9d7bc40 100644
--- a/tests/nsstest.c
+++ b/tests/nsstest.c
@@ -49,7 +49,7 @@ testGetHostByName(const void *opaque)
     char buf[BUF_SIZE] = { 0 };
     char **addrList;
     int rv, tmp_errno = 0, tmp_herrno = 0;
-    size_t i = 0;
+    size_t i = 0, j = 0;
 
     if (!data)
         goto cleanup;
@@ -141,30 +141,29 @@ testGetHostByName(const void *opaque)
             goto cleanup;
         }
 
-        if (!data->ipAddr[i]) {
+        for (j = 0; data->ipAddr[j]; j++) {
+            if (STREQ(data->ipAddr[j], ipAddr))
+                break;
+        }
+
+        if (!data->ipAddr[j]) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            "Unexpected address %s", ipAddr);
             VIR_FREE(ipAddr);
             goto cleanup;
         }
-
-        if (STRNEQ(data->ipAddr[i], ipAddr)) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           "Address mismatch. Expected %s got %s",
-                           data->ipAddr[i], ipAddr);
-            VIR_FREE(ipAddr);
-            goto cleanup;
-        }
         VIR_FREE(ipAddr);
 
         addrList++;
         i++;
     }
 
-    if (data->ipAddr[i]) {
+    for (j = 0; data->ipAddr[j]; j++)
+        ;
+
+    if (i != j) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "Address mismatch. Expected %s got nothing",
-                       data->ipAddr[i]);
+                       "Expected %zu addresses, got %zu", j, i);
         goto cleanup;
     }
 
-- 
2.7.3


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