date: 2019-12-19
email: panzh8266@163.com
github: https://github.com/Jess-Pan
1. monkey 跑测常见问题
monkey跑测一般会发生在硬件更换物料(内存、存储)后,需要进行一次跑测来确认物料的稳定性,提供该料是否可以用于生产的依据。作为系统软件开发,需要协助测试分析log文件内容,着重关注系统核心服务的存活状态、输出log是否为乱码、kernel层的报错等等会导致系统关机、重启、卡死等现象的问题
1.1 手机断电
- kernel_log 中会有如下报错
<12>[22737.747509] (2)[278:health@2.0-serv]healthd: battery l=0 v=3084 t=37.0 h=2 st=2 c=2042 fc=1397000 cc=0 chg=u
1.2 大量核心服务死亡
-
main_log 中可以看到大段的核心服务死亡,一般为系统进程崩溃,watchdog自发的重启服务,伴随着有预兆的重启
01-01 16:46:23.909 203 203 I ServiceManager: service 'sim_manager' died 01-01 16:46:23.909 203 203 I ServiceManager: service 'content' died 01-01 16:46:23.909 203 203 I ServiceManager: service 'powerguru' died 01-01 16:46:23.909 203 203 I ServiceManager: service 'sensorservice' died 01-01 16:46:23.909 203 203 I ServiceManager: service 'power' died 01-01 16:46:23.909 203 203 I ServiceManager: service 'gfxinfo' died 01-01 16:46:23.909 203 203 I ServiceManager: service 'permission' died 01-01 16:46:23.909 203 203 I ServiceManager: service 'telephony.registry' died 01-01 16:46:23.909 203 203 I ServiceManager: service 'telephony.registry0' died 01-01 16:46:23.909 203 203 I ServiceManager: service 'procstats' died 01-01 16:46:23.909 203 203 I ServiceManager: service 'bluetooth_manager' died
1.3 异常掉电
- 所谓异常掉电就是电池在操作过程中突然掉落,或者电源接线处本身接触不良
- 测试现象突兀,使用过程中突然黑屏(关机 / 黑屏卡死 / 重启),重启的主要原因为硬件可能做了掉电保护,让系统重启;若是没有做掉电保护现象一般不包括重启,不同的测试人员对该现象描述不同,还需要进行现场确认
- 判断方式
- main_log 中没有关机预兆,没有系统服务大量死亡现象
- kernel_log 同样没有关机预兆,没有
panic
,没有error
1.4 watchdog 引起的系统重启
watchdog 本身分为硬件看门狗和软件看门狗,我们正常看到的属于软件看门狗的范畴,它会在system_server发生死锁、程序跑飞时,杀死系统进程,然后重新启动system_server,让系统从不正常的状态回到工作状态中。这个过程我们称为软件重启,这个过程会输出一些制式的log
当然,偶尔也会看到硬件看门狗,log输出信息类似,但是会明显看到有关于内存地址的报错,出现这样的问题需要联系硬件确定问题报错点。
软件重启:重启核心服务,不涉及kernel层,上层应用重新启动但是下层依然在运行
硬件重启:kernel层重启,断电重启
-
kernel_log 中可以找到类似log
04ECE5 01-02 13:02:55.657 1813 2072 W Watchdog: *** WATCHDOG KILLING SYSTEM PROCESS: Blocked in handler on PackageManager (PackageManager) 04ECE6 01-02 13:02:55.657 1813 2072 W Watchdog: PackageManager stack trace: 04ECE7 01-02 13:02:55.658 1813 2072 W Watchdog: at android.os.BinderProxy.transactNative(Native Method) 04ECE8 01-02 13:02:55.658 1813 2072 W Watchdog: at android.os.BinderProxy.transact(Binder.java:790)
1.5 kernel 层报错
- kernel_log / last_kmsg 会找到类似log
[29125.251579] -(2)[95:hps_main]---[ end trace f42e54c6cd9c9843 ]---
[29125.809523] -(2)[95:hps_main]Kernel panic - not syncing: Fatal exception
[29128.972461] -(2)[95:hps_main]SMP: failed to stop secondary CPUs
这种报错属于驱动层面报错,需要联系驱动定位报错位置
1.6 log中出现大量乱码
- 这个判断条件需要首先排除
- 异常断电造成的乱码,一般乱码位置为文件末尾
- 网络数据传输输出的乱码,因为输出传输一般为字节流,输出即为乱码
- 一些加密的log输出
1.7 monkey启动关机流程
- 一般我们可以在monkey_log中看到 log
// Allowing start of Intent { act=com.android.internal.intent.action.REQUEST_SHUTDOWN cmp=android/com.android.internal.app.ShutdownActivity } in package android
//[calendar_time:2019-01-01 23:36:25.452 system_uptime:40971637]
2. 手动测试常见问题
2.1 硬件功能问题
- 确认跑测前该功能是否正常
- 确认硬件是否安装
2.2 重载测试,应用失去响应
- 小内存手机,重载anr属于正常现象
- 从log中需要观察发生anr时间段的后台任务
3.3 突然关机
- 异常掉电
3. 附上测试常用的monkey命令
3.1 monkey 系统跑测 (忽略报错)
adb shell "monkey
-p com.google.android.calendar
-p com.mediatek.camera
-p com.android.chrome
-p com.android.deskclock
-p com.android.contacts
-p com.facebook.katana
-p com.google.android.apps.nbu.files
-p com.android.gallery3d
-p com.google.android.gm.lite
-p com.google.android.talk
-p com.instagram.android
-p jp.naver.line.android
-p com.google.android.apps.mapslite
-p com.google.android.apps.messaging
-p com.android.music
-p com.android.dialer
-p com.android.vending
-p com.tencent.mobileqq
-p com.android.settings
-p com.skype.raider
-p com.tencent.mm
-p com.whatsapp
-p com.twitter.android
-p com.google.android.apps.youtube.mango
-p com.android.soundrecorder
-p com.google.android.play.games
--throttle 200 --ignore-crashes --ignore-timeouts --ignore-security-exceptions -v 10000000 > /sdcard/monkey.log"
3.2 单个应用跑测(不忽略错误)
adb shell "monkey -p com.mediatek.camera --throttle 200 -v 10000000 > /sdcard/monkey.log"
3.3 个人常用跑monkey脚本
#!/bin/bash
readonly time=$(date "+%Y%m%d%H%M")
readonly defaultCount=100000
readonly defaultTypeOne="--throttle 200 --ignore-crashes --ignore-timeouts --ignore-security-exceptions"
readonly defaultTypeTwo="--throttle 200"
readonly defaultlogUrl="${HOME}/Desktop/${time}"
readonly defaultlogUrl_SDcard="/sdcard/monkey_log.txt"
read -p "please input packages name: " packages
if [[ -z ${packages} ]]; then
# null
echo "未指定跑测应用包名"
exit
fi
echo "packages : ${packages}"
echo
read -p "please input monkey count: " inputCount
if [[ -z ${inputCount} ]]; then
count=${defaultCount}
echo "default count : ${defaultCount}"
else
count=${inputCount}
echo "count : ${count}"
fi
echo
read -p "please choose monkey test type \
1. ${defaultTypeOne} \
2. ${defaultTypeTwo} : " inputType
if [[ -z ${inputType} ]]; then
type=${defaultTypeOne}
echo "default type : ${type}"
elif [[ ${inputType} -eq 1 ]]; then
type=${defaultTypeOne}
echo "default type : ${type}"
elif [[ ${inputType} -eq 2 ]]; then
type=${defaultTypeTwo}
echo "default type : ${type}"
else
echo "error !"
fi
echo
read -p "please choose space for monkey_log \
1. ${defaultlogUrl} \
2. ${defaultlogUrl_SDcard}: " logUrl
if [[ ${logUrl} -eq 1 ]]; then
logUrl=${defaultlogUrl}
elif [[ logUrl -eq 2 ]]; then
logUrl=${defaultlogUrl_SDcard}
echo "logUrl : ${defaultlogUrl-SDcard}"
read -p "Are you sure to continue? [y/n] " continue
case ${continue} in
[yY]*)
adb shell "monkey ${packages} ${type} -v ${count} > ${logUrl}"
exit
;;
[nN]*)
echo exit
;;
*)
echo "Just"
exit
;;
esac
else
echo "input error!"
exit
fi
echo "logUrl = ${logUrl}"
echo
read -p "Are you sure to continue? [y/n] " continue
case $continue in
[yY]*)
if [ ! -d ${logUrl} ]; then
mkdir -p ${logUrl}
echo "目标文件夹不存在,创建目录 : ${logUrl}"
else
echo "目标文件夹存在"
fi
adb shell monkey -p ${packages} ${type} -v ${count} 2>&1 | tee ${logUrl}/monkey_log.txt
;;
[nN]*)
echo exit
;;
*)
echo "Just input n(N) or y(Y)"
exit
;;
esac
3.4 打断monkey脚本
#!/bin/bash
monkey_pid=`adb shell ps -ef | grep monkey | grep -v "grep" | awk '{print $2}'`
echo "monkey_pid = ${monkey_pid}"
if [[ -z ${monkey_pid} ]]; then
echo "没有monkey在执行"
else
adb shell kill ${monkey_pid}
echo "kill sucessfully"
fi