def start(device):
    devices = device["devices"]
    try:
        num = device["match_num"]
        app = {}
        mkdirInit(devices, app, num)
        # mc = BaseMonkeyConfig.monkeyConfig(PATH("./monkey.ini"))

        mc = BaseMonkeyConfig.monkeyConfig("./monkey.ini")
        # 打开想要的activity
        # ba.open_app(mc["package_name"], mc["activity"], devices) 留着备用可以统计每次打开哪个页面的启动时间等
        # monkey开始测试
        if not os.path.exists('./monkey_log'):
            os.mkdir('./monkey_log')

        mc["log"] = PATH("./monkey_log") + "\\" + str(uuid.uuid4())
        mc["monkey_log"] = mc["log"] + "monkey.log"
        mc["cmd"] = mc['cmd'] + mc["monkey_log"]
        start_monkey(devices, "adb -s " + devices + " shell " + mc["cmd"],
                     mc["log"])
        time.sleep(1)
        starttime = datetime.datetime.now()
        pid = BaseMonitor.get_pid(mc["package_name"], devices)
        cpu_kel = BaseMonitor.get_cpu_kel(devices)
        beforeBattery = BaseMonitor.get_battery(devices)
        while True:
            with open(mc["monkey_log"], encoding='utf-8') as monkeylog:
                time.sleep(1)  # 每1秒采集检查一次
                BaseMonitor.cpu_rate(pid, cpu_kel, devices)
                BaseMonitor.get_men(mc["package_name"], devices)
                BaseMonitor.get_fps(mc["package_name"], devices)
                BaseMonitor.get_flow(pid, mc["net"], devices)
                BaseMonitor.get_battery(
                    devices)  # 上方的beforeBattery和下方afterBattery会使电量列多两行,后面再优化
                if monkeylog.read().count('Monkey finished') > 0:
                    endtime = datetime.datetime.now()
                    # print(str(devices) + "测试完成!")
                    writeSum(1, path=PATH("./info/sumInfo.pickle"))
                    app[devices]["header"]["beforeBattery"] = beforeBattery
                    app[devices]["header"][
                        "afterBattery"] = BaseMonitor.get_battery(devices)
                    app[devices]["header"]["net"] = mc["net"]
                    app[devices]["header"]["monkey_log"] = mc["monkey_log"]
                    app[devices]["header"]["time"] = str(
                        (endtime - starttime).seconds) + "秒"
                    writeInfo(app, PATH("./info/info.pickle"))
                    break
                    # go.info[devices]["header"]["sumTime"] = str((endtime - starttime).seconds) + "秒"
                    # report(go.info)
        if readInfo(PATH("./info/sumInfo.pickle")) <= 0:
            print(readInfo(PATH("./info/info.pickle")))
            report(readInfo(PATH("./info/info.pickle")))
            # subprocess.Popen("taskkill /f /t /im adb.exe", shell=True)
            shutil.rmtree((PATH("./info/")))  # 删除持久化目录
            path = os.path.abspath('./')
            print("\n" + '{0:*^79}'.format('测试完成!') +
                  '\n{0:*^79}'.format('测试报告:' + path))
    except:
        print('>>>Stopping monkey process...')
        stop_monkey(devices)
Beispiel #2
0
def start(devicess):
    devices = devicess["devices"]
    num = devicess["num"]
    app = {}
    mkdirInit(devices, app, num)
    mc = BaseMonkeyConfig.monkeyConfig(PATH("monkey.ini"))
    # 打开想要的activity
    # ba.open_app(mc["package_name"], mc["activity"], devices) 留着备用可以统计每次打开哪个页面的启动时间等
    # monkey开始测试
    mc["log"] = PATH("./log") + "\\" + str(uuid.uuid4())
    mc["monkey_log"] = mc["log"] + "monkey.log"
    mc["cmd"] = mc['cmd'] + mc["monkey_log"]
    start_monkey("adb -s " + devices + " shell " + mc["cmd"], mc["log"])
    time.sleep(1)
    starttime = datetime.datetime.now()
    pid = BaseMonitor.get_pid(mc["package_name"], devices)
    cpu_kel = BaseMonitor.get_cpu_kel(devices)
    beforeBattery = BaseMonitor.get_battery(devices)
    print 'start------------123'
    while True:
        with open(mc["monkey_log"], 'a+') as monkeylog:
            time.sleep(1)  # 每1秒采集检查一次
            print "star()----1"
            BaseMonitor.cpu_rate(pid, cpu_kel, devices)
            BaseMonitor.get_men(mc["package_name"], devices)
            BaseMonitor.get_fps(mc["package_name"], devices)
            print "mc vm :", mc["vm"]
            BaseMonitor.get_flow(pid, mc["vm"], devices)  # 获取流量
            BaseMonitor.get_battery(devices)
            bflag1 = (monkeylog.read().count('Monkey finished') > 0)
            bflag2 = (monkeylog.read().count('Monkey aborted due to error') >
                      0)
            if bflag1 or bflag2:
                endtime = datetime.datetime.now()
                print(str(devices) + "测试完成咯")
                writeSum(1, path=PATH("./info/sumInfo.pickle"))
                app[devices]["header"]["beforeBattery"] = beforeBattery
                app[devices]["header"][
                    "afterBattery"] = BaseMonitor.get_battery(devices)
                app[devices]["header"]["net"] = mc["net"]
                app[devices]["header"]["monkey_log"] = mc["monkey_log"]
                app[devices]["header"]["time"] = str(
                    (endtime - starttime).seconds) + "秒"
                writeInfo(app, PATH("./info/info.pickle"))
                break
                # go.info[devices]["header"]["sumTime"] = str((endtime - starttime).seconds) + "秒"
                # report(go.info)
    if readInfo(PATH("./info/sumInfo.pickle")) <= 0:
        print(readInfo(PATH("./info/info.pickle")))
        report(readInfo(PATH("./info/info.pickle")))  # 这里有问题
        subprocess.Popen("taskkill /f /t /im adb.exe", shell=True)
        # shutil.rmtree((PATH("./info/"))) # 删除持久化目录
        print("------来吧------")
