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"
56 StatCmd_GetSize="stat --printf=%s"
61 ## @param $1 the string to be printed.
62 ## @brief Prepare report result
64 if [[ "${SILENT}" == "0" ]]
68 ResultLog="$ResultLog$1\n"
72 ## @brief Report results of a test group (a "runTest.sh" in a testee directory)
74 if (( ${_fail} == 0 && ${_criticalFail} == 0 ))
76 writef "${Green}==================================================${NC}"
77 writef "${LightGreen}[PASSED]${NC} Test Group $_group ${Green}Passed${NC}"
79 if (( ${_criticalFail} > 0 ))
81 writef "${Green}==================================================${NC}"
82 writef "${Red}[FAILED]${NC} Test Group $_group has ${Red}failed cases ($_fail)${NC}"
84 writef "${Green}==================================================${NC}"
85 writef "${LightGreen}[PASSED]${NC} Test Group $_group has ${Red}failed cases ($_fail), but they are not critical.${NC}"
89 if [[ "$INDEPENDENT" -eq "1" ]]
94 writef "${_cases},${_pass},${_fail}"
95 echo "${ResultLog}" > ${_filename}
96 printf "\n${_filename}\n"
99 if (( ${_criticalFail} > 0 ))
108 ## @brief Initialize runTest.sh shell test case
109 function testInit() {
115 _group=`basename "$1"`
116 if [[ "${#_group}" -eq "0" ]]
118 _group="(Unspecified)"
121 writef "${Green}==================================================${NC}"
122 writef " Test Group ${Green}$_group${NC} Starts."
126 ## @brief Write Test Log
127 ## @param $1 1 = success / 0 = fail ($5 is not 1)
128 ## @param $2 test case ID (short string)
129 ## @param $3 test case description
130 ## @param $4 set 1 if this is not critical (don't care if it's pass or fail)_
131 ## @param $5 set 1 if $1==0 is success and $1!=0 is fail.
132 function testResult() {
133 if [[ "${PROGRESS}" -eq "1" ]]
135 echo "Case ${2}(${3}) report ${1}" > /dev/stderr
140 if [[ "${5}" -eq "1" ]]; then
141 if [[ "${1}" -eq "0" ]]; then
145 if [[ "${1}" -eq "1" ]]; then
150 if [[ "${_good}" -eq "1" ]]
152 writef "${LightGreen}[PASSED]${NC} ${Green}$2${NC}:$3${NC}"
156 if [[ "${4}" == "1" ]]
158 writef "${Purple}[FAILED][Ignorable] $2${NC}:${Purple}$3${NC}"
160 writef "${Red}[FAILED][Critical] $2${NC}:${Purple}$3${NC}"
161 _criticalFail=$((_criticalFail+1))
166 ## @fn callTestSuccess()
167 ## @brief Call Test Case (a shell script), expected exit = 0
168 ## @param $1 Full path to the executable (e.g., ~/script/a1.sh)
169 ## @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
170 ## @param $3 test case ID
171 ## @param $4 test case description
172 ## @param $5 set 1 if this is not critical (don't care if it's pass or fail)_
173 function callTestSuccess() {
176 if (( ${retcode} == 0 ))
178 testResult 1 "$3" "$4" $5
180 testResult 0 "$3" "$4 ret($retcode)" $5
184 ## @fn callTestFail()
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 callTestFail() {
194 if (( ${retcode} != 0 ))
196 testResult 1 "$3" "$4 ret($retcode)" $5
198 testResult 0 "$3" "$4" $5
202 ## @fn callTestExitEq()
203 ## @brief Call Test Case (a shell script), expected exit == $5
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 Expected exit code.
209 ## @param $6 set 1 if this is not critical (don't care if it's pass or fail)_
210 function callTestExitEq() {
213 if (( ${retcode} == $5 ))
215 testResult 1 "$3" "$4" $6
217 testResult 0 "$3" "$4 ret($retcode)" $6
221 ## @fn callCompareTest()
222 ## @brief Compare two result files expected to be equal
223 ## @param $1 Path to result 1 (golden)
224 ## @param $2 Path to result 2 (test run)
225 ## @param $3 test case ID
226 ## @param $4 test case description
227 ## @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)
228 ## @param $6 set 1 if this is not critical (don't care if it's pass or fail)_
229 function callCompareTest() {
233 # If cmp is symlink, then it could be from busybox and it does not support "-n" option
234 if [[ $? == 0 && ! -L $(which cmp) ]]
237 if (( $5 == 0 )); then
238 # Size should be same as well.
241 elif (( $5 == 1 )); then
242 # Compare up to the size of golden
243 cmp -n `${StatCmd_GetSize} $1` $1 $2
245 elif (( $5 == 2 )); then
246 # Compare up to the size of test-run
247 cmp -n `${StatCmd_GetSize} $2` $1 $2
250 # Compare up to $5 bytes.
251 cmp -n `${StatCmd_GetSize} $5` $1 $2
254 if (( ${output} == 0 )); then
259 testResult $output "$3" "$4" $6
261 # use internal logic (slower!)
262 bufsize=`${StatCmd_GetSize} $1`
263 if (( $5 == 2 )); then
264 bufsize=`${StatCmd_GetSize} $2`
268 diff <(dd bs=1 count=$bufsize if=$1 &>/dev/null) <(dd bs=1 count=$bufsize if=$2 &>/dev/null)
270 if (( ${output} == 0 )); then
275 testResult $output "$3" "$4" $6
280 ## @brief Execute gst-launch with given arguments
281 ## @todo Separate this function to "gstreamer extension plugin"
282 ## @param $1 gst-launch-1.0 Arguments
283 ## @param $2 test case ID
284 ## @param $3 set 1 if this is not critical (don't care if it's pass or fail)
285 ## @param $4 set 1 if this passes if gstLaunch fails.
286 ## @param $5 set 1 to enable PERFORMANCE test.
288 if [[ "$VALGRIND" -eq "1" ]]; then
289 calloutputprefix='valgrind --track-origins=yes'
291 calloutput=$(eval $calloutputprefix gst-launch-1.0 -f -q $1)
295 if [[ "${4}" -eq "1" ]]; then
296 if [[ "${retcode}" -ne "0" ]]; then
300 if [[ "${retcode}" -eq "0" ]]; then
305 if [[ "$desired" -eq "1" ]]; then
306 testResult 1 "$2" "gst-launch of case $2" $3
308 testResult 0 "$2" "gst-launch of case $2" $3
311 if [[ "$5" -eq "1" ]]; then
312 if (( ${#GST_DEBUG_DUMP_DOT_DIR} -le 1 )); then
313 GST_DEBUG_DUMP_DOT_DIR="./performance"
315 dot -Tpng $GST_DEBUG_DUMP_DOT_DIR/*.PLAYING_PAUSED.dot > $GST_DEBUG_DUMP_DOT_DIR/debug/$base/$2.png
316 gst-report-1.0 --dot $GST_DEBUG_DUMP_DOT_DIR/*.gsttrace | dot -Tsvg > $GST_DEBUG_DUMP_DOT_DIR/profile/$base/$2.svg
317 rm -f $GST_DEBUG_DUMP_DOT_DIR/*.dot
318 rm -f $GST_DEBUG_DUMP_DOT_DIR/*.gsttrace
322 ## @fn convertBMP2PNG()
323 ## @brief Convert all *.bmp to *.png in the current directory
324 ## @todo macronice "bmp2png" searching.
325 ## @todo Separate this function to "gstreamer extension plugin"
326 function convertBMP2PNG() {
328 if [ -x bmp2png ]; then
331 if [ -x ../bmp2png ]; then
334 if [ -x ../../bmp2png ]; then
337 tool="../../../bmp2png"
338 # Try this and die if fails
344 if [[ $X = *"GRAY8"* ]]; then