From b8cea60c37a948c23ecd1681cdae85fc259d36b6 Mon Sep 17 00:00:00 2001 From: Horshack Date: Sat, 4 Mar 2023 20:19:18 -0500 Subject: [PATCH] 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 (horshack@live.com) --- t/test_opts.sh | 209 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100755 t/test_opts.sh diff --git a/t/test_opts.sh b/t/test_opts.sh new file mode 100755 index 0000000000..628734f12e --- /dev/null +++ b/t/test_opts.sh @@ -0,0 +1,209 @@ + #!/bin/bash + +# +############################################################################# +# +# test_opts.sh +# +# Script for testing all permutations of command-line options +# +# See sampleTest() for how to define your own test +# + +# +# set these variables for your test environment: +# +fio_executable=./fio + +# +# Demonstration of using this script +# +function sampleTest() { + + # + # sample test execution + # + # 1) Create each of your command-line groups (each in a separate array) + # 2) List the names of all your groups in one array + # 3) Define arguments that are common to all groups (if any) + # 4) Call execGroupList + # + # See getNextCmdLinePermutation() for how the permutation works + # + + local numjobs=("numjobs=1" "numjobs=8") + local rw=("rw=write" "rw=randrw") + local bs=("bs=512" "bs=64K") + local thread=("" "thread") # groups can have empty members, to test with and without option + local all=("numjobs" "rw" "bs" "thread") + + local commonArgs="-name=test -ioengine=null -size=500M -group_reporting -runtime=5" + + echo -e "\nHere are the permutations of options:\n" + printAllPermutations "${all[@]}"; + echo -e "\nHere are options common to all permutations:\n" + echo -e "${commonArgs}\n" + + read -p "Press enter to start tests..." + + execGroupList "test" "$commonArgs" "${all[@]}" +} + +# +# Iterates the next permutation for groups of command-line options +# +# Parameters: +# +# $1 Permutation to generate, 0..n-1, where 'n' is the total +# number of combinations possible in the groups passed. +# $2 Array containing list of array names, each of which contains +# a group of command-line options +# +# Return Value: +# +# retVal Command line string generated +# +# Example: +# +# ops=("op=read" "op=write") +# sizes=("size=10MB" "size=20MB" "size=50MB") +# all=("ops" "sizes") +# +# getNextCmdLinePermutation {0..6} "${all[@]}"; +# +# Results for each permutation number passed: +# +# 0: "--op=read --size=10MB" +# 1: "--op=write --size=10MB" +# 2: "--op=read --size=20MB" +# 3: "--op=write --size=20MB" +# 4: "--op=read --size=50MB" +# 5: "--op=write --size=50MB" +# 6: "" (invalid permutation #) +# +function getNextCmdLinePermutation() { + + local permutationToGet=$1 + shift + local allArgGroups=("$@") + local numArgGroups="${#allArgGroups[@]}" + local cmdLine="" + local groupNum n + + for ((groupNum=0, n=permutationToGet; groupNum