Beispiel #3
0
def start(devicess):
    devices = devicess["devices"]
    print(devices)
    num = devicess["num"]
    print(num)
    app = {}
    print(app)
    mkdirInit(devices, app, num)
    mc = BaseMonkeyConfig.monkeyConfig(PATH("monkey.ini"))
    # 打开想要的activity
    # ba.open_app(mc["package_name"], mc["activity"], devices) 留着备用可以统计每次打开哪个页面的启动时间等
    # monkey开始测试
    mc["log"] = PATH("./log") + "\\" + str(uuid.uuid4())
    mc["monkey_log"] = mc["log"] + "monkey.log"
    mc["cmd"] = mc['cmd'] + mc["monkey_log"]
    start_monkey("adb -s " + devices + " shell " + mc["cmd"], mc["log"])
    time.sleep(1)
    starttime = datetime.datetime.now()
    pid = BaseMonitor.get_pid(mc["package_name"], devices)
    cpu_kel = BaseMonitor.get_cpu_kel(devices)
    beforeBattery = BaseMonitor.get_battery(devices)
    while True:
        with open(mc["monkey_log"], encoding='utf-8') as monkeylog:
            time.sleep(1)  # 每1秒采集检查一次
            BaseMonitor.cpu_rate(pid, cpu_kel, devices)
            BaseMonitor.get_men(mc["package_name"], devices)
            BaseMonitor.get_fps(mc["package_name"], devices)
            BaseMonitor.get_flow(pid, mc["net"], devices)
            BaseMonitor.get_battery(devices)
            if monkeylog.read().count('Monkey finished') > 0:
                endtime = datetime.datetime.now()
                print(str(devices) + "测试完成咯")
                writeSum(1, path=PATH("./info/sumInfo.pickle"))
                app[devices]["header"]["beforeBattery"] = beforeBattery
                app[devices]["header"][
                    "afterBattery"] = BaseMonitor.get_battery(devices)
                app[devices]["header"]["net"] = mc["net"]
                app[devices]["header"]["monkey_log"] = mc["monkey_log"]
                app[devices]["header"]["time"] = str(
                    (endtime - starttime).seconds) + "秒"
                writeInfo(app, PATH("./info/info.pickle"))
                break
                # go.info[devices]["header"]["sumTime"] = str((endtime - starttime).seconds) + "秒"
                # report(go.info)
    if readInfo(PATH("./info/sumInfo.pickle")) <= 0:
        print(readInfo(PATH("./info/info.pickle")))
        report(readInfo(PATH("./info/info.pickle")))
        subprocess.Popen("taskkill /f /t /im adb.exe", shell=True)
