Monkey测试
描述:实现monkey24h持续测试,持续抓取日志,测试指定包名
一、实现monkey24h持续测试
使用shell语言,循环执行monkey命令,写入到txt文件,保存格式为monkey.sh。随后push推入到待测设备,通过shell命令运行文件,实现24h持续测试
1.准备monkey.sh文件
echo "\n******************monkey start********************"
while true
do
monkey --throttle 300 --pkg-whitelist-file /ota_download/whitelist.txt --pct-appswitch 10 --pct-touch 50 --pct-motion 30 --pct-pinchzoom 10 --ignore-timeouts --ignore-security-exceptions --monitor-native-crashes --ignore-crashes -v -v -v 10000
sleep 2
done
2.推入文件
adb push monkey.sh ota_download
3.执行文件
cd 到ota_download 路径下执行命令nohup ./monkey.sh &
此时便实现24h持续monkey测试
二、实现monkey测试同时抓取日志
同样使用shell语言,循环copy日志到指定路径保存。这里我准备了三个文件cplog.sh,dmabuf_dump,dump_info.sh
1.准备cplog.sh
#!/bin/sh
while true; do
echo "\n******************cp log******************** at $(date)"
cp ../data/vstgloballogcontrol ./ -r
cp ../data/anr ./ -r
cp ../data/tombstones ./ -r
rm -rf /data/vstgloballogcontrol/TencentFiles
rm -rf /data/vstgloballogcontrol/vrLog
rm -rf /data/vstgloballogcontrol/GNSS
sync
sleep 1800
done
2.准备dmabuf_dump
已上传资源文件
3.准备dump_info.sh
#!/bin/sh
<<'COMMENT'
Shmem: 2160 kB -> MEMINFO_SHMEM @
SUnreclaim: 333136 kB -> MEMINFO_SLAB_UNRECLAIMABLE @
KernelStack: 12496 kB -> MEMINFO_KERNEL_STACK @
PageTables: 21204 kB -> MEMINFO_PAGE_TABLES @
VmallocUsed: 182700 kB -> MEMINFO_VMALLOC_USED @
COMMENT
tar_file="/ota_download/"`date +%H%M`"_mem_res.csv"
TOP_NAME="top"
ZONEINFO_NAME="zoneinfo"
MEMINFO_NAME="meminfo"
SURFACE_NAME="surfaceflinger"
WINDOW_NAME="window"
INPUT_NAME="input"
PROCRANK_NAME="procrank"
DUMPSYS_MEMINFO_NAME="dumpsys_meminfo"
SS_NAME="ss"
PS_NAME="ps"
DMABUF_LOG_NAME="dmabuf"
FILE_PRE_STRING="log"
TIME=`date +%Y-%m-%d-%H-%M-%S`
top_log_file=${TOP_NAME}_${FILE_PRE_STRING}.txt
zoneinfo_log_file=${ZONEINFO_NAME}_${FILE_PRE_STRING}.txt
meminfo_log_file=${MEMINFO_NAME}_${FILE_PRE_STRING}.txt
surfaceflinger_log_file=${SURFACE_NAME}_${FILE_PRE_STRING}.txt
window_log_file=${WINDOW_NAME}_${FILE_PRE_STRING}.txt
input_log_file=${INPUT_NAME}_${FILE_PRE_STRING}.txt
procrank_log_file=${PROCRANK_NAME}_${FILE_PRE_STRING}.txt
dumpsys_meminfo_log_file=${DUMPSYS_MEMINFO_NAME}_${FILE_PRE_STRING}.txt
dmabuf_log_file=${DMABUF_LOG_NAME}_${FILE_PRE_STRING}.txt
ss_log_file=${SS_NAME}_${FILE_PRE_STRING}.txt
ps_log_file=${PS_NAME}_${FILE_PRE_STRING}.txt
rm ${top_log_file}
rm ${zoneinfo_log_file}
rm ${meminfo_log_file}
rm ${surfaceflinger_log_file}
rm ${window_log_file}
rm ${input_log_file}
rm ${procrank_log_file}
rm ${dumpsys_meminfo_log_file}
rm ${ss_log_file}
rm ${ps_log_file}
rm ${dmabuf_log_file}
while true
do
echo "\n******************top info********************" >> ${top_log_file}
echo $(date +%Y-%m-%d\ %H:%M:%S) >> $top_log_file
top -n 1 -m 200 -s 6 >> ${top_log_file}
echo "\n******************zoneinfo********************" >> ${zoneinfo_log_file}
echo $(date +%Y-%m-%d\ %H:%M:%S) >> $zoneinfo_log_file
cat /proc/zoneinfo >> ${zoneinfo_log_file}
echo "\n******************meminfo********************" >> ${meminfo_log_file}
echo $(date +%Y-%m-%d\ %H:%M:%S) >> $meminfo_log_file
cat /proc/meminfo >> ${meminfo_log_file}
echo "\n******************SurfaceFlinger********************" >> ${surfaceflinger_log_file}
echo $(date +%Y-%m-%d\ %H:%M:%S) >> $surfaceflinger_log_file
dumpsys SurfaceFlinger >> ${surfaceflinger_log_file}
echo "\n******************window********************" >> ${window_log_file}
echo $(date +%Y-%m-%d\ %H:%M:%S) >> $window_log_file
dumpsys window -a >> ${window_log_file}
echo "\n******************input********************" >> ${input_log_file}
echo $(date +%Y-%m-%d\ %H:%M:%S) >> $input_log_file
dumpsys input >> ${input_log_file}
echo "\n******************ss********************" >> ${ss_log_file}
echo $(date +%Y-%m-%d\ %H:%M:%S) >> $ss_log_file
ss -arp >> ${ss_log_file}
echo "\n******************ps********************" >> ${ps_log_file}
echo $(date +%Y-%m-%d\ %H:%M:%S) >> $ps_log_file
ps -AT >> ${ps_log_file}
echo "\n******************procrank********************" >> ${procrank_log_file}
echo $(date +%Y-%m-%d\ %H:%M:%S) >> $procrank_log_file
procrank -u >> ${procrank_log_file}
echo "\n******************dumpsys meminfo********************" >> ${dumpsys_meminfo_log_file}
echo $(date +%Y-%m-%d\ %H:%M:%S) >> $dumpsys_meminfo_log_file
dumpsys meminfo >> ${dumpsys_meminfo_log_file}
echo "\n******************dmabuf info********************" >> ${dmabuf_log_file}
echo $(date +%Y-%m-%d\ %H:%M:%S) >> $dmabuf_log_file
./dmabuf_dump >> ${dmabuf_log_file}
sleep 10
done
#echo "Shmem,SUnreclaim,KernelStack,PageTables,VmallocUsed,ION, calculate_total, dumpsys_meminfo_total" | tee ${tar_file}
4.推入文件
adb push cplog.sh ota_download
adb push dmabuf_dump ota_download
adb push dump_info.sh ota_download
5.执行文件
cd 到ota_download 路径下分别执行命令
nohup ./cplog.sh &
nohup ./dump_info.sh &
此时便实现monkey测试时同步抓取日志
三、测试指定包名
1.通过添加白名单即可。准备whitelist.txt文件
com.android.visteon.automatic_parking
com.android.visteon.avm
com.android.visteon.hvac
com.iflytek.autofly.avatar
com.iflytek.autofly.map
com.iflytek.cutefly.speechclient.hmi
com.kika.car.inputmethod
com.njda.carplay
com.tencent.mm
com.tencent.wecar
com.tencent.wecarflow
com.tencent.wecarnavi
com.txznet.ai.handbook
com.tencent.wecar.karaoke
com.txznet.txz
com.visteon.android.carplaycontroller
com.visteon.health
com.visteon.launcher
com.ts.cockpit.parking
com.ts.cockpit.dmsservice
com.txznet.ai.handbook
com.visteon.smartscene
com.visteon.systemsettings
com.visteon.txzing.accountcenter
com.visteon.txzing.appstore
com.visteon.txzing.btphone
com.visteon.txzing.ecall
com.visteon.txzing.familytime
com.visteon.txzing.iqiyi
com.visteon.txzing.media
com.visteon.txzing.photovideo
com.visteon.txzing.safe
com.visteon.txzing.screensaver
com.visteon.vehiclesettings
com.visteon.vtwox
2.推送文件
adb push whitelist.txt ota_download
此时便实现测试指定包
四、结束monkey
切断电源或者
重新打开一个cmd窗口
1.adb shell
2.top | grep monkey
这时可以看到monkey测试的id
3.adb shell
4.kill id
五、拷贝日志
adb pull /ota_download C:\monkey_log
六、分析日志
通常需要关注的日志有1.anr文件 2.crash.log文件
crash.sh里搜索process来筛选所有出现crash包名和时间点
根据时间点找到对应的main文件
注意:
1.monkey测试前同步设备时间到北京时间
2.删除旧日志rm -rf *
3.先执行拷贝日志文件,最后执行运行monkey文件
4.monkey测试报告模板