• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3AUTO_TEST_ANDROID_PATH=`pwd`
4AUTO_TEST_SRC_PATH="../../../"
5AUTO_TEST_RES_PATH="${AUTO_TEST_ANDROID_PATH}/report"
6if [ ! -d ${AUTO_TEST_RES_PATH} ]
7then
8mkdir -p ${AUTO_TEST_RES_PATH}
9else
10echo "Will delete those outdate xml in the report"
11rm -f ${AUTO_TEST_RES_PATH}/*.xml
12fi
13#Prepare android build enviroment
14echo please set the enviroment variable as:
15echo export ANDROID_HOME="path of android sdk"
16echo export ANDROID_NDK_HOME="path of android ndk"
17ANDROID_SDK_PATH=${ANDROID_HOME}
18ANDROID_NDK_PATH=${ANDROID_NDK_HOME}
19ANDROID_MAKE_PARAMS="OS=android NDKROOT=${ANDROID_NDK_PATH} TARGET=android-19"
20
21if [ "#${ANDROID_SDK_PATH}" = "#" ]
22then
23echo Please set ANDROID_HOME with the path of Android SDK
24exit 1
25fi
26if [ "#${ANDROID_NDK_PATH}" = "#" ]
27then
28echo Please set ANDROID_NDK_HOME with the path of Android NDK
29exit 1
30fi
31#make build
32cd ${AUTO_TEST_SRC_PATH}
33find ./ -name *.o -exec rm -f {} \;
34find ./ -name *.d -exec rm -f {} \;
35make clean
36make $ANDROID_MAKE_PARAMS test
37
38if [ $? -ne 0 ]
39then
40   echo Build error,check with the trace of make
41   exit 1
42fi
43
44#find apk
45echo Start to find unittest apk
46apk_name=`find ./ -name MainActivity-debug.apk`
47if [ "#${apk_name}" = "#" ]
48then
49  echo Fail to find encoder APK.
50  exit 1
51fi
52
53#prepare devices
54ADB=${ANDROID_SDK_PATH}/platform-tools/adb
55
56#get devices
57devices=`$ADB devices | awk -F" " '/\tdevice/{print $1}'`
58if [ "#$devices" = "#" ];then
59   echo "Have not any android devices."
60   exit 1
61fi
62
63#run apk
64run_apk() {
65local apk=$1;
66local rand=` date +%s`
67apk_id="com.cisco.codec.unittest"
68apk_main="com.cisco.codec.unittest/.MainActivity"
69test_path="/sdcard/welsenc"
70log_grep_params="welsenc"
71test_res=./res
72xml_file="sdcard/codec_unittest.xml"
73for 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
98done
99}
100for 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
111done
112
113