From 3e8703368b786162f6b53c464218bbf61717f924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Thu, 2 Aug 2018 12:32:07 +0100 Subject: [PATCH] tests: mock virRandomBits to make it endian stable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Tested-by: Boris Fiuczynski Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrangé --- tests/virrandommock.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/virrandommock.c b/tests/virrandommock.c index 99a55a576a..3079b8bacb 100644 --- a/tests/virrandommock.c +++ b/tests/virrandommock.c @@ -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) -- GitLab