-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaunchTest.sh
executable file
·165 lines (134 loc) · 4.1 KB
/
launchTest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
# author: gaoqi <gaoqi@changba.com>
case "$(uname -s)" in
Darwin)
INFO(){ echo "$1"; }
WARNING(){ echo "$1"; }
ERROR(){ echo "$1"; }
;;
*)
INFO(){ echo "$1"; }
WARNING(){ echo "$1"; }
ERROR(){ echo "$1"; }
;;
esac
isCommandInPath(){
which $1 &> /dev/null
if [ $? -eq 0 ]; then
echo "true"
else
echo "false"
fi
}
if [[ `isCommandInPath adb` = "false" || `isCommandInPath aapt` = "false" ]]; then
ERROR "please make sure you have added *tools*, *build-tools*, *platform-tools* dirs of android sdk in you PATH environment: $PATH"
exit 1
fi
coldLaunch(){
INFO "start cold launch 3 times"
for i in {1..3}
do
echo "-----第 $i 次冷启动测试-----"
#first forcestop,launch others app,and launch test app
#adb shell am force-stop com.tencent.karaoke
adb shell am force-stop $PackageName
adb shell am start -n com.android.browser/com.android.browser.BrowserActivity>/dev/null 2>&1
#adb shell am start -W com.tencent.mm/com.tencent.mm.ui.LauncherUI>/dev/null 2>&1
sleep 10s
#TotalTime[i]=`adb shell am start -W com.tencent.karaoke/com.tencent.karaoke.module.splash.ui.SplashBaseActivity |grep TotalTime|awk -F ' ' '{print $2}'|tr -d "\r"`
TotalTime[i]=`adb shell am start -W $PackageName/$ActivityName |grep TotalTime|awk -F ' ' '{print $2}'|tr -d "\r"`
sleep 3s
echo ${TotalTime[i]}
done
max=0
for n in "${TotalTime[@]}"
do
((n>max)) && max=$n
done
echo "冷启动峰值:$max ms"
avg=0
sum=$((${TotalTime[1]} + ${TotalTime[2]} + ${TotalTime[3]}))
avg=$[$sum/3]
echo "冷启动均值:$avg ms"
}
warmLaunch(){
INFO "start warm launch 3 times"
for i in {1..3}
do
echo "-----第 $i 次热启动测试-----"
#first forcestop,launch others app,and launch test app
#adb shell am force-stop com.tencent.karaoke
adb shell am start -W $PackageName/$ActivityName>/dev/null 2>&1
adb shell am start -n com.android.browser/com.android.browser.BrowserActivity>/dev/null 2>&1
#adb shell am start -W com.tencent.mm/com.tencent.mm.ui.LauncherUI>/dev/null 2>&1
sleep 10s
#TotalTime[i]=`adb shell am start -W com.tencent.karaoke/com.tencent.karaoke.module.splash.ui.SplashBaseActivity |grep TotalTime|awk -F ' ' '{print $2}'|tr -d "\r"`
TotalTime[i]=`adb shell am start -W $PackageName/$ActivityName |grep TotalTime|awk -F ' ' '{print $2}'|tr -d "\r"`
sleep 3s
echo ${TotalTime[i]}
done
max=0
for n in "${TotalTime[@]}"
do
((n>max)) && max=$n
done
echo "热启动峰值:$max ms"
avg=0
sum=$((${TotalTime[1]} + ${TotalTime[2]} + ${TotalTime[3]}))
avg=$[$sum/3]
echo "热启动均值:$avg ms"
}
firstLaunch(){
echo "start first launch 3 times"
for i in {1..3}
do
echo "-----第 $i 次首次启动测试-----"
uninsallApp
installApp
#first forcestop,launch others app,and launch test app
#adb shell am force-stop com.tencent.karaoke
#TotalTime[i]=`adb shell am start -W com.tencent.karaoke/com.tencent.karaoke.module.splash.ui.SplashBaseActivity |grep TotalTime|awk -F ' ' '{print $2}'|tr -d "\r"`
TotalTime[i]=`adb shell am start -W $PackageName/$ActivityName |grep TotalTime|awk -F ' ' '{print $2}'|tr -d "\r"`
sleep 3s
echo ${TotalTime[i]}
done
max=0
for n in "${TotalTime[@]}"
do
((n>max)) && max=$n
done
echo "热启动峰值:$max ms"
avg=0
sum=$((${TotalTime[1]} + ${TotalTime[2]} + ${TotalTime[3]}))
avg=$[$sum/3]
echo "热启动均值:$avg ms"
}
installApp(){
echo "----重新安装被测APP $PackageName ----"
apps_dir=$(pwd)
echo $apps_dir
adb install $apps_dir/$PackageName.apk
}
uninsallApp(){
echo "-----开始卸载被测App $PackageName-----"
adb uninstall $PackageName
}
echo -n "请输入被测包名:"
read PackageName
echo -n "请输入启动Activity:"
read ActivityName
echo -e "-----请输入测试类型:----- \n 冷启动测试输入1 \n 热启动测试输入2 \n 首次安装启动时间输入3"
read testType
if [[ $testType -eq 1 ]]; then
echo "-----冷启动测试-----"
coldLaunch
elif [[ $testType -eq 2 ]]; then
echo "-----热启动测试-----"
warmLaunch
elif [[ $testType -eq 3 ]]; then
echo "-----首次安装启动测试-----"
firstLaunch
else
ERROR "测试Tpye输入错误"
fi
echo "----测试结束----"