From fd86da586bd324da88b567bfa21832bc08322a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Fierek?= Date: Tue, 24 Jan 2017 08:08:35 +0100 Subject: [PATCH] Stabilize the harness automation tool. (#1174) --- .../autothreadharness/harness_case.py | 7 +-- .../autothreadharness/harness_controller.py | 22 ++++++---- .../autothreadharness/runner.py | 43 ++++++++++++++----- 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/tools/harness-automation/autothreadharness/harness_case.py b/tools/harness-automation/autothreadharness/harness_case.py index 8a71896cc..8bf3ec93f 100644 --- a/tools/harness-automation/autothreadharness/harness_case.py +++ b/tools/harness-automation/autothreadharness/harness_case.py @@ -176,12 +176,13 @@ class HarnessCase(unittest.TestCase): return for device in settings.GOLDEN_DEVICES: + port, _ = device try: - with OpenThreadController(device) as otc: - logger.info('Resetting %s' % device) + with OpenThreadController(port) as otc: + logger.info('Resetting %s' % port) otc.reset() except: - logger.exception('Failed to reset device %s' % device) + logger.exception('Failed to reset device %s' % port) self.history.mark_bad_golden_device(device) return diff --git a/tools/harness-automation/autothreadharness/harness_controller.py b/tools/harness-automation/autothreadharness/harness_controller.py index 780e0a593..41c4030b0 100644 --- a/tools/harness-automation/autothreadharness/harness_controller.py +++ b/tools/harness-automation/autothreadharness/harness_controller.py @@ -107,16 +107,22 @@ class HarnessController(object): def _try_kill(self, proc): logger.info('Try kill process') - times = 3 - proc.kill() + times = 1 + while proc.poll() is None: - logger.info('Trial %d failed', times) - if times == 0: + proc.kill() + + 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() - else: - times = times - 1 - time.sleep(5) - proc.kill() def __del__(self): self.stop() diff --git a/tools/harness-automation/autothreadharness/runner.py b/tools/harness-automation/autothreadharness/runner.py index 2df107e65..183a4ee74 100644 --- a/tools/harness-automation/autothreadharness/runner.py +++ b/tools/harness-automation/autothreadharness/runner.py @@ -52,7 +52,9 @@ logger.setLevel(logging.INFO) RESUME_SCRIPT_PATH = '%appdata%\\Microsoft\\Windows\\Start Menu\\Programs\\' \ 'Startup\\continue_harness.bat' + class SimpleTestResult(unittest.TestResult): + def __init__(self, path, auto_reboot_args=None, manual_reset=False): '''Record test results in json file @@ -118,7 +120,6 @@ class SimpleTestResult(unittest.TestResult): # close explorers os.system('taskkill /f /im explorer.exe && start explorer.exe') - def addSuccess(self, test): logger.info('case[%s] pass', test.__class__.__name__) super(SimpleTestResult, self).addSuccess(test) @@ -143,20 +144,36 @@ class SimpleTestResult(unittest.TestResult): super(SimpleTestResult, self).addError(test, err) 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): - """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: - 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, 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 skip (str): types cases to skip ''' + if not os.path.exists(settings.OUTPUT_PATH): + os.mkdir(settings.OUTPUT_PATH) if delete_history: os.system('del history.json') @@ -188,6 +207,7 @@ def discover(names=None, pattern=['*.py'], skip='efp', dry_run=False, blacklist= try: log = json.load(open(result_file, 'r')) except: + logger.exception('Failed to open result file') pass if not log: @@ -274,6 +294,7 @@ def discover(names=None, pattern=['*.py'], skip='efp', dry_run=False, blacklist= suite.run(result) + def main(): parser = argparse.ArgumentParser(description='Thread harness test case runner') parser.add_argument('--auto-reboot', '-a', action='store_true', default=False,