1# -*- coding: utf-8 -*- 2import os 3 4from test_case import ITestCase 5 6 7class ProcessCheck(ITestCase): 8 9 def __init__(self, controllers): 10 super().__init__(controllers) 11 12 def setup(self): 13 self.step('前置条件1: 检查process.txt配置文件是否存在') 14 self.asserts.assert_true(os.path.exists(os.path.join(self.local_resource_path, 'process.txt'))) 15 16 def process(self): 17 self.step('步骤1: 检查process是否存在') 18 with open(os.path.join(self.local_resource_path, 'process.txt'), 'r+') as f: 19 text = f.read() 20 two_check_process_list = text.split('#####')[1].split()[0:-1] 21 other_process_list = text.split('#####')[2].split() 22 lose_process = [] 23 for pname in two_check_process_list: 24 pids = self.common_oh.shell(self.Phone1, 'pidof {}'.format(pname)) 25 try: 26 pidlist = pids.split() 27 for pid in pidlist: 28 int(pid) 29 self.step('{} pid is {}'.format(pname, pid)) 30 except: 31 lose_process.append(pname) 32 self.common_oh.wait(self.Phone1, 1) 33 34 all_p = self.common_oh.shell(self.Phone1, 'ps -elf') 35 for pname in other_process_list: 36 if pname not in all_p: 37 lose_process.append(pname) 38 try: 39 self.asserts.assert_true(len(lose_process) == 0) 40 except: 41 self.step('步骤2:丢失的进程有: {}'.format(lose_process)) 42 self.common_oh.shell(self.Phone1, 'cd /data/log/faultlog/temp && tar -cf after_test_cppcrash{}.tar cppcrash*'.format(self.device_name)) 43 self.common_oh.pullFile(self.Phone1, '/data/log/faultlog/temp/after_test_cppcrash{}.tar'.format(self.device_name), os.path.normpath(self.local_save_path)) 44 # fault logger 45 self.common_oh.shell(self.Phone1, 'cd /data/log/faultlog/faultlogger && tar -cf after_test_jscrash{}.tar jscrash*'.format(self.device_name)) 46 self.common_oh.pullFile(self.Phone1, '/data/log/faultlog/faultlogger/after_test_jscrash{}.tar'.format(self.device_name), os.path.normpath(self.local_save_path)) 47 self.step('步骤2: 冒烟测试失败,丢失的进程有: {}'.format(lose_process)) 48 raise 49 50 def teardown(self): 51 self.step('后置条件1: 进程检查结束') 52