Skip to content

Commit b8cea60

Browse files
Add t/test_opts.sh - Automated testing of command line options
New script for testing combinations of command-line options. You define groups of options and this script will execute all permutations of those options. For example: numjobs=("numjobs=1" "numjobs=8") rw=("rw=write" "rw=randrw") bs=("bs=512" "bs=64K") thread=("" "thread") all=("numjobs" "rw" "bs" "thread") commonArgs="-name=test -ioengine=null -size=500M" Will execute fio with permutations of options: Permutation 0: --numjobs=1 --rw=write --bs=512 Permutation 1: --numjobs=8 --rw=write --bs=512 Permutation 2: --numjobs=1 --rw=randrw --bs=512 Permutation 3: --numjobs=8 --rw=randrw --bs=512 Permutation 4: --numjobs=1 --rw=write --bs=64K Permutation 5: --numjobs=8 --rw=write --bs=64K Permutation 6: --numjobs=1 --rw=randrw --bs=64K Permutation 7: --numjobs=8 --rw=randrw --bs=64K Permutation 8: --numjobs=1 --rw=write --bs=512 --thread Permutation 9: --numjobs=8 --rw=write --bs=512 --thread Permutation 10: --numjobs=1 --rw=randrw --bs=512 --thread Permutation 11: --numjobs=8 --rw=randrw --bs=512 --thread Permutation 12: --numjobs=1 --rw=write --bs=64K --thread Permutation 13: --numjobs=8 --rw=write --bs=64K --thread Permutation 14: --numjobs=1 --rw=randrw --bs=64K --thread Permutation 15: --numjobs=8 --rw=randrw --bs=64K --thread All permutations will have these options in common: -name=test -ioengine=null -size=500M Signed-off-by: Adam Horshack ([email protected])
1 parent 051b578 commit b8cea60

File tree

1 file changed

+209
-0
lines changed

1 file changed

+209
-0
lines changed

t/test_opts.sh

+209
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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 Test description
162+
# $2 Arguments common to all fio invocations
163+
# $3 Array of command-line option groups. See getNextCmdLinePermutation()
164+
# for format
165+
#
166+
# Return Value:
167+
#
168+
# None - exits script on error
169+
#
170+
function execGroupList() {
171+
172+
local permutationNumber countArgPermutations permutationArgs
173+
local testDescription="$1"
174+
local commonArgs="$2"
175+
shift 2
176+
local allArgGroups=("$@")
177+
178+
getNumCmdLinePermutations "${allArgGroups[@]}"; countArgPermutations=$retVal
179+
180+
echo
181+
echo "**** Starting \"${testDescription}\" - ${countArgPermutations} permutations of arguments..."
182+
echo
183+
184+
for ((permutationNumber=0; permutationNumber < countArgPermutations; permutationNumber++)); do
185+
getNextCmdLinePermutation $permutationNumber "${allArgGroups[@]}"; permutationArgs=$retVal;
186+
echo "** Executing permutation ${permutationNumber}, args: ${permutationArgs}"
187+
execFio "$commonArgs $permutationArgs"
188+
done
189+
190+
echo
191+
echo "**** Finished \"${testDescription}\" - ${countArgPermutations} permutations of arguments..."
192+
echo
193+
}
194+
195+
function printAllPermutations() {
196+
local allArgGroups=("$@")
197+
local permutationNumber countArgPermutations permutationArgs
198+
getNumCmdLinePermutations "${allArgGroups[@]}"; countArgPermutations=$retVal
199+
for ((permutationNumber=0; permutationNumber < countArgPermutations; permutationNumber++)); do
200+
getNextCmdLinePermutation $permutationNumber "${allArgGroups[@]}"; permutationArgs=$retVal;
201+
echo "Permutation ${permutationNumber}: ${permutationArgs}"
202+
done
203+
}
204+
205+
#
206+
# execute tests
207+
#
208+
sampleTest
209+

0 commit comments

Comments
 (0)