Feature: write summary with negative cases
[platform/upstream/SSAT.git] / ssat-api.sh
index de38937..2b11b08 100644 (file)
@@ -48,6 +48,16 @@ fi
 
 ResultLog=""
 
+# Platform dependent variables
+KernelName=$(uname -s)
+if [[ "${KernelName}" == "Darwin" ]]; then
+       StatCmd_GetSize="stat -f %z"
+       SO_EXT="dylib"
+else
+       StatCmd_GetSize="stat --printf=%s"
+       SO_EXT="so"
+fi
+
 ## @fn writef()
 ## @private
 ## @param $1 the string to be printed.
@@ -63,7 +73,7 @@ function writef() {
 ## @fn report()
 ## @brief Report results of a test group (a "runTest.sh" in a testee directory)
 function report() {
-       if (( ${_fail} == 0 ))
+       if (( ${_fail} == 0 && ${_criticalFail} == 0 ))
        then
                writef "${Green}==================================================${NC}"
                writef "${LightGreen}[PASSED]${NC} Test Group $_group ${Green}Passed${NC}"
@@ -74,7 +84,7 @@ function report() {
                        writef "${Red}[FAILED]${NC} Test Group $_group has ${Red}failed cases ($_fail)${NC}"
                else
                        writef "${Green}==================================================${NC}"
-                       writef "${LightGreen}[PASSED]${NC} Test Group $_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 ignorable cases and not critical.${NC}"
                fi
        fi
 
@@ -83,7 +93,14 @@ function report() {
        # do nothing
                echo ""
        else
-               writef "${_cases},${_pass},${_fail}"
+               _ignore=$((_fail-_criticalFail))
+               _fail=${_criticalFail}
+               if [[ "${COUNTNEGATIVE}" -eq "1" ]]
+               then
+                       writef "${_cases},${_pass},${_fail},${_ignore},${_neg}"
+               else
+                       writef "${_cases},${_pass},${_fail},${_ignore}"
+               fi
                echo "${ResultLog}" > ${_filename}
                printf "\n${_filename}\n"
        fi
@@ -103,6 +120,7 @@ function testInit() {
        _fail=0
        _criticalFail=0
        _cases=0
+       _neg=0
        _filename=$(mktemp)
        _group=`basename "$1"`
        if [[ "${#_group}" -eq "0" ]]
@@ -139,6 +157,14 @@ function testResult() {
                fi
        fi
 
+       if [[ "${COUNTNEGATIVE}" -eq "1" ]]
+       then
+               if [[ "${2}\n" =~ "${COUNTNEGATIVEPOSTFIX}\n" ]]
+               then
+                       _neg=$((_neg+1))
+               fi
+       fi
+
        if [[ "${_good}" -eq "1" ]]
        then
                writef "${LightGreen}[PASSED]${NC} ${Green}$2${NC}:$3${NC}"
@@ -147,7 +173,7 @@ function testResult() {
                _fail=$((_fail+1))
                if [[ "${4}" == "1" ]]
                then
-                       writef "${Purple}[FAILED][Ignorable] $2${NC}:${Purple}$3${NC}"
+                       writef "${Purple}[IGNORED] $2${NC}:${Purple}$3${NC}"
                else
                        writef "${Red}[FAILED][Critical] $2${NC}:${Purple}$3${NC}"
                        _criticalFail=$((_criticalFail+1))
@@ -222,7 +248,8 @@ function callCompareTest() {
        # Try cmp.
        output=0
        command -v cmp
-       if (( $? == 0 ))
+       # If cmp is symlink, then it could be from busybox and it does not support "-n" option
+       if [[ $? == 0 && ! -L $(which cmp) ]]
        then
                # use cmp
                if (( $5 == 0 )); then
@@ -231,15 +258,15 @@ function callCompareTest() {
                        output=$?
                elif (( $5 == 1 )); then
                        # Compare up to the size of golden
-                       cmp -n `stat --printf="%s" $1` $1 $2
+                       cmp -n `${StatCmd_GetSize} $1` $1 $2
                        output=$?
                elif (( $5 == 2 )); then
                        # Compare up to the size of test-run
-                       cmp -n `stat --printf="%s" $2` $1 $2
+                       cmp -n `${StatCmd_GetSize} $2` $1 $2
                        output=$?
                else
                        # Compare up to $5 bytes.
-                       cmp -n `stat --printf="%s" $5` $1 $2
+                       cmp -n `${StatCmd_GetSize} $5` $1 $2
                        output=$?
                fi
                if (( ${output} == 0 )); then
@@ -249,9 +276,21 @@ function callCompareTest() {
                fi
                testResult $output "$3" "$4" $6
        else
-               # use internal logic (slower!)
-               echo NYI
-               testResult 0 "$3" "Cannot test. cmp not found." $6
+           # use internal logic (slower!)
+           bufsize=`${StatCmd_GetSize} $1`
+           if (( $5 == 2 )); then
+               bufsize=`${StatCmd_GetSize} $2`
+           else
+               bufsize=$5
+           fi
+           diff <(dd bs=1 count=$bufsize if=$1 &>/dev/null) <(dd bs=1 count=$bufsize if=$2 &>/dev/null)
+           output=$?
+           if (( ${output} == 0 )); then
+               output=1
+           else
+               output=0
+           fi
+           testResult $output "$3" "$4" $6
        fi
 }
 
@@ -267,7 +306,11 @@ function gstTest() {
        if [[ "$VALGRIND" -eq "1" ]]; then
                calloutputprefix='valgrind --track-origins=yes'
        fi
-       calloutput=$(eval $calloutputprefix gst-launch-1.0 -f -q $1)
+       if [[ "${SILENT}" -eq "1" ]]; then
+               calloutput=$(eval $calloutputprefix gst-launch-1.0 -f -q $1 &> /dev/null)
+       else
+               calloutput=$(eval $calloutputprefix gst-launch-1.0 -f -q $1)
+       fi
 
        retcode=$?
        desired=0