修复OHJSUnit多测试套场景下App Die时用例统计丢失的bug

Signed-off-by: deveco_test <liguangjie1@huawei.com>
This commit is contained in:
deveco_test 2022-08-29 12:01:00 +08:00 committed by liguangjie
parent e9dbb7e50b
commit db1e0ad281
2 changed files with 22 additions and 11 deletions

View File

@ -251,7 +251,8 @@ class OHJSUnitTestDriver(IDriver):
0o755)
self.config.device.execute_shell_command(command="hilog -r")
with os.fdopen(hilog_open, "a") as hilog_file_pipe:
self.config.device.clear_crash_log()
if hasattr(self.config.device, "clear_crash_log"):
self.config.device.clear_crash_log()
self.config.device.start_catch_device_log(hilog_file_pipe=hilog_file_pipe)
self._run_oh_jsunit(config_file, request)
except Exception as exception:
@ -264,7 +265,8 @@ class OHJSUnitTestDriver(IDriver):
serial = "{}_{}".format(str(self.config.device.__get_serial__()), time.time_ns())
log_tar_file_name = "{}_{}".format(str(serial).replace(
":", "_"), request.get_module_name())
self.config.device.start_get_crash_log(log_tar_file_name)
if hasattr(self.config.device, "start_get_crash_log"):
self.config.device.start_get_crash_log(log_tar_file_name)
self.config.device.stop_catch_device_log()
self.result = check_result_report(
request.config.report_path, self.result, self.error_message)
@ -305,8 +307,9 @@ class OHJSUnitTestDriver(IDriver):
oh_jsunit_para_parse(self.runner, self.config.testargs)
test_to_run = self._collect_test_to_run()
LOG.info("Collected test count is: %s" % (len(test_to_run)
if test_to_run else 0))
LOG.info("Collected test count is: {}, test count is: {}".
format(len(self.runner.expect_tests_dict.keys()),
len(test_to_run) if test_to_run else 0))
finally:
do_module_kit_teardown(request)
@ -350,7 +353,7 @@ class OHJSUnitTestDriver(IDriver):
self.rerun = True if is_rerun == 'true' else False
if not package and not module:
raise ParamError("Neither package nor moodle is found"
raise ParamError("Neither package nor module is found"
" in config file.", error_no="03201")
timeout_config = get_config_value("shell-timeout",
json_config.get_driver(), False)
@ -372,8 +375,9 @@ class OHJSUnitTestDriver(IDriver):
def _do_test_run(self, listener):
test_to_run = self._collect_test_to_run()
LOG.info("Collected test count is: %s" % (len(test_to_run)
if test_to_run else 0))
LOG.info("Collected test count is: {}, test count is: {}".
format(len(self.runner.expect_tests_dict.keys()),
len(test_to_run) if test_to_run else 0))
if not test_to_run or not self.rerun:
self.runner.run(listener)
self.runner.notify_finished()

View File

@ -1242,6 +1242,9 @@ class OHJSUnitTestParser(IParser):
pos = self.runner.suite_recorder.get(suite.suite_name)[0]
if len(test_des_list) == len(report_listener.result[pos][1]):
continue
interval = len(test_des_list) - len(report_listener.result[pos][1])
LOG.info("{} tests in {} had missed".format(
interval, suite.suite_name))
for test_des in test_des_list:
is_contain = False
for case in report_listener.result[pos][1]:
@ -1257,6 +1260,8 @@ class OHJSUnitTestParser(IParser):
test_result.run_time = 0
test_result.code = ResultCode.BLOCKED.value
report_listener.result[pos][1].append(test_result)
LOG.debug("Add {}#{}".format(test_des.class_name,
test_des.test_name))
def _handle_lacking_whole_suite(self, report_listener):
all_suite_set = set(self.runner.expect_tests_dict.keys())
@ -1265,13 +1270,15 @@ class OHJSUnitTestParser(IParser):
suite_name_set = set()
for suite in report_listener.suites.values():
suite_name_set.add(suite.suite_name)
un_suite_set.union(all_suite_set.difference(suite_name_set))
for un_suite in un_suite_set:
un_suite_set = all_suite_set.difference(suite_name_set)
if un_suite_set:
LOG.info("{} suites had missed.".format(len(un_suite_set)))
for name in un_suite_set:
test_des_list = self.runner.expect_tests_dict.get(
un_suite.suite_name, [])
name, [])
current_suite = self.state_machine.suite(reset=True)
current_suite.test_num = len(test_des_list)
current_suite.suite_name = self.current_value
current_suite.suite_name = name
for listener in self.get_listeners():
suite = copy.copy(current_suite)
listener.__started__(LifeCycle.TestSuite, suite)