Print this page
7290 ZFS test suite needs to control what utilities it can run
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
   1 #
   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
   5 # 1.0 of the CDDL.
   6 #
   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.
  10 #
  11 
  12 #
  13 # Copyright (c) 2012 by Delphix. All rights reserved.
  14 #
  15 
  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')
  18 
  19 typeset -a checksum_props=('on' 'off' 'fletcher2' 'fletcher4' 'sha256')
  20 
  21 #
  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.
  26 #
  27 function get_rand_prop
  28 {
  29         typeset prop_array=($(eval echo \${$1[@]}))
  30         typeset -i num_props=$2
  31         typeset -i start=$3
  32         typeset retstr=""
  33 
  34         [[ -z $prop_array || -z $num_props || -z $start ]] && \
  35             log_fail "get_rand_prop: bad arguments"
  36 
  37         typeset prop_max=$((${#prop_array[@]} - 1))
  38         typeset -i i
  39         for i in $($SHUF -i $start-$prop_max -n $num_props); do
  40                 retstr="${prop_array[$i]} $retstr"
  41         done
  42         echo $retstr
  43 }
  44 
  45 function get_rand_compress
  46 {
  47         get_rand_prop compress_props $1 2
  48 }
  49 
  50 function get_rand_compress_any
  51 {
  52         get_rand_prop compress_props $1 0
  53 }
  54 
  55 function get_rand_checksum
  56 {
  57         get_rand_prop checksum_props $1 2
  58 }
  59 
   1 #
   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
   5 # 1.0 of the CDDL.
   6 #
   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.
  10 #
  11 
  12 #
  13 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
  14 #
  15 
  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')
  18 
  19 typeset -a checksum_props=('on' 'off' 'fletcher2' 'fletcher4' 'sha256')
  20 
  21 #
  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.
  26 #
  27 function get_rand_prop
  28 {
  29         typeset prop_array=($(eval echo \${$1[@]}))
  30         typeset -i num_props=$2
  31         typeset -i start=$3
  32         typeset retstr=""
  33 
  34         [[ -z $prop_array || -z $num_props || -z $start ]] && \
  35             log_fail "get_rand_prop: bad arguments"
  36 
  37         typeset prop_max=$((${#prop_array[@]} - 1))
  38         typeset -i i
  39         for i in $(shuf -i $start-$prop_max -n $num_props); do
  40                 retstr="${prop_array[$i]} $retstr"
  41         done
  42         echo $retstr
  43 }
  44 
  45 function get_rand_compress
  46 {
  47         get_rand_prop compress_props $1 2
  48 }
  49 
  50 function get_rand_compress_any
  51 {
  52         get_rand_prop compress_props $1 0
  53 }
  54 
  55 function get_rand_checksum
  56 {
  57         get_rand_prop checksum_props $1 2
  58 }
  59