mirror of
https://github.com/espressif/openthread.git
synced 2026-09-16 14:10:09 +00:00
Stabilize the harness automation tool. (#1174)
This commit is contained in:
committed by
Jonathan Hui
parent
8134d32729
commit
fd86da586b
@@ -176,12 +176,13 @@ class HarnessCase(unittest.TestCase):
|
|||||||
return
|
return
|
||||||
|
|
||||||
for device in settings.GOLDEN_DEVICES:
|
for device in settings.GOLDEN_DEVICES:
|
||||||
|
port, _ = device
|
||||||
try:
|
try:
|
||||||
with OpenThreadController(device) as otc:
|
with OpenThreadController(port) as otc:
|
||||||
logger.info('Resetting %s' % device)
|
logger.info('Resetting %s' % port)
|
||||||
otc.reset()
|
otc.reset()
|
||||||
except:
|
except:
|
||||||
logger.exception('Failed to reset device %s' % device)
|
logger.exception('Failed to reset device %s' % port)
|
||||||
self.history.mark_bad_golden_device(device)
|
self.history.mark_bad_golden_device(device)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -107,16 +107,22 @@ class HarnessController(object):
|
|||||||
|
|
||||||
def _try_kill(self, proc):
|
def _try_kill(self, proc):
|
||||||
logger.info('Try kill process')
|
logger.info('Try kill process')
|
||||||
times = 3
|
times = 1
|
||||||
proc.kill()
|
|
||||||
while proc.poll() is None:
|
while proc.poll() is None:
|
||||||
logger.info('Trial %d failed', times)
|
proc.kill()
|
||||||
if times == 0:
|
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
if proc.poll() is not None:
|
||||||
|
logger.info('Process has been killed')
|
||||||
|
break
|
||||||
|
|
||||||
|
logger.info('Trial {} failed'.format(times))
|
||||||
|
times += 1
|
||||||
|
|
||||||
|
if times > 3:
|
||||||
raise SystemExit()
|
raise SystemExit()
|
||||||
else:
|
|
||||||
times = times - 1
|
|
||||||
time.sleep(5)
|
|
||||||
proc.kill()
|
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ logger.setLevel(logging.INFO)
|
|||||||
RESUME_SCRIPT_PATH = '%appdata%\\Microsoft\\Windows\\Start Menu\\Programs\\' \
|
RESUME_SCRIPT_PATH = '%appdata%\\Microsoft\\Windows\\Start Menu\\Programs\\' \
|
||||||
'Startup\\continue_harness.bat'
|
'Startup\\continue_harness.bat'
|
||||||
|
|
||||||
|
|
||||||
class SimpleTestResult(unittest.TestResult):
|
class SimpleTestResult(unittest.TestResult):
|
||||||
|
|
||||||
def __init__(self, path, auto_reboot_args=None, manual_reset=False):
|
def __init__(self, path, auto_reboot_args=None, manual_reset=False):
|
||||||
'''Record test results in json file
|
'''Record test results in json file
|
||||||
|
|
||||||
@@ -118,7 +120,6 @@ class SimpleTestResult(unittest.TestResult):
|
|||||||
# close explorers
|
# close explorers
|
||||||
os.system('taskkill /f /im explorer.exe && start explorer.exe')
|
os.system('taskkill /f /im explorer.exe && start explorer.exe')
|
||||||
|
|
||||||
|
|
||||||
def addSuccess(self, test):
|
def addSuccess(self, test):
|
||||||
logger.info('case[%s] pass', test.__class__.__name__)
|
logger.info('case[%s] pass', test.__class__.__name__)
|
||||||
super(SimpleTestResult, self).addSuccess(test)
|
super(SimpleTestResult, self).addSuccess(test)
|
||||||
@@ -143,20 +144,36 @@ class SimpleTestResult(unittest.TestResult):
|
|||||||
super(SimpleTestResult, self).addError(test, err)
|
super(SimpleTestResult, self).addError(test, err)
|
||||||
self.add_result(test, None, str(err[1]))
|
self.add_result(test, None, str(err[1]))
|
||||||
|
|
||||||
|
|
||||||
|
def __print_fw_version_of_device_connected_to_port(port):
|
||||||
|
'''Print firmware version of a device connected to the COM port'''
|
||||||
|
try:
|
||||||
|
with OpenThreadController(port) as otc:
|
||||||
|
print('%s: %s' % (port, otc.version))
|
||||||
|
except:
|
||||||
|
logger.exception('failed to get version of %s' % port)
|
||||||
|
|
||||||
|
|
||||||
def list_devices(names=None, continue_from=None, **kwargs):
|
def list_devices(names=None, continue_from=None, **kwargs):
|
||||||
"""List devices in settings file and print versions"""
|
'''List devices in settings file and print versions'''
|
||||||
|
|
||||||
|
ports = []
|
||||||
|
|
||||||
|
if names:
|
||||||
|
ports = list(names)
|
||||||
|
|
||||||
if continue_from:
|
|
||||||
continue_from = settings.GOLDEN_DEVICES.index(continue_from)
|
|
||||||
else:
|
else:
|
||||||
continue_from = 0
|
ports = [port for port, _type in settings.GOLDEN_DEVICES if _type == 'OpenThread']
|
||||||
|
|
||||||
|
if continue_from:
|
||||||
|
continue_from = ports.index(continue_from)
|
||||||
|
else:
|
||||||
|
continue_from = 0
|
||||||
|
|
||||||
|
ports = list(ports[continue_from:])
|
||||||
|
|
||||||
|
map(__print_fw_version_of_device_connected_to_port, ports)
|
||||||
|
|
||||||
for port in names or settings.GOLDEN_DEVICES[continue_from:]:
|
|
||||||
try:
|
|
||||||
with OpenThreadController(port) as otc:
|
|
||||||
print('%s: %s' % (port, otc.version))
|
|
||||||
except:
|
|
||||||
logger.exception('failed to get version of %s' % port)
|
|
||||||
|
|
||||||
def discover(names=None, pattern=['*.py'], skip='efp', dry_run=False, blacklist=None, name_greps=None,
|
def discover(names=None, pattern=['*.py'], skip='efp', dry_run=False, blacklist=None, name_greps=None,
|
||||||
manual_reset=False, delete_history=False, max_devices=0,
|
manual_reset=False, delete_history=False, max_devices=0,
|
||||||
@@ -168,6 +185,8 @@ def discover(names=None, pattern=['*.py'], skip='efp', dry_run=False, blacklist=
|
|||||||
documentation for more details
|
documentation for more details
|
||||||
skip (str): types cases to skip
|
skip (str): types cases to skip
|
||||||
'''
|
'''
|
||||||
|
if not os.path.exists(settings.OUTPUT_PATH):
|
||||||
|
os.mkdir(settings.OUTPUT_PATH)
|
||||||
|
|
||||||
if delete_history:
|
if delete_history:
|
||||||
os.system('del history.json')
|
os.system('del history.json')
|
||||||
@@ -188,6 +207,7 @@ def discover(names=None, pattern=['*.py'], skip='efp', dry_run=False, blacklist=
|
|||||||
try:
|
try:
|
||||||
log = json.load(open(result_file, 'r'))
|
log = json.load(open(result_file, 'r'))
|
||||||
except:
|
except:
|
||||||
|
logger.exception('Failed to open result file')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not log:
|
if not log:
|
||||||
@@ -274,6 +294,7 @@ def discover(names=None, pattern=['*.py'], skip='efp', dry_run=False, blacklist=
|
|||||||
|
|
||||||
suite.run(result)
|
suite.run(result)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='Thread harness test case runner')
|
parser = argparse.ArgumentParser(description='Thread harness test case runner')
|
||||||
parser.add_argument('--auto-reboot', '-a', action='store_true', default=False,
|
parser.add_argument('--auto-reboot', '-a', action='store_true', default=False,
|
||||||
|
|||||||
Reference in New Issue
Block a user