class testcase(unittest.TestCase): logger = set_logger(__name__) sdk = tools.get_api() model = tools.get_model() filters = tools.get_filter() filter_count = int(tools.read_job_config()['filter_count']) unfilter_count = int(tools.read_job_config()['unfilter_count']) timeout = tools.read_job_config()['case_timeout'] def setUp(self): self.timeout_flag = None self.flag1 = 0 self.flag2 = 0 self.key=None self.logger.info('X/E 测试chip0 filter uuid被动扫描 chip1 filter uuid 主动扫描,S chip0 filter uuid 主动扫描') self.timer = Timer(self.timeout, self.set_timeout) self.timer.start() def tearDown(self): self.timer.cancel() # 测试方法 def test_scan_filter_uuid(self): if self.model.startswith('S') or self.model.startswith('s'): a = threading.Thread(target=self.chip0_scan, args=(0, self.filters['filter_uuid'])) a.setDaemon(True) a.start() while True: if self.flag1 == 1: self.assertTrue(True) self.logger.info('pass\n') break elif self.timeout_flag: self.logger.info('fail\n') self.fail('Case failed,start scan timeout.') self.logger.error("Case failed,start scan timeout.") break else: a = threading.Thread(target=self.chip0_scan, args=(1, self.filters['filter_uuid'])) b = threading.Thread(target=self.chip1_scan, args=(0, self.filters['filter_uuid'])) a.setDaemon(True) b.setDaemon(True) b.start() a.start() while True: if self.flag1==1 and self.flag2==1: self.assertTrue(True) self.logger.info('pass\n') break elif self.timeout_flag: self.logger.info('fail\n') self.fail('Case failed,case timeout.') self.logger.error("Case failed,start scan timeout.") # break sys.exit(1)
class testcase(unittest.TestCase): logger = set_logger(__name__) sdk = tools.get_api() model = tools.get_model() filter_count = int(tools.read_job_config()['filter_count']) unfilter_count = int(tools.read_job_config()['unfilter_count']) timeout = tools.read_job_config()['case_timeout'] def setUp(self): self.timeout_flag = None self.flag1 = 0 self.flag2 = 0 self.key=None self.logger.info('X/E 测试chip0 filter duplicate主动扫描 chip1 不加filter duplicate主动扫描,S chip0 filter duplicate 被动扫描') self.timer = Timer(self.timeout, self.set_timeout) self.timer.start() def tearDown(self): self.timer.cancel()
class testcase(unittest.TestCase): logger = set_logger(__name__) sdk = tools.get_api() model = tools.get_model() filters = tools.get_filter() filter_count = int(tools.read_job_config()['filter_count']) unfilter_count = tools.read_job_config()['unfilter_count'] timeout = tools.read_job_config()['case_timeout'] def setUp(self): self.timeout_flag = None self.flag1 = 0 self.flag2 = 0 self.logger.info('测试X/E chip0 不加filter rssi被动扫描 chip1 filter uuid 被动扫描,S chip0 不加filter uuid 主动扫描') self.timer = Timer(10, self.set_timeout) self.timer.start() def tearDown(self): self.timer.cancel()
class testcase(unittest.TestCase): logger = set_logger(__name__) sdk = tools.get_api() model = tools.get_model() filter_count = int(tools.read_job_config()['filter_count']) unfilter_count = int(tools.read_job_config()['unfilter_count']) timeout = tools.read_job_config()['case_timeout'] local=tools.read_job_config()["local"] def setUp(self): self.timeout_flag = None self.flag1 = 0 self.flag2 = 0 self.key=None self.logger.info('X/E duration 参数测试chip0 主动扫 chip1 被动扫d=5.58s ,S chip0 主动扫d=7.8s ') self.timer = Timer(self.timeout, self.set_timeout) self.timer.start() def tearDown(self): self.timer.cancel()
class testcase(unittest.TestCase): logger = set_logger(__name__) sdk = tools.get_api() model = tools.get_model() filters = tools.get_filter() timeout = tools.read_job_config()['case_timeout'] filter_count = int(tools.read_job_config()['filter_count']) unfilter_count = int(tools.read_job_config()['unfilter_count']) def setUp(self): self.timeout_flag = None self.flag1 = 0 self.flag2 = 0 self.logger.info('测试chip0 filter name主动扫描,chip1 不加过虑主动扫描') self.timer = Timer(self.timeout, self.set_timeout) self.timer.start() def tearDown(self): self.timer.cancel() #测试方法 # noinspection PyUnreachableCode,PyUnreachableCode def test_scan_filter_name(self): if self.model.startswith('S') or self.model.startswith('s'): a = threading.Thread(target=self.chip0_scan, args=(1, self.filters['filter_name'])) b = threading.Thread(target=self.chip0_scan, args=(0, )) a.setDaemon(True) b.setDaemon(True) b.start() a.start() while True: if self.flag1 == 2: self.assertTrue(True) self.logger.info('pass\n') break elif self.timeout_flag: self.logger.info('fail\n') self.fail('Case failed,start scan timeout.') self.logger.error("Case failed,start scan timeout.") break else: a = threading.Thread(target=self.chip0_scan, args=(1, self.filters['filter_name'])) b = threading.Thread(target=self.chip1_scan, args=(0, )) a.setDaemon(True) b.setDaemon(True) b.start() a.start() while True: if self.flag1 == 1 and self.flag2 == 1: self.assertTrue(True) self.logger.info('pass\n') break elif self.timeout_flag: self.logger.info('fail\n') self.fail('Case failed,start scan timeout.') self.logger.error("Case failed,start scan timeout.") break # noinspection PyUnreachableCode def chip0_scan(self, active=0, filter_name=None): #step1:chip 1 start passive scan,then start chip0 scan. with closing( self.sdk.scan(chip=0, active=active, filter_name=filter_name)) as self.sse1: count = 0 for message in self.sse1: if message.startswith('data'): msg = json.loads(message[5:]) if filter_name: #进入开启过滤的扫描结果判断流程 if count < self.filter_count: print('chip0', count, message) name = msg['name'] if name != self.filters['filter_name']: self.fail('filter name failed.') self.logger.debug('filter name failed.') break else: count += 1 else: self.flag1 += 1 self.logger.debug( 'Step 1:chip0 start scan with filter name success.' ) break else: #进入不开启过滤的扫描结果判断流程 if count < 300: print('chip0', count, message) count += 1 else: self.flag1 += 1 self.logger.debug( 'Step 1:chip0 start scan with no filter name success.' ) break # noinspection PyUnreachableCode def chip1_scan(self, active=0, filter_name=None): #step2:start chip0 scan. with closing( self.sdk.scan(chip=1, active=active, filter_name=filter_name)) as self.sse2: count = 0 tmp_name = [] for message in self.sse2: if message.startswith('data'): msg = json.loads(message[5:]) if filter_name: if count < self.filter_count: print('chip1', count, message) name = msg['name'] if name != filter_name: self.fail('filter name failed.') self.logger.debug('filter name failed.') break else: count += 1 else: self.flag2 += 1 self.logger.debug( 'Step 2:chip1 start scan with filter name success.' ) break else: #进入不开启过滤的扫描结果判断流程 if count < self.unfilter_count: print('chip1', count, message) count += 1 else: self.flag2 += 1 self.logger.debug( 'Step 2:chip1 start scan with no filter name success.' ) break def set_timeout(self): self.timeout_flag = True
class testcase(unittest.TestCase): logger = set_logger(__name__) sdk = get_api() model = get_model() def setUp(self): self.timeout_flag = None self.flag1 = None self.flag2 = None self.logger.info('测试两个芯片同时开启被动扫描') self.timer = Timer(30, self.timeout) self.timer.start() def tearDown(self): self.timer.cancel() # noinspection PyUnreachableCode def test_chips_start_scan_meanwhile(self): if self.model.startswith('S') or self.model.startswith('s'): self.assertTrue(True) else: threading.Thread(target=self.chip0_scan).start() threading.Thread(target=self.chip1_scan).start() while True: if self.flag1 and self.flag2: self.assertTrue(True) self.logger.info('pass\n') break elif self.timeout_flag: self.logger.info('fail\n') self.fail('Case failed,start scan timeout.') self.logger.error("Case failed,start scan timeout.") break # noinspection PyUnreachableCode def chip0_scan(self): #step1:chip 1 start passive scan,then start chip0 scan. with closing(self.sdk.scan(chip=0)) as self.sse1: count = 0 for message in self.sse1: if count < 300: if message.startswith('data'): # print('chip0',message) count += 1 if 'scanData' in message: self.fail('Scan passive mode error',message) break elif 'keep-alive' in message: pass else: self.logger.error('start scan fail,%s' % message) else: self.flag1 = True self.logger.debug('Step 1:chip0 start passive scan success.') break # noinspection PyUnreachableCode def chip1_scan(self): #step2:start chip0 scan. with closing(self.sdk.scan(chip=1)) as self.sse2: count = 0 for message in self.sse2: if count < 300: if message.startswith('data'): # print('chip1',message) count += 1 if 'scanData' in message: self.fail('Scan passive mode error',message) break elif 'keep-alive' in message: pass else: self.logger.error('Step 2:start scan fail,%s' % message) else: self.flag2 = True self.logger.debug('Step 2:chip1 start active scan success ') break def timeout(self): self.timeout_flag = True
class testcase(unittest.TestCase): logger = set_logger(__name__) local_sdk, cloud_sdk = tools.get_all_api() model = tools.get_model() filters = tools.get_filter() timeout = tools.read_job_config()['case_timeout'] def setUp(self): self.timeout_flag = None self.flag1 = None self.flag2 = None self.logger.info('测试点:测试chip0 local扫描的同时,chip1进行cloud扫描') self.timer = Timer(self.timeout, self.set_timeout) self.timer.start() def tearDown(self): self.timer.cancel() def test_scan_on_cloud_local(self): a = threading.Thread(target=self.local_scan) b = threading.Thread(target=self.cloud_scan) a.setDaemon(True) b.setDaemon(True) b.start() a.start() while True: if self.flag1 and self.flag2: self.assertTrue(True) self.logger.info('pass\n') break elif self.timeout_flag: self.logger.info('fail\n') self.fail('Case failed,start scan timeout.') self.logger.error("Case failed,start scan timeout.") break def test_step(self): self.flag = None #step1:start local scan. with closing(self.local_sdk.scan(chip=1)) as self.sse2: count = 0 for message in self.sse2: if message.startswith('data'): if count < 100: print('local', count, message) count += 1 else: self.flag = True self.logger.debug('Step 1: start local scan success.') break #step3:停止本地扫描 time.sleep(3) self.logger.debug('Step 2: stop local scan success.') #step2:start cloud scan. with closing(self.cloud_sdk.scan(chip=0)) as self.sse1: count = 0 for message in self.sse1: if message.startswith('data'): if count < 100: print('cloud', count, message) count += 1 else: self.flag = True self.logger.debug('Step 3:start cloud scan success.') break def set_timeout(self): self.timeout_flag = True
class testcase(unittest.TestCase): logger = set_logger(__name__) sdk = tools.get_api() model = tools.get_model() filter_count = int(tools.read_job_config()['filter_count']) unfilter_count = int(tools.read_job_config()['unfilter_count']) timeout = tools.read_job_config()['case_timeout'] local = tools.read_job_config()["local"] def setUp(self): self.timeout_flag = None self.flag1 = 0 self.flag2 = 0 self.key = None self.logger.info( 'X/E duration 参数测试chip0 被动扫 chip1 主动扫 d=9.99s,S chip0 被动扫d=9.99s ' ) self.timer = Timer(self.timeout, self.set_timeout) self.timer.start() def tearDown(self): self.timer.cancel() # 测试方法 # noinspection PyUnreachableCode def test_scan_filter_duplicates(self): # duration1=2 if self.local == "True": if self.model.startswith('S') or self.model.startswith('s'): a = threading.Thread(target=self.chip0_scan, args=(1, 9.99)) a.setDaemon(True) a.start() while True: if self.flag1 == 1: self.logger.info('pass\n') break elif self.timeout_flag: self.logger.info('fail\n') self.fail('Case failed,start scan timeout.') self.logger.error("Case failed,start scan timeout.") break else: a = threading.Thread(target=self.chip0_scan, args=(1, )) b = threading.Thread(target=self.chip1_scan, args=(0, 9.99)) a.setDaemon(True) b.setDaemon(True) b.start() a.start() while True: if self.flag1 == 1 and self.flag2 == 1: self.logger.info('pass\n') break elif self.timeout_flag: self.logger.info('fail\n') self.fail('Case failed,case timeout.') self.logger.error("Case failed,start scan timeout.") break sys.exit(1) else: self.logger.info("AC不需要测试duration参数,duration参数只对AP端生效") pass def chip0_scan(self, active=0, duration=None): # step1:chip 1 start passive scan,then start chip0 scan. if not duration is None: if isinstance(duration, str): duration1 = 5 print("字符串duration=", duration1) # 负数和0 扫描5s后停止 elif duration <= 0: duration1 = 5 print("负数和0 duration=", duration1) # 小数位数小于等于3时,会按照设置的时间停止扫描;小数位数大于3时,参数不起效,一直扫描数据 elif duration > float(str(duration)[:5]): duration1 = None print("小数位数大于3 duration=", duration1) else: duration1 = duration else: duration1 = None with closing(self.sdk.scan(chip=0, active=active, duration=duration1)) as self.sse1: if duration1: # time.sleep(duration1+0.5) d1 = datetime.datetime.now() print("start time at", datetime.datetime.now()) for message in self.sse1: continue d2 = datetime.datetime.now() print("end time at ", datetime.datetime.now()) t = float(((d2 - d1).seconds)) + float( (d2 - d1).microseconds / 1000 / 1000) - 1 print("second", t) if t <= duration1: self.flag1 += 1 self.logger.info( "Step 1:chip0 start scan with duration success.") else: self.fail("chip 0 duration failed") self.logger.debug("chip 0 duration failed") else: count = 0 for message in self.sse1: if message.startswith("data"): msg = json.loads(message[5:]) count += 1 print("chip 0 ", count, message) if count > self.unfilter_count: self.flag1 += 1 self.logger.info( "Step 1:chip0 start scan with no duration success." ) break # noinspection PyUnreachableCode def chip1_scan(self, active=0, duration=None): # step2:start chip1 scan. # 字符串 扫描5s后停止 if not duration is None: if isinstance(duration, str): duration1 = 5 print("字符串duration=", duration1) # 负数和0 扫描5s后停止 elif duration <= 0: duration1 = 5 print("负数和0 duration=", duration1) # 小数位数小于等于3时,会按照设置的时间停止扫描;小数位数大于3时,参数不起效,一直扫描数据 elif duration > float(str(duration)[:5]): duration1 = None print("小数位数大于3 duration=", duration1) else: duration1 = duration else: duration1 = None with closing(self.sdk.scan(chip=1, active=active, duration=duration1)) as self.sse1: if duration1: # time.sleep(duration1+0.5) d1 = datetime.datetime.now() print("start time at", datetime.datetime.now()) for message in self.sse1: continue d2 = datetime.datetime.now() print("end time at ", datetime.datetime.now()) t = float(((d2 - d1).seconds)) + float( (d2 - d1).microseconds / 1000 / 1000) - 0.5 print("second", t) if t <= duration1: self.flag2 += 1 self.logger.info( "Step 1:chip1 start scan with duration success.") else: self.fail("chip 0 duration failed") self.logger.debug("chip 1 duration failed") else: count = 0 for message in self.sse1: if message.startswith("data"): msg = json.loads(message[5:]) count += 1 print("chip 0 ", count, message) if count > self.unfilter_count: self.flag2 += 1 self.logger.info( "Step 1:chip1 start scan with no duration success." ) break def set_timeout(self): self.timeout_flag = True
class testcase(unittest.TestCase): logger = set_logger(__name__) sdk = get_api() model = get_model() timeout = read_job_config()['case_timeout'] def setUp(self): self.logger.info('测试在不同芯片之间,按先后顺序,能否成功开启扫描') self.timer = Timer(self.timeout,self.close) self.timer.start() def tearDown(self): self.timer.cancel() def test_start_scan_in_diff_chip(self): flag = None if self.model.startswith('S')or self.model.startswith('s'): self.logger.debug('if model is s1000系列的产品,直接pass') #if model is s1000系列的产品,直接pass self.assertTrue(True) else: #step1:chip 0 start scan,then stop scan with closing(self.sdk.scan(chip = 0)) as self.sse: for message in self.sse: if message.startswith('data'): flag = True self.logger.debug("step1:chip 0 start scan,then stop scan success") self.sse.close() elif 'keep-alive' in message: pass else: flag = False self.logger.error('start scan fail,%s'%message) #step2:chip 1 start scan,then stop scan. with closing(self.sdk.scan(chip = 1)) as self.sse: for message in self.sse: if message.startswith('data'): flag = True self.logger.debug("step2:chip 1 start scan,then stop scan success") self.sse.close() elif 'keep-alive' in message: pass else: flag = False self.logger.error('start scan fail,%s'%message) #step3:chip 0 start scan,then change to chip1 scan. with closing(self.sdk.scan(chip = 0)) as self.sse: for message in self.sse: if message.startswith('data'): flag = True self.logger.debug("step3:chip 0 start scan,then change to chip1 scan success") # self.change_scan(flag) self.sse.close() elif 'keep-alive' in message: pass else: flag = False self.logger.error('start scan fail,%s'%message) #step4:chip 1 start scan,then change to chip0 scan. with closing(self.sdk.scan(chip = 1)) as self.sse: for message in self.sse: if message.startswith('data'): flag = True self.logger.debug("step4:chip 1 start scan,then change to chip0 scan success") # self.change_scan2(flag) self.sse.close() elif 'keep-alive' in message: pass else: flag = False self.logger.error('start scan fail,%s'%message) #step5:chip 0 start scan,then change to chip1 scan. with closing(self.sdk.scan(chip = 1)) as self.sse: for message in self.sse: if message.startswith('data'): flag = True self.logger.debug("step5:chip 0 start scan,then change to chip1 scan success.") self.sse.close() elif 'keep-alive' in message: pass else: flag = False self.logger.error('start scan fail,%s'%message) self.assertTrue(flag) if flag: self.logger.info('case pass\n') else: self.logger.info('case fail\n')
class testcase(unittest.TestCase): logger = set_logger(__name__) api = get_api() model = get_model() def setUp(self): self.logger.info('测试设备的主被动扫描切换功能') self.timer = Timer(30, self.close) self.timer.start() def tearDown(self): self.timer.cancel() # noinspection PyUnreachableCode,PyUnreachableCode,PyUnreachableCode,PyUnreachableCode,PyUnreachableCode,PyUnreachableCode,PyUnreachableCode def test_change_scan_mode(self): flag = None count = 0 if self.model.startswith('S') or self.model.startswith('s'): with closing(self.api.scan(active=0)) as self.sse1: count = 0 for data1 in self.sse1: if count < 200: if 'scanData' in data1: self.fail('passive scan start fail') self.logger.error('passive scan start fail') break else: count += 1 flag = True else: flag = True # self.sse.close() self.logger.debug('Step1:passive scan start success') break with closing(self.api.scan(active=1)) as self.sse2: count = 0 for data2 in self.sse2: if count < 200: if 'scanData' in data2: flag = True self.logger.debug( 'Step2:Active scan start success') break else: count += 1 else: self.fail('Active scan start failed') self.logger.error('Step2:Active scan start fail') break with closing(self.api.scan(active=0)) as self.sse3: count = 0 for data3 in self.sse3: if count < 200: if 'scanData' in data3: self.fail('passive scan start fail') self.logger.error('passive scan start fail') break else: count += 1 else: flag = True self.logger.debug('Step3:passive scan start success') break with closing(self.api.scan(active=1)) as self.sse4: count = 0 for data4 in self.sse4: if count < 200: if 'scanData' in data4: flag = True self.logger.debug( 'Step5:Active scan start success') break else: count += 1 else: self.fail('Active scan start failed') self.logger.error('Step5:Active scan start fail') break self.assertTrue(flag) if flag: self.logger.info('pass\n') else: self.logger.info('fail\n') else: with closing(self.api.scan(active=0)) as self.sse1: count = 0 for data1 in self.sse1: if count < 200: if 'scanData' in data1: self.fail('passive scan start fail') self.sse1.close() self.logger.error('passive scan start fail') else: count += 1 flag = True else: flag = True # self.sse.close() self.logger.debug('Step1:passive scan start success') break with closing(self.api.scan(active=1)) as self.sse2: count = 0 for data2 in self.sse2: if count < 200: if 'scanData' in data2: flag = True self.logger.debug( 'Step1:Active scan start success') break else: count += 1 flag = True else: self.fail('Active scan start failed') self.sse2.close() self.logger.error('Step2:Active scan start success') with closing(self.api.scan(active=0)) as self.sse3: count = 0 for data3 in self.sse3: if count < 200: if 'scanData' in data3: self.fail('passive scan start fail') self.sse3.close() self.logger.error('passive scan start fail') else: count += 1 flag = True else: flag = True self.logger.debug('Step3:passive scan start success') break with closing(self.api.scan(active=1)) as self.sse4: count = 0 for data4 in self.sse4: if count < 200: if 'scanData' in data4: flag = True self.logger.debug( 'Step1:Active scan start success') break else: count += 1 flag = True else: self.fail('Active scan start failed') self.sse4.close() self.logger.error('Step4:Active scan start success') with closing(self.api.scan(chip=1, active=0)) as self.sse5: count = 0 for data1 in self.sse5: if count < 200: if 'scanData' in data1: self.fail('passive scan start fail') self.sse5.close() self.logger.error('passive scan start fail') else: count += 1 flag = True else: flag = True # self.sse.close() self.logger.debug('Step1:passive scan start success') break with closing(self.api.scan(chip=1, active=1)) as self.sse6: count = 0 for data2 in self.sse6: if count < 200: if 'scanData' in data2: flag = True self.logger.debug( 'Step1:Active scan start success') break else: count += 1 flag = True else: self.fail('Active scan start failed') self.sse6.close() self.logger.error('Step2:Active scan start success') with closing(self.api.scan(chip=1, active=0)) as self.sse7: count = 0 for data3 in self.sse7: if count < 200: if 'scanData' in data3: self.fail('passive scan start fail') self.sse7.close() self.logger.error('passive scan start fail') else: count += 1 flag = True else: flag = True self.logger.debug('Step3:passive scan start success') break with closing(self.api.scan(chip=1, active=1)) as self.sse8: count = 0 for data4 in self.sse8: if count < 200: if 'scanData' in data4: flag = True self.logger.debug( 'Step1:Active scan start success') break else: count += 1 flag = True else: self.fail('Active scan start failed') self.sse8.close() self.logger.error('Step4:Active scan start success') if flag: self.logger.info('pass\n') else: self.logger.info('fail\n') # noinspection PyUnreachableCode def close(self): self.fail("Case failed,start scan timeout.") self.logger.error("Case failed,start scan timeout.")