3 ## @file utc_gtest_run.sh
4 ## @author Jongsoo Yoon <join.yoon@samsung.com>, Mikolaj Czyzewski <m.czyzewski@samsung.com>
7 ## @brief This shell-script file is made to test all unit test cases automatically for Chromium EFL API
9 # Tests can be run in a four different ways:
11 # ./utc_gtest_run.sh -s utc_blink_ewk_view_visibility_set.POS_TEST1
13 # ./utc_gtest_run.sh -s utc_blink_ewk_view_user_agent*
14 # -tests listed in the file (each test_name/API_function in separate line)
15 # ./utc_gtest_run.sh -l file
17 # ./utc_gtest_run.sh -a
19 # To generate list of all tests:
20 # ./utc_gtest_run.sh -g (to stdout)
21 # ./utc_gtest_run.sh -g > all_tests.txt
22 # ./utc_gtest_run.sh -g | grep ewk_view > ewk_view_tests.txt
24 # The test results are generated in /opt/usr/utc_results/unittest-result-{DATE}-{TIME}
25 # To parse the results:
26 # ./utc_gtest_run.sh -p /opt/usr/utc_results/unittest-result-{DATE}-{TIME}
27 # This creates file unittest-result-{DATE}-{TIME}.txt in current directory.
31 Usage: utc_gtest_run.sh [OPTION]
33 -g generate list of all tests
35 -l file run all tests from a text file (every test pattern in separate line)
36 -p dir search directory for xml files, parse them and print results
37 -s name run single test
41 function getHostArch() {
42 echo $(uname -m | sed -e \
43 's/i.86/ia32/;s/x86_64/x64/;s/amd64/x64/;s/arm.*/arm/;s/i86pc/ia32/')
46 # Set target environment depending on the host architecture
48 case "$(getHostArch)" in
50 UTC_EXEC="ewk_unittests"
51 tmp_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
52 CHROMIUM_DIR=$(dirname $tmp_dir)
54 binaries=($(find "$CHROMIUM_DIR/out.x64" -type f -name "$UTC_EXEC"))
55 num_of_bin=${#binaries[@]}
59 echo "=== No $UTC_EXEC binary found. Exiting ==="
63 echo "=== Only one utc binary found: ==="
64 echo "=== ${binaries[@]} ==="
68 echo "=== Please choose utc binary to run: ==="
70 for bin in ${binaries[@]}; do
76 if [[ $number =~ ^-?[0-9]+$ ]] && [ $number -ge 1 ] && [ $number -le $num_of_bin ]; then
79 echo "=== Please enter an integer from 1 to $num_of_bin ==="
82 EXEC="${binaries[$number-1]}"
83 echo "=== Running $EXEC ==="
87 UTC_RESULTS_ROOT_DIR=/tmp/utc_results
89 CHROMIUM_EFL_LIBDIR="$(dirname $EXEC)/lib"
90 CHROMIUM_EFL_DEPENDENCIES_LIBDIR="$CHROMIUM_DIR/out.x64/Dependencies/Root/lib64"
91 export LD_LIBRARY_PATH="$CHROMIUM_EFL_DEPENDENCIES_LIBDIR:$CHROMIUM_EFL_LIBDIR:${LD_LIBRARY_PATH}"
92 export UTC_RESOURCE_PATH="$CHROMIUM_DIR/ewk/unittest/resources"
93 EXEC="$EXEC --disable-gpu-driver-bug-workarounds"
97 UTC_EXEC=ewk_unittests
98 EXEC="/opt/usr/utc_exec/$UTC_EXEC"
100 UTC_RESULTS_ROOT_DIR=/opt/usr/utc_results
101 killall -s QUIT lockscreen
105 echo "=== Unsupported architecture ==="
109 FILE_DATE=$(date +%y%m%d_%H%M%S)
110 UTC_RESULT_DIR="$UTC_RESULTS_ROOT_DIR/unittest-result-$FILE_DATE"
114 [ "$1" = "--" ] && shift
116 echo "=== EXEC = $EXEC ==="
117 echo "=== UTC_RESULT_DIR = $UTC_RESULT_DIR ==="
122 echo -e "=== Test results were saved in \033[0;34m$UTC_RESULT_DIR\033[0m ==="
125 # Parse single xml file and print result
126 function parse_xml () {
128 if [ ! -e "$xml_file" ]; then
129 echo "=== File $xml_file doesn't exist ==="
133 testsuite_count=$(xmllint --xpath "count(//testsuites/testsuite)" $xml_file)
134 for (( i=1; i<=$testsuite_count; i++ )); do
135 testcase_count=$(xmllint --xpath "count(//testsuites/testsuite[$i]/testcase)" $xml_file)
136 for (( j=1; j<=$testcase_count; j++ )); do
137 classname=$(xmllint --xpath "string(//testsuites/testsuite[$i]/testcase[$j]/@classname)" $xml_file)
138 name=$(xmllint --xpath "string(//testsuites/testsuite[$i]/testcase[$j]/@name)" $xml_file)
139 message=$(xmllint --xpath "string(//testsuites/testsuite[$i]/testcase[$j]/failure/@message)" $xml_file)
140 message=$(echo $message | tr -d "\n\r")
141 if [ -n "$message" ]; then
142 echo "FAILURE $classname.$name $message"
144 echo "SUCCESS $classname.$name"
150 # Search directory for xml files, parse them and print results
151 function parse_dir () {
153 pushd $xml_dir &>/dev/null
154 echo "=== Parsing files in: `pwd` ==="
156 for file in *.xml; do
157 echo "$(parse_xml $file)"
163 # Generate list of all tests and print it to stdout
164 function generate_tests_list () {
170 list=$($EXEC --gtest_list_tests --gtest_filter="$filter" | egrep "^[a-zA-Z ]")
175 if [[ $line == utc_* ]]; then
178 echo "$utc_line$line"
184 function run_test () {
186 if [ -n "$test_name" ]; then
187 echo "=== Running test $test_name ==="
188 file="$UTC_RESULT_DIR/$test_name.xml"
190 # Generate fake xml file that tells about possible segfault
191 if [ ! -f $file ]; then
192 IFS='.' read -ra name <<< "$test_name"
193 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" >> $file
194 echo "<testsuites tests=\"1\" failures=\"0\" disabled=\"0\" errors=\"1\" time=\"0.1\" name=\"AllTests\">" >> $file
195 echo " <testsuite name=\"${name[0]}\" tests=\"1\" failures=\"0\" disabled=\"0\" errors=\"1\" time=\"0.1\">" >> $file
196 echo " <testcase name=\"${name[1]}\" status=\"run\" time=\"0.1\" classname=\"${name[0]}\">" >> $file
197 echo " <failure message=\"SIGSEGV\" type=\"\"></failure>" >> $file
198 echo " </testcase>" >> $file
199 echo " </testsuite>" >> $file
200 echo "</testsuites>" >> $file
203 $EXEC --gtest_output="xml:$UTC_RESULT_DIR/$test_name.xml" --gtest_filter="$test_name"
204 echo "=== Finished test $test_name ==="
207 echo "=== No test name specified ==="
212 # Run tests listed in file
213 function run_list () {
215 if [ -f "$test_file" ]; then
216 echo "=== Running tests from file: $test_file ==="
218 echo "=== Test file not specified ==="
222 ## Assume that in this file are only patterns (i.e. ewk_view_application_name) instead of
223 ## full test names (i.e. utc_blink_ewk_view_application_name_for_user_agent_set.POS_TEST).
224 ## So for each pattern we find all matching tests and run them one by one.
225 while read test_pattern; do
226 find_tests=$(generate_tests_list "$test_pattern")
227 while read single_test; do
228 run_test "$single_test"
229 done <<< "$find_tests"
232 echo "=== Finished running tests from file: $test_file ==="
236 echo "=== Running all test ==="
240 done <<< "$(generate_tests_list)"
242 echo "=== Finished running all test ==="
245 while getopts "aghHl:p:s:" opt; do
250 mkdir -p $UTC_RESULT_DIR
255 # generate list of all tests
269 mkdir -p $UTC_RESULT_DIR
278 if [ ! -e "$xml_dir" ]; then
279 echo "=== Directory '$xml_dir' doesn't exist ==="
283 result=$(parse_dir $xml_dir)
284 file_name="$(basename "$xml_dir").txt"
285 file="$UTC_RESULTS_ROOT_DIR/$file_name"
287 echo "$result" > $file
288 success=$(echo "$result" | grep "^SUCCESS" | wc -l)
289 failure=$(echo "$result" | grep "^FAILURE" | wc -l)
290 sigsegv=$(echo "$result" | grep "SIGSEGV" | wc -l)
291 echo "" | tee -a $file
292 echo "SUCCESS : $success" | tee -a $file
293 echo "FAILURE : $failure ($sigsegv)" | tee -a $file
294 echo "TOTAL : $(expr $success + $failure)" | tee -a $file
295 echo "" | tee -a $file
296 echo "=== Results saved to $UTC_RESULTS_ROOT_DIR/$file_name ==="
302 mkdir -p $UTC_RESULT_DIR