4 ## @author MyungJoo Ham <myungjoo.ham@gmail.com>
6 ## @brief This executes test groups and reports aggregated test results.
7 ## @return 0 if all PASSED. Positive if some FAILED.
8 ## @todo Separate GStreamer related functions as plugins
10 ## This uses sed, date, cmp
12 ## If there is no arguments specified, this will search for all "runTest.sh" in
13 ## the subdirectory of this file and regard them as the test groups.
15 ## If a testgroup (runTest.sh) returns 0 while there are failed testcase,
16 ## it implies that the failed testcases may be ignored and it's good to go.
18 ## If --help or -h is given, this will show detailed description.
22 ## @section intro Introduction
23 ## - Introduction : Shell Script Automated Tester
24 ## @section Program Program Name
25 ## - Program Name : ssat
26 ## - Program Details : SSAT is a software testing framework for test cases written in BASH shell scripts.
27 ## It can search for test scripts recursively from a given path and summarize the test results.
28 ## If there is any "critical" fail, ssat will return non-zero values on its exit.
29 ## @section INOUTPUT Input/output data
30 ## - INPUT : Test Cases (If not supplied, the current path is the root of test cases)
31 ## - OUTPUT : Summary of test results to stdout. Exit code of 0 if success, non-zero if not success.
32 ## @section CREATEINFO Code information
33 ## - Initial date : 2018/06/22
37 BASEPATH=`dirname "$0"`
38 BASENAME=`basename "$0"`
45 date=`date +"%b %d %Y"`
47 ## @fn createTemplate()
48 ## @brief Generate runTest template file
50 ## Note that the generated template has no license.
51 ## The SSAT user may put their own license for the generated files.
52 ## I hereby grant the right to relicense the generated files.
53 function createTemplate() {
54 if [[ -f "runTest.sh" ]]
56 printf "Cannot create runTest.sh here. The file already exists at $(pwd).\n\n"
60 echo -e "#!/usr/bin/env bash\n\
62 ## @file runTest.sh\n\
63 ## @author MyungJoo Ham <myungjoo.ham@gmail.com>\n\
65 ## @brief This is a template file for SSAT test cases. You may designate your own license.\n\
67 if [[ \"\$SSATAPILOADED\" != \"1\" ]]\n\
71 search=\"ssat-api.sh\"\n\
73 printf \"\${Blue}Independent Mode\${NC}\\n\"\n\
75 testInit \$1 # You may replace this with Test Group Name\n\
77 #testResult 1 T1 \"Dummy Test1\"\n\
78 #callTestSuccess gst-launch-1.0 \"-q videotestsrc ! videoconvert ! autovideosink\" T2 \"This may run indefinitely\"\n\
79 #callCompareTest golden.log executeResult.log T3 \"The two files must be same\" 0\n\
81 report\n" > runTest.sh
94 printf "usage: ${BASENAME} [--help] [<path>] [--testcase <filename>] [--nocolor] [--showstdout] [--createtemplate]\n\n"
95 printf "These are common ${Red}ssat${NC} commands used:\n\n"
96 printf "Test all test-groups in the current ($(pwd)) directory, recursively\n"
97 printf " (no options specified)\n"
98 printf " $ ${BASENAME}\n"
100 printf "Test all test-groups in the specified directory, recursively\n"
102 printf " $ ${BASENAME} /home/username/test\n"
103 printf " If there are multiple paths, the last one will be used\n"
105 printf "Search for \"filename\" as the testcase scripts\n"
106 printf " --testcase or -t\n"
107 printf " $ ${BASENAME} --testcase cases.sh\n"
108 printf " Search for cases.sh instead of runTest.sh\n"
110 printf "Do not emit colored text\n"
111 printf " --nocolor or -n\n"
113 printf "Show stdout of test cases\n"
114 printf " --showstdout or -s\n"
116 printf "Create a template 'runTest.sh' test group at your current directory\n"
117 printf " --createtemplate or -c\n"
119 printf "Show progress during execution\n"
120 printf " --progress or -p\n"
122 printf "Enable valgrind to perform memcheck\n"
123 printf " --enable-valgrind or -vg\n"
125 printf "Shows this message\n"
126 printf " --help or -h\n"
127 printf " $ ${BASENAME} --help \n"
152 -vg|--enable-valgrind)
156 *) # Unknown, which is probably target (the path to root-dir of test groups).
162 source ${BASEPATH}/ssat-api.sh
164 if [[ "${#TARGET}" -eq "0" ]]
179 while read -d $'\0' file
181 CASEBASEPATH=`dirname "$file"`
182 CASENAME=`basename "$CASEBASEPATH"`
188 if [[ "$PROGRESS" -eq "1" ]]; then
189 printf "[Starting] $CASENAME\n"
191 pushd $CASEBASEPATH > /dev/null
192 output=$(. $file $CASEBASEPATH)
196 logfile="${output##*$'\n'}"
197 resultlog=$(<$logfile)
198 effectiveOutput=`printf "$resultlog" | sed '$d'`
199 log="$log$effectiveOutput\n"
201 lastline=`printf "${resultlog}" | sed '$!d'`
211 TNtcpass=$((TNtcpass+Npass))
212 TNtcfail=$((TNtcfail+Nfail))
213 TNtcignore=$((TNtcignore+Nignore))
215 TNgroup=$((TNgroup+1))
216 if [[ "$retcode" -eq "0" ]]
218 TNgrouppass=$((TNgrouppass+1))
219 groupLog="${groupLog}${LightGreen}[PASSED]${NC} ${Blue}${CASENAME}${NC} ($Npass passed among $Ntc cases)\n"
221 TNgroupfail=$((TNgroupfail+1))
222 groupLog="${groupLog}${Red}[FAILED]${NC} ${Blue}${CASENAME}${NC} ($Npass passed among $Ntc cases)\n"
227 done < <(find $TARGET -name $TESTCASE -print0)
229 printf "\n\n==================================================\n\n"
231 printf "==================================================\n\n"
233 printf "==================================================\n"
235 if (( ${TNgroupfail} == 0 ))
237 printf "${LightGreen}[PASSED] ${Blue}All Test Groups (${TNgroup}) Passed!${NC}\n"
238 printf " TC Passed: ${TNtcpass} / Failed: ${TNtcfail} / Ignored: ${TNtcignore}\n\n";
241 printf "${Red}[FAILED] ${Purple}There are failed test groups! (${TNgroupfail})${NC}\n"
242 printf " TC Passed: ${TNtcpass} / Failed: ${TNtcfail} / Ignored: ${TNtcignore}\n\n";
245 # gather reports & publish them.