kill monkey.py
import StringIO
import subprocess
def main():
output = subprocess.check_output("adb shell ps")
buf = StringIO.StringIO(output)
for line in buf:
if "com.android.commands.monkey" in line:
fragments = line.split()
pid = fragments[1]
subprocess.call("adb shell kill -9 " + pid)
return
if __name__ == '__main__':
main()
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
fd_dump_zs.sh
#!/system/bin/sh
# 20170330 pei
# use by fd_dump_zs.sh process_name
psid=`ps |grep $1 | head -1 | busybox awk '{print $2}'`
while true
do
date >> /sdcard/monkeytest/fd.log
lsof -p $psid >> /sdcard/monkeytest/fd.log
sleep 10
done
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
monkey.py
#-*-coding:utf8-*-
import threading,shutil,re
import os,sys,time,tarfile
from optparse import OptionParser
import linecache
__author__ = 'wushiwen'
def prepare(SN):
time.sleep(1)
os.system("adb -s %s root" % SN)
os.system("adb -s %s remount" % SN)
os.system("adb -s %s shell settings put system screen_off_timeout 27000000" % SN)
time.sleep(1)
os.system("adb -s %s shell rm -rf /sdcard/monkeytest/" % SN)
os.system("adb -s %s shell mkdir /sdcard/monkeytest/" % SN)
os.system('adb -s %s shell am broadcast -a android.intent.action.MEDIA_MOUNTED -d "file:///mnt/sdcard" ' % SN)
os.system("adb -s %s push monkeyAll.sh /data/local/tmp/ " % SN)
os.system("adb -s %s push whitelist.txt /sdcard/ " % SN)
os.system("adb -s %s push monkeyDump.sh /data/local/tmp/ " % SN)
os.system("adb -s %s push fd_dump_zs.sh /data/local/tmp/ " % SN)
os.system("adb -s %s shell chmod 777 /data/local/tmp/monkeyAll.sh " % SN)
os.system("adb -s %s shell chmod 777 /data/local/tmp/monkeyDump.sh " % SN)
os.system("adb -s %s shell chmod 777 /data/local/tmp/fd_dump_zs.sh " % SN)
os.system("adb -s %s shell input swipe 500 1000 500 50 100" % SN)
os.system("adb -s %s shell input swipe 500 1000 500 50 100" % SN)
os.system("adb -s %s shell input swipe 500 1000 500 50 100" % SN)
return True
def search_sn():
command = 'adb devices'
os.system(command)
output = os.popen(command).read()
if 'List of devices attached' in output:
deviceslist = [device.split('\t')[0] for device in output.split('\n')[1:] if device != '']
if len(deviceslist)>0:
print (deviceslist)
return deviceslist
else:
print ('no devices found, script exit')
return False
sys.exit()
else:
print ('adb status error, script exit')
return False
sys.exit(1)
def runMonkey(SN):
os.system("adb -s %s shell sh /data/local/tmp/monkeyAll.sh" % SN)
return
def runDump(SN):
os.system("adb -s %s shell sh /data/local/tmp/monkeyDump.sh" % SN)
return
def batch_flash():
sn_list = search_sn()
workers = []
for sn in sn_list:
workers.append(threading.Thread(target=prepare, args=(sn,)))
for worker in workers:
worker.start()
for worker in workers:
worker.join()
print ('prepare ok')
players = []
for sn in sn_list:
players.append(threading.Thread(target=runMonkey, args=(sn,)))
players.append(threading.Thread(target=runDump, args=(sn,)))
for player in players:
player.start()
time.sleep(1)
for player in players:
player.join()
os.system("adb shell pm list package>whitelist.txt")
f = linecache.getlines('whitelist.txt') #调用文件
filename = 'whitelist.txt'
with open(filename,'w') as f_obj:
for x in f:
y = x.replace('package:','')
if y.find('engineermode') == -1 and y.find('com.mediatek.mtklogger') == -1:
f_obj.write(y)
os.system("adb shell setprop persist.qiku.adb.input 1")
if __name__ == '__main__':
print ('==================================================================')
print (' START monkey ')
print ('============START monkey==============START monkey=============================')
batch_flash()
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
monkeyAll.sh
echo "start monkey"
echo "get log"
logcat -v threadtime > /sdcard/monkeytest/logcat.txt &
logcat -v threadtime -b kernel > /sdcard/monkeytest/kernel.txt &
nohup sh /data/local/tmp/fd_dump_zs.sh system_server > /dev/null &
monkey --pkg-whitelist-file /sdcard/whitelist.txt -s $RANDOM --throttle 300 --bugreport --ignore-crashes --ignore-timeouts --ignore-native-crashes -v -v -v 1000000 2>/sdcard/monkeytest/error.txt 1>/sdcard/monkeytest/info.txt
echo "end monkey"
logcat -d -b radio -v threadtime > /sdcard/monkeytest/radio.txt
logcat -d -b events -v threadtime > /sdcard/monkeytest/events.txt
logcat -d -b system -v threadtime > /sdcard/monkeytest/system.txt
getprop > /sdcard/monkeytest/props.txt
env > /sdcard/monkeytest/env.txt
dmesg > /sdcard/monkeytest/dmesg.txt
cat /proc/last_kmsg > /sdcard/monkeytest/last_kmsg.txt
cat /sys/fs/pstore/console-ramoops > /sdcard/monkeytest/console-ramoops
ps > /sdcard/monkeytest/ps.txt
ps -t > /sdcard/monkeytest/ps_t.txt
top -n 1 -t > /sdcard/monkeytest/top_t.txt
tinymix > /sdcard/monkeytest/tinymix.txt
cat /proc/cmdline > /sdcard/monkeytest/cmdline.txt
ls -lR /data > /sdcard/monkeytest/userdata_check.txt
echo 1 > /proc/sys/kernel/sysrq
echo w > /proc/sysrq-trigger
dmesg > /sdcard/monkeytest/dmesg_sysrq_blocked_tasks.txt
dumpsys power> /sdcard/monkeytest/power.txt
dmesg > /sdcard/monkeytest/dmesg_sysrq.txt
echo "getting screenshot ..."
screencap -p /sdcard/monkeytest/screenshot.png
echo "getting bugreport ... "
bugreport > /sdcard/monkeytest/bugreport.txt
echo "getting dropbox,anr,tombstones,logd...."
cp -fr /data/system/dropbox /sdcard/monkeytest/dropbox
cp -fr /data/anr /sdcard/monkeytest/anr
cp -fr /data/tombstones /sdcard/monkeytest/tombstones
cp -fr /data/misc/logd /sdcard/monkeytest/logd
cp -fr /data/mtklog /sdcard/monkeytest/mtklogs
cp -fr /data/cplc_info /sdcard/monkeytest/cplc
cp -fr /sdcard/logs /sdcard/monkeytest/offlinelogs
cp -fr /sdcard/tcpdump /sdcard/monkeytest/tcpdump
echo "doooooooooone\n"
exit
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
monkeyDump.sh
echo "start dump"
echo "get dump log"
#!/system/bin/sh
while true
do
sleep 80
echo "============`date +%Y_%m_%d-%H-%M-%S`============" >> /sdcard/monkeytest/meminfo.txt
dumpsys meminfo >> /sdcard/monkeytest/meminfo.txt
done
echo "end dump"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
start.bat
python monkey.py
pause
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
导出包名.bat
pause
adb shell pm list package>whitelist.txt
pause
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
设置亮屏.bat
echo 设置时间为
adb shell settings put system screen_off_timeout 999999999
pause
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
F6手机的monkey限制.bat
adb shell setprop persist.qiku.adb.input 1
pause