def __process__(self, lines): if not self.state_machine.suites_is_started(): self.state_machine.trace_logs.extend(lines) for line in lines: if not check_pub_key_exist(): LOG.debug(line) self.parse(line)
def _generate_summary(self): if not self.summary_data_report_exist: return summary_ini_content = \ "[default]\n" \ "Platform=%s\n" \ "Test Type=%s\n" \ "Device Name=%s\n" \ "Host Info=%s\n" \ "Test Start/ End Time=%s\n" \ "Execution Time=%s\n" % ( self.exec_info.platform, self.exec_info.test_type, self.exec_info.device_name, self.exec_info.host_info, self.exec_info.test_time, self.exec_info.execute_time) if self.exec_info.product_params: for key, value in self.exec_info.product_params.items(): summary_ini_content = "{}{}".format(summary_ini_content, "%s=%s\n" % (key, value)) summary_ini_content = "{}{}".format( summary_ini_content, "Log Path=%s\n" % self.exec_info.log_path) # write summary_ini_content summary_filepath = os.path.join(self.report_path, ReportConstant.summary_ini) with open(summary_filepath, 'wb') as file_handler: if check_pub_key_exist(): cipher_text = do_rsa_encrypt(summary_ini_content) file_handler.write(cipher_text) else: file_handler.write(bytes(summary_ini_content, 'utf-8')) LOG.info("generate summary ini: %s", summary_filepath)
def _generate_vision_reports(self): if not self.summary_data_report_exist: LOG.error("summary data report not exists") return if check_pub_key_exist(): from xdevice import SuiteReporter if not SuiteReporter.get_report_result(): LOG.error("summary data report not exists") return self.summary_data_path = SuiteReporter.get_report_result()[0][1] SuiteReporter.clear_report_result() # parse data summary_element_tree = self.data_helper.parse_data_report( self.summary_data_path) parsed_data = self.vision_helper.parse_element_data( summary_element_tree, self.report_path, self.task_info) self.exec_info, summary, _ = parsed_data if not check_pub_key_exist(): LOG.info( "Summary result: modules: %s, modules done: %s, total: " "%s, passed: %s, failed: %s, blocked: %s, ignored: %s, " "unavailable: %s", summary.modules, summary.modules_done, summary.result.total, summary.result.passed, summary.result.failed, summary.result.blocked, summary.result.ignored, summary.result.unavailable) LOG.info("Log path: %s", self.exec_info.log_path) # generate summary vision report report_generate_flag = self._generate_vision_report( parsed_data, ReportConstant.summary_title, ReportConstant.summary_vision_report) # generate details vision report if report_generate_flag and summary.result.total > 0: self._generate_vision_report(parsed_data, ReportConstant.details_title, ReportConstant.details_vision_report) # generate failures vision report if summary.result.total != ( summary.result.passed + summary.result.ignored) or \ summary.result.unavailable > 0: self._generate_vision_report(parsed_data, ReportConstant.failures_title, ReportConstant.failures_vision_report)
def generate_report(summary_vision_path, report_context): vision_file = open(summary_vision_path, "wb") if check_pub_key_exist(): cipher_text = do_rsa_encrypt(report_context) vision_file.write(cipher_text) else: vision_file.write(bytes(report_context, "utf-8")) vision_file.close() LOG.info("generate vision report: %s", summary_vision_path)
def __started__(self, lifecycle, test_result): if check_pub_key_exist(): return if lifecycle == LifeCycle.TestSuite: LOG.debug("Start test suite [%s] with %s tests" % (test_result.suite_name, test_result.test_num)) self.test_num = test_result.test_num elif lifecycle == LifeCycle.TestCase: LOG.debug("testStarted(%s#%s)" % (test_result.test_class, test_result.test_name))
def __done__(self, result_code="", message=""): msg_fmt = "" if message: msg_fmt = ", message is {}".format(message) for parser in self.parsers: parser.__process__([message]) if not check_pub_key_exist(): LOG.debug("result code is: {}{}".format(result_code, msg_fmt)) for parser in self.parsers: parser.__done__()
def __skipped__(lifecycle, test_result, **kwargs): if check_pub_key_exist(): return del kwargs if lifecycle == LifeCycle.TestSuite: LOG.debug("Test suite [{}] skipped".format(test_result.suite_name)) elif lifecycle == LifeCycle.TestCase: ret = ResultCode(test_result.code).name LOG.debug("[{}] {}#{}".format(ret, test_result.test_class, test_result.test_name))
def parse(self, line): if self.state_machine.suites_is_started() or self._is_cpp_test_dryrun( line): if self._is_cpp_test_dryrun(line): self.handle_suites_started_tag() elif self._is_class(line): self._process_class_line(line) elif self._is_method(line): self._process_method_line(line) else: if not check_pub_key_exist(): LOG.debug("line ignored: %s" % line)
def generate_report(element, file_name): if check_pub_key_exist(): plain_text = DataHelper.to_string(element) cipher_text = do_rsa_encrypt(plain_text) with open(file_name, "wb") as file_handler: file_handler.write(cipher_text) else: tree = ElementTree.ElementTree(element) tree.write(file_name, encoding="UTF-8", xml_declaration=True, short_empty_elements=True) LOG.info("generate data report: %s", file_name)
def __init__(self, results, report_name, report_path=None, **kwargs): """ create suite report :param results: [(suite_result, [case_results]), (suite_result, [case_results]), ...] :param report_name: suite report name :param report_path: suite report path """ self.results = results self.data_helper = DataHelper() self.report_name = report_name self.report_path = report_path self.suite_data_path = os.path.join( self.report_path, report_name + self.data_helper.DATA_REPORT_SUFFIX) self.args = kwargs from xdevice import Scheduler if not check_pub_key_exist() and Scheduler.mode != "decc": SuiteReporter.suite_report_result.clear()
def data_reports(self): if check_pub_key_exist() or self._check_mode(ReportConstant.decc_mode): from xdevice import SuiteReporter suite_reports = SuiteReporter.get_report_result() data_reports = [(suite_report[1], ReportConstant.empty_name) for suite_report in suite_reports] SuiteReporter.clear_report_result() return data_reports if not os.path.isdir(self.report_path): return [] data_reports = [] result_path = os.path.join(self.report_path, "result") for root, _, files in os.walk(self.report_path): for file_name in files: if not file_name.endswith(self.data_helper.DATA_REPORT_SUFFIX): continue module_name = self._find_module_name(result_path, root) data_reports.append((os.path.join(root, file_name), module_name)) return data_reports
def _generate_data_report(self): # initial element test_suites_element = self.data_helper.initial_suites_element() # update test suites element update_flag = self._update_test_suites(test_suites_element) if not update_flag: return # generate report if not self._check_mode(ReportConstant.decc_mode): self.data_helper.generate_report(test_suites_element, self.summary_data_path) # set SuiteReporter.suite_report_result if not check_pub_key_exist() and not self._check_mode( ReportConstant.decc_mode): return from xdevice import SuiteReporter SuiteReporter.suite_report_result = [ (self.summary_data_path, DataHelper.to_string(test_suites_element)) ] if self._check_mode(ReportConstant.decc_mode): try: from devicetest.agent.auth_server import Handler from xdevice import Scheduler Handler.upload_task_summary_results( SuiteReporter.suite_report_result[0][1]) tmp_element = self.data_helper.initial_suites_element() for child in test_suites_element: result, _ = Scheduler.get_script_result(child) if result == "Passed": tmp_element.append(child) SuiteReporter.suite_report_result = [ (self.summary_data_path, DataHelper.to_string(tmp_element)) ] except ModuleNotFoundError as error: LOG.error("module not found %s", error.args)
def __ended__(self, lifecycle, test_result, **kwargs): if check_pub_key_exist(): return from _core.utils import convert_serial del kwargs if lifecycle == LifeCycle.TestSuite: LOG.debug("End test suite [%s] and cost %sms." % (test_result.suite_name, test_result.run_time)) elif lifecycle == LifeCycle.TestCase: LOG.debug("testEnded(%s#%s)" % (test_result.test_class, test_result.test_name)) ret = ResultCode(test_result.code).name if self.test_num: LOG.info("[%s/%s %s] %s#%s %s" % (test_result.current, self.test_num, convert_serial(self.device_sn), test_result.test_class, test_result.test_name, ret)) else: LOG.info("[%s/- %s] %s#%s %s" % (test_result.current, convert_serial(self.device_sn), test_result.test_class, test_result.test_name, ret))
def __process__(self, lines): for line in lines: if not check_pub_key_exist(): LOG.debug(line) self.parse(line)
def handle_test_run_failed(error_msg): if not error_msg: error_msg = "Unknown error" if not check_pub_key_exist(): LOG.debug("error_msg:%s" % error_msg)