【Python】设备重启测试

①添加读取键盘输入功能,方便测试者选择压测次数!
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")

转载于:https://www.cnblogs.com/wucaiyun1/p/11018224.html

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值