• 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"
6mkdir -p ${AUTO_TEST_RES_PATH}
7#Prepare android build enviroment
8echo please set the enviroment variable as:
9echo export ANDROID_HOME="path of android sdk"
10echo export ANDROID_NDK_HOME="path of android ndk"
11ANDROID_SDK_PATH=${ANDROID_HOME}
12ANDROID_NDK_PATH=${ANDROID_NDK_HOME}
13ANDROID_MAKE_PARAMS="OS=android NDKROOT=${ANDROID_NDK_PATH} TARGET=android-19"
14
15if [ "#${ANDROID_SDK_PATH}" = "#" ]
16then
17echo Please set ANDROID_HOME with the path of Android SDK
18exit 1
19fi
20if [ "#${ANDROID_NDK_PATH}" = "#" ]
21then
22echo Please set ANDROID_NDK_HOME with the path of Android NDK
23exit 1
24fi
25#make build
26cd ${AUTO_TEST_SRC_PATH}
27find ./ -name *.o -exec rm -f {} \;
28find ./ -name *.d -exec rm -f {} \;
29make $ANDROID_MAKE_PARAMS
30
31if [ $? -ne 0 ]
32then
33   echo Build error,check with the trace of make
34   exit 1
35fi
36
37ENCDEC=$1
38#find apk
39if [ ${ENCDEC} = "enc" ]
40then
41echo Start to find enc apk
42apk_name=`find ./ -name WelsEncTest-debug.apk`
43if [ "#${apk_name}" = "#" ]
44then
45  echo Fail to find encoder APK.
46  exit 1
47fi
48else
49echo Start to find dec apk
50apk_name=`find ./ -name WelsDecTest-debug.apk`
51if [ "#${apk_name}" = "#" ]
52then
53echo Fail to find decoder APK.
54exit 1
55fi
56fi
57
58#prepare devices
59ADB=${ANDROID_SDK_PATH}/platform-tools/adb
60
61#get devices
62devices=`$ADB devices | awk -F" " '/\tdevice/{print $1}'`
63if [ "#$devices" = "#" ];then
64   echo "Have not any android devices."
65   exit 1
66fi
67
68#run apk
69run_apk() {
70local apk=$1;
71local rand=` date +%s`
72
73if [[ "${apk}" =~ "WelsDecTest-debug.apk" ]]
74then
75   apk_id="com.wels.dec"
76   apk_main="com.wels.dec/.WelsDecTest"
77   test_path="/sdcard/welsdec"
78   log_grep_params="welsdec"
79   test_res=${AUTO_TEST_ANDROID_PATH}/../DecoderPerfTestRes
80   report_file=${AUTO_TEST_RES_PATH}/decPerf
81
82fi
83if [[ "${apk}" =~ "WelsEncTest-debug.apk" ]]
84then
85  apk_id="com.wels.enc"
86  apk_main="com.wels.enc/.WelsEncTest"
87  test_path="/sdcard/welsenc"
88  log_grep_params="welsenc"
89  test_res=${AUTO_TEST_ANDROID_PATH}/../EncoderPerfTestRes
90  report_file=${AUTO_TEST_RES_PATH}/encPerf
91fi
92space="limit"
93for dev in $devices; do
94    dev_info_file=${AUTO_TEST_RES_PATH}/${dev}.log
95    $ADB -s $dev uninstall ${apk_id}
96    $ADB -s $dev install -r ${apk}
97    #TODO: output more info about android device such as name,cpu,memory,and also power comsumption.
98    #echo `$ADB -s $dev shell cat /system/build.prop |grep ro.product.model | awk -F"=" '{print $2}'`>${dev_info_file}
99    #push resources
100    #For limited devices space
101    if [ ${space} = "limit" ]
102    then
103    test_res_bak=${test_res}_bak
104    mv ${test_res} ${test_res_bak}
105    mkdir -p ${test_res}
106    test_case=`ls ${test_res_bak}`
107    for case in ${test_case}
108    do
109       echo ${case}
110        cp -r ${test_res_bak}/${case} ${test_res}/.
111        $ADB -s $dev push ${test_res} ${test_path}
112        #before start logcat,kill logcat
113        pid=`$ADB -s $dev shell ps | grep logcat | awk '{print $2;}'`
114        [ "#$pid" != "#" ] && $ADB -s $dev shell kill $pid >/dev/null
115        $ADB -s $dev logcat -c
116        $ADB -s $dev logcat |grep ${log_grep_params} >>${report_file}_${dev}_${rand}.log &
117        $ADB -s $dev shell am start -n ${apk_main}
118        # check whetehr the app is finished every 2 sec
119        for (( ; ; )); do
120            $ADB -s $dev shell ps | grep ${apk_id}
121            if [ $? -ne 0 ]; then
122                sleep 2
123                $ADB -s $dev shell ps | grep ${apk_id}
124                [ $? -ne 0 ] && break
125            fi
126            sleep 2
127        done
128
129        # kill logcat
130        pid=`$ADB -s $dev shell ps | grep logcat | awk '{print $2;}'`
131        [ "#$pid" != "#" ] && $ADB -s $dev shell kill $pid >/dev/null
132
133        #delete the res
134        $ADB -s $dev shell rm -rf ${test_path}
135        rm -rf ${test_res}/${case}
136    done
137    rm -rf ${test_res}
138    mv ${test_res_bak} ${test_res}
139    else
140    $ADB -s $dev push ${test_res} ${test_path}
141    #before start logcat,kill logcat
142    pid=`$ADB -s $dev shell ps | grep logcat | awk '{print $2;}'`
143    [ "#$pid" != "#" ] && $ADB -s $dev shell kill $pid >/dev/null
144    $ADB -s $dev logcat -c
145    $ADB -s $dev logcat |grep ${log_grep_params} >${report_file}_${dev}_${rand}.log &
146    $ADB -s $dev shell am start -n ${apk_main}
147    # check whetehr the app is finished every 2 sec
148    for (( ; ; )); do
149    $ADB -s $dev shell ps | grep ${apk_id}
150    if [ $? -ne 0 ]; then
151        sleep 2
152        $ADB -s $dev shell ps | grep ${apk_idi}
153        [ $? -ne 0 ] && break
154    fi
155    sleep 2
156    done
157
158    # kill logcat
159    pid=`$ADB -s $dev shell ps | grep logcat | awk '{print $2;}'`
160    [ "#$pid" != "#" ] && $ADB -s $dev shell kill $pid >/dev/null
161
162    #delete the res
163    $ADB -s $dev shell rm -rf ${test_path}
164    fi
165
166done
167}
168for apk in ${apk_name};do
169   run_apk $apk;
170   if [ $? -ne 0 ]
171   then
172     echo There is something wrong happened when run ${apk_name}
173     exit 1
174   else
175     echo Finished $ENCDEC performance test on android
176     echo The test result is at ./android/report/xxx.log
177     echo xxxxxxxxxxxxxxxAndroid $ENCDEC Endxxxxxxxxxxxxxxxx
178   fi
179done
180
181