From 74595f267afd489694f4fbbc907bde849e220b1c Mon Sep 17 00:00:00 2001 From: mipengwei Date: Mon, 23 May 2022 15:11:17 +0800 Subject: [PATCH 1/2] refactor: --- .idea/.gitignore | 3 +++ .idea/codeStyles/codeStyleConfig.xml | 5 +++++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/test_developertest.iml | 14 ++++++++++++++ .idea/vcs.xml | 6 ++++++ libs/benchmark/report/generate_report.py | 8 ++++---- libs/fuzzlib/fuzzer_helper.py | 8 ++++---- libs/fuzzlib/tools/colored.py | 2 +- libs/fuzzlib/tools/run_result.py | 3 ++- src/core/config/config_manager.py | 16 ++++++---------- src/core/config/parse_parts_config.py | 15 ++++++--------- src/core/driver/lite_driver.py | 3 --- src/core/testcase/testcase_manager.py | 12 ++++++------ src/core/utils.py | 14 ++++++-------- 16 files changed, 81 insertions(+), 46 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/test_developertest.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d1e22ec --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b7dc1b9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/test_developertest.iml b/.idea/test_developertest.iml new file mode 100644 index 0000000..5bc8264 --- /dev/null +++ b/.idea/test_developertest.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/libs/benchmark/report/generate_report.py b/libs/benchmark/report/generate_report.py index a268bf4..e70c1cc 100644 --- a/libs/benchmark/report/generate_report.py +++ b/libs/benchmark/report/generate_report.py @@ -160,10 +160,10 @@ class BenchmarkReport(object): module_name, testsuit_name, json_file) self.benchmark_list = mdl_summary_list - if sbs_name in system_summary_dic.keys() \ - and testsuit_name in system_summary_dic[sbs_name].keys(): + if sbs_name in system_summary_dic.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.get(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..0084add 100644 --- a/libs/fuzzlib/tools/run_result.py +++ b/libs/fuzzlib/tools/run_result.py @@ -79,7 +79,8 @@ 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..710663c 100755 --- a/src/core/config/config_manager.py +++ b/src/core/config/config_manager.py @@ -214,19 +214,15 @@ class UserConfigManager(object): root = tree.getroot() node = root.find(target_name) - if not node: - return None if sub_target != "": node = node.find(sub_target) - if not node: - return None - - for sub in node: - if sub.text is None: - data_dic[sub.tag] = "" - else: - data_dic[sub.tag] = sub.text + if node: + for sub in node: + if sub.text is None: + data_dic[sub.tag] = "" + else: + data_dic[sub.tag] = sub.text except ET.ParseError as xml_exception: LOG.error(("Parse %s fail!" % self.filepath) + xml_exception.args) return data_dic 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..8a4296f 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 @@ -291,14 +290,12 @@ class LiteUnitTest(IDriver): show help info. """ self.log.info("this is test driver for cpp test") - return None def show_driver_info(self): """ 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..dc0db97 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, @@ -108,17 +108,17 @@ class TestCaseManager(object): continue if suffix_name == ".dex": - suite_file_dictionary["DEX"].append(suite_file) + suite_file_dictionary.get("DEX", []).append(suite_file) elif suffix_name == ".hap": - suite_file_dictionary["JST"].append(suite_file) + suite_file_dictionary.get("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) + suite_file_dictionary.get("PYT", []).append(suite_file) elif suffix_name == "": - suite_file_dictionary["CXX"].append(suite_file) + suite_file_dictionary.get("CXX", []).append(suite_file) elif suffix_name == ".bin": - suite_file_dictionary["BIN"].append(suite_file) + suite_file_dictionary.get("BIN", []).append(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 From d94ea45f5339e89753d339ab481e55fd54149d9e Mon Sep 17 00:00:00 2001 From: mipengwei Date: Mon, 23 May 2022 15:22:44 +0800 Subject: [PATCH 2/2] Signed-off-by:mipengwei --- .idea/.gitignore | 3 --- .idea/codeStyles/codeStyleConfig.xml | 5 ----- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/misc.xml | 4 ---- .idea/modules.xml | 8 -------- .idea/test_developertest.iml | 14 -------------- .idea/vcs.xml | 6 ------ 7 files changed, 46 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/codeStyles/codeStyleConfig.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/test_developertest.iml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index a55e7a1..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index d1e22ec..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index b7dc1b9..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/test_developertest.iml b/.idea/test_developertest.iml deleted file mode 100644 index 5bc8264..0000000 --- a/.idea/test_developertest.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file -- Gitee