2 # This file and its contents are supplied under the terms of the
3 # Common Development and Distribution License ("CDDL"), version 1.0.
4 # You may only use this file in accordance with the terms of version
7 # A full copy of the text of the CDDL should have accompanied this
8 # source. A copy of the CDDL is also available via the Internet at
9 # http://www.illumos.org/license/CDDL.
13 # Copyright (c) 2012 by Delphix. All rights reserved.
16 typeset -a compress_props=('on' 'off' 'lzjb' 'gzip' 'gzip-1' 'gzip-2' 'gzip-3'
17 'gzip-4' 'gzip-5' 'gzip-6' 'gzip-7' 'gzip-8' 'gzip-9' 'zle')
19 typeset -a checksum_props=('on' 'off' 'fletcher2' 'fletcher4' 'sha256')
22 # Given the property array passed in, return 'num_props' elements to the
23 # user, excluding any elements below 'start.' This allows us to exclude
24 # 'off' and 'on' which can be either unwanted, or a duplicate of another
25 # property respectively.
27 function get_rand_prop
29 typeset prop_array=($(eval echo \${$1[@]}))
30 typeset -i num_props=$2
34 [[ -z $prop_array || -z $num_props || -z $start ]] && \
35 log_fail "get_rand_prop: bad arguments"
37 typeset prop_max=$((${#prop_array[@]} - 1))
39 for i in $($SHUF -i $start-$prop_max -n $num_props); do
40 retstr="${prop_array[$i]} $retstr"
45 function get_rand_compress
47 get_rand_prop compress_props $1 2
50 function get_rand_compress_any
52 get_rand_prop compress_props $1 0
55 function get_rand_checksum
57 get_rand_prop checksum_props $1 2
60 function get_rand_checksum_any
62 get_rand_prop checksum_props $1 0