1# vim: filetype=sh 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or http://www.opensolaris.org/os/licensing. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27# ident "@(#)zfs_get_common.kshlib 1.3 07/03/14 SMI" 28# 29 30. $STF_SUITE/include/libtest.kshlib 31 32# 33# According to $elements, $prefix and $separator, the function random produce 34# the number of $counter combination. 35# 36# $1 elements which is used to get the combination. 37# $2 prefix is appended to the combination 38# $3 separator between the combination, such as ' ' or ',' 39# $4 counter is the number of combination which you want to get. 40# 41function gen_option_str # $elements $prefix $separator $counter 42{ 43 typeset elements="" 44 typeset prefix=${2} 45 typeset separator=${3} 46 typeset -i counter=${4:-0} 47 typeset -i i=0 48 typeset comb_str="" 49 50 for e in $1; do 51 elements[i]="$e" 52 (( i += 1 )) 53 done 54 (( ${#elements[@]} == 0 )) && log_fail "The elements can't be empty." 55 56 typeset -i item=0 57 typeset -i j=0 58 typeset -i numb_item=0 59 60 # Loop and get the specified number combination strings. 61 i=0 62 while (( i < counter )); do 63 j=0 64 numb_item=0 65 comb_str="" 66 67 # Get random number items for each combinations. 68 (( numb_item = ($RANDOM % ${#elements[@]}) + 1 )) 69 70 while (( j < numb_item )); do 71 # Random select elements from the array 72 (( item = $RANDOM % ${#elements[@]} )) 73 74 if (( ${#comb_str} == 0 )); then 75 comb_str=${elements[item]} 76 else 77 comb_str=$comb_str$separator${elements[item]} 78 fi 79 (( j += 1 )) 80 done 81 82 print "$prefix$comb_str" 83 84 (( i += 1 )) 85 done 86} 87 88# 89# Cleanup the volume snapshot and filesystem snapshot were created for 90# this test case. 91# 92function cleanup 93{ 94 datasetexists $TESTPOOL/$TESTVOL@$TESTSNAP && \ 95 destroy_snapshot $TESTPOOL/$TESTVOL@$TESTSNAP 96 datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \ 97 destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP 98 99 [[ -e $TESTFILE0 ]] && log_must $RM $TESTFILE0 100} 101