From dc55779df1d478234c5aee8cc985ed10ea5b39c8 Mon Sep 17 00:00:00 2001 From: Buke Po Date: Wed, 14 Dec 2016 13:29:50 +0800 Subject: [PATCH] Improvements for r33 (#1071) * get firmware version at runtime * walkaround harness hang issue --- .../autothreadharness/harness_case.py | 10 ++++++++++ .../autothreadharness/harness_controller.py | 10 +++++++++- tools/harness-thci/OpenThread.py | 7 ++----- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tools/harness-automation/autothreadharness/harness_case.py b/tools/harness-automation/autothreadharness/harness_case.py index cdba8e6e0..427c01d10 100644 --- a/tools/harness-automation/autothreadharness/harness_case.py +++ b/tools/harness-automation/autothreadharness/harness_case.py @@ -36,6 +36,7 @@ from selenium.common.exceptions import UnexpectedAlertPresentException import json import logging import os +import subprocess import re import time import unittest @@ -648,6 +649,15 @@ class HarnessCase(unittest.TestCase): self.timeout -= 1 + # check if already ended capture + if self.timeout % 10 == 0: + lines = self._hc.tail() + if 'SUCCESS: The process "dumpcap.exe" with PID ' in lines: + logger.info('Tshark should be ended now, lets wait at most 30 seconds.') + if not self.wait_until(lambda: 'tshark.exe' not in subprocess.check_output('tasklist'), 30): + res = subprocess.check_output('taskkill /t /f /im tshark.exe', stderr=subprocess.STDOUT, shell=True) + logger.info(res) + # Wait until case really stopped self.wait_until(lambda: self._browser.find_element_by_id('runTest') and True, 30) diff --git a/tools/harness-automation/autothreadharness/harness_controller.py b/tools/harness-automation/autothreadharness/harness_controller.py index 8fed929d2..4fde3aad6 100644 --- a/tools/harness-automation/autothreadharness/harness_controller.py +++ b/tools/harness-automation/autothreadharness/harness_controller.py @@ -50,6 +50,7 @@ class HarnessController(object): def __init__(self, result_dir=None): self.result_dir = result_dir + self.harness_file = '' def start(self): logger.info('Starting harness service') @@ -58,7 +59,9 @@ class HarnessController(object): else: env = dict(os.environ, PYTHONPATH='%s\\Thread_Harness;%s\\ThirdParty\\hsdk-python\\src' % (settings.HARNESS_HOME, settings.HARNESS_HOME)) - with open('%s\\harness-%s.log' % (self.result_dir, time.strftime('%Y%m%d%H%M%S')), 'w') as harnessOut: + + self.harness_file = '%s\\harness-%s.log' % (self.result_dir, time.strftime('%Y%m%d%H%M%S')) + with open(self.harness_file, 'w') as harnessOut: self.harness = subprocess.Popen([settings.HARNESS_HOME + '\\Python27\\python.exe', settings.HARNESS_HOME + '\\Thread_Harness\\Run.py'], cwd=settings.HARNESS_HOME, @@ -91,6 +94,11 @@ class HarnessController(object): else: logger.warning('Miniweb not started yet') + def tail(self): + with open(self.harness_file) as harnessOut: + harnessOut.seek(-100, 2) + return ''.join(harnessOut.readlines()) + def _try_kill(self, proc): logger.info('Try kill process') times = 3 diff --git a/tools/harness-thci/OpenThread.py b/tools/harness-thci/OpenThread.py index 052cc4110..e2a7c983f 100755 --- a/tools/harness-thci/OpenThread.py +++ b/tools/harness-thci/OpenThread.py @@ -49,7 +49,6 @@ linesepx = re.compile(r'\r\n|\n') """regex: used to split lines""" class OpenThread(IThci): - firmware = 'g7d33184; CC2538; Dec 1 2016 15:43:40' UIStatusMsg = '' networkDataRequirement = '' # indicate Thread device requests full or stable network data isPowerDown = False # indicate if Thread device experiences a power down event @@ -70,7 +69,6 @@ class OpenThread(IThci): self.mac = kwargs.get('EUI') self.port = kwargs.get('SerialPort') self.handle = None - self.UIStatusMsg = self.firmware self.networkName = ModuleHelper.Default_NwkName self.networkKey = ModuleHelper.Default_NwkKey self.channel = ModuleHelper.Default_Channel @@ -674,10 +672,9 @@ class OpenThread(IThci): self.handle = socket.create_connection((host, port)) self.handle.setblocking(0) self._is_net = True - # check connectivity, this make sure bad device fail on initializing - self.__sendCommand('state') else: raise Exception('Unknown port schema') + self.UIStatusMsg = self.getVersionNumber() def closeConnection(self): """close current serial port connection""" @@ -1164,7 +1161,7 @@ class OpenThread(IThci): def getVersionNumber(self): """get OpenThread stack firmware version number""" print '%s call getVersionNumber' % self.port - return self.firmware + return self.__sendCommand('version')[0] def setPANID(self, xPAN): """set Thread Network PAN ID