From nobody Mon May 6 10:20:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153312890077346.49688501636081; Wed, 1 Aug 2018 06:08:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 822613084044; Wed, 1 Aug 2018 13:08:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F0CF130B9535; Wed, 1 Aug 2018 13:08:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CC3544A46C; Wed, 1 Aug 2018 13:08:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w71D8EmF022267 for ; Wed, 1 Aug 2018 09:08:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4088D10EE79F; Wed, 1 Aug 2018 13:08:14 +0000 (UTC) Received: from thyrus.usersys.redhat.com (unknown [10.43.2.212]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B2E7B10EE79E; Wed, 1 Aug 2018 13:08:11 +0000 (UTC) From: Pino Toscano To: libvir-list@redhat.com Date: Wed, 1 Aug 2018 15:08:07 +0200 Message-Id: <20180801130807.16944-1-ptoscano@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: bwalk@linux.ibm.com Subject: [libvirt] [PATCH] tests: viriscsitest: make it work on big endian archs X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 01 Aug 2018 13:08:18 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Bjoern Walk --- 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 =20 #include "testutils.h" +#include "virrandom.h" =20 #ifdef WIN32 int @@ -36,6 +37,32 @@ main(void) =20 # define VIR_FROM_THIS VIR_FROM_NONE =20 +bool isLittleEndian(void); +bool isLittleEndian(void) +{ + static int cache =3D -1; + if (cache < 0) { + int val =3D 1; + char *ptr =3D (char *)&val; + cache =3D *ptr ? 1 : 0; + } + return cache > 0; +} + + +int +virRandomBytes(unsigned char *buf, + size_t buflen) +{ + size_t i; + const bool isLE =3D isLittleEndian(); + + for (i =3D 0; i < buflen; i++) + buf[i] =3D isLE ? i : buflen - i - 1; + + return 0; +} + static const char *iscsiadmSessionOutput =3D "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; } =20 -VIR_TEST_MAIN_PRELOAD(mymain, - abs_builddir "/.libs/virrandommock.so") +VIR_TEST_MAIN(mymain) #endif /* WIN32 */ --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list