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 not critical.${NC}"
91 if [[ "$INDEPENDENT" -eq "1" ]]
96 writef "${_cases},${_pass},${_fail}"
97 echo "${ResultLog}" > ${_filename}
98 printf "\n${_filename}\n"
101 if (( ${_criticalFail} > 0 ))
110 ## @brief Initialize runTest.sh shell test case
111 function testInit() {
117 _group=`basename "$1"`
118 if [[ "${#_group}" -eq "0" ]]
120 _group="(Unspecified)"
123 writef "${Green}==================================================${NC}"
124 writef " Test Group ${Green}$_group${NC} Starts."
128 ## @brief Write Test Log
129 ## @param $1 1 = success / 0 = fail ($5 is not 1)
130 ## @param $2 test case ID (short string)
131 ## @param $3 test case description
132 ## @param $4 set 1 if this is not critical (don't care if it's pass or fail)_
133 ## @param $5 set 1 if $1==0 is success and $1!=0 is fail.
134 function testResult() {
135 if [[ "${PROGRESS}" -eq "1" ]]
137 echo "Case ${2}(${3}) report ${1}" > /dev/stderr
142 if [[ "${5}" -eq "1" ]]; then
143 if [[ "${1}" -eq "0" ]]; then
147 if [[ "${1}" -eq "1" ]]; then
152 if [[ "${_good}" -eq "1" ]]
154 writef "${LightGreen}[PASSED]${NC} ${Green}$2${NC}:$3${NC}"
158 if [[ "${4}" == "1" ]]
160 writef "${Purple}[FAILED][Ignorable] $2${NC}:${Purple}$3${NC}"
162 writef "${Red}[FAILED][Critical] $2${NC}:${Purple}$3${NC}"
163 _criticalFail=$((_criticalFail+1))
168 ## @fn callTestSuccess()
169 ## @brief Call Test Case (a shell script), expected exit = 0
170 ## @param $1 Full path to the executable (e.g., ~/script/a1.sh)
171 ## @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
172 ## @param $3 test case ID
173 ## @param $4 test case description
174 ## @param $5 set 1 if this is not critical (don't care if it's pass or fail)_
175 function callTestSuccess() {
178 if (( ${retcode} == 0 ))
180 testResult 1 "$3" "$4" $5
182 testResult 0 "$3" "$4 ret($retcode)" $5
186 ## @fn callTestFail()
187 ## @brief Call Test Case (a shell script), expected exit != 0
188 ## @param $1 Full path to the executable (e.g., ~/script/a1.sh)
189 ## @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
190 ## @param $3 test case ID
191 ## @param $4 test case description
192 ## @param $5 set 1 if this is not critical (don't care if it's pass or fail)_
193 function callTestFail() {
196 if (( ${retcode} != 0 ))
198 testResult 1 "$3" "$4 ret($retcode)" $5
200 testResult 0 "$3" "$4" $5
204 ## @fn callTestExitEq()
205 ## @brief Call Test Case (a shell script), expected exit == $5
206 ## @param $1 Full path to the executable (e.g., ~/script/a1.sh)
207 ## @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
208 ## @param $3 test case ID
209 ## @param $4 test case description
210 ## @param $5 Expected exit code.
211 ## @param $6 set 1 if this is not critical (don't care if it's pass or fail)_
212 function callTestExitEq() {
215 if (( ${retcode} == $5 ))
217 testResult 1 "$3" "$4" $6
219 testResult 0 "$3" "$4 ret($retcode)" $6
223 ## @fn callCompareTest()
224 ## @brief Compare two result files expected to be equal
225 ## @param $1 Path to result 1 (golden)
226 ## @param $2 Path to result 2 (test run)
227 ## @param $3 test case ID
228 ## @param $4 test case description
229 ## @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)
230 ## @param $6 set 1 if this is not critical (don't care if it's pass or fail)_
231 function callCompareTest() {
235 # If cmp is symlink, then it could be from busybox and it does not support "-n" option
236 if [[ $? == 0 && ! -L $(which cmp) ]]
239 if (( $5 == 0 )); then
240 # Size should be same as well.
243 elif (( $5 == 1 )); then
244 # Compare up to the size of golden
245 cmp -n `${StatCmd_GetSize} $1` $1 $2
247 elif (( $5 == 2 )); then
248 # Compare up to the size of test-run
249 cmp -n `${StatCmd_GetSize} $2` $1 $2
252 # Compare up to $5 bytes.
253 cmp -n `${StatCmd_GetSize} $5` $1 $2
256 if (( ${output} == 0 )); then
261 testResult $output "$3" "$4" $6
263 # use internal logic (slower!)
264 bufsize=`${StatCmd_GetSize} $1`
265 if (( $5 == 2 )); then
266 bufsize=`${StatCmd_GetSize} $2`
270 diff <(dd bs=1 count=$bufsize if=$1 &>/dev/null) <(dd bs=1 count=$bufsize if=$2 &>/dev/null)
272 if (( ${output} == 0 )); then
277 testResult $output "$3" "$4" $6
282 ## @brief Execute gst-launch with given arguments
283 ## @todo Separate this function to "gstreamer extension plugin"
284 ## @param $1 gst-launch-1.0 Arguments
285 ## @param $2 test case ID
286 ## @param $3 set 1 if this is not critical (don't care if it's pass or fail)
287 ## @param $4 set 1 if this passes if gstLaunch fails.
288 ## @param $5 set 1 to enable PERFORMANCE test.
290 if [[ "$VALGRIND" -eq "1" ]]; then
291 calloutputprefix='valgrind --track-origins=yes'
293 if [[ "${SILENT}" -eq "1" ]]; then
294 calloutput=$(eval $calloutputprefix gst-launch-1.0 -f -q $1 &> /dev/null)
296 calloutput=$(eval $calloutputprefix gst-launch-1.0 -f -q $1)
301 if [[ "${4}" -eq "1" ]]; then
302 if [[ "${retcode}" -ne "0" ]]; then
306 if [[ "${retcode}" -eq "0" ]]; then
311 if [[ "$desired" -eq "1" ]]; then
312 testResult 1 "$2" "gst-launch of case $2" $3
314 testResult 0 "$2" "gst-launch of case $2" $3
317 if [[ "$5" -eq "1" ]]; then
318 if (( ${#GST_DEBUG_DUMP_DOT_DIR} -le 1 )); then
319 GST_DEBUG_DUMP_DOT_DIR="./performance"
321 dot -Tpng $GST_DEBUG_DUMP_DOT_DIR/*.PLAYING_PAUSED.dot > $GST_DEBUG_DUMP_DOT_DIR/debug/$base/$2.png
322 gst-report-1.0 --dot $GST_DEBUG_DUMP_DOT_DIR/*.gsttrace | dot -Tsvg > $GST_DEBUG_DUMP_DOT_DIR/profile/$base/$2.svg
323 rm -f $GST_DEBUG_DUMP_DOT_DIR/*.dot
324 rm -f $GST_DEBUG_DUMP_DOT_DIR/*.gsttrace
328 ## @fn convertBMP2PNG()
329 ## @brief Convert all *.bmp to *.png in the current directory
330 ## @todo macronice "bmp2png" searching.
331 ## @todo Separate this function to "gstreamer extension plugin"
332 function convertBMP2PNG() {
334 if [ -x bmp2png ]; then
337 if [ -x ../bmp2png ]; then
340 if [ -x ../../bmp2png ]; then
343 tool="../../../bmp2png"
344 # Try this and die if fails
350 if [[ $X = *"GRAY8"* ]]; then