[PATCH] tests: viriscsitest: make it work on big endian archs

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

 



viriscsitest tries to ensure the interface IQN used is a specific one,
checking later on that it is the same all during the whole test.  Since
the IQN generation involves random bytes, viriscsitest got a fake
virRandomBytes from the virrandommock helper library, setting static
values.  virRandomBits(), called by virStorageBackendCreateIfaceIQN(),
always requests 8 random bytes, chopping off the ones not requested by
the caller -- this meant that on big endian machines it would chop bytes
from the wrong size of the data buffer, and thus not returning the
expected numbers.

As a fix, do not rely on the mock virRandomBytes, but provide an own
version of it: this version will fill the values in the expected order,
depending on the endianness of the system.  This way, the result of
virStorageBackendCreateIfaceIQN() will be what the test actually
expects.

Signed-off-by: Pino Toscano <ptoscano@xxxxxxxxxx>
---
 tests/viriscsitest.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c
index 4fd7ff6e19..d43c0115d3 100644
--- a/tests/viriscsitest.c
+++ b/tests/viriscsitest.c
@@ -21,6 +21,7 @@
 #include <config.h>
 
 #include "testutils.h"
+#include "virrandom.h"
 
 #ifdef WIN32
 int
@@ -36,6 +37,32 @@ main(void)
 
 # define VIR_FROM_THIS VIR_FROM_NONE
 
+bool isLittleEndian(void);
+bool isLittleEndian(void)
+{
+    static int cache = -1;
+    if (cache < 0) {
+        int val = 1;
+        char *ptr = (char *)&val;
+        cache = *ptr ? 1 : 0;
+    }
+    return cache > 0;
+}
+
+
+int
+virRandomBytes(unsigned char *buf,
+               size_t buflen)
+{
+    size_t i;
+    const bool isLE = isLittleEndian();
+
+    for (i = 0; i < buflen; i++)
+        buf[i] = isLE ? i : buflen - i - 1;
+
+    return 0;
+}
+
 static const char *iscsiadmSessionOutput =
     "tcp: [1] 10.20.30.40:3260,1 iqn.2004-06.example:example1:iscsi.test\n"
     "tcp: [2] 10.20.30.41:3260,1 iqn.2005-05.example:example1:iscsi.hello\n"
@@ -368,6 +395,5 @@ mymain(void)
     return EXIT_SUCCESS;
 }
 
-VIR_TEST_MAIN_PRELOAD(mymain,
-                      abs_builddir "/.libs/virrandommock.so")
+VIR_TEST_MAIN(mymain)
 #endif /* WIN32 */
-- 
2.17.1

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux