From 602f667285b3c72bfdcd68578105ff1cc83a36e8 Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Mon, 13 Jan 2020 18:21:42 -0500 Subject: [PATCH] ZTS: Clean up properties.shlib a bit Fixes the last property having an empty value on FreeBSD and makes the code a bit more readable. Reviewed-by: Kjeld Schouten Reviewed-by: Igor Kozhukhov Reviewed-by: Brian Behlendorf Reviewed-by: George Melikov Signed-off-by: Ryan Moeller Closes #9834 --- tests/zfs-tests/include/properties.shlib | 43 ++++++++++++++---------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/tests/zfs-tests/include/properties.shlib b/tests/zfs-tests/include/properties.shlib index ea8449fc63..1b6f5a4e59 100644 --- a/tests/zfs-tests/include/properties.shlib +++ b/tests/zfs-tests/include/properties.shlib @@ -34,47 +34,54 @@ typeset -a vol_props=('compress' 'checksum' 'copies' 'logbias' 'primarycache' 'secondarycache' 'redundant_metadata' 'sync') # -# Given the property array passed in, return 'num_props' elements to the -# user, excluding any elements below 'start.' This allows us to exclude -# 'off' and 'on' which can be either unwanted, or a duplicate of another -# property respectively. +# Given the 'prop' passed in, return 'num_vals' elements of the corresponding +# values array to the user, excluding any elements below 'first.' This allows +# us to exclude 'off' and 'on' which can be either unwanted, or a duplicate of +# another property respectively. # -function get_rand_prop +function get_rand_prop_vals { - typeset prop_array=($(eval echo \${$1[@]})) - typeset -i num_props=$2 - typeset -i start=$3 + typeset prop=$1 + typeset -i num_vals=$2 + typeset -i first=$3 + + [[ -z $prop || -z $num_vals || -z $first ]] && \ + log_fail "get_rand_prop_vals: bad arguments" + typeset retstr="" - [[ -z $prop_array || -z $num_props || -z $start ]] && \ - log_fail "get_rand_prop: bad arguments" + typeset prop_vals_var=${prop}_prop_vals + typeset -a prop_vals=($(eval echo \${${prop_vals_var}[@]})) - typeset prop_max=$((${#prop_array[@]} - 1)) + [[ -z $prop_vals ]] && \ + log_fail "get_rand_prop_vals: bad prop $prop" + + typeset -i last=$((${#prop_vals[@]} - 1)) typeset -i i - for i in $(range_shuffle $start $prop_max | head -n $num_props); do - retstr="${prop_array[$i]} $retstr" + for i in $(range_shuffle $first $last | head -n $num_vals); do + retstr="${prop_vals[$i]} $retstr" done echo $retstr } function get_rand_checksum { - get_rand_prop checksum_prop_vals $1 2 + get_rand_prop_vals checksum $1 2 } function get_rand_checksum_any { - get_rand_prop checksum_prop_vals $1 0 + get_rand_prop_vals checksum $1 0 } function get_rand_recsize { - get_rand_prop recsize_prop_vals $1 0 + get_rand_prop_vals recsize $1 0 } function get_rand_large_recsize { - get_rand_prop recsize_prop_vals $1 9 + get_rand_prop_vals recsize $1 9 } # @@ -137,7 +144,7 @@ function randomize_ds_props fi for prop in $proplist; do - typeset val=$(get_rand_prop "${prop}_prop_vals" 1 0) + typeset val=$(get_rand_prop_vals $prop 1 0) log_must zfs set $prop=$val $ds done }