Debian Codegraph @

autotest/unitTest/android/run_AutoTest_android.sh

raw
1 #!/bin/bash
2
3 AUTO_TEST_ANDROID_PATH=`pwd`
4 AUTO_TEST_SRC_PATH="../../../"
5 AUTO_TEST_RES_PATH="${AUTO_TEST_ANDROID_PATH}/report"
6 if [ ! -d ${AUTO_TEST_RES_PATH} ]
7 then
8 mkdir -p ${AUTO_TEST_RES_PATH}
9 else
10 echo "Will delete those outdate xml in the report"
11 rm -f ${AUTO_TEST_RES_PATH}/*.xml
12 fi
13 #Prepare android build enviroment
14 echo please set the enviroment variable as:
15 echo export ANDROID_HOME="path of android sdk"
16 echo export ANDROID_NDK_HOME="path of android ndk"
17 ANDROID_SDK_PATH=${ANDROID_HOME}
18 ANDROID_NDK_PATH=${ANDROID_NDK_HOME}
19 ANDROID_MAKE_PARAMS="OS=android NDKROOT=${ANDROID_NDK_PATH} TARGET=android-19"
20
21 if [ "#${ANDROID_SDK_PATH}" = "#" ]
22 then
23 echo Please set ANDROID_HOME with the path of Android SDK
24 exit 1
25 fi
26 if [ "#${ANDROID_NDK_PATH}" = "#" ]
27 then
28 echo Please set ANDROID_NDK_HOME with the path of Android NDK
29 exit 1
30 fi
31 #make build
32 cd ${AUTO_TEST_SRC_PATH}
33 find ./ -name *.o -exec rm -f {} \;
34 find ./ -name *.d -exec rm -f {} \;
35 make clean
36 make $ANDROID_MAKE_PARAMS test
37
38 if [ $? -ne 0 ]
39 then
40 echo Build error,check with the trace of make
41 exit 1
42 fi
43
44 #find apk
45 echo Start to find unittest apk
46 apk_name=`find ./ -name MainActivity-debug.apk`
47 if [ "#${apk_name}" = "#" ]
48 then
49 echo Fail to find encoder APK.
50 exit 1
51 fi
52
53 #prepare devices
54 ADB=${ANDROID_SDK_PATH}/platform-tools/adb
55
56 #get devices
57 devices=`$ADB devices | awk -F" " '/\tdevice/{print $1}'`
58 if [ "#$devices" = "#" ];then
59 echo "Have not any android devices."
60 exit 1
61 fi
62
63 #run apk
64 run_apk() {
65 local apk=$1;
66 local rand=` date +%s`
67 apk_id="com.cisco.codec.unittest"
68 apk_main="com.cisco.codec.unittest/.MainActivity"
69 test_path="/sdcard/welsenc"
70 log_grep_params="welsenc"
71 test_res=./res
72 xml_file="sdcard/codec_unittest.xml"
73 for dev in $devices; do
74 #dev_info_file=${AUTO_TEST_RES_PATH}/${dev}.log
75 report_file=${AUTO_TEST_RES_PATH}/codec_unittest_${dev}_${rand}.xml
76 $ADB -s $dev uninstall ${apk_id}
77 $ADB -s $dev install -r ${apk}
78 #TODO: output more info about android device such as name,cpu,memory,and also power comsumption.
79 echo `$ADB -s $dev shell cat /system/build.prop |grep ro.product.model | awk -F"=" '{print $2}'`>${dev_info_file}
80 $ADB -s $dev push ${test_res} /sdcard/res
81 $ADB -s $dev shell am start --es path "$xml_file" -n ${apk_main}
82 # check whetehr the app is finished every 2 sec
83 for (( ; ; )); do
84 $ADB -s $dev shell ps | grep ${apk_id}
85 if [ $? -ne 0 ]; then
86 sleep 2
87 $ADB -s $dev shell ps | grep ${apk_id}
88 [ $? -ne 0 ] && break
89 fi
90 sleep 2
91 done
92
93 # kill logcat
94 $ADB -s $dev pull ${xml_file} ${report_file}
95 #delete the res
96 $ADB -s $dev shell rm -rf ${xml_file}
97 $ADB -s $dev shell rm -rf /sdcard/res
98 done
99 }
100 for apk in ${apk_name};do
101 run_apk $apk;
102 if [ $? -ne 0 ]
103 then
104 echo There is something wrong happened when run ${apk_name}
105 exit 1
106 else
107 echo Finished unit test on android
108 echo The test result is at ./android/report/xxx.xml
109 echo xxxxxxxxxxxxxxxAndroid unittest Endxxxxxxxxxxxxxxxx
110 fi
111 done
112