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'
51 # Platform dependent variables
52 KernelName=$(uname -s)
53 if [[ "${KernelName}" == "Darwin" ]]; then
54 StatCmd_GetSize="stat -f %z"
57 StatCmd_GetSize="stat --printf=%s"
63 ## @param $1 the string to be printed.
64 ## @brief Prepare report result
66 if [[ "${SILENT}" == "0" ]]
70 ResultLog="$ResultLog$1\n"
74 ## @brief Report results of a test group (a "runTest.sh" in a testee directory)
76 if (( ${_fail} == 0 && ${_criticalFail} == 0 ))
78 writef "${Green}==================================================${NC}"
79 writef "${LightGreen}[PASSED]${NC} Test Group $_group ${Green}Passed${NC}"
81 if (( ${_criticalFail} > 0 ))
83 writef "${Green}==================================================${NC}"
84 writef "${Red}[FAILED]${NC} Test Group $_group has ${Red}failed cases ($_fail)${NC}"
86 writef "${Green}==================================================${NC}"
87 writef "${LightGreen}[PASSED]${NC} Test Group $_group has ${Red}failed cases ($_fail), but they are ignorable cases and not critical.${NC}"
91 if [[ "$INDEPENDENT" -eq "1" ]]
96 _ignore=$((_fail-_criticalFail))
97 _fail=${_criticalFail}
98 if [[ "${COUNTNEGATIVE}" -eq "1" ]]
100 writef "${_cases},${_pass},${_fail},${_ignore},${_neg}"
102 writef "${_cases},${_pass},${_fail},${_ignore}"
104 echo "${ResultLog}" > ${_filename}
105 printf "\n${_filename}\n"
108 if (( ${_criticalFail} > 0 ))
117 ## @brief Initialize runTest.sh shell test case
118 function testInit() {
125 _group=`basename "$1"`
126 if [[ "${#_group}" -eq "0" ]]
128 _group="(Unspecified)"
131 writef "${Green}==================================================${NC}"
132 writef " Test Group ${Green}$_group${NC} Starts."
136 ## @brief Write Test Log
137 ## @param $1 1 = success / 0 = fail ($5 is not 1)
138 ## @param $2 test case ID (short string)
139 ## @param $3 test case description
140 ## @param $4 set 1 if this is not critical (don't care if it's pass or fail)_
141 ## @param $5 set 1 if $1==0 is success and $1!=0 is fail.
142 function testResult() {
143 if [[ ${PROGRESSLOGLEVEL} -gt 1 ]]
145 echo "Case ${2}(${3}) report ${1}" >&2
150 if [[ "${5}" -eq "1" ]]; then
151 if [[ "${1}" -eq "0" ]]; then
155 if [[ "${1}" -eq "1" ]]; then
160 if [[ "${COUNTNEGATIVE}" -eq "1" ]]
162 if [[ "${2}\n" =~ "${COUNTNEGATIVEPOSTFIX}\n" ]]
168 if [[ "${_good}" -eq "1" ]]
170 writef "${LightGreen}[PASSED]${NC} ${Green}$2${NC}:$3${NC}"
174 if [[ "${4}" == "1" ]]
176 writef "${Purple}[IGNORED] $2${NC}:${Purple}$3${NC}"
178 writef "${Red}[FAILED][Critical] $2${NC}:${Purple}$3${NC}"
179 _criticalFail=$((_criticalFail+1))
184 ## @fn callTestSuccess()
185 ## @brief Call Test Case (a shell script), expected exit = 0
186 ## @param $1 Full path to the executable (e.g., ~/script/a1.sh)
187 ## @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
188 ## @param $3 test case ID
189 ## @param $4 test case description
190 ## @param $5 set 1 if this is not critical (don't care if it's pass or fail)_
191 function callTestSuccess() {
194 if (( ${retcode} == 0 ))
196 testResult 1 "$3" "$4" $5
198 testResult 0 "$3" "$4 ret($retcode)" $5
202 ## @fn callTestFail()
203 ## @brief Call Test Case (a shell script), expected exit != 0
204 ## @param $1 Full path to the executable (e.g., ~/script/a1.sh)
205 ## @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
206 ## @param $3 test case ID
207 ## @param $4 test case description
208 ## @param $5 set 1 if this is not critical (don't care if it's pass or fail)_
209 function callTestFail() {
212 if (( ${retcode} != 0 ))
214 testResult 1 "$3" "$4 ret($retcode)" $5
216 testResult 0 "$3" "$4" $5
220 ## @fn callTestExitEq()
221 ## @brief Call Test Case (a shell script), expected exit == $5
222 ## @param $1 Full path to the executable (e.g., ~/script/a1.sh)
223 ## @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
224 ## @param $3 test case ID
225 ## @param $4 test case description
226 ## @param $5 Expected exit code.
227 ## @param $6 set 1 if this is not critical (don't care if it's pass or fail)_
228 function callTestExitEq() {
231 if (( ${retcode} == $5 ))
233 testResult 1 "$3" "$4" $6
235 testResult 0 "$3" "$4 ret($retcode)" $6
239 ## @fn callCompareTest()
240 ## @brief Compare two result files expected to be equal
241 ## @param $1 Path to result 1 (golden)
242 ## @param $2 Path to result 2 (test run)
243 ## @param $3 test case ID
244 ## @param $4 test case description
245 ## @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)
246 ## @param $6 set 1 if this is not critical (don't care if it's pass or fail)_
247 function callCompareTest() {
250 if [[ ! -f "$1" || ! -f "$2" ]]; then
251 testResult $output "$3" "$4" $6
255 # If cmp is symlink, then it could be from busybox and it does not support "-n" option
256 if [[ $? == 0 && ! -L $(which cmp) ]]
259 if (( $5 == 0 )); then
260 # Size should be same as well.
263 elif (( $5 == 1 )); then
264 # Compare up to the size of golden
265 cmp -n `${StatCmd_GetSize} $1` $1 $2
267 elif (( $5 == 2 )); then
268 # Compare up to the size of test-run
269 cmp -n `${StatCmd_GetSize} $2` $1 $2
272 # Compare up to $5 bytes.
273 cmp -n `${StatCmd_GetSize} $5` $1 $2
276 if (( ${output} == 0 )); then
281 testResult $output "$3" "$4" $6
283 # use internal logic (slower!)
284 bufsize=`${StatCmd_GetSize} $1`
285 if (( $5 == 2 )); then
286 bufsize=`${StatCmd_GetSize} $2`
290 diff <(dd bs=1 count=$bufsize if=$1 &>/dev/null) <(dd bs=1 count=$bufsize if=$2 &>/dev/null)
292 if (( ${output} == 0 )); then
297 testResult $output "$3" "$4" $6
302 ## @brief Execute gst-launch with given arguments
303 ## @todo Separate this function to "gstreamer extension plugin"
304 ## @param $1 gst-launch-1.0 Arguments
305 ## @param $2 test case ID
306 ## @param $3 set 1 if this is not critical (don't care if it's pass or fail)
307 ## @param $4 set 1 if this passes if gstLaunch fails.
308 ## @param $5 set 1 to enable PERFORMANCE test.
309 ## @param $6 set a positive value (seconds) to enable timeout mode.
311 if [[ "$VALGRIND" -eq "1" ]]; then
312 calloutputprefix="valgrind --track-origins=yes ${VALGRIND_SUPPRESSION}"
316 if [[ "${6}" -gt "0" ]]; then
317 if ! command -v timeout &> /dev/null
319 if command -v perl &> /dev/null
321 timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
328 if [[ "${6}" -gt "0" && $TIMEOUT_AVAIL -eq 1 ]]; then
329 if [[ "${SILENT}" -eq "1" ]]; then
330 calloutput=$(eval timeout ${6} $calloutputprefix gst-launch-1.0 -f -q $1 &> /dev/null)
332 calloutput=$(eval timeout ${6} $calloutputprefix gst-launch-1.0 -f -q $1)
335 if [[ "${SILENT}" -eq "1" ]]; then
336 calloutput=$(eval $calloutputprefix gst-launch-1.0 -f -q $1 &> /dev/null)
338 calloutput=$(eval $calloutputprefix gst-launch-1.0 -f -q $1)
344 if [[ "${4}" -eq "1" ]]; then
345 if [[ "${retcode}" -ne "0" ]]; then
349 if [[ "${retcode}" -eq "0" ]]; then
354 if [[ "$desired" -eq "1" ]]; then
355 testResult 1 "$2" "gst-launch of case $2" $3
357 testResult 0 "$2" "gst-launch of case $2" $3
360 if [[ "$5" -eq "1" ]]; then
361 if (( ${#GST_DEBUG_DUMP_DOT_DIR} -le 1 )); then
362 GST_DEBUG_DUMP_DOT_DIR="./performance"
364 dot -Tpng $GST_DEBUG_DUMP_DOT_DIR/*.PLAYING_PAUSED.dot > $GST_DEBUG_DUMP_DOT_DIR/debug/$base/$2.png
365 gst-report-1.0 --dot $GST_DEBUG_DUMP_DOT_DIR/*.gsttrace | dot -Tsvg > $GST_DEBUG_DUMP_DOT_DIR/profile/$base/$2.svg
366 rm -f $GST_DEBUG_DUMP_DOT_DIR/*.dot
367 rm -f $GST_DEBUG_DUMP_DOT_DIR/*.gsttrace
372 ## @fn gstTestBackground()
373 ## @brief Execute gst-launch in background with given arguments.
374 ## @param $1 gst-launch-1.0 Arguments, with pipeline description at the end. The pipeline should have async=false for sink elements (skip preroll!).
375 ## @param $2 test case ID
376 ## @param $3 set 1 if this is not critical (don't care if it's pass or fail)
377 ## @param $4 set 1 if this passes if launching the pipeline fails. (pass if timeout expires)
378 ## @param $5 set timeout for launching the pipeline in seconds (not the pipeline EOS). default = 10.
379 ## @return $pid The PID of the background gstreamer pipeline.
380 function gstTestBackground() {
381 local marker=$(mktemp)
387 if [ "$4" == "1" ]; then
394 if [ "$5" == "" ]; then
395 # no changes in timeout. do nothing
398 if [ $5 -gt 0 ]; then
401 # ignore if it's < 1. do nothing
406 pipeline="$1 videotestsrc num-buffers=1 ! video/x-raw,width=4,height=4,format=RGB ! filesink location=${marker}"
407 gst-launch-1.0 $pipeline &
410 for i in $(seq 1 ${timeout})
412 if [ -f "$marker" ]; then
413 markersize=$(stat -c%s ${marker})
414 if [ $markersize -ge 48 ]; then
415 testResult ${launchSuccess} $2 "gst-launch in background of case $2" $3
423 testResult ${launchFail} $2 "gst-launch in background of case $2" $3
427 ## @fn convertBMP2PNG()
428 ## @brief Convert all *.bmp to *.png in the current directory
429 ## @todo macronice "bmp2png" searching.
430 ## @todo Separate this function to "gstreamer extension plugin"
431 function convertBMP2PNG() {
433 if [ -x bmp2png ]; then
436 if [ -x ../bmp2png ]; then
439 if [ -x ../../bmp2png ]; then
442 tool="../../../bmp2png"
443 # Try this and die if fails
449 if [[ $X = *"GRAY8"* ]]; then