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() {
127 if [[ "${5}" -eq "1" ]]; then
128 if [[ "${1}" -eq "0" ]]; then
132 if [[ "${1}" -eq "1" ]]; then
137 if [[ "${_good}" -eq "1" ]]
139 writef "${LightGreen}[PASSED]${NC} ${Green}$2${NC}:$3${NC}"
143 if [[ "${4}" == "1" ]]
145 writef "${Purple}[FAILED][Ignorable] $2${NC}:${Purple}$3${NC}"
147 writef "${Red}[FAILED][Critical] $2${NC}:${Purple}$3${NC}"
148 _criticalFail=$((_criticalFail+1))
153 ## @fn callTestSuccess()
154 ## @brief Call Test Case (a shell script), expected exit = 0
155 ## @param $1 Full path to the executable (e.g., ~/script/a1.sh)
156 ## @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
157 ## @param $3 test case ID
158 ## @param $4 test case description
159 ## @param $5 set 1 if this is not critical (don't care if it's pass or fail)_
160 function callTestSuccess() {
163 if (( ${retcode} == 0 ))
165 testResult 1 "$3" "$4" $5
167 testResult 0 "$3" "$4 ret($retcode)" $5
171 ## @fn callTestFail()
172 ## @brief Call Test Case (a shell script), expected exit != 0
173 ## @param $1 Full path to the executable (e.g., ~/script/a1.sh)
174 ## @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
175 ## @param $3 test case ID
176 ## @param $4 test case description
177 ## @param $5 set 1 if this is not critical (don't care if it's pass or fail)_
178 function callTestFail() {
181 if (( ${retcode} != 0 ))
183 testResult 1 "$3" "$4 ret($retcode)" $5
185 testResult 0 "$3" "$4" $5
189 ## @fn callTestExitEq()
190 ## @brief Call Test Case (a shell script), expected exit == $5
191 ## @param $1 Full path to the executable (e.g., ~/script/a1.sh)
192 ## @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
193 ## @param $3 test case ID
194 ## @param $4 test case description
195 ## @param $5 Expected exit code.
196 ## @param $6 set 1 if this is not critical (don't care if it's pass or fail)_
197 function callTestExitEq() {
200 if (( ${retcode} == $5 ))
202 testResult 1 "$3" "$4" $6
204 testResult 0 "$3" "$4 ret($retcode)" $6
208 ## @fn callCompareTest()
209 ## @brief Compare two result files expected to be equal
210 ## @param $1 Path to result 1 (golden)
211 ## @param $2 Path to result 2 (test run)
212 ## @param $3 test case ID
213 ## @param $4 test case description
214 ## @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)
215 ## @param $6 set 1 if this is not critical (don't care if it's pass or fail)_
216 function callCompareTest() {
223 if (( $5 == 0 )); then
224 # Size should be same as well.
227 elif (( $5 == 1 )); then
228 # Compare up to the size of golden
229 cmp -n `stat --printf="%s" $1` $1 $2
231 elif (( $5 == 2 )); then
232 # Compare up to the size of test-run
233 cmp -n `stat --printf="%s" $2` $1 $2
236 # Compare up to $5 bytes.
237 cmp -n `stat --printf="%s" $5` $1 $2
240 if (( ${output} == 0 )); then
245 testResult $output "$3" "$4" $6
247 # use internal logic (slower!)
249 testResult 0 "$3" "Cannot test. cmp not found." $6
254 ## @brief Execute gst-launch with given arguments
255 ## @todo Separate this function to "gstreamer extension plugin"
256 ## @param $1 gst-launch-1.0 Arguments
257 ## @param $2 test case ID
258 ## @param $3 set 1 if this is not critical (don't care if it's pass or fail)
259 ## @param $4 set 1 if this passes if gstLaunch fails.
260 ## @param $5 set 1 to enable PERFORMANCE test.
262 calloutput=$(gst-launch-1.0 -q $1)
265 if [[ "${4}" -eq "1" ]]; then
266 if [[ "${retcode}" -ne "0" ]]; then
270 if [[ "${retcode}" -eq "0" ]]; then
275 if [[ "$desired" -eq "1" ]]; then
276 testResult 1 "$2" "gst-launch of case $2" $3
278 testResult 0 "$2" "gst-launch of case $2" $3
281 if [[ "$5" -eq "1" ]]; then
282 if (( ${#GST_DEBUG_DUMP_DOT_DIR} -le 1 )); then
283 GST_DEBUG_DUMP_DOT_DIR="./performance"
285 dot -Tpng $GST_DEBUG_DUMP_DOT_DIR/*.PLAYING_PAUSED.dot > $GST_DEBUG_DUMP_DOT_DIR/debug/$base/$2.png
286 gst-report-1.0 --dot $GST_DEBUG_DUMP_DOT_DIR/*.gsttrace | dot -Tsvg > $GST_DEBUG_DUMP_DOT_DIR/profile/$base/$2.svg
287 rm -f $GST_DEBUG_DUMP_DOT_DIR/*.dot
288 rm -f $GST_DEBUG_DUMP_DOT_DIR/*.gsttrace
292 ## @fn convertBMP2PNG()
293 ## @brief Convert all *.bmp to *.png in the current directory
294 ## @todo macronice "bmp2png" searching.
295 ## @todo Separate this function to "gstreamer extension plugin"
296 function convertBMP2PNG() {
298 if [ -x bmp2png ]; then
301 if [ -x ../bmp2png ]; then
304 if [ -x ../../bmp2png ]; then
307 tool="../../../bmp2png"
308 # Try this and die if fails
314 if [[ $X = *"GRAY8"* ]]; then