diff options
author | Ryan Moeller <[email protected]> | 2020-01-08 12:08:30 -0500 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2020-01-08 09:08:30 -0800 |
commit | f8d55b95a5ed825d4fb50cc8e0e03edf25bd44e3 (patch) | |
tree | 19915594bbce237365aa2b1964801862fe32f67e | |
parent | 028e3b3b1a8d15a9ab5a0c925ca32fd3851cfa36 (diff) |
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 <[email protected]>
Reviewed-by: Kjeld Schouten <[email protected]>
Reviewed-by: Igor Kozhukhov <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: George Melikov <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes #9820
10 files changed, 34 insertions, 35 deletions
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index 7e9dd52f1..e2274d1b1 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -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 { diff --git a/tests/zfs-tests/include/math.shlib b/tests/zfs-tests/include/math.shlib index 0c3508ec2..692a2a45b 100644 --- a/tests/zfs-tests/include/math.shlib +++ b/tests/zfs-tests/include/math.shlib @@ -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 +} diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_timestamp.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_timestamp.ksh index 5efaff8cd..a4cedca49 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_timestamp.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_timestamp.ksh @@ -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 } diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib index 7b018da1b..783ae54e7 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade.kshlib @@ -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 -} diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_008_pos.ksh index 173d7f68c..d93091965 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_008_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_upgrade/zpool_upgrade_008_pos.ksh @@ -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 diff --git a/tests/zfs-tests/tests/functional/redacted_send/redacted.kshlib b/tests/zfs-tests/tests/functional/redacted_send/redacted.kshlib index d3d219bb9..5150ec5d8 100644 --- a/tests/zfs-tests/tests/functional/redacted_send/redacted.kshlib +++ b/tests/zfs-tests/tests/functional/redacted_send/redacted.kshlib @@ -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 diff --git a/tests/zfs-tests/tests/functional/redundancy/redundancy_001_pos.ksh b/tests/zfs-tests/tests/functional/redundancy/redundancy_001_pos.ksh index b5557f1f7..90d14f600 100755 --- a/tests/zfs-tests/tests/functional/redundancy/redundancy_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/redundancy/redundancy_001_pos.ksh @@ -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 # diff --git a/tests/zfs-tests/tests/functional/redundancy/redundancy_002_pos.ksh b/tests/zfs-tests/tests/functional/redundancy/redundancy_002_pos.ksh index b16687dbe..74bda1999 100755 --- a/tests/zfs-tests/tests/functional/redundancy/redundancy_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/redundancy/redundancy_002_pos.ksh @@ -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 # diff --git a/tests/zfs-tests/tests/functional/redundancy/redundancy_003_pos.ksh b/tests/zfs-tests/tests/functional/redundancy/redundancy_003_pos.ksh index a1ca2cb76..b7b791b24 100755 --- a/tests/zfs-tests/tests/functional/redundancy/redundancy_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/redundancy/redundancy_003_pos.ksh @@ -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 diff --git a/tests/zfs-tests/tests/functional/redundancy/redundancy_004_neg.ksh b/tests/zfs-tests/tests/functional/redundancy/redundancy_004_neg.ksh index cb4603af8..7ee51051e 100755 --- a/tests/zfs-tests/tests/functional/redundancy/redundancy_004_neg.ksh +++ b/tests/zfs-tests/tests/functional/redundancy/redundancy_004_neg.ksh @@ -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" |