[Fix] Multi Test Group
authorMyungJoo Ham <myungjoo.ham@gmail.com>
Sat, 23 Jun 2018 14:40:52 +0000 (23:40 +0900)
committerMyungJoo Ham <myungjoo.ham@gmail.com>
Sat, 23 Jun 2018 14:40:52 +0000 (23:40 +0900)
Fix bugs of handling multiple test groups.
Added "create template" for easy test group creation.

TODO: need to support "PATH" searching

Signed-off-by: MyungJoo Ham <myungjoo.ham@gmail.com>
exampleCase/group1A/runTest.sh
exampleCase/group2A/runTest.sh [new file with mode: 0755]
ssat-api.sh
ssat.sh

index 85a9d39..0b30b70 100755 (executable)
@@ -2,8 +2,8 @@
 
 if [[ "$SSATAPILOADED" != "1" ]]
 then
-       echo "Not Loaded"
        SILENT=0
+       INDEPENDENT=1
        search="ssat-api.sh"
        source $search
 
@@ -14,16 +14,18 @@ then
                count=$((count+1))
                if (( ${count} > 5 ))
                then
-                       break
+                       echo "Cannot find ssat-api.sh"
+                       exit 1
                fi
 
                search="../${search}"
                source $search
                retcode=$?
        done
+       printf "${Blue}Independent Mode${NC}\n"
 fi
 
-testInit
+testInit $1
 
 testResult 1 T1 "Dummy Test 1"
 testResult 1 T2 "Dummy Test 2"
