qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] tests/Makefile.include non-portable use of $RANDOM
@ 2017-07-13 17:32 Peter Maydell
  2017-07-13 18:42 ` Kamil Rytarowski
  2017-07-13 20:16 ` Eric Blake
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Maydell @ 2017-07-13 17:32 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Eric Blake, Markus Armbruster

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-07-13 21:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-13 17:32 [Qemu-devel] tests/Makefile.include non-portable use of $RANDOM Peter Maydell
2017-07-13 18:42 ` Kamil Rytarowski
2017-07-13 20:16 ` Eric Blake
2017-07-13 21:15   ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).