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# Copyright (c) 2021 Matt Fiddaman 30# 31 32. $STF_SUITE/include/libtest.shlib 33 34# 35# According to $elements, $prefix and $separator, the function random produce 36# the number of $counter combination. 37# 38# $1 elements which is used to get the combination. 39# $2 prefix is appended to the combination 40# $3 separator between the combination, such as ' ' or ',' 41# $4 counter is the number of combination which you want to get. 42# 43function gen_option_str # $elements $prefix $separator $counter 44{ 45 typeset elements="" 46 typeset prefix=${2} 47 typeset separator=${3} 48 typeset -i counter=${4:-0} 49 typeset -i i=0 50 typeset comb_str="" 51 52 for e in $1; do 53 elements[i]="$e" 54 (( i += 1 )) 55 done 56 (( ${#elements[@]} == 0 )) && log_fail "The elements can't be empty." 57 58 typeset -i item=0 59 typeset -i j=0 60 typeset -i numb_item=0 61 62 # Loop and get the specified number combination strings. 63 i=0 64 while (( i < counter )); do 65 j=0 66 numb_item=0 67 comb_str="" 68 69 # Get random number items for each combinations. 70 (( numb_item = ($RANDOM % ${#elements[@]}) + 1 )) 71 72 while (( j < numb_item )); do 73 # Random select elements from the array 74 (( item = $RANDOM % ${#elements[@]} )) 75 76 if (( ${#comb_str} == 0 )); then 77 comb_str=${elements[item]} 78 else 79 comb_str=$comb_str$separator${elements[item]} 80 fi 81 (( j += 1 )) 82 done 83 84 echo "$prefix$comb_str" 85 86 (( i += 1 )) 87 done 88} 89 90# 91# Cleanup the volume snapshot, filesystem snapshots, clones, volume bookmark, 92# and filesystem bookmark that were created for this test case. 93# 94function cleanup 95{ 96 datasetexists $TESTPOOL/$TESTVOL@$TESTSNAP && \ 97 destroy_snapshot $TESTPOOL/$TESTVOL@$TESTSNAP 98 datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \ 99 destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP 100 101 datasetexists $TESTPOOL/$TESTCLONE && \ 102 destroy_clone $TESTPOOL/$TESTCLONE 103 datasetexists $TESTPOOL/$TESTFS@$TESTSNAP1 && \ 104 destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP1 105 106 bkmarkexists $TESTPOOL/$TESTVOL#$TESTBKMARK && \ 107 destroy_bookmark $TESTPOOL/$TESTVOL#$TESTBKMARK 108 bkmarkexists $TESTPOOL/$TESTFS#$TESTBKMARK && \ 109 destroy_bookmark $TESTPOOL/$TESTFS#$TESTBKMARK 110 111 [[ -e $TESTFILE0 ]] && log_must rm $TESTFILE0 112} 113