From nobody Thu May 2 17:52:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500029517983912.1820640041938; Fri, 14 Jul 2017 03:51:57 -0700 (PDT) Received: from localhost ([::1]:36923 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVyCR-0004ln-FK for importer@patchew.org; Fri, 14 Jul 2017 06:51:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVy6P-0007xj-O8 for qemu-devel@nongnu.org; Fri, 14 Jul 2017 06:45:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVy6L-0004w8-3n for qemu-devel@nongnu.org; Fri, 14 Jul 2017 06:45:41 -0400 Received: from [2001:8b0:1d0::2] (port=37578 helo=orth.archaic.org.uk) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVy6K-0004pi-PI for qemu-devel@nongnu.org; Fri, 14 Jul 2017 06:45:36 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dVy62-0007ii-Dh; Fri, 14 Jul 2017 11:45:18 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 14 Jul 2017 11:45:17 +0100 Message-Id: <1500029117-6387-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH] tests: Handle $RANDOM not being supported by the shell X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kamil Rytarowski , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In various places in our test makefiles and scripts we use the shell $RANDOM to create a random number. This is a bash specific extension, and doesn't work on other shells. With dash the shell doesn't complain, it just effectively always evaluates $RANDOM to 0: echo $((RANDOM + 32768)) =3D> 32768 However, on NetBSD the shell will complain: "-sh: arith: syntax error: "RANDOM + 32768" which means that "make check" fails. Switch to using "${RANDOM:-0}" instead of $RANDOM, which will portably either give us a random number or zero. This means that on non-bash shells we don't get such good test coverage via the MALLOC_PERTURB_ setting, but we were already in that situation for non-bash shells. Our only other uses of $RANDOM (in tests/qemu-iotests/check and tests/qemu-iotests/162) are in shell scripts which use a #!/bin/bash line so they are always run under bash. Suggested-by: Eric Blake Signed-off-by: Peter Maydell Reviewed-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: Kamil Rytarowski Reviewed-by: Stefan Hajnoczi --- tests/Makefile.include | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 6d6cb74..f6310d2 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -826,7 +826,7 @@ $(patsubst %, check-qtest-%, $(QTEST_TARGETS)): check-q= test-%: $(check-qtest-y) $(if $(CONFIG_GCOV),@rm -f *.gcda */*.gcda */*/*.gcda */*/*/*.gcda,) $(call quiet-command,QTEST_QEMU_BINARY=3D$*-softmmu/qemu-system-$* \ QTEST_QEMU_IMG=3Dqemu-img$(EXESUF) \ - MALLOC_PERTURB_=3D$${MALLOC_PERTURB_:-$$((RANDOM % 255 + 1))} \ + MALLOC_PERTURB_=3D$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))} \ gtester $(GTESTER_OPTIONS) -m=3D$(SPEED) $(check-qtest-$*-y) $(check-qte= st-generic-y),"GTESTER","$@") $(if $(CONFIG_GCOV),@for f in $(gcov-files-$*-y) $(gcov-files-generic-y);= do \ echo Gcov report for $$f:;\ @@ -837,7 +837,7 @@ $(patsubst %, check-qtest-%, $(QTEST_TARGETS)): check-q= test-%: $(check-qtest-y) $(patsubst %, check-%, $(check-unit-y)): check-%: % $(if $(CONFIG_GCOV),@rm -f *.gcda */*.gcda */*/*.gcda */*/*/*.gcda,) $(call quiet-command, \ - MALLOC_PERTURB_=3D$${MALLOC_PERTURB_:-$$((RANDOM % 255 + 1))} \ + MALLOC_PERTURB_=3D$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))} \ gtester $(GTESTER_OPTIONS) -m=3D$(SPEED) $*,"GTESTER","$*") $(if $(CONFIG_GCOV),@for f in $(gcov-files-$(subst tests/,,$*)-y) $(gcov-= files-generic-y); do \ echo Gcov report for $$f:;\ --=20 2.7.4