①添加读取键盘输入功能,方便测试者选择压测次数!
Python提供了 input() 内置函数从标准输入读入一行文本,默认的标准输入是键盘。
input 可以接收一个Python表达式作为输入,并将运算结果返回。
例:
#!/usr/bin/python3
str = input("请输入:");
print ("你输入的内容是: ", str)
这会产生如下对应的结果:
请输入:ABCD
你输入的内容是: ABCD
#!/usr/bin/python
# -*- coding: UTF-8 -*-
'''
==============================================================================================
Usage:
This script performs task that pressure test for automatic restart of equipment.
python RebootTest.py
Examples:
python RebootTest.py
==============================================================================================
'''
import os
import time
rebootCount = int(input("请输入重启次数:"));
print ("你输入的次数是: ", rebootCount)
def find_device():
# os.system('adb kill-server')
# os.system('adb start-server')
# os.system('adb root')
# os.system('adb remount')
print("adb devices")
os.system('adb devices')
def reboot():
os.system('adb reboot')
def screen_downup():
os.system('adb shell input keyevent 26')
def power_downup():
os.system('adb shell sendevent /dev/input/event0 1 116 1')
os.system('adb shell sendevent /dev/input/event0 0 0 0')
os.system('adb shell sendevent /dev/input/event0 1 116 0')
os.system('adb shell sendevent /dev/input/event0 0 0 0')
def get_log(name,count):
os.system('adb logcat -t 50000 > '+name+count+'.log')
#重启
for i in range(0,rebootCount):
find_device
screen_downup()
print("screen_down")
time.sleep(5)
screen_downup()
print("screen_up")
time.sleep(5)
print("power_down")
power_downup()
time.sleep(5)
print("power_up")
power_downup()
count=str(i)
get_log(name="reboot",count=count)
print("auto_reboot loop again")
reboot()
print("wait auto_reboot 60s")
time.sleep(60)
print("auto_reboot finish\n")