diff --git a/exampleCase/group2A/runTest.sh b/exampleCase/group2A/runTest.sh
new file mode 100755 (executable)
index 0000000..537402e
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+if [[ "$SSATAPILOADED" != "1" ]]
+then
+       SILENT=0
+       INDEPENDENT=1
+       search="ssat-api.sh"
+       source $search
+
+       retcode=$?
+       count=0
+       while (( ${retcode} != 0 ))
+       do
+               count=$((count+1))
+               if (( ${count} > 5 ))
+               then
+                       echo "Cannot find ssat-api.sh"
+                       exit 1
+               fi
+
+               search="../${search}"
+               source $search
+               retcode=$?
+       done
+       printf "${Blue}Independent Mode${NC}\n"
+fi
+
+testInit $1
+
+testResult 1 TA "Dummy Test A"
+testResult 1 TB "Dummy Test B"
+
+report
index a9b09a1..627cacd 100644 (file)
@@ -64,22 +64,27 @@ function report {
        if (( ${_fail} == 0 ))
        then
                writef "${Green}==================================================${NC}"
-               writef "${LightGreen}[PASSED]${NC} Test Group ${Green}Passed${NC}"
+               writef "${LightGreen}[PASSED]${NC} Test Group $_group ${Green}Passed${NC}"
        else
                if (( ${_criticalFail} > 0 ))
                then
                        writef "${Green}==================================================${NC}"
-                       writef "${Red}[FAILED]${NC} Test Group has ${Red}failed cases ($_fail)${NC}"
+                       writef "${Red}[FAILED]${NC} Test Group $_group has ${Red}failed cases ($_fail)${NC}"
                else
                        writef "${Green}==================================================${NC}"
-                       writef "${LightGreen}[PASSED]${NC} Test Group has ${Red}failed cases ($_fail), but they are not critical.${NC}"
+                       writef "${LightGreen}[PASSED]${NC} Test Group $_group has ${Red}failed cases ($_fail), but they are not critical.${NC}"
                fi
        fi
 
-       writef "${_cases}/${_pass}/${_fail}"
-
-       echo "${ResultLog}" > $_filename
-       printf "$_filename\n"
+       if [[ "$INDEPENDENT" -eq "1" ]]
+       then
+       # do nothing
+               echo ""
+       else
+               writef "${_cases},${_pass},${_fail}"
+               echo "${ResultLog}" > $_filename
+               printf "$_filename\n"
+       fi
 
        if (( ${_criticalFail} > 0 ))
        then
@@ -95,6 +100,14 @@ function testInit {
        _criticalFail=0
        _cases=0
        _filename=$(mktemp)
+       _group=`basename "$1"`
+       if [[ "${#_group}" -eq "0" ]]
+       then
+               _group="(Unspecified)"
+       fi
+
+       writef "${Green}==================================================${NC}"
+       writef "    Test Group ${Green}$_group${NC} Starts."
 }
 
 ##
diff --git a/ssat.sh b/ssat.sh
index 8885a0d..2fba709 100755 (executable)
--- a/ssat.sh
+++ b/ssat.sh
@@ -24,6 +24,34 @@ TESTCASE="runTest.sh"
 #
 SILENT=1
 
+function createTemplate {
+       if [[ -f "runTest.sh" ]]
+       then
+               printf "Cannot create runTest.sh here. The file already exists at $(pwd).\n\n"
+               exit 1
+       fi
+
+       echo -e "#!/usr/bin/env bash\n\
+if [[ \"\$SSATAPILOADED\" != \"1\" ]]\n\
+then\n\
+       SILENT=0\n\
+       INDEPENDENT=1\n\
+       search=\"ssat-api.sh\"\n\
+       source \$search\n\
+       printf \"\${Blue}Independent Mode\${NC}\\n\"\n\
+fi\n\
+testInit \$1 # You may replace this with Test Group Name\n\
+\n\
+#testResult 1 T1 \"Dummy Test1\"\n\
+#callTestSuccess gst-launch-1.0 \"-q videotestsrc ! videoconvert ! autovideosink\" T2 \"This may run indefinitely\"\n\
+#callCompareTest golden.log executeResult.log T3 \"The two files must be same\" 0\n\
+\n\
+report\n" > runTest.sh
+chmod a+x runTest.sh
+
+       exit 0
+}
+
 # Handle arguments
 POSITIONAL=()
 while [[ $# -gt 0 ]]
@@ -31,7 +59,7 @@ do
        key="$1"
        case $key in
        -h|--help)
-               printf "usage: ${BASENAME} [--help] [<path>] [--testcase <filename>] [--nocolor] [--showstdout]\n\n"
+               printf "usage: ${BASENAME} [--help] [<path>] [--testcase <filename>] [--nocolor] [--showstdout] [--createtemplate]\n\n"
                printf "These are common ${Red}ssat${NC} commands used:\n\n"
                printf "Test all test-groups in the current ($(pwd)) directory, recursively\n"
                printf "    (no options specified)\n"
@@ -53,6 +81,9 @@ do
                printf "Show stdout of test cases\n"
                printf "    --showstdout or -s\n"
                printf "\n"
+               printf "Create a template 'runTest.sh' test group at your current directory\n"
+               printf "    --createtemplate or -c\n"
+               printf "\n"
                printf "Shows this message\n"
                printf "    --help or -h\n"
                printf "    $ ${BASENAME} --help \n"
@@ -72,6 +103,10 @@ do
        SILENT=0
        shift
        ;;
+       -c|--createtemplate)
+       createTemplate
+       shift
+       ;;
        *) # Unknown, which is probably target (the path to root-dir of test groups).
        TARGET="$1"
        esac
@@ -103,18 +138,17 @@ do
        tmpfile=$(mktemp)
 
        pushd $CASEBASEPATH > /dev/null
-       output=$(. $file)
+       output=$(. $file $CASEBASEPATH)
        retcode=$?
        popd > /dev/null
 
        logfile="${output##*$'\n'}"
-
        resultlog=$(<$logfile)
        effectiveOutput=`printf "$resultlog" | sed '$d'`
        log="$log$effectiveOutput\n"
 
        lastline=`printf "${resultlog}" | sed '$!d'`
-       IFS=/
+       IFS=,
        set $lastline
        Ntc=$1
        Npass=$2