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 <behlendorf1@llnl.gov> Reviewed-by: John Kennedy <john.kennedy@delphix.com> Signed-off-by: Ryan Moeller <ryan@ixsystems.com> Closes #9824
This commit is contained in:
parent
4abd7d80b2
commit
90ae48733c
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user