提交 e2c2ec25 编写于 作者: O openharmony_ci 提交者: Gitee

!56 解决issue:https://gitee.com/openharmony/xts_acts/issues/I4EXQA?from=project-issue

Merge pull request !56 from alex_hold/cherry-pick-1635333693
...@@ -1610,9 +1610,9 @@ class JSUnitTestDriver(IDriver): ...@@ -1610,9 +1610,9 @@ class JSUnitTestDriver(IDriver):
self.result = check_result_report( self.result = check_result_report(
request.config.report_path, self.result, self.error_message) request.config.report_path, self.result, self.error_message)
def generate_console_output(self, device_log_file, request): def generate_console_output(self, device_log_file, request, timeout):
LOG.info("prepare to read device log, may wait some time") LOG.info("prepare to read device log, may wait some time")
result_message = self.read_device_log(device_log_file, "") result_message = self.read_device_log(device_log_file, timeout)
report_name = request.get_module_name() report_name = request.get_module_name()
parsers = get_plugin( parsers = get_plugin(
...@@ -1632,21 +1632,26 @@ class JSUnitTestDriver(IDriver): ...@@ -1632,21 +1632,26 @@ class JSUnitTestDriver(IDriver):
handler = ShellHandler(parser_instances) handler = ShellHandler(parser_instances)
process_command_ret(result_message, handler) process_command_ret(result_message, handler)
def read_device_log(self, device_log_file, result_message): def read_device_log(self, device_log_file, timeout=60):
device_log_file_open = os.open(device_log_file, os.O_RDONLY, LOG.info("The timeout is {} seconds".format(timeout))
stat.S_IWUSR | stat.S_IRUSR) while time.time() - self.start_time <= timeout:
result_message = ""
with os.fdopen(device_log_file_open, "r", encoding='utf-8') \ with open(device_log_file, "r", encoding='utf-8') \
as file_read_pipe: as file_read_pipe:
while True: lines = file_read_pipe.readlines()
data = file_read_pipe.readline() for line in lines:
if not data or not data.strip(): if line.find("JSApp:") != -1:
break result_message += line
# only filter JSApp log if "[end] run suites end" in line:
if data.find("JSApp:") != -1: LOG.info("Find the end mark then analysis result")
result_message += data return result_message
if data.find("[end] run suites end") != -1: # if test not finished, wait 5 seconds
break else:
LOG.info("did not find the end mark then wait 5 seconds")
time.sleep(5)
else:
LOG.error("Hjsunit run timeout {}s reached".format(timeout))
raise RuntimeError("Hjsunit run timeout!")
return result_message return result_message
def _run_jsunit(self, config_file, request): def _run_jsunit(self, config_file, request):
...@@ -1674,30 +1679,29 @@ class JSUnitTestDriver(IDriver): ...@@ -1674,30 +1679,29 @@ class JSUnitTestDriver(IDriver):
hilog_open = os.open(hilog, os.O_WRONLY | os.O_CREAT | os.O_APPEND, hilog_open = os.open(hilog, os.O_WRONLY | os.O_CREAT | os.O_APPEND,
0o755) 0o755)
# execute test case
command = "shell aa start -d 123 -a %s -b %s" \
% (ability_name, package)
result_value = self.config.device.hdc_command(command)
if result_value and "success" in str(result_value).lower():
setattr(self, "start_success", True)
LOG.info("execute %s's testcase success. result value=%s"
% (package, result_value))
else:
LOG.info("execute %s's testcase failed. result value=%s"
% (package, result_value))
raise RuntimeError("hjsunit test run error happened!")
with os.fdopen(hilog_open, "a") as hilog_file_pipe: with os.fdopen(hilog_open, "a") as hilog_file_pipe:
self.config.device.start_catch_device_log(hilog_file_pipe) self.config.device.start_catch_device_log(hilog_file_pipe)
# execute test case
command = "shell aa start -d 123 -a %s -b %s" \ self.start_time = time.time()
% (ability_name, package) timeout_config = get_config_value('test-timeout',
json_config.get_driver(),
result_value = self.config.device.hdc_command(command) False, 60000)
if "success" in str(result_value).lower(): timeout = int(timeout_config) / 1000
setattr(self, "start_success", True) self.generate_console_output(hilog, request, timeout)
LOG.info("execute %s's testcase success. result value=%s"
% (package, result_value))
else:
LOG.info("execute %s's testcase failed. result value=%s"
% (package, result_value))
self.start_time = time.time()
timeout_config = get_config_value('test-timeout',
json_config.get_driver(),
False, 60000)
timeout = int(timeout_config)/1000
LOG.info("wait {}s to keep app log".format(timeout))
time.sleep(timeout)
hilog_file_pipe.flush()
self.generate_console_output(hilog, request)
finally: finally:
do_module_kit_teardown(request) do_module_kit_teardown(request)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册