]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: mock virRandomBits to make it endian stable
authorDaniel P. Berrangé <berrange@redhat.com>
Thu, 2 Aug 2018 11:32:07 +0000 (12:32 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 2 Aug 2018 13:24:40 +0000 (14:24 +0100)
virRandomBits is implemented in terms of virRandomBytes. Although we
mock virRandomBytes to give a stable value, this is not sufficient to
make virRandomBits give a stable value. The result of virRandomBits will
vary depending on endianness. Thus we mock virRandomBits to return a
stable value directly.

Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Tested-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
tests/virrandommock.c

index 99a55a576aa9f3fc865afc1863152d24b51450ca..3079b8bacb2f6852712f4026ed91cdd94a22c8d5 100644 (file)
@@ -44,6 +44,14 @@ virRandomBytes(unsigned char *buf,
     return 0;
 }
 
+uint64_t virRandomBits(int nbits)
+{
+    /* Chosen by a fair roll of a 2^64 sided dice */
+    uint64_t ret = 0x0706050403020100;
+    if (nbits < 64)
+        ret &= ((1ULL << nbits) - 1);
+    return ret;
+}
 
 int virRandomGenerateWWN(char **wwn,
                          const char *virt_type ATTRIBUTE_UNUSED)