OSDN Git Service

tests: Handle $RANDOM not being supported by the shell
authorPeter Maydell <peter.maydell@linaro.org>
Fri, 14 Jul 2017 10:45:17 +0000 (11:45 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Thu, 20 Jul 2017 14:00:00 +0000 (15:00 +0100)
commit64f871e3c92ecd3c72a37b48bcf12812f0057734
tree000faed7ffc059ce25662c85d5fb194f42fff049
parentb1449edb799909f531b806538c48dc86d701c4b2
tests: Handle $RANDOM not being supported by the shell

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 <eblake@redhat.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Kamil Rytarowski <n54@gmx.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 1500029117-6387-1-git-send-email-peter.maydell@linaro.org
tests/Makefile.include