How to use get_cpuinfo method in Airtest

Best Python code snippet using Airtest

linux_test.py

Source:linux_test.py Github

copy

Full Screen

...90 tools.clear_cache_all()91 def tearDown(self):92 super(TestCPUInfo, self).tearDown()93 tools.clear_cache_all()94 def get_cpuinfo(self, text):95 self.mock(linux, '_read_cpuinfo', lambda: text)96 return linux.get_cpuinfo()97 def test_get_cpuinfo_exynos(self):98 self.assertEqual({99 u'flags': [100 u'edsp',101 u'fastmult',102 u'half',103 u'idiva',104 u'idivt',105 u'neon',106 u'swp',107 u'thumb',108 u'thumbee',109 u'tls',110 u'vfp',111 u'vfpv3',112 u'vfpv4',113 ],114 u'model': (0, 3087, 4),115 u'name':116 u'SAMSUNG EXYNOS5',117 u'revision':118 u'0000',119 u'serial':120 u'',121 u'vendor':122 u'ARMv7 Processor rev 4 (v7l)',123 }, self.get_cpuinfo(EXYNOS_CPU_INFO))124 def test_get_cpuinfo_cavium(self):125 self.assertEqual({126 u'flags': [127 u'aes',128 u'asimd',129 u'atomics',130 u'crc32',131 u'evtstrm',132 u'fp',133 u'pmull',134 u'sha1',135 u'sha2',136 ],137 u'model': (1, 161, 1),138 u'vendor':139 u'N/A',140 }, self.get_cpuinfo(CAVIUM_CPU_INFO))141 def test_get_cpuinfo_mips(self):142 self.assertEqual({143 u'flags': [u'mips2', u'mips3', u'mips4', u'mips5', u'mips64r2'],144 u'name': 'Cavium Octeon II V0.1',145 }, self.get_cpuinfo(MIPS64_CPU_INFO))146 @unittest.skipIf(not sys.platform.startswith('linux'), 'linux only test')147 def test_get_num_processors(self):148 self.assertTrue(linux.get_num_processors() != 0)149K8S_CGROUP = """1508:freezer:/k8s.io/baa2c4c148cc83e36b7f14fe9145c58b742c82b244f77e32cda50cf8f26a27a51517:blkio:/k8s.io/baa2c4c148cc83e36b7f14fe9145c58b742c82b244f77e32cda50cf8f26a27a51526:net_cls:/k8s.io/baa2c4c148cc83e36b7f14fe9145c58b742c82b244f77e32cda50cf8f26a27a51535:memory:/k8s.io/baa2c4c148cc83e36b7f14fe9145c58b742c82b244f77e32cda50cf8f26a27a51544:cpu,cpuacct:/k8s.io/baa2c4c148cc83e36b7f14fe9145c58b742c82b244f77e32cda50cf8f26a27a51553:cpuset:/k8s.io/baa2c4c148cc83e36b7f14fe9145c58b742c82b244f77e32cda50cf8f26a27a51562:devices:/k8s.io/baa2c4c148cc83e36b7f14fe9145c58b742c82b244f77e32cda50cf8f26a27a51571:name=systemd:/k8s.io/baa2c4c148cc83e36b7f14fe9145c58b742c82b244f77e32cda50cf8f26a27a5158"""159NO_K8S_CGROUP = """...

Full Screen

Full Screen

hostinfo.py

Source:hostinfo.py Github

copy

Full Screen

1#!/usr/bin/env python2#coding:utf83from subprocess import Popen,PIPE4import urllib,urllib25import pickle6import json7import re8###[hostname message]#####9def get_HostnameInfo(file):10 with open(file,'r') as fd:11 #data = fd.read().split('\n')12 #for line in data:13 #if line.startswith('HOSTNAME'):14 #hostname = line.split('=')[1]15 #break16 return hostname17#####[ipaddr message]#####18def get_Ipaddr():19 P = Popen(['ifconfig'],stdout=PIPE)20 data = P.stdout.read()21 list = []22 str = ''23 option = False24 lines = data.split('\n')25 for line in lines:26 if not line.startswith(' '):27 list.append(str)28 str = line29 else:30 str += line31 while True:32 if '' in list:33 list.remove('')34 else:35 break36 r_devname = re.compile('(eth\d*|lo)') 37 r_mac = re.compile('HWaddr\s([A-F0-9:]{17})')38 r_ip = re.compile('addr:([\d.]{7,15})')39 for line in list:40 devname = r_devname.findall(line)41 mac = r_mac.findall(line)42 ip = r_ip.findall(line)43 if mac:44 return ip[0]45#####[osversion message]#####46def get_OsVerion(file):47 with open(file) as fd:48 lines = fd.readlines()49 os_version = lines[0][:-8]50 return os_version51#####[memory message]#####52def get_MemoryInfo(file):53 with open(file) as fd:54 data_list = fd.read().split('\n')55 MemTotal_line = data_list[0]56 Memory_K = MemTotal_line.split()[1]57 Memory_G = float(Memory_K)/1000/100058 Memory_G2 = '%.2f' % Memory_G59 memory = Memory_G2 + 'G'60 return memory61#####[disk message]#####62def get_DiskInfo():63 p = Popen(['fdisk','-l'],stdout=PIPE,stderr=PIPE)64 stdout,stderr = p.communicate()65 diskdata = stdout66 disk_initial_size = 067 re_disk_type = re.compile(r'Disk /dev/[shd]{1}.*:\s+[\d.\s\w]*,\s+([\d]+).*')68 disk_size_bytes = re_disk_type.findall(diskdata)69 for size in disk_size_bytes:70 disk_initial_size += int(size)71 disk_size_total_bytes = '%.2f' % (float(disk_initial_size)/1000/1000/1000)72 disk_size_total_G = disk_size_total_bytes + 'G'73 disk = disk_size_total_G74 return disk75#####[cpu message]#####76def get_CpuInfo():77 p = Popen(['cat','/proc/cpuinfo'],stdout=PIPE,stderr=PIPE)78 stdout, stderr = p.communicate()79 cpudata = stdout.strip()80 cpu_dict = {}81 re_cpu_cores = re.compile(r'processor\s+:\s+([\d])')82 re_vendor_id = re.compile(r'vendor_id\s+:\s([\w]+)')83 re_model_name = re.compile(r'model name\s+:\s+(.*)')84 res_cpu_cores = re_cpu_cores.findall(cpudata)85 cpu_dict['Cpu_Cores'] = int(res_cpu_cores[-1]) + 186 res_vendor_id = re_vendor_id.findall(cpudata)87 cpu_dict['Vendor_Id'] = res_vendor_id[-1]88 res_model_name = re_model_name.findall(cpudata)89 cpu_dict['Model_Name'] = res_model_name[-1]90 return cpu_dict91#####[Demi message]#####92def get_dmidecode():93 P = Popen(['dmidecode'],stdout=PIPE)94 data = P.stdout.read()95 lines = data.split('\n\n')96 dmidecode_line = lines[2] 97 line = [i.strip() for i in dmidecode_line.split('\n') if i]98 Manufacturer = line[2].split(': ')[-1]99 product = line[3].split(': ')[-1]100 sn = line[5].split(': ')[-1]101 return Manufacturer,product,sn102if __name__ == '__main__':103 #####[get data]#####104 #hostname = get_HostnameInfo('/etc/sysconfig/network')105 hostname = get_HostnameInfo('/etc/hostname')106 ip = get_Ipaddr()107 osversion = get_OsVerion('/etc/issue')108 memory = get_MemoryInfo('/proc/meminfo')109 disk = get_DiskInfo()110 Vendor_Id = get_CpuInfo()['Vendor_Id']111 Model_Name = get_CpuInfo()['Model_Name']112 Cpu_Cores = get_CpuInfo()['Cpu_Cores']113 Manufacturer,product,sn = get_dmidecode()114 #####[get dict]##### 115 test = {116 'hostname':hostname,117 'ip':ip,118 'osversion':osversion,119 'memory':memory,120 'disk':disk,121 'vendor_id':Vendor_Id,122 'model_name':Model_Name,123 'cpu_core':Cpu_Cores,124 'product':product,125 'Manufacturer':Manufacturer,126 'sn':sn,127 }128 data = urllib.urlencode(test)...

Full Screen

Full Screen

InfoGet.py

Source:InfoGet.py Github

copy

Full Screen

...10 #self.cpu_data = []11 self.mem_data = [["时间","内存占用"]]1213 #获取cup信息,并返回14 def get_cpuinfo(self):15 #self.cpu_data = [["时间","CPU占用"]]16 self.cpu_data=[]17 result = os.popen("adb shell dumpsys cpuinfo | findstr com.smzc.hci")18 cpuinfo = result.readline().split("%")[0].strip()19 currtent_time = self.get_currenttime()20 print("cpu:%s"%cpuinfo,"time:%s"%currtent_time)21 self.cpu_data.append([currtent_time,cpuinfo])22 print(self.cpu_data)23 excelOprate().add_data("cpu占用",self.cpu_data)24 return self.cpu_data25262728 #获取当前时间29 def get_currenttime(self):30 #current_times = time.time()31 current_times = time.strftime("%H:%M:%S",time.localtime())32 return current_times3334 #执行获取alldata列表35 def run(self,sleep_time):36 while True:37 self.get_cpuinfo()38 #self.count-=1;39 time.sleep(sleep_time)40 #cpu_data = monitor.get_cpuinfo()4142434445464748if __name__ == '__main__':49 monitor = GetInfo()50 monitor.run(1)51525354

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful