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