xref: /titanic_41/usr/src/test/zfs-tests/include/properties.shlib (revision d583b39bfb4e2571d3e41097c5c357ffe353ad45)
1*d583b39bSJohn Wren Kennedy#
2*d583b39bSJohn Wren Kennedy# This file and its contents are supplied under the terms of the
3*d583b39bSJohn Wren Kennedy# Common Development and Distribution License ("CDDL"), version 1.0.
4*d583b39bSJohn Wren Kennedy# You may only use this file in accordance with the terms of version
5*d583b39bSJohn Wren Kennedy# 1.0 of the CDDL.
6*d583b39bSJohn Wren Kennedy#
7*d583b39bSJohn Wren Kennedy# A full copy of the text of the CDDL should have accompanied this
8*d583b39bSJohn Wren Kennedy# source.  A copy of the CDDL is also available via the Internet at
9*d583b39bSJohn Wren Kennedy# http://www.illumos.org/license/CDDL.
10*d583b39bSJohn Wren Kennedy#
11*d583b39bSJohn Wren Kennedy
12*d583b39bSJohn Wren Kennedy#
13*d583b39bSJohn Wren Kennedy# Copyright (c) 2012 by Delphix. All rights reserved.
14*d583b39bSJohn Wren Kennedy#
15*d583b39bSJohn Wren Kennedy
16*d583b39bSJohn Wren Kennedytypeset -a compress_props=('on' 'off' 'lzjb' 'gzip' 'gzip-1' 'gzip-2' 'gzip-3'
17*d583b39bSJohn Wren Kennedy    'gzip-4' 'gzip-5' 'gzip-6' 'gzip-7' 'gzip-8' 'gzip-9' 'zle')
18*d583b39bSJohn Wren Kennedy
19*d583b39bSJohn Wren Kennedytypeset -a checksum_props=('on' 'off' 'fletcher2' 'fletcher4' 'sha256')
20*d583b39bSJohn Wren Kennedy
21*d583b39bSJohn Wren Kennedy#
22*d583b39bSJohn Wren Kennedy# Given the property array passed in, return 'num_props' elements to the
23*d583b39bSJohn Wren Kennedy# user, excluding any elements below 'start.' This allows us to exclude
24*d583b39bSJohn Wren Kennedy# 'off' and 'on' which can be either unwanted, or a duplicate of another
25*d583b39bSJohn Wren Kennedy# property respectively.
26*d583b39bSJohn Wren Kennedy#
27*d583b39bSJohn Wren Kennedyfunction get_rand_prop
28*d583b39bSJohn Wren Kennedy{
29*d583b39bSJohn Wren Kennedy	typeset prop_array=($(eval echo \${$1[@]}))
30*d583b39bSJohn Wren Kennedy	typeset -i num_props=$2
31*d583b39bSJohn Wren Kennedy	typeset -i start=$3
32*d583b39bSJohn Wren Kennedy	typeset retstr=""
33*d583b39bSJohn Wren Kennedy
34*d583b39bSJohn Wren Kennedy	[[ -z $prop_array || -z $num_props || -z $start ]] && \
35*d583b39bSJohn Wren Kennedy	    log_fail "get_rand_prop: bad arguments"
36*d583b39bSJohn Wren Kennedy
37*d583b39bSJohn Wren Kennedy	typeset prop_max=$((${#prop_array[@]} - 1))
38*d583b39bSJohn Wren Kennedy	typeset -i i
39*d583b39bSJohn Wren Kennedy	for i in $($SHUF -i $start-$prop_max -n $num_props); do
40*d583b39bSJohn Wren Kennedy		retstr="${prop_array[$i]} $retstr"
41*d583b39bSJohn Wren Kennedy	done
42*d583b39bSJohn Wren Kennedy	echo $retstr
43*d583b39bSJohn Wren Kennedy}
44*d583b39bSJohn Wren Kennedy
45*d583b39bSJohn Wren Kennedyfunction get_rand_compress
46*d583b39bSJohn Wren Kennedy{
47*d583b39bSJohn Wren Kennedy	get_rand_prop compress_props $1 2
48*d583b39bSJohn Wren Kennedy}
49*d583b39bSJohn Wren Kennedy
50*d583b39bSJohn Wren Kennedyfunction get_rand_compress_any
51*d583b39bSJohn Wren Kennedy{
52*d583b39bSJohn Wren Kennedy	get_rand_prop compress_props $1 0
53*d583b39bSJohn Wren Kennedy}
54*d583b39bSJohn Wren Kennedy
55*d583b39bSJohn Wren Kennedyfunction get_rand_checksum
56*d583b39bSJohn Wren Kennedy{
57*d583b39bSJohn Wren Kennedy	get_rand_prop checksum_props $1 2
58*d583b39bSJohn Wren Kennedy}
59*d583b39bSJohn Wren Kennedy
60*d583b39bSJohn Wren Kennedyfunction get_rand_checksum_any
61*d583b39bSJohn Wren Kennedy{
62*d583b39bSJohn Wren Kennedy	get_rand_prop checksum_props $1 0
63*d583b39bSJohn Wren Kennedy}
64