|
| 1 | + #!/bin/bash |
| 2 | + |
| 3 | +# |
| 4 | +############################################################################# |
| 5 | +# |
| 6 | +# test_opts.sh |
| 7 | +# |
| 8 | +# Script for testing all permutations of command-line options |
| 9 | +# |
| 10 | +# See sampleTest() for how to define your own test |
| 11 | +# |
| 12 | + |
| 13 | +# |
| 14 | +# set these variables for your test environment: |
| 15 | +# |
| 16 | +fio_executable=./fio |
| 17 | + |
| 18 | +# |
| 19 | +# Demonstration of using this script |
| 20 | +# |
| 21 | +function sampleTest() { |
| 22 | + |
| 23 | + # |
| 24 | + # sample test execution |
| 25 | + # |
| 26 | + # 1) Create each of your command-line groups (each in a separate array) |
| 27 | + # 2) List the names of all your groups in one array |
| 28 | + # 3) Define arguments that are common to all groups (if any) |
| 29 | + # 4) Call execGroupList |
| 30 | + # |
| 31 | + # See getNextCmdLinePermutation() for how the permutation works |
| 32 | + # |
| 33 | + |
| 34 | + local numjobs=("numjobs=1" "numjobs=8") |
| 35 | + local rw=("rw=write" "rw=randrw") |
| 36 | + local bs=("bs=512" "bs=64K") |
| 37 | + local thread=("" "thread") # groups can have empty members, to test with and without option |
| 38 | + local all=("numjobs" "rw" "bs" "thread") |
| 39 | + |
| 40 | + local commonArgs="-name=test -ioengine=null -size=500M -group_reporting -runtime=5" |
| 41 | + |
| 42 | + echo -e "\nHere are the permutations of options:\n" |
| 43 | + printAllPermutations "${all[@]}"; |
| 44 | + echo -e "\nHere are options common to all permutations:\n" |
| 45 | + echo -e "${commonArgs}\n" |
| 46 | + |
| 47 | + read -p "Press enter to start tests..." |
| 48 | + |
| 49 | + execGroupList "test" "$commonArgs" "${all[@]}" |
| 50 | +} |
| 51 | + |
| 52 | +# |
| 53 | +# Iterates the next permutation for groups of command-line options |
| 54 | +# |
| 55 | +# Parameters: |
| 56 | +# |
| 57 | +# $1 Permutation to generate, 0..n-1, where 'n' is the total |
| 58 | +# number of combinations possible in the groups passed. |
| 59 | +# $2 Array containing list of array names, each of which contains |
| 60 | +# a group of command-line options |
| 61 | +# |
| 62 | +# Return Value: |
| 63 | +# |
| 64 | +# retVal Command line string generated |
| 65 | +# |
| 66 | +# Example: |
| 67 | +# |
| 68 | +# ops=("op=read" "op=write") |
| 69 | +# sizes=("size=10MB" "size=20MB" "size=50MB") |
| 70 | +# all=("ops" "sizes") |
| 71 | +# |
| 72 | +# getNextCmdLinePermutation {0..6} "${all[@]}"; |
| 73 | +# |
| 74 | +# Results for each permutation number passed: |
| 75 | +# |
| 76 | +# 0: "--op=read --size=10MB" |
| 77 | +# 1: "--op=write --size=10MB" |
| 78 | +# 2: "--op=read --size=20MB" |
| 79 | +# 3: "--op=write --size=20MB" |
| 80 | +# 4: "--op=read --size=50MB" |
| 81 | +# 5: "--op=write --size=50MB" |
| 82 | +# 6: "" (invalid permutation #) |
| 83 | +# |
| 84 | +function getNextCmdLinePermutation() { |
| 85 | + |
| 86 | + local permutationToGet=$1 |
| 87 | + shift |
| 88 | + local allArgGroups=("$@") |
| 89 | + local numArgGroups="${#allArgGroups[@]}" |
| 90 | + local cmdLine="" |
| 91 | + local groupNum n |
| 92 | + |
| 93 | + for ((groupNum=0, n=permutationToGet; groupNum<numArgGroups; groupNum++)); do |
| 94 | + local -n groupVals="${allArgGroups[groupNum]}" |
| 95 | + local numItemsInGroup=${#groupVals[@]} |
| 96 | + local itemIndexInGroup=$((n % numItemsInGroup)) |
| 97 | + local item="${groupVals[itemIndexInGroup]}" |
| 98 | + if [[ -n $item ]]; then |
| 99 | + cmdLine+="--${item} " |
| 100 | + fi # else this is an empty item, ex: args=("" "numjobs=4") |
| 101 | + n=$((n / numItemsInGroup)) |
| 102 | + done |
| 103 | + # n==0 if permutation # specified is invalid/beyond groups |
| 104 | + if ((n == 0)); then retVal="$cmdLine"; else retVal=""; fi |
| 105 | +} |
| 106 | + |
| 107 | +# |
| 108 | +# Calculates the number of command line permutations for a group |
| 109 | +# |
| 110 | +# Parameters: |
| 111 | +# |
| 112 | +# $1 Array containing list of array names, each of which |
| 113 | +# contains a group of command-line options |
| 114 | +# |
| 115 | +# Return Value: |
| 116 | +# |
| 117 | +# retVal Generated command line string |
| 118 | +# |
| 119 | +function getNumCmdLinePermutations() { |
| 120 | + local allArgGroups=("$@") |
| 121 | + local numArgGroups="${#allArgGroups[@]}" |
| 122 | + local groupNum count |
| 123 | + for ((groupNum=0, count=1; groupNum<numArgGroups; groupNum++)); do |
| 124 | + local -n groupVals="${allArgGroups[groupNum]}" |
| 125 | + if [[ -z ${groupVals[@]} ]]; then |
| 126 | + echo "Error: Command group \"${allArgGroups[groupNum]}\" not defined"; |
| 127 | + exit 1 |
| 128 | + fi |
| 129 | + count=$((count * ${#groupVals[@]})) |
| 130 | + done |
| 131 | + retVal=$count |
| 132 | + |
| 133 | +} |
| 134 | + |
| 135 | +# |
| 136 | +# Executes fio |
| 137 | +# |
| 138 | +# Parameters: |
| 139 | +# |
| 140 | +# $1 Arguments |
| 141 | +# |
| 142 | +# Return Value: |
| 143 | +# |
| 144 | +# None - exits script on error |
| 145 | +# |
| 146 | +function execFio() { |
| 147 | + args="$1" |
| 148 | + "${fio_executable}" $args; exitCode=$? |
| 149 | + if [ $exitCode -ne 0 ]; then |
| 150 | + echo "*** FAILED - exit code is ${exitCode} ***"; |
| 151 | + echo "Full Args: $args" |
| 152 | + exit $exitCode |
| 153 | + fi |
| 154 | +} |
| 155 | + |
| 156 | +# |
| 157 | +# Executes all permutations for groups of command line options |
| 158 | +# |
| 159 | +# Parameters: |
| 160 | +# |
| 161 | +# $1 Arguments common to all fio invocations |
| 162 | +# $2 Array of command-line option groups. See getNextCmdLinePermutation() |
| 163 | +# for format |
| 164 | +# |
| 165 | +# Return Value: |
| 166 | +# |
| 167 | +# None - exits script on error |
| 168 | +# |
| 169 | +function execGroupList() { |
| 170 | + |
| 171 | + local permutationNumber countArgPermutations permutationArgs |
| 172 | + local testDescription="$1" |
| 173 | + local commonArgs="$2" |
| 174 | + shift 2 |
| 175 | + local allArgGroups=("$@") |
| 176 | + |
| 177 | + getNumCmdLinePermutations "${allArgGroups[@]}"; countArgPermutations=$retVal |
| 178 | + |
| 179 | + echo |
| 180 | + echo "**** Starting \"${testDescription}\" - ${countArgPermutations} permutations of arguments..." |
| 181 | + echo |
| 182 | + |
| 183 | + for ((permutationNumber=0; permutationNumber < countArgPermutations; permutationNumber++)); do |
| 184 | + getNextCmdLinePermutation $permutationNumber "${allArgGroups[@]}"; permutationArgs=$retVal; |
| 185 | + echo "** Executing permutation ${permutationNumber}, args: ${permutationArgs}" |
| 186 | + execFio "$commonArgs $permutationArgs" |
| 187 | + done |
| 188 | + |
| 189 | + echo |
| 190 | + echo "**** Finished \"${testDescription}\" - ${countArgPermutations} permutations of arguments..." |
| 191 | + echo |
| 192 | +} |
| 193 | + |
| 194 | +function printAllPermutations() { |
| 195 | + local allArgGroups=("$@") |
| 196 | + local permutationNumber countArgPermutations permutationArgs |
| 197 | + getNumCmdLinePermutations "${allArgGroups[@]}"; countArgPermutations=$retVal |
| 198 | + for ((permutationNumber=0; permutationNumber < countArgPermutations; permutationNumber++)); do |
| 199 | + getNextCmdLinePermutation $permutationNumber "${allArgGroups[@]}"; permutationArgs=$retVal; |
| 200 | + echo "Permutation ${permutationNumber}: ${permutationArgs}" |
| 201 | + done |
| 202 | +} |
| 203 | + |
| 204 | +# |
| 205 | +# execute tests |
| 206 | +# |
| 207 | +sampleTest |
| 208 | + |
0 commit comments