From patchwork Fri Jul 14 10:45:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107763 Delivered-To: patches@linaro.org Received: by 10.140.101.44 with SMTP id t41csp724404qge; Fri, 14 Jul 2017 03:45:22 -0700 (PDT) X-Received: by 10.28.113.21 with SMTP id m21mr2305863wmc.80.1500029122039; Fri, 14 Jul 2017 03:45:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500029122; cv=none; d=google.com; s=arc-20160816; b=l6VFNpY7PEDpY+c4RYuGsaOqM5fkoAk1FlPBC0zrzLD0iRHMaLAgskjAQmm+VoAIfQ BsjM2fJfHJV95VHurtVxrtNleKqK8/M9jZIVnirEkmq35g1QOj/BEw27XwcQh3hs81eM 9q4sASlHd9S5EH0qT+qPt1uQO679ZeQff6Uxx0l/XRldliob3OCsEOabXdr0RJgMbUuC kO1rj1rDEeT4CCdsjFIDcKr+We3259Z4gpNvc/wtXVwkgv6ZFtNgqSu7CYHzVdJnEzUp MppiorHzmzJmD6XnTRKyMK9o/6sPQBs7pAHg3KsFGAle6H2g7jZdexz9TayvLg7VnHmZ DAyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=Bqv2yVRyXTwFxeZE6r5DUPINdkUSrTN7QnI5nORCLc4=; b=Ziv6NBveIdjEuEzcWabI5agIhyHGK/ZVkE9MbIKjiPzlsc6j0NE/VVa2Gwjp/nwjEJ oAL3vrkBs6wVn9hQ8B8Gu+0LPP9AXrtEFq7l8maq9poX/7RRgINx4vIDkm1tH6b/WJx1 uvmxVkfcAz008TQWwRxkDM4dBtShNuQCSIdchhfgdfCnu7rGtD5fX8Q8yWagcTT6dL4f n9B41H2pFnjhkS/YH86FYYmurDgJXbUHtGNOZdTymkfFT8iOx1e7ZvkoisawYy38AsQg TI9vB+E5sRWMeUIxN59TGSLfElxkGxGRxJEGVdU/PymzqAMcjqpfyaahiNqJCydKUhxg B04Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id f185si1982766wma.113.2017.07.14.03.45.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jul 2017 03:45:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 Cc: patches@linaro.org, Eric Blake , Kamil Rytarowski Subject: [PATCH] tests: Handle $RANDOM not being supported by the shell 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 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)) => 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 --- tests/Makefile.include | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.7.4 Reviewed-by: Kamil Rytarowski Reviewed-by: Fam Zheng Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi 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-qtest-%: $(check-qtest-y) $(if $(CONFIG_GCOV),@rm -f *.gcda */*.gcda */*/*.gcda */*/*/*.gcda,) $(call quiet-command,QTEST_QEMU_BINARY=$*-softmmu/qemu-system-$* \ QTEST_QEMU_IMG=qemu-img$(EXESUF) \ - MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$((RANDOM % 255 + 1))} \ + MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))} \ gtester $(GTESTER_OPTIONS) -m=$(SPEED) $(check-qtest-$*-y) $(check-qtest-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-qtest-%: $(check-qtest-y) $(patsubst %, check-%, $(check-unit-y)): check-%: % $(if $(CONFIG_GCOV),@rm -f *.gcda */*.gcda */*/*.gcda */*/*/*.gcda,) $(call quiet-command, \ - MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$((RANDOM % 255 + 1))} \ + MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))} \ gtester $(GTESTER_OPTIONS) -m=$(SPEED) $*,"GTESTER","$*") $(if $(CONFIG_GCOV),@for f in $(gcov-files-$(subst tests/,,$*)-y) $(gcov-files-generic-y); do \ echo Gcov report for $$f:;\