ZTS: Eliminate functions named 'random'

The name overlaps with a command needed by FreeBSD.
There is also no sense having two 'random' functions that do nearly
the same thing, so consolidate to just the more general one and name
it 'random_int_between'.

Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Kjeld Schouten <kjeld@schouten-lebbing.nl>
Reviewed-by: Igor Kozhukhov <igor@dilos.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Signed-off-by: Ryan Moeller <ryan@ixsystems.com>
Closes #9820
This commit is contained in:
Ryan Moeller
2020-01-08 12:08:30 -05:00
committed by Brian Behlendorf
parent 028e3b3b1a
commit f8d55b95a5
10 changed files with 34 additions and 35 deletions
-9
View File
@@ -3349,15 +3349,6 @@ function get_min
echo $min
}
#
# Generate a random number between 1 and the argument.
#
function random
{
typeset max=$1
echo $(( ($RANDOM % $max) + 1 ))
}
# Write data that can be compressed into a directory
function write_compressible
{
+22
View File
@@ -119,3 +119,25 @@ function verify_ne # <a> <b> <type>
log_fail "Compared $type should be not equal: $a == $b"
fi
}
# A simple function to get a random number between two bounds (inclusive)
#
# Probably not the most efficient for large ranges, but it's okay.
#
# Note since we're using $RANDOM, 32767 is the largest number we
# can accept as the upper bound.
#
# $1 lower bound
# $2 upper bound
function random_int_between
{
typeset -i min=$1
typeset -i max=$2
typeset -i rand=0
while [[ $rand -lt $min ]] ; do
rand=$(( $RANDOM % $max + 1))
done
echo $rand
}
@@ -50,7 +50,7 @@ function create_random # <fspath> <count>
while (( i < count )); do
log_must touch "$fspath/file$i"
sleep $(random 3)
sleep $(random_int_between 1 3)
(( i = i + 1 ))
done
}
@@ -138,22 +138,3 @@ function check_poolversion
log_fail "$pool: zpool reported version $actual, expected $vers"
fi
}
# A simple function to get a random number between two bounds
# probably not the most efficient for large ranges, but it's okay.
# Note since we're using $RANDOM, 32767 is the largest number we
# can accept as the upper bound.
# $1 lower bound
# $2 upper bound
function random
{
typeset min=$1
typeset max=$2
typeset rand=0
while [[ $rand -lt $min ]] ; do
rand=$(( $RANDOM % $max + 1))
done
echo $rand
}
@@ -30,6 +30,7 @@
# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib
#
@@ -67,7 +68,7 @@ MAX_VER=15
for ver_old in $VERSIONS; do
typeset -n pool_name=ZPOOL_VERSION_${ver_old}_NAME
typeset ver_new=$(random $ver_old $MAX_VER)
typeset -i ver_new=$(random_int_between $ver_old $MAX_VER)
create_old_pool $ver_old
log_must zpool upgrade -V $ver_new $pool_name > /dev/null
@@ -100,7 +100,7 @@ function setup_holes
log_must zfs create $sendfs/manyrm
for i in {1..256}; do
log_must stride_dd -i /dev/urandom -o $mntpnt/manyrm/f$i -b 512 \
-c $(random 100) -s $(random 4)
-c $(random_int_between 1 100) -s $(random_int_between 1 4)
done
log_must zfs snapshot $sendfs/manyrm@snap
@@ -29,6 +29,7 @@
# Copyright (c) 2013 by Delphix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
#
@@ -50,7 +51,7 @@ verify_runnable "global"
log_assert "Verify raidz pool can withstand one device is failing."
log_onexit cleanup
typeset -i cnt=$(random 2 5)
typeset -i cnt=$(random_int_between 2 5)
setup_test_env $TESTPOOL raidz $cnt
#
@@ -29,6 +29,7 @@
# Copyright (c) 2013 by Delphix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
#
@@ -50,7 +51,7 @@ verify_runnable "global"
log_assert "Verify raidz2 pool can withstand two devices are failing."
log_onexit cleanup
typeset -i cnt=$(random 3 5)
typeset -i cnt=$(random_int_between 3 5)
setup_test_env $TESTPOOL raidz2 $cnt
#
@@ -29,6 +29,7 @@
# Copyright (c) 2013 by Delphix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
#
@@ -50,7 +51,7 @@ verify_runnable "global"
log_assert "Verify mirrored pool can withstand N-1 devices are failing or missing."
log_onexit cleanup
typeset -i cnt=$(random 2 5)
typeset -i cnt=$(random_int_between 2 5)
setup_test_env $TESTPOOL mirror $cnt
typeset -i i=1
@@ -29,6 +29,7 @@
# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/redundancy/redundancy.kshlib
#
@@ -50,7 +51,7 @@ verify_runnable "global"
log_assert "Verify striped pool have no data redundancy."
log_onexit cleanup
typeset -i cnt=$(random 2 5)
typeset -i cnt=$(random_int_between 2 5)
setup_test_env $TESTPOOL "" $cnt
damage_devs $TESTPOOL 1 "keep_label"