diff options
author | Ryan Moeller <[email protected]> | 2020-01-09 12:31:17 -0500 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2020-01-09 09:31:17 -0800 |
commit | 90ae48733c6bf6343213525d50cb9d731fb22dfd (patch) | |
tree | eb3a834fa49f396fb33bcceb4b8284ddec28b1be /tests | |
parent | 4abd7d80b2904135a9518cebf190f36f4f3fa3a8 (diff) |
ZTS: Provide an alternative to shuf for FreeBSD
There was a shuf package but the upstream for the port has recently
disappeared, so it is no longer available.
Create a function to hide the usage of shuf. Implement using seq|random
on FreeBSD.
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: John Kennedy <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes #9824
Diffstat (limited to 'tests')
5 files changed, 21 insertions, 5 deletions
diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg index 5ca2575fc..71f3476cb 100644 --- a/tests/zfs-tests/include/commands.cfg +++ b/tests/zfs-tests/include/commands.cfg @@ -82,7 +82,6 @@ export SYSTEM_FILES_COMMON='arp seq setfacl sh - shuf sleep sort ssh @@ -122,6 +121,7 @@ export SYSTEM_FILES_FREEBSD='chflags mkfifo newfs pw + random sha256 swapctl sysctl @@ -157,6 +157,7 @@ export SYSTEM_FILES_LINUX='attr setenforce setfattr sha256sum + shuf udevadm useradd userdel diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index e2274d1b1..b3bd3dfdf 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -3934,3 +3934,18 @@ function faketty script --return --quiet -c "$*" /dev/null fi } + +# +# Produce a random permutation of the integers in a given range (inclusive). +# +function range_shuffle # begin end +{ + typeset -i begin=$1 + typeset -i end=$2 + + if is_freebsd; then + seq ${begin} ${end} | random -f - + else + shuf -i ${begin}-${end} + fi +} diff --git a/tests/zfs-tests/include/properties.shlib b/tests/zfs-tests/include/properties.shlib index cc37e769d..ea8449fc6 100644 --- a/tests/zfs-tests/include/properties.shlib +++ b/tests/zfs-tests/include/properties.shlib @@ -51,7 +51,7 @@ function get_rand_prop typeset prop_max=$((${#prop_array[@]} - 1)) typeset -i i - for i in $(shuf -i $start-$prop_max -n $num_props); do + for i in $(range_shuffle $start $prop_max | head -n $num_props); do retstr="${prop_array[$i]} $retstr" done echo $retstr diff --git a/tests/zfs-tests/tests/functional/mv_files/random_creation.ksh b/tests/zfs-tests/tests/functional/mv_files/random_creation.ksh index 45c46f83c..05ddf6298 100755 --- a/tests/zfs-tests/tests/functional/mv_files/random_creation.ksh +++ b/tests/zfs-tests/tests/functional/mv_files/random_creation.ksh @@ -11,7 +11,7 @@ DIR="${TESTDIR}/RANDOM_SMALL" log_must mkdir "${DIR}" count=0 -for i in $(shuf -i 1-"${RC_PASS1}") ; do +for i in $(range_shuffle 1 "${RC_PASS1}") ; do if ! touch "${DIR}/${i}" ; then log_fail "error creating ${i} after ${count} files" fi diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_005_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_005_pos.ksh index ceae7292a..6d51acbe9 100755 --- a/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_005_pos.ksh @@ -63,9 +63,9 @@ typeset -i pageblocks volblocks max_swaplow ((max_swaplow = (volblocks - (pageblocks * 2)))) for i in {0..10}; do - swaplow=$(shuf -n 1 -i ${pageblocks}-${max_swaplow}) + swaplow=$(range_shuffle ${pageblocks} ${max_swaplow} | head -n 1) ((maxlen = max_swaplow - swaplow)) - swaplen=$(shuf -n 1 -i ${pageblocks}-${maxlen}) + swaplen=$(range_shuffle ${pageblocks} ${maxlen} | head -n 1) log_must swap -a $swapname $swaplow $swaplen log_must swap -d $swapname $swaplow done |