Skip to content

Commit

Permalink
Simplify for loop iteration termination conditions
Browse files Browse the repository at this point in the history
Several tests use a for() loop to perform some action a random number of
times.

The termination condition of the loops contained a reference to $RANDOM.
Because this expression is evaluated after each pass through the loop,
the index was compared against a different random number each time.  The
actual behavior was thus more like a while() loop with a random
termination condition than a typical for loop.

This patch evalutes $RANDOM once to determine the number of passes
through the loop, so the code's behavior is more obvious.

Signed-off-by: Olaf Faaland <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #9
  • Loading branch information
ofaaland authored and behlendorf committed Apr 5, 2016
1 parent e6d0ae5 commit f4a019b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion randcreate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ fi
set -x

while :; do
for ((i=0; i< $(( $RANDOM % 256 )); i++)) ; do
let loops=$(( $RANDOM % 256 ))
for ((i=0; i< ${loops} ; i++)) ; do
wait_for_mount $MOUNTPOINT
wait_for_export
parent=`rand_directory`
Expand Down
3 changes: 2 additions & 1 deletion randdataset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ while :; do

# Create some datasets then randomly destroy datasets
# with 50% probability.
for ((i=0; i< $(( $RANDOM % 64 )); i++)) ; do
let loops=$(( $RANDOM % 64 ))
for ((i=0; i< ${loops} ; i++)) ; do
parent=`rand_dataset`
ds=$(mktemp -u `perl -e 'print "X" x int rand 255 + 1'`)
ZFS_CREATE_OPT=""
Expand Down
3 changes: 2 additions & 1 deletion randmkdir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ fi
set -x

while :; do
for ((i=0; i< $(( $RANDOM % 64 )); i++)) ; do
let loops=$(( $RANDOM % 64 ))
for ((i=0; i< ${loops} ; i++)) ; do
wait_for_mount $MOUNTPOINT
wait_for_export
parent=`rand_directory`
Expand Down
3 changes: 2 additions & 1 deletion randsymlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ fi
set -x

while :; do
for ((i=0; i< $(( $RANDOM % 256 )); i++)) ; do
let loops=$(( $RANDOM % 256 ))
for ((i=0; i< ${loops} ; i++)) ; do
wait_for_mount $MOUNTPOINT
wait_for_export
parent=`rand_directory`
Expand Down

0 comments on commit f4a019b

Please sign in to comment.