From c38d5019a8595ba82cc18647b8ffcb190165cb29 Mon Sep 17 00:00:00 2001 From: mipengwei Date: Mon, 23 May 2022 09:44:37 +0000 Subject: [PATCH] Signed-off-by:mipengwei --- libs/benchmark/report/generate_report.py | 6 ++-- libs/fuzzlib/fuzzer_helper.py | 8 ++--- libs/fuzzlib/tools/colored.py | 2 +- libs/fuzzlib/tools/run_result.py | 2 +- src/core/config/config_manager.py | 4 +-- src/core/config/parse_parts_config.py | 15 ++++------ src/core/driver/lite_driver.py | 2 -- src/core/testcase/testcase_manager.py | 37 +++++++++++++++--------- src/core/utils.py | 14 ++++----- 9 files changed, 47 insertions(+), 43 deletions(-) diff --git a/libs/benchmark/report/generate_report.py b/libs/benchmark/report/generate_report.py index a268bf4..280b617 100644 --- a/libs/benchmark/report/generate_report.py +++ b/libs/benchmark/report/generate_report.py @@ -161,9 +161,9 @@ class BenchmarkReport(object): self.benchmark_list = mdl_summary_list if sbs_name in system_summary_dic.keys() \ - and testsuit_name in system_summary_dic[sbs_name].keys(): + and testsuit_name in system_summary_dic.get(sbs_name, {}).keys(): subsystem_summary_dic = \ - system_summary_dic[sbs_name][testsuit_name] + system_summary_dic[sbs_name].get(testsuit_name, {}) subsystem_summary_dic["children"] += \ self._remove_iterations(mdl_summary_list) else: @@ -187,7 +187,7 @@ class BenchmarkReport(object): self._remove_iterations(mdl_summary_list) self.sbs_mdl_summary_list.append(subsystem_summary_dic) system_summary_dic[sbs_name] = {} - system_summary_dic[sbs_name][testsuit_name] = \ + system_summary_dic.get(sbs_name, {})[testsuit_name] = \ subsystem_summary_dic subsystem_summary_dic["pm"] = "unknown" subsystem_summary_dic["owner"] = "unknown" diff --git a/libs/fuzzlib/fuzzer_helper.py b/libs/fuzzlib/fuzzer_helper.py index b8c6217..53bd9a8 100644 --- a/libs/fuzzlib/fuzzer_helper.py +++ b/libs/fuzzlib/fuzzer_helper.py @@ -92,11 +92,11 @@ def _get_fuzzer_yaml_config(fuzzer_name): "projects", fuzzer_name, "project.yaml") + yaml_config = {} if not os.path.exists(project_yaml_path): - return None - #log run stdout to fuzzlog dir - with open(project_yaml_path) as filehandle: - yaml_config = yaml.safe_load(filehandle) + # log run stdout to fuzzlog dir + with open(project_yaml_path) as filehandle: + yaml_config = yaml.safe_load(filehandle) return yaml_config diff --git a/libs/fuzzlib/tools/colored.py b/libs/fuzzlib/tools/colored.py index fae3edf..21e0dc9 100644 --- a/libs/fuzzlib/tools/colored.py +++ b/libs/fuzzlib/tools/colored.py @@ -40,7 +40,7 @@ class Colored(object): @staticmethod def get_project_logger(log_project="default"): - if log_project in Colored.PROJECT_LOGGER_MAP: + if log_project in Colored.PROJECT_LOGGER_MAP.keys(): return Colored.PROJECT_LOGGER_MAP[log_project] logger = Colored(log_project) Colored.PROJECT_LOGGER_MAP[log_project] = logger diff --git a/libs/fuzzlib/tools/run_result.py b/libs/fuzzlib/tools/run_result.py index 5fb2b6e..17328ae 100644 --- a/libs/fuzzlib/tools/run_result.py +++ b/libs/fuzzlib/tools/run_result.py @@ -79,7 +79,7 @@ class RunResult(): if html_format: f.write(RunResult.filter_log(render_detail(self.crash_info))) else: - f.write(RunResult.filter_log(self.crash_info["backtrace"])) + f.write(RunResult.filter_log(self.crash_info.get("backtrace", ""))) if __name__ == "__main__": diff --git a/src/core/config/config_manager.py b/src/core/config/config_manager.py index 3b463f6..165a644 100755 --- a/src/core/config/config_manager.py +++ b/src/core/config/config_manager.py @@ -215,12 +215,12 @@ class UserConfigManager(object): node = root.find(target_name) if not node: - return None + return data_dic if sub_target != "": node = node.find(sub_target) if not node: - return None + return data_dic for sub in node: if sub.text is None: diff --git a/src/core/config/parse_parts_config.py b/src/core/config/parse_parts_config.py index 3e51417..1eaa280 100755 --- a/src/core/config/parse_parts_config.py +++ b/src/core/config/parse_parts_config.py @@ -52,16 +52,14 @@ class ParsePartsConfig(object): def get_infos_data(self): config_filepath = self.get_config_file_path() + data_dic = {} if not os.path.exists(config_filepath): print("Error: %s is not exist." % config_filepath) - return None, None - - data_dic = None - with open(config_filepath, 'r') as file_handle: - data_dic = json.load(file_handle) - if not data_dic: - print("Error: json file load error.") - return None, None + else: + with open(config_filepath, 'r') as file_handle: + data_dic = json.load(file_handle) + if not data_dic: + print("Error: json file load error.") # open source branch, the part form of all product is "phone" if is_open_source_product(self.productform): @@ -70,7 +68,6 @@ class ParsePartsConfig(object): product_data_dic = data_dic.get(self.productform, None) if product_data_dic is None: print("Error: product_data_dic is None.") - return None, None subsystem_infos = product_data_dic.get("subsystem_infos", None) part_infos = product_data_dic.get("part_infos", None) diff --git a/src/core/driver/lite_driver.py b/src/core/driver/lite_driver.py index 1f755f4..89fe534 100755 --- a/src/core/driver/lite_driver.py +++ b/src/core/driver/lite_driver.py @@ -80,7 +80,6 @@ class LiteUnitTest(IDriver): def __check_failed__(self, msg): self.log.error("check failed {}".format(msg)) - return None def __check_environment__(self, device_options): pass @@ -298,7 +297,6 @@ class LiteUnitTest(IDriver): show driver info. """ self.log.info("this is test driver for cpp test") - return None def __result__(self): pass diff --git a/src/core/testcase/testcase_manager.py b/src/core/testcase/testcase_manager.py index d0ac52a..3c37a58 100755 --- a/src/core/testcase/testcase_manager.py +++ b/src/core/testcase/testcase_manager.py @@ -59,7 +59,7 @@ class TestCaseManager(object): test_type, options) for key, value in suit_file_dic.items(): - suit_file_dic[key] = value + temp_dic[key] + suit_file_dic[key] = value + temp_dic.get(key, "") return suit_file_dic def get_test_file_data_by_test_type(self, test_case_path, @@ -72,6 +72,28 @@ class TestCaseManager(object): else: LOG.error("Test case dir does not exist. %s" % test_case_out_path) return suit_file_dictionary + + def check_dic(self, suffix_name, suite_file_dictionary, suite_file): + """ + + :param suffix_name: + :param suite_file_dictionary: + :param suite_file: + :return: + """ + suffix_dic = { + ".dex": "DEX", + ".hap": "JST", + ".py": "PYT", + "": "CXX", + ".bin": "BIN" + } + if suffix_name in suffix_dic.keys(): + if suite_file_dictionary.get(suffix_name, []) and isinstance( + suite_file_dictionary.get(suffix_name, []), list): + suite_file_dictionary[suffix_dic[suffix_name]].append(suite_file) + else: + suite_file_dictionary[suffix_dic[suffix_name]] = [suite_file] def get_all_test_file(self, test_case_out_path, options): suite_file_dictionary = copy.deepcopy(TESTFILE_TYPE_DATA_DIC) @@ -107,18 +129,7 @@ class TestCaseManager(object): options): continue - if suffix_name == ".dex": - suite_file_dictionary["DEX"].append(suite_file) - elif suffix_name == ".hap": - suite_file_dictionary["JST"].append(suite_file) - elif suffix_name == ".py": - if not self.check_python_test_file(suite_file): - continue - suite_file_dictionary["PYT"].append(suite_file) - elif suffix_name == "": - suite_file_dictionary["CXX"].append(suite_file) - elif suffix_name == ".bin": - suite_file_dictionary["BIN"].append(suite_file) + self.check_dic(suffix_name, suite_file_dictionary, suite_file) return suite_file_dictionary diff --git a/src/core/utils.py b/src/core/utils.py index fc0a589..e7e4212 100755 --- a/src/core/utils.py +++ b/src/core/utils.py @@ -124,14 +124,12 @@ def parse_device_name(product_form): device_json_file = os.path.join(sys.source_code_root_path, "productdefine", "common", "products", "{}.json".format(product_form)) - if not os.path.exists(device_json_file): - return None - - with open(device_json_file, 'r') as json_file: - json_info = json.load(json_file) - if not json_info: - return None - device_name = json_info.get('product_device') + json_info = {} + if os.path.exists(device_json_file): + with open(device_json_file, 'r') as json_file: + json_info = json.load(json_file) + + device_name = json_info.get('product_device', None) return device_name -- Gitee