Merge "Refactoring Animated image visual" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / execute.sh
1 #!/bin/bash
2
3 TEMP=`getopt -o dhsSmfqp: --long debug,help,failnorerun,quiet,serial,tct,modules,prefix: -n 'execute.sh' -- "$@"`
4
5 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
6
7 # Note the quotes around `$TEMP': they are essential!
8 eval set -- "$TEMP"
9
10 function usage
11 {
12     echo -e "Usage: execute.sh [-d][-s|-S|-r][-q] [module|testcase]"
13     echo -e "       execute.sh\t\tExecute test cases from all modules in parallel"
14     echo -e "       execute.sh -f \tExecute test cases from all modules in parallel without rerunning failed test cases"
15     echo -e "       execute.sh -d <testcase>\tDebug testcase"
16     echo -e "       execute.sh -p <prefix>\tExecute all testcases named with <prefix>"
17     echo -e "       execute.sh [module]\tExecute test cases from the given module in parallel"
18     echo -e "       execute.sh -s [module]\t\tExecute test cases in serial using Testkit-Lite"
19     echo -e "       execute.sh -S [module]\t\tExecute test cases in serial"
20     echo -e "       execute.sh -q|--quiet ...\tExecute test cases, but don't write output"
21     echo -e "       execute.sh <testcase>\tFind and execute the given test case"
22     exit 2
23 }
24
25 opt_tct=0
26 opt_serial=""
27 opt_modules=0
28 opt_debug=0
29 opt_noFailedRerun="";
30 opt_quiet="";
31 opt_match="";
32 while true ; do
33     case "$1" in
34         -h|--help)     usage ;;
35         -d|--debug)    opt_debug=1 ; shift ;;
36         -s|--tct)      opt_tct=1 ; shift ;;
37         -f|--nofailedrerun) opt_noFailedRerun="-f" ; shift ;;
38         -S|--serial)   opt_serial="-s" ; shift ;;
39         -q|--quiet)    opt_quiet="-q" ; shift ;;
40         -p|--prefix)   opt_match="-m $2" ; shift 2;;
41         -m|--modules)  opt_modules=1 ; shift ;;
42         --) shift; break;;
43         *) echo "Internal error $1!" ; exit 1 ;;
44     esac
45 done
46
47 function execute_tct
48 {
49     scripts/tctestsgen.sh $1 `pwd` desktop $2
50     testkit-lite -f `pwd`/tests.xml -o tct-${1}-core-tests.xml  -A --comm localhost
51     scripts/add_style.pl $1
52 }
53
54 function summary_start
55 {
56     start=`date +"%Y-%m-%d_%H_%M_%S"`
57     cat > summary.xml <<EOF
58 <?xml version="1.0" encoding="UTF-8"?>
59 <?xml-stylesheet type="text/xsl" href="./style/summary.xsl"?>
60 <result_summary plan_name="Core">
61   <other xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string" />
62   <summary test_plan_name="Dali">
63     <start_at>$start</start_at>
64     <end_at>$start</end_at>
65   </summary>
66 EOF
67 }
68
69 function summary_end
70 {
71     cat >> summary.xml <<EOF
72 </result_summary>
73 EOF
74 }
75
76 function output_start
77 {
78     start=`date +"%Y-%m-%d_%H_%M_%S"`
79     cat > tct-${1}-core-tests.xml <<EOF
80 <?xml version="1.0" encoding="UTF-8"?>
81 <?xml-stylesheet type="text/xsl" href="./style/testresult.xsl"?>
82 <test_definition>
83 <environment build_id="" device_id="localhost" device_model="" device_name="N/A" host="Ubuntu" manufacturer="" resolution="N/A" screen_size="N/A"><other /></environment>
84 <summary test_plan_name="Empty test_plan_name"><start_at>$start</start_at><end_at>$start</end_at></summary>
85   <suite category="Core APIs" name="tct-$1-core-tests">
86     <set name="default" set_debug_msg="automated-tests.auto.suite_1_set_1.dlog">
87 EOF
88 }
89
90
91 function output_end
92 {
93     cat >> tct-${1}-core-tests.xml <<EOF
94     </set>
95   </suite>
96 </test_definition>
97 EOF
98 }
99
100
101 if [ $opt_modules == 1 ] ; then
102     modules= get_modules
103     echo $modules
104     exit 0
105 fi
106
107 # Clean up old test results
108 rm -f tct*core-tests.xml
109
110 # Clean up old coverage data
111 [ -d ../build/tizen ] && rm -f ../build/tizen/dali/.libs/*.gcda
112 [ -d ../build/tizen-cmake ] && find ../build/tizen-cmake/ -name \*.gcda -exec rm {} \;
113
114 find build \( -name "*.gcda" \) -exec rm '{}' \;
115
116 ASCII_BOLD="\e[1m"
117 ASCII_RESET="\e[0m"
118
119 modules=`ls -1 src/ | grep -v CMakeList | grep -v common | grep -v manual`
120 if [ -f summary.xml ] ; then unlink summary.xml ; fi
121
122 if [ $opt_tct == 1 ] ; then
123     # Use Test-kit lite
124     # Run all test case executables serially, create XML output
125     if [ -n "$1" ] ; then
126         execute_tct $1 $*
127     else
128         for mod in $modules
129         do
130             if [ $mod != 'common' ] && [ $mod != 'manual' ]; then
131
132                 echo -ne "$ASCII_BOLD"
133                 echo -e "Executing $mod$ASCII_RESET"
134                 execute_tct $mod $*
135             fi
136         done
137     fi
138
139     scripts/summarize.pl
140
141 else
142     # Execute test cases using own test harness
143
144     if [ -z "$1" ] ; then
145         # No arguments:
146         # Execute each test executable in turn (by default, runs tests in parallel)
147         summary_start
148         for mod in $modules
149         do
150             echo -e "$ASCII_BOLD"
151             echo -e "Executing $mod$ASCII_RESET"
152             output_start $mod
153             dbus-launch build/src/$mod/tct-$mod-core $opt_serial $opt_noFailedRerun $opt_quiet $opt_match
154             output_end $mod
155         done
156         summary_end
157
158     elif [ -f "build/src/$1/tct-$1-core" ] ; then
159         # First argument is an executable filename - execute only that with any
160         # remaining arguments
161         summary_start
162         module=$1
163         shift;
164         output_start ${module}
165         dbus-launch build/src/$module/tct-$module-core $opt_serial $opt_noFailedRerun $opt_quiet $opt_match $*
166         output_end ${module}
167         summary_end
168
169     else
170         # First argument is not an executable. Is it a test case name?
171         # Try executing each executable with the test case name until success/known failure
172         for mod in $modules
173         do
174             output=`build/src/$mod/tct-$mod-core $1`
175             ret=$?
176             if [ $ret -ne 6 ] ; then
177                 if [ $opt_debug -ne 0 ] ; then
178                     echo DEBUGGING:
179                     dbus-launch gdb --args build/src/$mod/tct-$mod-core $1
180
181                 else
182                     echo $output
183                     if [ $ret -eq 0 ] ; then echo -e "\nPassed" ; fi
184                 fi
185                 exit $ret
186             fi
187         done
188         echo $1 not found
189     fi
190 fi
191
192 if [ -f summary.xml ] ; then
193     scripts/output_summary.pl
194 fi
195
196 exit $?