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"`
43 date=`date +"%b %d %Y"`
45 ## @fn createTemplate()
46 ## @brief Generate runTest template file
48 ## Note that the generated template has no license.
49 ## The SSAT user may put their own license for the generated files.
50 ## I hereby grant the right to relicense the generated files.
51 function createTemplate() {
52 if [[ -f "runTest.sh" ]]
54 printf "Cannot create runTest.sh here. The file already exists at $(pwd).\n\n"
58 echo -e "#!/usr/bin/env bash\n\
60 ## @file runTest.sh\n\
61 ## @author MyungJoo Ham <myungjoo.ham@gmail.com>\n\
63 ## @brief This is a template file for SSAT test cases. You may designate your own license.\n\
65 if [[ \"\$SSATAPILOADED\" != \"1\" ]]\n\
69 search=\"ssat-api.sh\"\n\
71 printf \"\${Blue}Independent Mode\${NC}\\n\"\n\
73 testInit \$1 # You may replace this with Test Group Name\n\
75 #testResult 1 T1 \"Dummy Test1\"\n\
76 #callTestSuccess gst-launch-1.0 \"-q videotestsrc ! videoconvert ! autovideosink\" T2 \"This may run indefinitely\"\n\
77 #callCompareTest golden.log executeResult.log T3 \"The two files must be same\" 0\n\
79 report\n" > runTest.sh
92 printf "usage: ${BASENAME} [--help] [<path>] [--testcase <filename>] [--nocolor] [--showstdout] [--createtemplate]\n\n"
93 printf "These are common ${Red}ssat${NC} commands used:\n\n"
94 printf "Test all test-groups in the current ($(pwd)) directory, recursively\n"
95 printf " (no options specified)\n"
96 printf " $ ${BASENAME}\n"
98 printf "Test all test-groups in the specified directory, recursively\n"
100 printf " $ ${BASENAME} /home/username/test\n"
101 printf " If there are multiple paths, the last one will be used\n"
103 printf "Search for \"filename\" as the testcase scripts\n"
104 printf " --testcase or -t\n"
105 printf " $ ${BASENAME} --testcase cases.sh\n"
106 printf " Search for cases.sh instead of runTest.sh\n"
108 printf "Do not emit colored text\n"
109 printf " --nocolor or -n\n"
111 printf "Show stdout of test cases\n"
112 printf " --showstdout or -s\n"
114 printf "Create a template 'runTest.sh' test group at your current directory\n"
115 printf " --createtemplate or -c\n"
117 printf "Shows this message\n"
118 printf " --help or -h\n"
119 printf " $ ${BASENAME} --help \n"
140 *) # Unknown, which is probably target (the path to root-dir of test groups).
146 source ${BASEPATH}/ssat-api.sh
148 if [[ "${#TARGET}" -eq "0" ]]
162 while read -d $'\0' file
164 CASEBASEPATH=`dirname "$file"`
165 CASENAME=`basename "$CASEBASEPATH"`
171 pushd $CASEBASEPATH > /dev/null
172 output=$(. $file $CASEBASEPATH)
176 logfile="${output##*$'\n'}"
177 resultlog=$(<$logfile)
178 effectiveOutput=`printf "$resultlog" | sed '$d'`
179 log="$log$effectiveOutput\n"
181 lastline=`printf "${resultlog}" | sed '$!d'`
190 TNtcpass=$((TNtcpass+Npass))
191 TNtcfail=$((TNtcfail+Nfail))
193 TNgroup=$((TNgroup+1))
194 if [[ "$retcode" -eq "0" ]]
196 TNgrouppass=$((TNgrouppass+1))
197 groupLog="${groupLog}${LightGreen}[PASSED]${NC} ${Blue}${CASENAME}${NC} ($Npass passed among $Ntc cases)\n"
199 TNgroupfail=$((TNgroupfail+1))
200 groupLog="${groupLog}${Red}[FAILED]${NC} ${Blue}${CASENAME}${NC} ($Npass passed among $Ntc cases)\n"
203 done < <(find $TARGET -name $TESTCASE -print0)
205 printf "\n\n==================================================\n\n"
208 printf "==================================================\n\n"
210 printf "==================================================\n"
212 if (( ${TNgroupfail} == 0 ))
214 printf "${LightGreen}[PASSED] ${Blue}All Test Groups (${TNgroup}) Passed!${NC}\n"
215 printf " TC Passed: ${TNtcpass} / Failed: ${TNtcfail}\n\n";
218 printf "${Red}[FAILED] ${Purple}There are failed test groups! (${TNgroupfail})${NC}\n"
219 printf " TC Passed: ${TNtcpass} / Failed: ${TNtcfail}\n\n";
222 # gather reports & publish them.