Merge test folder of test branch
[iotivity.git] / test / src / automation / robot / robot_automation.sh
1 #!/bin/bash
2
3 #os=linux type=api module=ca tc="test case name" tag="tag name"
4 #os=linux type=sample_app module=ca tc="test case name" tag="tag name"
5 #os=linux type=sample_app module=ca,sm tc="test case name" tag="tag name"
6
7 function kill_app() {
8
9     app_name=${1}
10     
11     #killall ${app_name}
12     #kill -9 $(pgrep ${app_name})
13     pkill -9 ${app_name}
14 }
15
16 function write_system_failure () {
17
18     os_type=${1}
19     tc_type=${2}
20     module=${3}
21
22     if ! [[ -d "report" ]]; then
23         mkdir report
24     fi
25
26     echo "fail:${module}:${os_type}:system_failure:${tc_type}" >> report/robot_execution_status.txt
27 }
28
29 function android_connectivity_test() {
30
31     os_type=${1}
32     tc_type=${2}
33     module=${3}
34
35     android_devices=($(${ADB} devices | awk '/[a-zA-Z0-9]+[ \t]+device$/{print $1}'))
36
37     if [[ "${module}" == "re" || "${module}" == "pm" || "${module}" == "es" ]]; then
38         linux_ssid=$(iwgetid -r)
39         if [  "${linux_ssid}" == "" ]; then
40             echo "No wifi AP found for Linux"
41             return 1
42         fi
43         echo ${linux_ssid}
44     fi
45
46     for adb_device in "${android_devices[@]}"; do
47         android_ap=$(${ADB} -s ${adb_device}  shell dumpsys netstats | grep -E 'iface=wlan.*networkId' | tr -d '\r' | cut -d '=' -f 6 | cut -d '"' -f 2)
48         android_ap=$(echo ${android_ap})
49         android_ap=$(echo ${android_ap} | cut -d ' ' -f 1)
50
51         if [  "${android_ap}" == "" ]; then
52             echo "No wifi AP found for Android ${adb_device}"
53             return 1
54         fi
55
56         if [[ "${module}" == "re" || "${module}" == "pm" || "${module}" == "es" ]]; then
57             if [  "${linux_ssid}" == "${android_ap}" ]; then
58                 echo ${adb_device}" device is connected in same wifi AP"
59             else
60                 echo "Linux and Android device ${adb_device} aren't connected in same wifi AP"
61                 echo "Android connect to : " ${android_ap}
62                 echo "Linux connect to : " ${linux_ssid}
63                 return 1
64             fi
65         fi
66     done
67
68     if [[ "${module}" == "re" || "${module}" == "pm" || "${module}" == "es" ]]; then
69         linux_ip=$(ifconfig wlan0  | grep 'inet ' | cut -d ':' -f 2 | cut -d ' ' -f 1)
70         echo ${linux_ip}
71
72         if [  "${linux_ip}" == "" ]; then
73             echo "No wifi IP found for Linux"
74             return 1
75         fi
76
77         for adb_device in "${android_devices[@]}"; do
78             echo ${adb_device}
79             packet_loss=$(${ADB} -s ${adb_device} shell ping -c 10 ${linux_ip} | grep 'packet loss'| cut -d ',' -f 3 | cut -d '%' -f 1 )
80             echo "packet_loss : "${packet_loss}"%"
81             if [ ${packet_loss} -lt 50 ]; then
82                 echo "Linux device" ${linux_ip} "responses perfectly from Android ${adb_device}"
83             else
84                 echo "Linux device" ${linux_ip} "is not response perfectly from Android ${adb_device}"
85                 return 1
86             fi
87         done
88
89         for adb_device in "${android_devices[@]}"; do
90             echo ${adb_device}
91             android_ip=$(${ADB} -s ${adb_device} shell ip addr show wlan0  | grep 'inet ' | cut -d' ' -f6|cut -d/ -f1)
92             echo ${android_ip}
93             packet_loss=$(ping -c 3 ${android_ip} | grep 'packet loss'| cut -d ',' -f 3 | cut -d '%' -f 1 )
94             echo "packet_loss : "${packet_loss}"%"
95             if [ "${packet_loss}" -lt 50 ]; then
96                 echo "Android device" ${adb_device} "responses perfectly from linux"
97             else
98                 echo "Android device" ${adb_device} "is not response perfectly from linux"
99                 return 1
100             fi
101         done
102     fi
103 }
104
105 function tizen_connectivity_test() {
106
107     os_type=${1}
108     tc_type=${2}
109     module=${3}
110
111     echo "module ${module}"
112
113     tizen_devices=($(${SDB} devices | awk '/[a-zA-Z0-9]+[ \t]+device[ \t]+[a-zA-Z0-9-]+$/{print $1}'))
114
115     for sdb_device in "${tizen_devices[@]}";
116     do
117         sdb -s ${sdb_device} root on
118         tizen_ap=$(sdb -s ${sdb_device} shell dump_systemstate | grep -E '.*/wifi/connected_ap_name.*' | cut -d '=' -f 2 | cut -d ' ' -f 2)
119
120         if [ "${tizen_ap}" == "" ]; then
121             echo "Tizen device ${sdb_device} is not connected with any wifi AP"
122             return 1
123         fi
124
125         tizen_ap=$(echo ${tizen_ap} | tr -d '\r')
126         echo "Wifi ap for Tizen device ${sdb_device} is: ${tizen_ap}"
127     done
128
129     if [[ "${module}" == "re" || "${module}" == "es" ]]; then
130         linux_ssid=$(iwgetid -r)
131
132         if [  "${linux_ssid}" == "" ]; then
133             echo "No wifi AP found for Tizen Testhub"
134             return 1
135         fi
136
137         echo ${linux_ssid}
138
139         linux_ip=$(ifconfig wlan0  | grep 'inet ' | cut -d ':' -f 2 | cut -d ' ' -f 1)
140
141         if [  "${linux_ip}" == "" ]; then
142             echo "No wifi IP found for Tizen Testhub"
143             return 1
144         fi
145
146         echo ${linux_ip}
147     fi
148
149     for sdb_device in "${tizen_devices[@]}"; do
150         tizen_ap=$(${SDB} -s ${sdb_device} shell dump_systemstate | grep -E '.*/wifi/connected_ap_name.*' | cut -d '=' -f 2 | cut -d ' ' -f 2)
151         if [ "${tizen_ap}" == "" ]; then
152             echo "No wifi AP found for Tizen Device ${sdb_device}"
153             return 1
154         fi
155
156         tizen_ap=$(echo ${tizen_ap})
157         tizen_ap=$(echo ${tizen_ap} | cut -d ' ' -f 1)
158
159         if [[ "${module}" == "re" || "${module}" == "es" ]]; then
160             if [  "${linux_ssid}" == "${tizen_ap}" ]; then
161                 echo ${sdb_device}" device is connected in same wifi AP"
162             else
163                 echo "Tizen Testhub and Tizen device ${sdb_device} aren't connected in same wifi AP"
164                 echo "Tizen connect to: "${tizen_ap}
165                 echo "Linux connect to: "${linux_ssid}
166                 return 1
167             fi
168         fi
169     done
170
171     if [[ "${module}" == "re" || "${module}" == "es" ]]; then
172         for sdb_device in "${tizen_devices[@]}"; do
173             echo ${sdb_device}
174             tizen_ip=$(${SDB} -s ${sdb_device} shell ifconfig wlan0 | grep 'inet ' | cut -d ':' -f 2| cut -d ' ' -f 1)
175             echo ${tizen_ip}
176
177             packet_loss=$(ping -c 10 ${tizen_ip} | grep 'packet loss'| cut -d ',' -f 3 | cut -d '%' -f 1)
178             echo "packet_loss: ${packet_loss} %"
179
180             if [ "${packet_loss}" -lt 50 ]; then
181                 echo "Tizen device ${sdb_device} responses perfectly from Tizen Testhub"
182             else
183                 echo "Tizen device ${sdb_device} is not response perfectly from Tizen Testhub"
184                 return 1
185             fi
186         done
187     fi
188 }
189
190 function start_server() {
191
192     cwd=$(pwd)
193
194     if [[ ${x86} = "x86" ]]; then
195         if [[ ${MONGODB_ROOT} != "" ]]; then
196             if [[ -d ${MONGODB_ROOT} ]]; then
197                 fuser -k -n tcp ${MONGODB_PORT}
198                 if [[ -d ${MONGODB_ROOT}"/db" ]]; then
199                     rm -rf ${MONGODB_ROOT}"/db"
200                 fi
201                 mkdir ${MONGODB_ROOT}"/db"
202             fi
203         fi
204     fi
205
206     if [[ "${clean_build}" == "1" ]]; then
207         if [[ "${ENABLE_IOTIVITY_BUILD}" == "1" ]]; then
208             cd ${IOTIVITY_ROOT}
209
210             store_dir="../extlibs"
211
212             if [[ -d "${store_dir}" ]]; then
213                 rm -rf ${store_dir}
214             fi
215
216             mkdir ${store_dir}
217
218             if [[ -d "extlibs/tinycbor/tinycbor" ]]; then
219                 echo "creating backup of tinycbor"
220                 cd extlibs/tinycbor/tinycbor
221                 git clean -fx -d ""
222                 cd ../../../
223                 cp -rf extlibs/tinycbor/tinycbor ${store_dir}
224             fi
225             if [[ -d "extlibs/mbedtls/mbedtls" ]]; then
226                 echo "creating backup of mbedtls"
227                 cd extlibs/mbedtls/mbedtls
228                 git clean -fx -d ""
229                 cd ../../../
230                 cp -rf extlibs/mbedtls/mbedtls ${store_dir}
231             fi
232             if [[ -d "extlibs/gtest" ]]; then
233                 echo "creating backup of gtest"
234                 cp -rf extlibs/gtest ${store_dir}
235             fi
236             if [[ -d "extlibs/rapidjson" ]]; then
237                 echo "creating backup of rapidjson"
238                 cp -rf extlibs/rapidjson ${store_dir}
239             fi
240             if [[ -d "extlibs/hippomocks" ]]; then
241                 echo "creating backup of hippomocks"
242                 cp -rf extlibs/hippomocks ${store_dir}
243             fi
244
245             git clean -fx -d ""
246             rm -rf tmp
247             rm -rf *
248             git checkout .
249
250             if [[ -d "${store_dir}/tinycbor" ]]; then
251                 echo "restoring tinycbor"
252                 cp -rf ${store_dir}/tinycbor extlibs/tinycbor/
253             fi
254             if [[ -d "${store_dir}/mbedtls" ]]; then
255                 echo "restoring mbedtls"
256                 cp -rf ${store_dir}/mbedtls extlibs/mbedtls/
257             fi
258             if [[ -d "${store_dir}/gtest" ]]; then
259                 echo "restoring gtest"
260                 cp -rf ${store_dir}/gtest/*.zip extlibs/gtest/
261             fi
262             if [[ -d "${store_dir}/rapidjson" ]]; then
263                 echo "restoring rapidjson"
264                 cp -rf ${store_dir}/rapidjson/*.zip extlibs/rapidjson/
265             fi
266             if [[ -d "${store_dir}/hippomocks" ]]; then
267                 echo "restoring hippomocks"
268                 cp -rf ${store_dir}/hippomocks/*.zip extlibs/hippomocks/
269             fi
270
271             rm -rf ${store_dir}
272
273             cd ${cwd}
274         fi
275     fi
276     
277     if [[ "${complete_run}" == "1" ]]; then
278         rm -rf report/*
279     fi
280
281     cd ${IOTIVITY_ROOT}/build_common/linux
282     git checkout SConscript
283
284     if [[ "${COVERAGE}" != "0" ]]; then
285         echo "intentionally block coverage flag as it cause boost_thread not to be found( (cause unknown)"
286         #sed -i "/Import('env')/a env.AppendUnique(CCFLAGS = ['-ftest-coverage' , '-fprofile-arcs'])\nenv.AppendUnique(LIBS = ['gcov'])" ${IOTIVITY_ROOT}/build_common/linux/SConscript
287     fi
288
289     cd ${cwd}
290
291     cd device_lib
292     gradle install
293     ret=${?}
294     cd ${cwd}
295
296     if [[ ${ret} != 0 ]]; then
297         echo 'DeviceLib Build Falied'
298         exit 127
299     fi
300
301     pwd
302
303     if [[ "${start}" == *"server"* ]]; then
304         fuser -k -n tcp ${REMOTE_PORT}
305         cd helper
306         if [[ "${start}" = *"client"* ]]; then
307             gnome-terminal --tab -e "bash -c \"jython server_runner.py -i ${REMOTE_IP} -p ${REMOTE_PORT}\""
308             sleep 10s
309         else
310             jython server_runner.py -i ${REMOTE_IP} -p ${REMOTE_PORT}
311         fi
312         cd ${cwd}
313     fi
314 }
315
316 function start_client() {
317
318     if [[ "${is_parallel}" = "false" ]]; then
319         parallel_prefix=""
320         parallel_suffix=""
321     fi
322
323     if ! [[ -d "${TEST_ROOT}" ]]; then
324         echo 'TEST_ROOT Path does not Exsit'
325         exit 127
326     fi
327
328     cwd=`pwd`
329     cd ${TEST_ROOT}
330     TEST_ROOT=`pwd`
331
332     input="bin/linux/pid_list.txt"
333
334     if [ -f $input ]; then
335         while IFS= read -r var
336         do
337             var=`echo $var`
338             echo "$var"
339         done < "$input"
340         rm $input
341     fi
342
343     if [[ "${clean_build}" == "1" ]]; then
344         if [[ "${ENABLE_TC_BUILD}" == "1" ]]; then
345             git checkout -- bin
346             rm .sconsign.dblite
347             rm -rf bin
348         fi
349     fi
350
351     cd ${cwd}
352
353     if ! [[ -d "${TEST_MANAGER_ROOT}" ]]; then
354         echo 'TEST_MANAGER_ROOT Path does not Exsit'
355         exit 127
356     fi
357
358     cwd=`pwd`
359     cd ${TEST_MANAGER_ROOT}
360     TEST_MANAGER_ROOT=`pwd`
361     cd ${cwd}
362
363     filter=""
364
365     v=' --variable '
366
367     tctype_list=('api' 'bat' 'interop_app' 'sample_app')
368     os_list=('linux' 'android' 'tizen')
369
370     for tctype in ${tctype_list[@]};
371     do
372         if [[ "${given_tc_type}" != "all" && "${given_tc_type}" != *"${tctype}"* ]]; then
373             continue
374         fi
375
376         echo 'tctype: '${tctype}
377
378         module_list=('ri' 're' 'rc' 'sm' 'ns' 'rd' 'ic' 'ca' 'es' 'cs' 'pm' 'chp')
379
380         if [[ "${tctype}" == "bat" ]]; then
381             module_list=('build' 'coverage' 'unittest')
382         fi
383
384         for os_type in ${os_list[@]};
385         do
386             if [[ "${given_os_type}" != "all" && "${given_os_type}" != *"${os_type}"* ]]; then
387                 continue
388             fi
389
390             echo 'os: '${os_type}
391
392             for os2_type in ${os_list[@]};
393             do
394
395                 if [[ "${tctype}" == "interop_app" ]]; then
396                     if [[ "${given_os2_type}" != *"${os2_type}"* ]]; then
397                         continue
398                     fi
399                     echo ${os_type}'->'${os2_type}
400                 fi
401
402                 echo 'os2: '${os2_type} 
403
404                 for module_type in ${module_list[@]};
405                 do
406                     if [[ "${given_module_type}" != "all" && "${given_module_type}" != *"${module_type}"* ]]; then
407                         continue
408                     fi
409
410                     echo 'module_type: '${module_type}
411
412                     secured_list=('0')
413
414                     if [[ "${module_type}" == "pm" || "${module_type}" == "cs" ]]; then
415                         secured_list=('1')
416                     fi
417
418                     if [[ "${module_type}" == "es" ]]; then
419                         #secured_list=('0' '1')
420                         secured_list=('0')
421                     fi
422
423                     if [[ "${module_type}" == "chp" ]]; then
424                         secured_list=('0' '1')
425                     fi
426
427                     sdk_list=('undefined')
428                     sdk2_list=('undefined')
429
430                     if [[ "${tctype}" == "interop_app" ]]; then
431                         if [[ "${os_type}" == "linux" || "${os_type}" == "tizen" ]]; then
432                             if [[ "${module_type}" == "ns" || "${module_type}" == "cs" ]]; then
433                                 sdk_list=('csdk' 'cpp')
434                             fi
435                             if [[ "${module_type}" == "pm" ]]; then
436                                 if [[ "${tctype}" != "api" ]]; then
437                                     sdk_list=('csdk')
438                                 fi
439                             fi
440                         fi
441                         if [[ "${os2_type}" == "linux" || "${os2_type}" == "tizen" ]]; then
442                             if [[ "${module_type}" == "ns" || "${module_type}" == "cs" ]]; then
443                                 sdk2_list=('csdk' 'cpp')
444                             fi
445                             if [[ "${module_type}" == "pm" ]]; then
446                                 if [[ "${tctype}" != "api" ]]; then
447                                     sdk2_list=('csdk')
448                                 fi
449                             fi
450                         fi
451                     fi
452
453                     for secured_type in ${secured_list[@]};
454                     do
455                         echo 'secured_type: '${secured_type}
456
457                         for sdk_type in ${sdk_list[@]};
458                         do
459                             if [[ "${given_sdk}" != *"${sdk_type}"* ]]; then
460                                 continue
461                             fi
462
463                             for sdk2_type in ${sdk2_list[@]};
464                             do
465                                 if [[ "${given_sdk2}" != *"${sdk2_type}"* ]]; then
466                                     continue
467                                 fi
468
469                                 tc_file_filter="tc/${tctype}/Iotivity_Component*_*${os_type^}Test.txt"
470                                 if [[ "${tctype}" == "interop_app" ]]; then
471                                     tc_file_filter="tc/${tctype}/Iotivity_Component*_*Test.txt"
472                                 fi
473
474                                 for full_name in `ls -a ${tc_file_filter}`;
475                                 do
476                                     filter=''
477                                     common_filter=''
478
479                                     if [[ "${tctype}" == "api" || "${tctype}" == "bat" ]]; then
480                                         filter+=" --include=\""${module_type}"\""
481                                     fi
482
483                                     if [[ "${tctype}" == "sample_app" || "${tctype}" == "interop_app" ]]; then
484                                         if [[ "${full_name}" != *"_${module_type^^}_"* ]]; then
485                                             continue
486                                         fi
487                                     fi
488
489                                     if [[ "${tctype}" == "interop_app" ]]; then
490                                         filter+=" --include=all"
491                                         filter+=" --include=\""${os_type}-${os2_type}"\""
492                                     fi
493
494                                     echo 'file_name: '${full_name}
495
496                                     transport_list=('nstt') #nsmt for not specific transport type
497                                     qos_list=('nsmt') #nsmt for not specific message type
498
499                                     if [[ "${tctype}" == "interop_app" ]]; then
500                                         if [[ "${module_type}" == "ri" ]]; then
501                                             transport_list=('ip' 'tcp')
502                                             qos_list=('nsmt' 'non' 'con')
503                                         fi
504                                     fi
505
506                                     for transport_type in ${transport_list[@]};
507                                     do
508                                         if [[ "${given_transport_type}" != *"${transport_type}"* ]]; then
509                                             continue
510                                         fi
511
512                                         for qos_type in ${qos_list[@]};
513                                         do
514                                             if [[ "${given_msg_type}" != *"${qos_type}"* ]]; then
515                                                 continue
516                                             fi
517
518                                             temp_common_filter=${common_filter}
519                                             temp_filter=${filter}
520                                             interop_filter=''
521                                             if [[ "${tctype}" == "interop_app" ]]; then
522                                                 if [[ "${module_type}" == "ri" ]]; then
523                                                     interop_filter+=" --include=${qos_type}"
524                                                 fi
525                                             fi
526
527                                             common_filter+=${v}"MODULE:"${module_type}
528                                             common_filter+=${v}"TC_TYPE:"${tctype}
529                                             common_filter+=${v}"ENABLE_IOTIVITY_BUILD:"${ENABLE_IOTIVITY_BUILD}
530                                             common_filter+=${v}"ENABLE_TC_BUILD:"${ENABLE_TC_BUILD}
531                                             common_filter+=${v}"ENABLE_TC_RUN:"${ENABLE_TC_RUN}
532                                             common_filter+=${v}"ENABLE_SAMPLE_APP_RUN:"${ENABLE_SAMPLE_APP_RUN}
533
534                                             common_filter+=${v}"OS:"${os_type}
535                                             if [[ "${tctype}" == "interop_app" ]]; then
536                                                 common_filter+=${v}"OS2:"${os2_type}
537                                             fi
538
539                                             common_filter+=${v}"SECURED:"${secured_type}
540                                             common_filter+=${v}"SDK:"${sdk_type}
541                                             common_filter+=${v}"SDK2:"${sdk2_type}
542                                             common_filter+=${v}"TRANSPORT:"${transport_type}
543                                             common_filter+=${v}"QOS:"${qos_type}
544                                             common_filter+=${v}"RELEASE:"${RELEASE}
545                                             common_filter+=${v}"RELEASE_DIR:"${RELEASE_DIR}
546                                             common_filter+=${v}"CLEAN_BUILD:"${clean_build}
547                                             common_filter+=${v}"bit:"${bit}
548                                             common_filter+=${v}"J:"${J}
549
550                                             if [[ "${module_type}" == "cs" || "${module_type}" == "ic" || "${tctype}" == "bat" ]]; then
551                                                 common_filter+=${v}"MONGODB_ROOT:"${MONGODB_ROOT}
552                                                 common_filter+=${v}"MONGODB_FOLDER:"${MONGODB_FOLDER}
553                                                 common_filter+=${v}"KAFKA_ROOT:"${KAFKA_ROOT}
554                                                 common_filter+=${v}"AUTH_PROVIDER:"${AUTH_PROVIDER}
555                                                 common_filter+=${v}"AUTH_USERNAME:"${AUTH_USERNAME}
556                                                 common_filter+=${v}"AUTH_PASSWORD:"${AUTH_PASSWORD}
557                                             fi
558
559                                             if [[ "${os_type}" == "android" || ("${tctype}" == "interop_app" && "${os2_type}" == "android") ]]; then
560                                                 common_filter+=${v}"ANDROID_HOME:"${ANDROID_HOME}
561                                                 common_filter+=${v}"ADB:"${ANDROID_HOME}/platform-tools/adb
562                                                 common_filter+=${v}"PARAM_ANDROID_HOME:ANDROID_HOME="${ANDROID_HOME}
563                                                 common_filter+=${v}"PARAM_ANDROID_NDK:ANDROID_NDK="${ANDROID_NDK}
564                                                 common_filter+=${v}"PARAM_ANDROID_GRADLE:ANDROID_GRADLE="${ANDROID_GRADLE}
565
566                                                 if [[ "${arch}" == "" ]]; then
567                                                     common_filter+=${v}'ANDROID_TARGET_ARCH:armeabi'
568                                                 else
569                                                     common_filter+=${v}'ANDROID_TARGET_ARCH:'${arch}
570                                                 fi
571
572                                                 adb_devices=($(${ANDROID_HOME}/platform-tools/adb devices | awk '/[a-zA-Z0-9]+[ \t]+device$/{print $1}'))
573
574                                                 if [[ ${given_android_device_ids} != "" ]]; then
575                                                     given_adb_devices=(${given_android_device_ids//,/ })
576
577                                                     for given_adb_device in "${given_adb_devices[@]}";
578                                                     do
579                                                         found="0"
580                                                         for temp in "${adb_devices[@]}";
581                                                         do
582                                                             if [[ "${temp}" == "${given_adb_device}" ]]; then
583                                                                 found="1"
584                                                             fi
585                                                         done
586                                                         if [[ "${found}" == "0" ]]; then
587                                                             echo ${given_adb_device}' Android Device Id Not Found'
588                                                             write_system_failure ${os_type} ${tctype} ${module_type}
589                                                             exit 127
590                                                         fi
591                                                     done
592                                                     adb_devices=("${given_adb_devices[@]}")
593                                                 fi
594
595                                                 for adb_device in "${adb_devices[@]}";
596                                                 do
597                                                     echo ${adb_device}
598                                                 done
599
600                                                 if [[ "${adb_devices}" == "" ]]; then
601                                                     echo 'No android device found'
602                                                     write_system_failure ${os_type} ${tctype} ${module_type}
603                                                     exit 127
604                                                 else
605                                                     sz=${#adb_devices[@]}
606                                                     common_filter+=${v}"ANDROID_DEVICE_ID:"${adb_devices[0]}
607                                                     if [[ "${sz}" -gt 1 ]]; then
608                                                         common_filter+=${v}"PEER_ANDROID_DEVICE_ID:"${adb_devices[1]}
609                                                     elif [[ "${module_type}" == "ca" || ("${tctype}" == "interop_app" && "${os_type}" == "android" && "${os2_type}" == "android") || ("${tctype}" == "sample_app" && "${os_type}" == "android") ]]; then
610                                                         echo 'Two Devices Needed to run CA or interop_app or sample_app android TC'
611                                                         #common_filter+=${v}"PEER_ANDROID_DEVICE_ID:"${adb_devices[0]}
612                                                         write_system_failure ${os_type} ${tctype} ${module_type}
613                                                         exit 127
614                                                     fi
615                                                 fi
616
617                                                 android_connectivity_test ${os_type} ${tctype} ${module_type}
618                                                 ret=$?
619                                                 if [ ${ret} -ne 0 ]; then
620                                                     write_system_failure ${os_type} ${tctype} ${module_type}
621                                                     exit 127
622                                                 fi
623                                             fi
624                                             if [[ "${os_type}" == "tizen" || ("${tctype}" == "interop_app" && "${os2_type}" == "tizen") ]]; then
625                                                 common_filter+=${v}"TIZEN_HOME:"${TIZEN_HOME}
626                                                 common_filter+=${v}"SDB:"${SDB}
627                                                 common_filter+=${v}"GBS_ROOT_PARENT:"${HOME}
628                                                 common_filter+=${v}"RPM_VERSION:"${RPM_VERSION}
629                                                 if [[ "${arch}" == "" ]]; then
630                                                     common_filter+=${v}'TIZEN_TARGET_ARCH:armv7l'
631                                                 else
632                                                     common_filter+=${v}'TIZEN_TARGET_ARCH:'${arch}
633                                                 fi
634
635                                                 sdb_devices=($(${SDB} devices | awk '/[a-zA-Z0-9]+[ \t]+device[ \t]+[a-zA-Z0-9-]+$/{print $1}'))
636
637                                                 if [[ ${given_tizen_device_ids} != "" ]]; then
638                                                     given_sdb_devices=(${given_tizen_device_ids//,/ })
639
640                                                     for given_sdb_device in "${given_sdb_devices[@]}";
641                                                     do
642                                                         found="0"
643                                                         for temp in "${sdb_devices[@]}";
644                                                         do
645                                                             if [[ "${temp}" == "${given_sdb_device}" ]]; then
646                                                                 found="1"
647                                                             fi
648                                                         done
649                                                         if [[ "${found}" == "0" ]]; then
650                                                             echo ${given_sdb_device}' Tizen Device Id Not Found'
651                                                             write_system_failure ${os_type} ${tctype} ${module_type}
652                                                             exit 127
653                                                         fi
654                                                     done
655                                                     sdb_devices=("${given_sdb_devices[@]}")
656                                                 fi
657
658                                                 for sdb_device in "${sdb_devices[@]}";
659                                                 do
660                                                     echo ${sdb_device}
661                                                     ${SDB} -s ${sdb_device} root on
662
663                                                     output=$(${SDB} -s ${sdb_device} shell ls /opt/usr/media/bin/pid_list.txt)
664
665                                                     if [[ ${output} != *"No such file or directory"* ]]; then
666                                                         input=$(${SDB} -s ${sdb_device} shell cat /opt/usr/media/bin/pid_list.txt)
667
668                                                         while read -r var; do
669                                                             var=`echo $var`
670                                                             echo "$var"
671                                                             ${SDB} -s ${sdb_device} shell kill -9 $var
672                                                         done <<< "$input"
673
674                                                         ${SDB} -s ${sdb_device} shell rm /opt/usr/media/bin/pid_list.txt
675                                                     fi
676
677                                                 done
678
679                                                 if [[ "${sdb_devices}" == "" ]]; then
680                                                     echo 'No tizen device found'
681                                                     write_system_failure ${os_type} ${tctype} ${module_type}
682                                                     exit 127
683                                                 else
684                                                     sz=${#sdb_devices[@]}
685                                                     common_filter+=${v}"TIZEN_DEVICE_ID:"${sdb_devices[0]}
686                                                     if [[ "${sz}" -gt 1 ]]; then
687                                                         common_filter+=${v}"PEER_TIZEN_DEVICE_ID:"${sdb_devices[1]}
688                                                     elif [[ "${module_type}" == "ca" || ("${tctype}" == "interop_app" && "${os_type}" == "tizen" && "${os2_type}" == "tizen") ]]; then
689                                                     #elif [[ "${module_type}" == "ca" ]]; then
690                                                         echo 'Two Devices Needed to run CA, interop_app and sample_app tizen TC'
691                                                         #common_filter+=${v}"PEER_TIZEN_DEVICE_ID:"${sdb_devices[0]}
692                                                         write_system_failure ${os_type} ${tctype} ${module_type}
693                                                         exit 127
694                                                     fi
695                                                 fi
696
697                                                 tizen_connectivity_test ${os_type} ${tctype} ${module_type}
698                                                 ret=$?
699                                                 if [ ${ret} -ne 0 ]; then
700                                                     write_system_failure ${os_type} ${tctype} ${module_type}
701                                                     exit 127
702                                                 fi
703                                             fi
704                                             if [[ "${os_type}" == "linux" || "${os2_type}" == "linux" ]]; then
705                                                 common_filter+=${v}'LINUX_TARGET_ARCH:'${x86}
706                                             fi
707
708                                             filter+=${v}'LINUX_LIB_PATH:'${IOTIVITY_ROOT}/out/linux/${x86}/${RELEASE_DIR}
709
710                                             file_suffix=${module_type^^}'-'${tctype^^}'-'${os_type^}
711
712                                             if [[ "${os_type}" = "linux" ]]; then
713                                                 file_suffix+='-'${version}'-'${bit}
714                                             fi
715
716                                             if [[ "${sdk_type}" != "undefined" ]]; then
717                                                 file_suffix+='-'${sdk_type^^}
718                                             fi
719
720                                             if [[ "${tctype}" == "interop_app" ]]; then
721                                                 file_suffix+='-'${os2_type^}
722                                                 if [[ "${os2_type}" = "linux" ]]; then
723                                                     file_suffix+='-'${version}'-'${bit}
724                                                 fi
725                                             fi
726
727                                             if [[ "${sdk2_type}" != "undefined" ]]; then
728                                                 file_suffix+='-'${sdk2_type^^}
729                                             fi
730
731                                             if [[ "${transport_type}" != "nstt" ]]; then
732                                                 file_suffix+='-'${transport_type^^}
733                                             fi
734
735                                             if [[ "${qos_type}" != "nsmt" ]]; then
736                                                 file_suffix+='-'${qos_type^^}
737                                             fi
738
739                                             #file_suffix+='.html'
740
741                                             fullReport=' --report Report-'${file_suffix}'.html'
742                                             fullReport+=' --log Log-'${file_suffix}'.html'
743                                             fullReport+=' --output Output-'${file_suffix}'.xml'
744
745                                             if [[ "${given_version}" != *"${version}"* ]]; then
746                                                 continue
747                                             fi
748
749                                             if [[ "${given_bit}" != *"${bit}"* ]]; then
750                                                 continue
751                                             fi
752
753                                             if [[ "${start}" == "local" ]]; then
754                                                 filter+=${v}'LIB_MODE:file'
755                                             else
756                                                 filter+=${v}'LIB_MODE:client-server'
757                                             fi
758
759                                             filter+=${v}'REMOTE_IP:'${REMOTE_IP}
760                                             filter+=${v}'REMOTE_PORT:'${REMOTE_PORT}
761
762                                             filter+=${v}'ROBOT_ROOT:'${ROBOT_ROOT}
763
764                                             filter+=${v}'VERSION:'${version}
765                                             filter+=${v}'BIT:'${bit}
766                                             filter+=${v}'x86:'${x86}
767                                             filter+=${v}'IOTIVITY_ROOT:'${IOTIVITY_ROOT}
768                                             filter+=${v}'IOTIVITY_COMMIT_ID:'${IOTIVITY_COMMIT_ID}
769                                             filter+=${v}'TEST_ROOT:'${TEST_ROOT}
770                                             filter+=${v}'TEST_MANAGER_ROOT:'${TEST_MANAGER_ROOT}
771                                             filter+=${v}'COVERAGE:'${COVERAGE}
772                                             filter+=${v}'HTTP_PROXY_ADDRESS:'${HTTP_PROXY_ADDRESS}
773                                             filter+=${v}'HTTPS_PROXY_ADDRESS:'${HTTPS_PROXY_ADDRESS}
774                                             filter+=${v}'MONGODB_PORT:'${MONGODB_PORT}
775
776                                             if [[ "${module_type}" = "ca" ]]; then
777
778                                                 filter+=${v}"PEER_IP:"${PEER_IP}
779
780                                                 if [[ "${PEER_BIT}" = "64" ]]; then
781                                                     peer_x86='x86_64'
782                                                 else
783                                                     peer_x86='x86'
784                                                 fi
785
786                                                 filter+=${v}'PEER_x86:'${peer_x86}
787                                                 filter+=${v}'PEER_IOTIVITY_ROOT:'${PEER_IOTIVITY_ROOT}
788                                                 filter+=${v}'PEER_TEST_ROOT:'${PEER_TEST_ROOT}
789                                             fi
790
791                                             if [[ "${given_tc}" != "all" ]]; then
792                                                 filter+=" --test=\""${given_tc}"\""
793                                             fi
794
795                                             if [[ "${given_tag}" != "" ]]; then
796                                                 for each_tag in $(echo ${given_tag} | sed "s/,/ /g")
797                                                 do
798                                                     filter+=" --include=\""${each_tag}"\""
799                                                 done
800                                             fi
801
802                                             if [[ "${tctype}" == "interop_app" ]]; then
803                                                 command="jybot -T -d ./report/"${tctype}/${module_type}" "${fullReport}${common_filter}${filter}${interop_filter}" "${full_name}
804                                             else
805                                                 command="jybot -T -d ./report/"${tctype}/${os_type}" "${fullReport}${common_filter}${filter}" "${full_name}
806                                             fi
807
808                                             echo ${command}
809
810                                             if eval ${command}; then
811                                                 echo 'Successfully Run above command'
812                                             else
813                                                 echo 'Something wrong with above command'
814                                             fi
815                                             common_filter=${temp_common_filter}
816                                             filter=${temp_filter}
817                                         done
818                                     done
819                                 done
820                             done #done sdk2_type
821                         done
822                     done
823                 done
824
825                 if [[ "${tctype}" != "interop_app" ]]; then
826                     echo 'breaking loop for '${tctype}' '
827                     break
828                 fi
829             done
830         done
831     done
832
833     wait
834 }
835
836 ROBOT_ROOT=`pwd`
837
838 source "config.txt"
839
840 REMOTE_IP=($(ifconfig -a | grep "inet " | grep "Bcast:" | awk '{print $2}' | awk -F: '{print $2}'))
841 echo ${REMOTE_IP}
842
843 bit=$(getconf LONG_BIT)
844 echo 'bit: '${bit}
845 if [ "${bit}" == "64" ]; then
846     x86="x86_64"
847 else
848     x86="x86"
849 fi
850
851 version=$(echo $(lsb_release -r) | awk -F '[ .]+' '{print $2}')
852 echo 'version: '${version}
853
854 for i in `seq 1 $#`
855 do
856     eval arg=\${${i}}
857     arg=${arg// /+}
858     args+=${arg}" "
859 done
860
861 arg_parts=(${args//=/ })
862
863 len=${#arg_parts[@]}
864
865 given_os_type="android,linux,tizen"
866 given_os2_type="android,linux,tizen"
867 given_tc_type="api,bat,sample_app,interop_app"
868 given_module_type="all"
869 given_bit="32,64"
870 given_version="12,14, 16"
871 given_tc=all
872 given_tag=''
873 J='3'
874 start='server,client'
875 given_sdk='undefined,csdk,cpp,java'
876 given_sdk2='undefined,csdk,cpp,java'
877 given_msg_type='con,non,nsmt'
878 given_transport_type='ipv4,ipv6,tcp,nstt'
879 given_android_device_ids=''
880 given_tizen_device_ids=''
881
882 PEER_IP=${REMOTE_IP}
883 PEER_BIT=${bit}
884 PEER_VERSION=${version}
885 PEER_IOTIVITY_ROOT=${IOTIVITY_ROOT}
886 PEER_TEST_ROOT=${TEST_ROOT}
887 AUTH_PROVIDER='github'
888 MONGODB_FOLDER='mongodb-linux-i686-3.0.6'
889 MONGODB_PORT='27017'
890 HTTP_PROXY_ADDRESS=''
891 HTTPS_PROXY_ADDRESS=''
892 MONGODB_ROOT=''
893 JYTHON_PATH=''
894
895 clean_build='1'
896
897 i=0
898 while [ ${i} -lt ${len} ]; do
899     arg_parts[i]=${arg_parts[i],,}
900     let i=i+2
901 done
902
903 i=0
904 while [ ${i} -lt ${len} ]; do
905     if [[ "${arg_parts[i]}" = "os" ]]; then
906         given_os_type=${arg_parts[i+1],,}
907     elif [[ "${arg_parts[i]}" = "os2" ]]; then
908         given_os2_type=${arg_parts[i+1],,}
909     elif [[ "${arg_parts[i]}" = "type" ]]; then
910         given_tc_type=${arg_parts[i+1],,}
911     elif [[ "${arg_parts[i]}" = "module" ]]; then
912         given_module_type=${arg_parts[i+1],,}
913     elif [[ "${arg_parts[i]}" = "sdk" ]]; then
914         given_sdk=${arg_parts[i+1],,}
915     elif [[ "${arg_parts[i]}" = "sdk2" ]]; then
916         given_sdk2=${arg_parts[i+1],,}
917     elif [[ "${arg_parts[i]}" = "qos" ]]; then
918         given_msg_type=${arg_parts[i+1],,}
919     elif [[ "${arg_parts[i]}" = "transport" ]]; then
920         given_transport_type=${arg_parts[i+1],,}
921     elif [[ "${arg_parts[i]}" = "arch" ]]; then
922         arch=${arg_parts[i+1],,}
923     elif [[ "${arg_parts[i]}" = "j" ]]; then
924         J=${arg_parts[i+1]}
925     elif [[ "${arg_parts[i]}" = "tc" ]]; then
926         given_tc=${arg_parts[i+1]}
927         given_tc=${given_tc//+/ }
928     elif [[ "${arg_parts[i]}" = "tag" ]]; then
929         given_tag=${arg_parts[i+1]}
930         given_tag=${given_tag//+/ }
931     elif [[ "${arg_parts[i]}" = "start" ]]; then
932         start=${arg_parts[i+1],,}
933     elif [[ "${arg_parts[i]}" = "port" ]]; then
934         REMOTE_PORT=${arg_parts[i+1]}
935     elif [[ "${arg_parts[i]}" = "iotivity_root" ]]; then
936         IOTIVITY_ROOT=${arg_parts[i+1]}
937     elif [[ "${arg_parts[i]}" = "iotivity_commit_id" ]]; then
938         IOTIVITY_COMMIT_ID=${arg_parts[i+1]}
939     elif [[ "${arg_parts[i]}" = "test_root" ]]; then
940         TEST_ROOT=${arg_parts[i+1]}
941     elif [[ "${arg_parts[i]}" = "test_manager_root" ]]; then
942         TEST_MANAGER_ROOT=${arg_parts[i+1]}
943     elif [[ "${arg_parts[i]}" = "peer_ip" ]]; then
944         PEER_IP=${arg_parts[i+1]}
945     elif [[ "${arg_parts[i]}" = "peer_bit" ]]; then
946         PEER_BIT=${arg_parts[i+1]}
947     elif [[ "${arg_parts[i]}" = "peer_iotivity_root" ]]; then
948         PEER_IOTIVITY_ROOT=${arg_parts[i+1]}
949     elif [[ "${arg_parts[i]}" = "peer_test_root" ]]; then
950         PEER_TEST_ROOT=${arg_parts[i+1]}
951     elif [[ "${arg_parts[i]}" = "release" ]]; then
952         RELEASE=${arg_parts[i+1]}
953     elif [[ "${arg_parts[i]}" = "coverage" ]]; then
954         COVERAGE=${arg_parts[i+1]}
955     elif [[ "${arg_parts[i]}" = "android_home" ]]; then
956         ANDROID_HOME=${arg_parts[i+1]}
957     elif [[ "${arg_parts[i]}" = "android_ndk" ]]; then
958         ANDROID_NDK=${arg_parts[i+1]}
959     elif [[ "${arg_parts[i]}" = "android_gradle" ]]; then
960         ANDROID_GRADLE=${arg_parts[i+1]}
961     elif [[ "${arg_parts[i]}" = "tizen_home" ]]; then
962         TIZEN_HOME=${arg_parts[i+1]}
963     elif [[ "${arg_parts[i]}" = "gbs_root_parent" ]]; then
964         GBS_ROOT_PARENT=${arg_parts[i+1]}
965     elif [[ "${arg_parts[i]}" = "http_proxy_address" ]]; then
966         HTTP_PROXY_ADDRESS=${arg_parts[i+1]}
967     elif [[ "${arg_parts[i]}" = "https_proxy_address" ]]; then
968         HTTPS_PROXY_ADDRESS=${arg_parts[i+1]}
969     elif [[ "${arg_parts[i]}" = "kafka_root" ]]; then
970         KAFKA_ROOT=${arg_parts[i+1]}
971     elif [[ "${arg_parts[i]}" = "mongodb_root" ]]; then
972         MONGODB_ROOT=${arg_parts[i+1]}
973     elif [[ "${arg_parts[i]}" = "auth_provider" ]]; then
974         AUTH_PROVIDER=${arg_parts[i+1]}
975     elif [[ "${arg_parts[i]}" = "auth_username" ]]; then
976         AUTH_USERNAME=${arg_parts[i+1]}
977     elif [[ "${arg_parts[i]}" = "auth_password" ]]; then
978         AUTH_PASSWORD=${arg_parts[i+1]}
979     elif [[ "${arg_parts[i]}" = "android_device_ids" ]]; then
980         given_android_device_ids=${arg_parts[i+1]}
981     elif [[ "${arg_parts[i]}" = "tizen_device_ids" ]]; then
982         given_tizen_device_ids=${arg_parts[i+1]}
983     elif [[ "${arg_parts[i]}" = "jython_path" ]]; then
984         JYTHON_PATH=${arg_parts[i+1]}
985     elif [[ "${arg_parts[i]}" = "clean_build" ]]; then
986         clean_build=${arg_parts[i+1]}
987     elif [[ "${arg_parts[i]}" = "complete_run" ]]; then
988         complete_run=${arg_parts[i+1]}
989     fi
990     let i=i+2
991 done
992
993 if [[ "${RELEASE}" == "0" ]]; then
994     RELEASE_DIR='debug'
995 else
996     RELEASE_DIR='release'
997 fi
998
999 echo 'Release: '${RELEASE}
1000 echo 'Release_dir: '${RELEASE_DIR}
1001 echo 'Robot Root: '${ROBOT_ROOT}
1002
1003 JYTHON_BIN_PATH=${JYTHON_PATH}'/bin'
1004 if [[ "${JYTHON_PATH}" == "" ]]; then
1005     echo 'jython_path not given, looking into system path'
1006 elif [[ -d "${JYTHON_BIN_PATH}" ]]; then
1007     if [[ "${PATH}" != *"${JYTHON_BIN_PATH}"* ]]; then
1008         export PATH=${PATH}:${JYTHON_BIN_PATH}
1009     fi
1010     echo 'jython_path: '${JYTHON_PATH}
1011 else
1012     echo 'invalid jython_path: '${JYTHON_PATH}
1013 fi
1014
1015 if [[ -d "${ANDROID_HOME}/platform-tools" ]]; then
1016     if [[ "${PATH}" != *"${ANDROID_HOME}/platform-tools"* ]]; then
1017         export PATH=${PATH}:${ANDROID_HOME}/platform-tools
1018     fi
1019 fi
1020
1021 if [[ -d "${TIZEN_HOME}/tools" ]]; then
1022     if [[ "${PATH}" != *"${TIZEN_HOME}/tools"* ]]; then
1023         export PATH=${PATH}:${TIZEN_HOME}/tools
1024     fi
1025 fi
1026
1027 required_program_list=('gcc' 'g++' 'scons' 'java' 'jybot' 'git' 'python' 'python3' 'jython' 'gradle' 'unzip')
1028
1029 if ! [[ -d "${IOTIVITY_ROOT}" ]]; then
1030     echo 'Iotivity_ROOT path does not exist'
1031     exit 127
1032 fi
1033
1034 cwd=`pwd`
1035 cd ${IOTIVITY_ROOT}
1036 IOTIVITY_ROOT=`pwd`
1037 cd ${cwd}
1038
1039 if [[ "${start}" == *"client"* ]]; then
1040     if [[ "${given_tc_type}" == *"bat"* || "${given_module_type}" == *"cs"* || "${given_module_type}" == *"ic"* ]]; then
1041         if ! [[ -d "${KAFKA_ROOT}" ]]; then
1042             echo 'KAFKA_ROOT path does not exist'
1043             exit 127
1044         fi
1045         required_program_list+=('mvn')
1046     fi
1047 fi
1048
1049 if [[ "${start}" == *"client"* ]]; then
1050     if [[ "${given_os_type}" == *"android"* || ("${given_tc_type}" == *"interop_app"* && "${given_os2_type}" == *"android"*) ]]; then
1051         if [[ "${ANDROID_HOME}" != "" ]]; then
1052             if ! [[ -d "${ANDROID_HOME}" ]]; then
1053                 echo 'Invalid ANDROID_HOME path'
1054                 exit 127
1055             fi
1056         else
1057             echo 'ANDROID_HOME Empty'
1058         fi
1059
1060         if [[ "${ANDROID_NDK}" != "" ]]; then
1061             if ! [[ -d "${ANDROID_NDK}" ]]; then
1062                 echo 'Invalid ANDROID_NDK path'
1063                 exit 127
1064             fi
1065         fi
1066         if [[ "${ANDROID_GRADLE}" != "" ]]; then
1067             if ! [[ -f "${ANDROID_GRADLE}" ]]; then
1068                 echo 'Invalid ANDROID_GRADLE binary'
1069                 exit 127
1070             fi
1071         fi
1072         required_program_list+=('adb')
1073     fi
1074
1075     if [[ "${given_os_type}" == *"tizen"* || ("${given_tc_type}" == *"interop_app"* && "${given_os2_type}" == *"tizen"*) ]]; then
1076         if [[ "${TIZEN_HOME}" != "" ]]; then
1077             if ! [[ -d "${TIZEN_HOME}" ]]; then
1078                 echo 'Invalid TIZEN_HOME path'
1079                 exit 127
1080             fi
1081         else
1082             echo 'TIZEN_HOME Empty'
1083         fi
1084         required_program_list+=('sdb')
1085         required_program_list+=('gbs')
1086     fi
1087 fi
1088
1089 for required_program in ${required_program_list[@]};
1090 do
1091     if ! type "${required_program}" > /dev/null; then
1092         echo "${required_program} not exist"
1093         exit 127
1094     fi
1095 done
1096
1097 cwd=`pwd`
1098 cd ${TEST_ROOT}
1099 TEST_ROOT=`pwd`
1100 cd ${cwd}
1101
1102 export CLASSPATH=$CLASSPATH:${TEST_ROOT}/src/automation/robot/device_lib/build/lib/*:${TEST_ROOT}/src/automation/robot/device_lib/build/libs/*
1103 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${IOTIVITY_ROOT}/out/linux/${x86}/${RELEASE_DIR}:/usr/local/lib
1104
1105 ADB=${ANDROID_HOME}/platform-tools/adb
1106 SDB=${TIZEN_HOME}/tools/sdb
1107
1108 if [[ "${start}" != *"server"* ]]; then
1109     export CLASSPATH=$CLASSPATH:${TEST_ROOT}/src/automation/robot/helper/*
1110 fi
1111
1112 if [[ "${start}" == *"server"* || "${start}" == "local" ]]; then
1113     echo ClassPath = $CLASSPATH
1114     start_server
1115 fi
1116
1117 if [[ "${start}" == *"client"* || "${start}" == "local" ]]; then
1118     start_client
1119 fi
1120
1121 if [[ "${start}" == *"kill"* ]]; then
1122     fuser -k -n tcp ${REMOTE_PORT}
1123     kill_app iotivity_*
1124     if [[ -f "${TEST_ROOT}/bin/linux/SerialKiller" ]]; then
1125         cwd=`pwd`
1126         cd ${TEST_ROOT}/bin/linux/
1127         ./SerialKiller
1128         cd ${cwd}
1129     fi
1130 fi
1131
1132 echo "All Process is completed"