[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] tests/Makefile.include non-portable use of $RANDOM
From: |
Peter Maydell |
Subject: |
[Qemu-devel] tests/Makefile.include non-portable use of $RANDOM |
Date: |
Thu, 13 Jul 2017 18:32:21 +0100 |
Currently our test makefile does
MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$((RANDOM % 255 + 1))}
This works on bash, but $RANDOM is bash-specific.
On dash, it doesn't do what we want, but it does do something:
$ echo $((RANDOM % 255 + 1))
1
On NetBSD the shell complains:
# echo $((RANDOM % 255 + 1))
-sh: arith: syntax error: "RANDOM % 255 + 1"
and so 'make check' doesn't work.
Any suggestions for something more portable?
https://unix.stackexchange.com/questions/140750/generate-random-numbers-in-specific-range
suggests
awk 'BEGIN{srand(); print int(1+rand()*256)}'
and of course there are similar things possible with perl et al.
Or we could just have the makefile check whether we have bash,
and if not then set
RANDOM=4
(thus putting NetBSD into the same boat as all our dash users).
Opinions?
thanks
-- PMM
- [Qemu-devel] tests/Makefile.include non-portable use of $RANDOM,
Peter Maydell <=