Beispiel #4
0
def start(devicess):
    devices = devicess["devices"]
    num = devicess["num"]
    app = {}
    mkdirInit(devices, app, num)
    mc = BaseMonkeyConfig.monkeyConfig(PATH("monkey.ini"))
    # 打开想要的activity
    # ba.open_app(mc["package_name"], mc["activity"], devices) 留着备用可以统计每次打开哪个页面的启动时间等
    # monkey开始测试
    mc["log"] = PATH("./log") + "\\" + str(uuid.uuid4())
    mc["monkey_log"] = mc["log"] + "monkey.log"
    mc["cmd"] = mc['cmd'] + mc["monkey_log"]
    start_monkey("adb -s " + devices + " shell " + mc["cmd"], mc["log"])
    time.sleep(1)
    starttime = datetime.datetime.now()
    pid = BaseMonitor.get_pid(mc["package_name"], devices)
    cpu_kel = BaseMonitor.get_cpu_kel(devices)
    beforeBattery = BaseMonitor.get_battery(devices)
    while True:
        with open(mc["monkey_log"], encoding='utf-8') as monkeylog:
            time.sleep(1)  # 每1秒采集检查一次
            BaseMonitor.cpu_rate(pid, cpu_kel, devices)
            BaseMonitor.get_men(mc["package_name"], devices)
            BaseMonitor.get_fps(mc["package_name"], devices)
            BaseMonitor.get_flow(pid, mc["net"], devices)
            BaseMonitor.get_battery(devices)
            if monkeylog.read().count('Monkey finished') > 0:
                endtime = datetime.datetime.now()
                print(str(devices)+"测试完成咯")
                writeSum(1, path=PATH("./info/sumInfo.pickle"))
                app[devices] ["header"]["beforeBattery"] = beforeBattery
                app[devices]["header"]["afterBattery"] = BaseMonitor.get_battery(devices)
                app[devices]["header"]["net"] = mc["net"]
                app[devices]["header"]["monkey_log"] = mc["monkey_log"]
                app[devices]["header"]["time"] = str((endtime - starttime).seconds) + "秒"
                writeInfo(app, PATH("./info/info.pickle"))
                break
                    # go.info[devices]["header"]["sumTime"] = str((endtime - starttime).seconds) + "秒"
                    # report(go.info)
    if readInfo(PATH("./info/sumInfo.pickle")) <= 0:
        print(readInfo(PATH("./info/info.pickle")))
        report(readInfo(PATH("./info/info.pickle")))
        subprocess.Popen("taskkill /f /t /im adb.exe", shell=True)
Beispiel #5
0
def start(devicess):
    devices = devicess["devices"]
    num = devicess["num"]
    app = {}
    mkdirInit(devices, app, num)
    mc = BaseMonkeyConfig.monkeyConfig(PATH("monkey.ini"))
    now = datetime.datetime.now().strftime('%b-%d-%Y-%H-%M-%S')
    mc["log"] = PATH("./log") + "\\" + now
    mc["monkey_log"] = mc["log"] + "monkey.log"
    mc["cmd"] = mc['cmd'] + mc["monkey_log"]
    start_monkey("adb -s " + devices + " shell " + mc["cmd"], mc["log"])
    time.sleep(1)
    starttime = datetime.datetime.now()
    pid = BaseMonitor.get_pid(mc["package_name"], devices)
    cpu_kel = BaseMonitor.get_cpu_kel(devices)
    beforeBattery = BaseMonitor.get_battery(devices)
    while True:
        with open(mc["monkey_log"], encoding='utf-8') as monkeylog:
            time.sleep(1)  # 每1秒采集检查一次
            BaseMonitor.cpu_rate(pid, cpu_kel, devices)
            BaseMonitor.get_men(mc["package_name"], devices)
            BaseMonitor.get_fps(mc["package_name"], devices)
            BaseMonitor.get_battery(devices)
            if monkeylog.read().count('Monkey finished') > 0:
                endtime = datetime.datetime.now()
                print(str(devices) + "测试完成")
                writeSum(1, path=PATH("./info/sumInfo.pickle"))
                app[devices]["header"]["beforeBattery"] = beforeBattery
                app[devices]["header"][
                    "afterBattery"] = BaseMonitor.get_battery(devices)
                app[devices]["header"]["net"] = mc["net"]
                app[devices]["header"]["monkey_log"] = mc["monkey_log"]
                app[devices]["header"]["time"] = str(
                    (endtime - starttime).seconds) + "秒"
                writeInfo(app, PATH("./info/info.pickle"))
                break
    if readInfo(PATH("./info/sumInfo.pickle")) <= 0:
        print(readInfo(PATH("./info/info.pickle")))
        report(readInfo(PATH("./info/info.pickle")))
        subprocess.Popen("taskkill /f /t /im adb.exe", shell=True)
    # Monkey时手机日志,logcat
    logcatname = log + r"logcat.log"
    cmd2 = "adb logcat -d >%s" % (logcatname)
    os.popen(cmd2)

    #"导出traces文件"
    tracesname = log + r"traces.log"
    cmd3 = "adb shell cat /data/anr/traces.txt>%s" % tracesname
    os.popen(cmd3)


if __name__ == '__main__':
    ba = AdbCommon.AndroidDebugBridge()
    if ba.attached_devices():
        mc = BaseMonkeyConfig.monkeyConfig(PATH("monkey.ini"))
        # 打开想要的activity
        ba.open_app(mc["package_name"], mc["activity"])
        temp = ""

        # monkey开始测试

        start_monkey(mc["cmd"], mc["log"])
        time.sleep(1)
        starttime = datetime.datetime.now()

        while True:
            with open(mc["monkey_log"], encoding='utf-8') as monkeylog:
                BaseMonitor.get_cpu(mc["package_name"])
                BaseMonitor.get_men(mc["package_name"])
                BaseMonitor.get_fps(mc["package_name"])