def monkey_app(): status_shebei = huoqushebeizhuangtai() if status_shebei == 'device': try: packname = baoming_t1.get('0.0', END).split()[0] zhongzi = zhongzi_t.get('0.0', END).split()[0] time = time_t.get().split()[0] touch = touch_t.get('0.0', END).split()[0] huadong = huadong_t.get('0.0', END).split()[0] guiji = guiji_t.get('0.0', END).split()[0] xitong = xitong_t.get('0.0', END).split()[0] acti = acti_t.get('0.0', END).split()[0] event = event_t.get('0.0', END).split()[0] log = log_t.get('0.0', END).split()[0] danghang = danghang_t.get('0.0', END).split()[0] if len(packname) <= 5: LOG.info('请正确填写包名') messagebox.showwarning('提醒', '请正确填写包名') if int(touch) + int(huadong) + int(guiji) + int(danghang) + int( xitong) + int(acti) > 100: messagebox.showerror('提醒', '您输入的所有的事件的比例和不能超过100%') LOG.info('您输入的所有的事件的比例和不能超过100') adb_monkey(packagename=packname, s_num=zhongzi, throttle=time, pct_touch=touch, pct_motion=huadong, pct_trackball=guiji, pct_nav=danghang, pct_syskeys=xitong, pct_appswitch=acti, num=event, logfilepath=log) except: messagebox.showwarning('警告', '必须填写monkey相关数据') LOG.info('monkey 测试出错,原因:%s' % Exception) else: LOG.info('设备连接异常 请重新连接设备!') messagebox.showwarning('警告', '设备连接异常 请重新连接设备!')
def teread_cpu(): t3 = threading.Thread(target=qidongapp, args=()) t3.start() t3.join() if not t3.is_alive(): time.sleep(5) # threads = [] # t1 = threading.Thread(target=monkey_app, args=()) # t2 = threading.Thread(target=cpu_app, args=()) # threads.append(t1) # threads.append(t2) # for th in threads: # th.start() # th.join() monkey_app() time.sleep(5) cpu_app() LOG.info('线程执行完成') if __name__ == '__main__': LOG.info('测试小程序开始启动!测试开启!') try: status_shebei = huoqushebeizhuangtai() if status_shebei == 'device': teread_cpu() else: LOG('设备未连接或者连接异常!目前连接状态:%s' % status_shebei) except Exception as e: LOG.info('测试异常,原因:%s' % e)
def cpu_app(): status_shebei = huoqushebeizhuangtai() if status_shebei == 'device': xingneng_bao = xingneng_baoming.get('0.0', END).split()[0] xing = xing_t.get() if len(xingneng_bao) <= 5: LOG.info('包名必须真实有效') messagebox.showwarning('警告', '请检查您的包名') cishu_list = [] cpu_list = [] rescv_list = [] send_list = [] total_list = [] pass_list = [] i = 0 for i in range(int(xing)): nen_cun = getnencun(xingneng_bao) rescv, send, liulang_sum = liulang(xingneng_bao) cpu_caiji = caijicpu(xingneng_bao) neicun_t['state'] = 'normal' pass_list.append((nen_cun)) neicun_t.insert(tkinter.END, ('Pass值:%s' % nen_cun)) LOG.info('第%s次:Pass:%s' % (i, nen_cun)) neicun_t.insert(tkinter.END, '\n') neicun_t.see(END) neicun_t['state'] = 'disabled' cpu_t['state'] = 'normal' cpu_list.append((cpu_caiji.split('%')[0])) cpu_t.insert(tkinter.END, ('CPU占有率:%s' % cpu_caiji)) LOG.info('第%s次:CPU占用率:%s' % (i, cpu_caiji)) cpu_t.insert(tkinter.END, '\n') cpu_t.see(END) cpu_t['state'] = 'disabled' liulang_t['state'] = 'normal' total_list.append((liulang_sum)) rescv_list.append((rescv)) send_list.append((send)) liulang_t.insert(tkinter.END, ('总流量:%sk,上传流量:%sk,下载流量:%sk' % (liulang_sum, rescv, send))) LOG.info('第%s次:总流量:%sk,上传流量:%sk,下载流量:%sk' % (i, liulang_sum, rescv, send)) liulang_t.insert(tkinter.END, '\n') liulang_t.see(END) liulang_t['state'] = 'disabled' xingneng_btn['state'] = 'disabled' i += 1 cishu_list.append(int(i)) getcpu(cishu=cishu_list, start_cpu=cpu_list, recv_list=rescv_list, send_list=send_list, total_list=total_list, Pass_list=pass_list) xingneng_btn['state'] = 'normal' LOG.info('测试完成') messagebox.showinfo('提醒', '测试完毕,测试报告已经生成!') else: LOG.info('测试的设备必须正常连接,请注意') messagebox.showwarning('警告', '设备连接异常 请重新连接设备!')
def qidongapp(): start_tim = [] cishu = [] status_shebei = huoqushebeizhuangtai() if status_shebei == 'device': try: packname = baoming_t.get('0.0', END) acti = activ_t.get('0.0', END) cish = cishu_ac.get() except: LOG.info('获取不到测试数据,请检查!') messagebox.showinfo('提醒', '获取不到测试数据,请检查!') if len(acti) <= 1 or len(packname) <= 1: messagebox.showinfo('提醒', '包命或者包名activity不能为空') LOG.info('包命或者包名activity不能为空') else: if len(cish) <= 1: messagebox.showinfo('提醒', '次数不能为空') LOG.info('次数不能为空') else: i = 0 e1['state'] = 'normal' e1.delete(1.0, tkinter.END) sum = 0 for i in range(int(cish)): start_time = starttime_app(packagename=packname, packagenameactivicy=acti) start_tim.append(int(start_time[1])) cishu.append(i) if start_time is None: messagebox.showwarning('警告', '请检查您输入的包或者包的启动activity') break text = '第%s次启动时间:%s' % (i + 1, start_time[1]) LOG.info('第%s次启动时间:%s' % (i + 1, start_time[1])) sum += int(start_time[1]) e1['state'] = 'normal' e1.insert(tkinter.END, text) e1.insert(tkinter.END, '\n') e1.see(END) btn_start['state'] = 'disabled' e1.insert(tkinter.END, ('平均用时:%s' % (sum / int(cish)))) LOG.info(('平均用时:%s' % (sum / int(cish)))) qidongceshi(cishu=cishu, start=start_tim) messagebox.showinfo('提示', '测试报告已经生成,请到当前目录查看') LOG.info('测试报告已经生成,请到当前目录查看') e1['state'] = 'disabled' btn_start['state'] = 'normal' messagebox.showinfo('通知', '测试已经完成') LOG.info('测试已经完成') else: messagebox.showerror('警告', '设备连接异常') LOG.info('设备连接异常')
@logger('次用线程来启动测试!采集cpu占用率,上传下载流量,内存') def teread(): #如果不是ui界面,可以不用线程 for i in range(1): t = threading.Thread(target=cpu_app, args=()) t.start() @logger('启动app时间线程测试') def teread_start(): #如果不用ui界面,可以不用线程 for i in range(1): t = threading.Thread(target=qidongapp, args=()) t.start() if __name__ == '__main__': LOG.info('测试小程序开始启动!测试开启!') try: status_shebei = huoqushebeizhuangtai() if status_shebei == 'device': root = tkinter.Tk() root.title('雷子的安卓adb小工具') # root.geometry("1000x900") # root.resizable(width=False, height=False) tkinter.Label( root, text='性能参数展示', fg='red', font=("黑体", 15, "bold"), ).grid(row=0, column=3) cpu_t = tkinter.Text(root, height=5, width=30) cpu_t.grid(row=1, column=2)