4 ## @author MyungJoo Ham <myungjoo.ham@gmail.com>
6 ## @brief This is API set for SSAT (Shell Script Automated Tester)
9 if [[ "$nocolor" != "1" ]]
16 LightGreen='\033[1;32m'
20 LightBlue='\033[1;34m'
22 LightPurple='\033[1;35m'
24 LightCyan='\033[1;36m'
25 LightGray='\033[0;37m'
53 ## @param $1 the string to be printed.
54 ## @brief Prepare report result
56 if [[ "${SILENT}" == "0" ]]
60 ResultLog="$ResultLog$1\n"
64 ## @brief Report results of a test group (a "runTest.sh" in a testee directory)
66 if (( ${_fail} == 0 ))
68 writef "${Green}==================================================${NC}"
69 writef "${LightGreen}[PASSED]${NC} Test Group $_group ${Green}Passed${NC}"
71 if (( ${_criticalFail} > 0 ))
73 writef "${Green}==================================================${NC}"
74 writef "${Red}[FAILED]${NC} Test Group $_group has ${Red}failed cases ($_fail)${NC}"
76 writef "${Green}==================================================${NC}"
77 writef "${LightGreen}[PASSED]${NC} Test Group $_group has ${Red}failed cases ($_fail), but they are not critical.${NC}"
81 if [[ "$INDEPENDENT" -eq "1" ]]
86 writef "${_cases},${_pass},${_fail}"
87 echo "${ResultLog}" > ${_filename}
88 printf "${_filename}\n"
91 if (( ${_criticalFail} > 0 ))
100 ## @brief Initialize runTest.sh shell test case
101 function testInit() {
107 _group=`basename "$1"`
108 if [[ "${#_group}" -eq "0" ]]
110 _group="(Unspecified)"
113 writef "${Green}==================================================${NC}"
114 writef " Test Group ${Green}$_group${NC} Starts."
118 ## @brief Write Test Log
119 ## @param $1 1 = success / 0 = fail ($5 is not 1)
120 ## @param $2 test case ID (short string)
121 ## @param $3 test case description
122 ## @param $4 set 1 if this is not critical (don't care if it's pass or fail)_
123 ## @param $5 set 1 if $1==0 is success and $1!=0 is fail.
124 function testResult() {
125 if [[ "${PROGRESS}" -eq "1" ]]
127 echo "Case ${2}(${3}) report ${1}" > /dev/stderr
132 if [[ "${5}" -eq "1" ]]; then
133 if [[ "${1}" -eq "0" ]]; then
137 if [[ "${1}" -eq "1" ]]; then
142 if [[ "${_good}" -eq "1" ]]
144 writef "${LightGreen}[PASSED]${NC} ${Green}$2${NC}:$3${NC}"
148 if [[ "${4}" == "1" ]]
150 writef "${Purple}[FAILED][Ignorable] $2${NC}:${Purple}$3${NC}"
152 writef "${Red}[FAILED][Critical] $2${NC}:${Purple}$3${NC}"
153 _criticalFail=$((_criticalFail+1))
158 ## @fn callTestSuccess()
159 ## @brief Call Test Case (a shell script), expected exit = 0
160 ## @param $1 Full path to the executable (e.g., ~/script/a1.sh)
161 ## @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
162 ## @param $3 test case ID
163 ## @param $4 test case description
164 ## @param $5 set 1 if this is not critical (don't care if it's pass or fail)_
165 function callTestSuccess() {
168 if (( ${retcode} == 0 ))
170 testResult 1 "$3" "$4" $5
172 testResult 0 "$3" "$4 ret($retcode)" $5
176 ## @fn callTestFail()
177 ## @brief Call Test Case (a shell script), expected exit != 0
178 ## @param $1 Full path to the executable (e.g., ~/script/a1.sh)
179 ## @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
180 ## @param $3 test case ID
181 ## @param $4 test case description
182 ## @param $5 set 1 if this is not critical (don't care if it's pass or fail)_
183 function callTestFail() {
186 if (( ${retcode} != 0 ))
188 testResult 1 "$3" "$4 ret($retcode)" $5
190 testResult 0 "$3" "$4" $5
194 ## @fn callTestExitEq()
195 ## @brief Call Test Case (a shell script), expected exit == $5
196 ## @param $1 Full path to the executable (e.g., ~/script/a1.sh)
197 ## @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
198 ## @param $3 test case ID
199 ## @param $4 test case description
200 ## @param $5 Expected exit code.
201 ## @param $6 set 1 if this is not critical (don't care if it's pass or fail)_
202 function callTestExitEq() {
205 if (( ${retcode} == $5 ))
207 testResult 1 "$3" "$4" $6
209 testResult 0 "$3" "$4 ret($retcode)" $6
213 ## @fn callCompareTest()
214 ## @brief Compare two result files expected to be equal
215 ## @param $1 Path to result 1 (golden)
216 ## @param $2 Path to result 2 (test run)
217 ## @param $3 test case ID
218 ## @param $4 test case description
219 ## @param $5 0 if the size is expected to be equal as well. 1 if golden (result 1) might be smaller (will ignore rest of result 2). 2 if the opposite of 1. If $5 > 2, it denotes the max size of compared bytes. (compare the first $5 bytes only)
220 ## @param $6 set 1 if this is not critical (don't care if it's pass or fail)_
221 function callCompareTest() {
228 if (( $5 == 0 )); then
229 # Size should be same as well.
232 elif (( $5 == 1 )); then
233 # Compare up to the size of golden
234 cmp -n `stat --printf="%s" $1` $1 $2
236 elif (( $5 == 2 )); then
237 # Compare up to the size of test-run
238 cmp -n `stat --printf="%s" $2` $1 $2
241 # Compare up to $5 bytes.
242 cmp -n `stat --printf="%s" $5` $1 $2
245 if (( ${output} == 0 )); then
250 testResult $output "$3" "$4" $6
252 # use internal logic (slower!)
254 testResult 0 "$3" "Cannot test. cmp not found." $6
259 ## @brief Execute gst-launch with given arguments
260 ## @todo Separate this function to "gstreamer extension plugin"
261 ## @param $1 gst-launch-1.0 Arguments
262 ## @param $2 test case ID
263 ## @param $3 set 1 if this is not critical (don't care if it's pass or fail)
264 ## @param $4 set 1 if this passes if gstLaunch fails.
265 ## @param $5 set 1 to enable PERFORMANCE test.
267 calloutput=$(gst-launch-1.0 -q $1)
270 if [[ "${4}" -eq "1" ]]; then
271 if [[ "${retcode}" -ne "0" ]]; then
275 if [[ "${retcode}" -eq "0" ]]; then
280 if [[ "$desired" -eq "1" ]]; then
281 testResult 1 "$2" "gst-launch of case $2" $3
283 testResult 0 "$2" "gst-launch of case $2" $3
286 if [[ "$5" -eq "1" ]]; then
287 if (( ${#GST_DEBUG_DUMP_DOT_DIR} -le 1 )); then
288 GST_DEBUG_DUMP_DOT_DIR="./performance"
290 dot -Tpng $GST_DEBUG_DUMP_DOT_DIR/*.PLAYING_PAUSED.dot > $GST_DEBUG_DUMP_DOT_DIR/debug/$base/$2.png
291 gst-report-1.0 --dot $GST_DEBUG_DUMP_DOT_DIR/*.gsttrace | dot -Tsvg > $GST_DEBUG_DUMP_DOT_DIR/profile/$base/$2.svg
292 rm -f $GST_DEBUG_DUMP_DOT_DIR/*.dot
293 rm -f $GST_DEBUG_DUMP_DOT_DIR/*.gsttrace
297 ## @fn convertBMP2PNG()
298 ## @brief Convert all *.bmp to *.png in the current directory
299 ## @todo macronice "bmp2png" searching.
300 ## @todo Separate this function to "gstreamer extension plugin"
301 function convertBMP2PNG() {
303 if [ -x bmp2png ]; then
306 if [ -x ../bmp2png ]; then
309 if [ -x ../../bmp2png ]; then
312 tool="../../../bmp2png"
313 # Try this and die if fails
319 if [[ $X = *"GRAY8"* ]]; then