From 396ae9e50ed7c8f85200e9682e70f8c8cb5267a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=9B=BD=E8=BE=89?= Date: Tue, 30 Jul 2024 03:08:02 +0000 Subject: [PATCH 1/3] =?UTF-8?q?Signed-off-by:=20=E9=BB=84=E5=9B=BD?= =?UTF-8?q?=E8=BE=89=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 黄国辉 --- aw/python/distributed/common/devices.py | 77 +-- aw/python/distributed/common/manager.py | 34 +- .../distributed/distribute/distribute.py | 206 ++++---- libs/benchmark/report/benchmark_reporter.py | 1 + libs/benchmark/report/generate_report.py | 36 +- libs/fuzzlib/fuzzer_helper.py | 2 +- libs/fuzzlib/tools/colored.py | 61 ++- libs/fuzzlib/tools/run_result.py | 8 +- libs/fuzzlib/tools/templates.py | 2 +- .../keyword_registration/keyword_filter.py | 353 +++++++------- src/core/build/build_manager.py | 128 +++-- src/core/build/build_testcases.py | 205 ++++---- src/core/build/select_targets.py | 122 ++--- src/core/command/console.py | 212 +++++---- src/core/command/gen.py | 29 +- src/core/command/run.py | 74 ++- src/core/config/config_manager.py | 38 +- src/core/config/resource_manager.py | 241 +++++----- src/core/driver/drivers.py | 442 +++++++++--------- src/core/driver/lite_driver.py | 81 ++-- src/core/testcase/testcase_manager.py | 262 +++++------ src/core/testkit/kit_lite.py | 83 ++-- 22 files changed, 1347 insertions(+), 1350 deletions(-) diff --git a/aw/python/distributed/common/devices.py b/aw/python/distributed/common/devices.py index 913de00..8cb11ce 100755 --- a/aw/python/distributed/common/devices.py +++ b/aw/python/distributed/common/devices.py @@ -96,6 +96,44 @@ class DeviceShell: self.device_params = self.get_device_para( remote_ip, repote_port, device_sn) self.init_device() + + @classmethod + def execute_command(cls, command, print_flag=True, timeout=900): + try: + if print_flag: + print("command: " + command) + if subprocess.call(command, shell=True, timeout=timeout) == 0: + print("results: successed") + return True + except Exception as error: + print("Exception: %s" % str(error)) + print("results: failed") + return False + + @classmethod + def execute_command_with_output(cls, command, print_flag=True): + if print_flag: + print("command: " + command) + + proc = subprocess.Popen(command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=True) + result = "" + try: + data, _ = proc.communicate() + if isinstance(data, bytes): + result = data.decode("utf-8", "ignore") + finally: + proc.stdout.close() + proc.stderr.close() + return data if result else data + + @classmethod + def check_path_legal(cls, path): + if path and " " in path: + return "\"%s\"" % path + return path @classmethod def get_device_para(cls, remote_ip="", remote_port="", @@ -122,6 +160,7 @@ class DeviceShell: return device_para + def remount(self): if self.conn_type: remount = "target mount" @@ -185,19 +224,6 @@ class DeviceShell: command, QUOTATION_MARKS)) - @classmethod - def execute_command(cls, command, print_flag=True, timeout=900): - try: - if print_flag: - print("command: " + command) - if subprocess.call(command, shell=True, timeout=timeout) == 0: - print("results: successed") - return True - except Exception as error: - print("Exception: %s" % str(error)) - print("results: failed") - return False - def shell_with_output(self, command=""): return self.execute_command_with_output("%s %s shell %s%s%s" % ( HDC_TOOLS, @@ -205,28 +231,3 @@ class DeviceShell: QUOTATION_MARKS, command, QUOTATION_MARKS)) - - @classmethod - def execute_command_with_output(cls, command, print_flag=True): - if print_flag: - print("command: " + command) - - proc = subprocess.Popen(command, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - shell=True) - result = "" - try: - data, _ = proc.communicate() - if isinstance(data, bytes): - result = data.decode("utf-8", "ignore") - finally: - proc.stdout.close() - proc.stderr.close() - return data if result else data - - @classmethod - def check_path_legal(cls, path): - if path and " " in path: - return "\"%s\"" % path - return path \ No newline at end of file diff --git a/aw/python/distributed/common/manager.py b/aw/python/distributed/common/manager.py index ef58315..09bccfd 100755 --- a/aw/python/distributed/common/manager.py +++ b/aw/python/distributed/common/manager.py @@ -33,6 +33,23 @@ class DeviceManager: self.watch_device_list = [] self.make_device_list(result_path) + @staticmethod + def get_device_info_list(result): + device_info_list = [] + tmp_path = os.path.join(result, "temp") + device_info_file_path = os.path.join(tmp_path, + "device_info_file.txt") + + if os.path.exists(device_info_file_path): + with open(device_info_file_path, "r") as file_handle: + lines = file_handle.readlines() + for line in lines: + line = line.replace("\n", "") + line = line.strip() + temp = line.split(",") + device_info_list.append(temp) + return device_info_list + def make_device_adapter(self, device_info_list, device_name): device = DeviceShell(self.is_hdc, device_sn=device_info_list[0], remote_ip=device_info_list[2], @@ -71,22 +88,5 @@ class DeviceManager: setattr(self, device.name, device) return - @staticmethod - def get_device_info_list(result): - device_info_list = [] - tmp_path = os.path.join(result, "temp") - device_info_file_path = os.path.join(tmp_path, - "device_info_file.txt") - - if os.path.exists(device_info_file_path): - with open(device_info_file_path, "r") as file_handle: - lines = file_handle.readlines() - for line in lines: - line = line.replace("\n", "") - line = line.strip() - temp = line.split(",") - device_info_list.append(temp) - return device_info_list - ############################################################################## ############################################################################## diff --git a/aw/python/distributed/distribute/distribute.py b/aw/python/distributed/distribute/distribute.py index ad3e24c..e52d046 100755 --- a/aw/python/distributed/distribute/distribute.py +++ b/aw/python/distributed/distribute/distribute.py @@ -85,40 +85,6 @@ class Distribute: self.agent_list = agent_list self.hdc_tools = hdc_tools - def exec_agent(self, device, target_name, result_path, options): - driver = get_current_driver(device, target_name, self.hdc_tools) - if driver is None: - print("Error: driver is None.") - return False - - resource_dir = get_resource_dir(self.suite_dir, device.name) - - self._make_agent_desc_file(device) - device.push_file(os.path.join(self.suite_dir, "agent.desc"), - device.test_path) - device.push_file(os.path.join(resource_dir, target_name), - device.test_path) - - suite_path = os.path.join(self.suite_dir, target_name) - driver.execute(suite_path, result_path, options, background=True) - return self._check_thread(device, target_name) - - def exec_major(self, device, target_name, result_path, options): - driver = get_current_driver(device, target_name, self.hdc_tools) - if driver is None: - print("Error: driver is None.") - return False - - resource_dir = get_resource_dir(self.suite_dir, device.name) - self._make_major_desc_file() - device.push_file(os.path.join(self.suite_dir, "major.desc"), - device.test_path) - device.push_file(os.path.join(resource_dir, target_name), - device.test_path) - - suite_path = os.path.join(self.suite_dir, target_name) - return driver.execute(suite_path, result_path, options, background=False) - @staticmethod def pull_result(device, source_path, result_save_path): _, file_name = os.path.split(source_path) @@ -141,75 +107,6 @@ class Distribute: break return True if checksum < 100 else False - def _make_agent_desc_file(self, device): - agent_ip_list = "" - device_uuid_list = "" - - if self.hdc_tools != "hdc": - if self._query_device_uuid(self.major) != '': - device_uuid_list += self._query_device_uuid(self.major) + "," - - if self._query_device_ip(device) != "": - agent_ip_list += self._query_device_ip(device) + "," - - for agent in self.agent_list: - if self._query_device_uuid(agent): - device_uuid_list += self._query_device_uuid(agent) + "," - - config_info = DEVICE_INFO_TEMPLATE % (agent_ip_list, "8888", - device_uuid_list) - - config_agent_file = os.path.join(self.suite_dir, "agent.desc") - self._write_device_config(config_info, config_agent_file) - else: - if self._query_device_agent_uuid(self.major): - device_uuid_list += self._query_device_agent_uuid(self.major) + "," - - if self._query_device_hdc_ip(device): - agent_ip_list += self._query_device_hdc_ip(device) + "," - - for agent in self.agent_list: - if self._query_device_agent_uuid(agent): - device_uuid_list += self._query_device_agent_uuid(agent) + "," - - config_info = DEVICE_INFO_TEMPLATE % (agent_ip_list, "8888", - device_uuid_list) - - config_agent_file = os.path.join(self.suite_dir, "agent.desc") - self._write_device_config(config_info, config_agent_file) - - def _make_major_desc_file(self): - agent_ip_list = "" - device_uuid_list = "" - - if self.hdc_tools != "hdc": - if self._query_device_uuid(self.major) != "NoneTyple": - device_uuid_list += self._query_device_uuid(self.major) + "," - - for agent in self.agent_list: - if self._query_device_ip(agent) != "" and self._query_device_uuid(agent) != "": - agent_ip_list += self._query_device_ip(agent) + "," - device_uuid_list += self._query_device_uuid(agent) + "," - - config_info = DEVICE_INFO_TEMPLATE % (agent_ip_list, "8888", - device_uuid_list) - - config_major_file = os.path.join(self.suite_dir, "major.desc") - self._write_device_config(config_info, config_major_file) - else: - if self._query_device_major_uuid(self.major): - device_uuid_list += self._query_device_major_uuid(self.major) + "," - - for agent in self.agent_list: - if self._query_device_major_uuid(agent): - agent_ip_list += self._query_device_hdc_ip(agent) + "," - device_uuid_list += self._query_device_major_uuid(agent) + "," - config_info = DEVICE_INFO_TEMPLATE % (agent_ip_list, "8888", - device_uuid_list) - - config_major_file = os.path.join(self.suite_dir, "major.desc") - self._write_device_config(config_info, config_major_file) - @staticmethod def _query_device_ip(device): output = device.shell_with_output("getprop ro.hardware") @@ -316,6 +213,109 @@ class Distribute: with os.fdopen(os.open(file_path, FLAGS, MODES), 'w') as file_desc: file_desc.write(device_info) os.rename(file_path, final_file) + + def exec_agent(self, device, target_name, result_path, options): + driver = get_current_driver(device, target_name, self.hdc_tools) + if driver is None: + print("Error: driver is None.") + return False + + resource_dir = get_resource_dir(self.suite_dir, device.name) + + self._make_agent_desc_file(device) + device.push_file(os.path.join(self.suite_dir, "agent.desc"), + device.test_path) + device.push_file(os.path.join(resource_dir, target_name), + device.test_path) + + suite_path = os.path.join(self.suite_dir, target_name) + driver.execute(suite_path, result_path, options, background=True) + return self._check_thread(device, target_name) + + def exec_major(self, device, target_name, result_path, options): + driver = get_current_driver(device, target_name, self.hdc_tools) + if driver is None: + print("Error: driver is None.") + return False + + resource_dir = get_resource_dir(self.suite_dir, device.name) + self._make_major_desc_file() + device.push_file(os.path.join(self.suite_dir, "major.desc"), + device.test_path) + device.push_file(os.path.join(resource_dir, target_name), + device.test_path) + + suite_path = os.path.join(self.suite_dir, target_name) + return driver.execute(suite_path, result_path, options, background=False) + + def _make_agent_desc_file(self, device): + agent_ip_list = "" + device_uuid_list = "" + + if self.hdc_tools != "hdc": + if self._query_device_uuid(self.major) != '': + device_uuid_list += self._query_device_uuid(self.major) + "," + + if self._query_device_ip(device) != "": + agent_ip_list += self._query_device_ip(device) + "," + + for agent in self.agent_list: + if self._query_device_uuid(agent): + device_uuid_list += self._query_device_uuid(agent) + "," + + config_info = DEVICE_INFO_TEMPLATE % (agent_ip_list, "8888", + device_uuid_list) + + config_agent_file = os.path.join(self.suite_dir, "agent.desc") + self._write_device_config(config_info, config_agent_file) + else: + if self._query_device_agent_uuid(self.major): + device_uuid_list += self._query_device_agent_uuid(self.major) + "," + + if self._query_device_hdc_ip(device): + agent_ip_list += self._query_device_hdc_ip(device) + "," + + for agent in self.agent_list: + if self._query_device_agent_uuid(agent): + device_uuid_list += self._query_device_agent_uuid(agent) + "," + + config_info = DEVICE_INFO_TEMPLATE % (agent_ip_list, "8888", + device_uuid_list) + + config_agent_file = os.path.join(self.suite_dir, "agent.desc") + self._write_device_config(config_info, config_agent_file) + + def _make_major_desc_file(self): + agent_ip_list = "" + device_uuid_list = "" + + if self.hdc_tools != "hdc": + if self._query_device_uuid(self.major) != "NoneTyple": + device_uuid_list += self._query_device_uuid(self.major) + "," + + for agent in self.agent_list: + if self._query_device_ip(agent) != "" and self._query_device_uuid(agent) != "": + agent_ip_list += self._query_device_ip(agent) + "," + device_uuid_list += self._query_device_uuid(agent) + "," + + config_info = DEVICE_INFO_TEMPLATE % (agent_ip_list, "8888", + device_uuid_list) + + config_major_file = os.path.join(self.suite_dir, "major.desc") + self._write_device_config(config_info, config_major_file) + else: + if self._query_device_major_uuid(self.major): + device_uuid_list += self._query_device_major_uuid(self.major) + "," + + for agent in self.agent_list: + if self._query_device_major_uuid(agent): + agent_ip_list += self._query_device_hdc_ip(agent) + "," + device_uuid_list += self._query_device_major_uuid(agent) + "," + config_info = DEVICE_INFO_TEMPLATE % (agent_ip_list, "8888", + device_uuid_list) + + config_major_file = os.path.join(self.suite_dir, "major.desc") + self._write_device_config(config_info, config_major_file) ############################################################################## ############################################################################## diff --git a/libs/benchmark/report/benchmark_reporter.py b/libs/benchmark/report/benchmark_reporter.py index b90bf25..c95772c 100644 --- a/libs/benchmark/report/benchmark_reporter.py +++ b/libs/benchmark/report/benchmark_reporter.py @@ -29,6 +29,7 @@ from _core.logger import platform_logger __all__ = ["BenchmarkReporter"] LOG = platform_logger("BenchmarkReporter") + @Plugin(type=Plugin.REPORTER, id=TestType.benchmark) class BenchmarkReporter(IReporter): diff --git a/libs/benchmark/report/generate_report.py b/libs/benchmark/report/generate_report.py index 45ae6bd..4de2159 100644 --- a/libs/benchmark/report/generate_report.py +++ b/libs/benchmark/report/generate_report.py @@ -27,6 +27,7 @@ MODES = stat.S_IWUSR | stat.S_IRUSR SETTING_RED_STYLE = """\033[33;31m%s\033[0m""" + def load_json_data(json_file_path): json_data = {} if os.path.isfile(json_file_path): @@ -68,6 +69,7 @@ def get_file_list_by_postfix(path, postfix, filter_jar=""): file_list.append(file_path) return file_list + class BenchmarkReport(object): SUBSYSTEM_SUMMARY = "OHOS_SUBSYSTEM_SUMMARY" ENABLE_LINK = "OHOS_ENABLE_PASSCASE_LINK" @@ -89,23 +91,6 @@ class BenchmarkReport(object): self.benchmark_list = [] self._init_default_item() - def _init_default_item(self): - self.default_item.append("Subsystem") - self.default_item.append("Module") - self.default_item.append("Testsuit") - self.default_item.append("Benchmark") - self.default_item.append("Mode") - self.default_item.append("RunType") - self.default_item.append("TestTargetName") - self.default_item.append("TestTargetMethod") - self.default_item.append("Repetitions") - self.default_item.append("RepetitionIndex") - self.default_item.append("Threads") - self.default_item.append("Iterations") - self.default_item.append("Score") - self.default_item.append("CpuTime") - self.max_index = len(self.default_item) + 1000 - def generate_benchmark(self, args): if args is None or len(args) <= 2: print(SETTING_RED_STYLE % @@ -128,6 +113,23 @@ class BenchmarkReport(object): self._get_benchmark_result_data(src_path) self._generate_benchmark_summary_report(os.path.abspath(dest_path)) self._generate_all_benchmark_detail(os.path.abspath(dest_path)) + + def _init_default_item(self): + self.default_item.append("Subsystem") + self.default_item.append("Module") + self.default_item.append("Testsuit") + self.default_item.append("Benchmark") + self.default_item.append("Mode") + self.default_item.append("RunType") + self.default_item.append("TestTargetName") + self.default_item.append("TestTargetMethod") + self.default_item.append("Repetitions") + self.default_item.append("RepetitionIndex") + self.default_item.append("Threads") + self.default_item.append("Iterations") + self.default_item.append("Score") + self.default_item.append("CpuTime") + self.max_index = len(self.default_item) + 1000 def _remove_iterations(self, mdl_summary_list): final_mdl_summary = [] diff --git a/libs/fuzzlib/fuzzer_helper.py b/libs/fuzzlib/fuzzer_helper.py index e451ee3..424417f 100644 --- a/libs/fuzzlib/fuzzer_helper.py +++ b/libs/fuzzlib/fuzzer_helper.py @@ -166,7 +166,7 @@ def generate(args): #complie fuzzer project -def make(args, stdout=None): +def make(args, stdout=None): """make fuzzer module.""" color_logger = Colored.get_project_logger() diff --git a/libs/fuzzlib/tools/colored.py b/libs/fuzzlib/tools/colored.py index 865c1f3..69caa84 100644 --- a/libs/fuzzlib/tools/colored.py +++ b/libs/fuzzlib/tools/colored.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + import sys import os import time @@ -42,6 +43,12 @@ class Colored(object): PROJECT_LOGGER_MAP = {} + def __init__(self, log_project="default"): + self.is_debug = True + self.is_log_file = False + self.log_project = log_project + self.log_date = time.strftime("%Y%m%d%H%M%S", time.localtime()) + @staticmethod def get_project_logger(log_project="default"): if log_project in Colored.PROJECT_LOGGER_MAP: @@ -50,12 +57,26 @@ class Colored(object): Colored.PROJECT_LOGGER_MAP[log_project] = logger return logger - def __init__(self, log_project="default"): - self.is_debug = True - self.is_log_file = False - self.log_project = log_project - self.log_date = time.strftime("%Y%m%d%H%M%S", time.localtime()) + @staticmethod + def get_fuzz_log_dir(): + return Colored.LOG_DIR + @staticmethod + def log_task_init(project): + Colored.LOG_TO_FILE = True + Colored.LOG_PROJECT = project + Colored.LOG_DATE = time.strftime("%Y%m%d%H%M%S", time.localtime()) + + if not os.path.exists(Colored.LOG_DIR): + os.mkdir(Colored.LOG_DIR) + + project_log_dir = Colored.get_fuzz_project_log_dir() + if not os.path.exists(project_log_dir): + os.mkdir(project_log_dir) + + current_project_log_dir = Colored.get_fuzz_current_project_log_dir() + if not os.path.exists(current_project_log_dir): + os.mkdir(current_project_log_dir) def start_log_file(self): self.is_log_file = True @@ -70,7 +91,6 @@ class Colored(object): if not os.path.exists(current_project_log_dir): os.mkdir(current_project_log_dir) - def get_fuzz_project_log_dir(self): return os.path.join(Colored.LOG_DIR, self.log_project) @@ -89,7 +109,6 @@ class Colored(object): with os.fdopen(os.open(run_log, FLAGS, MODES), 'ab') as f: f.write(msg + "\n") - def color_str(self, color, s, tag=None): msg = "" if tag: @@ -100,7 +119,7 @@ class Colored(object): Colored.RESET ) else: - msg = '{}{}{}'.format( + msg = '{}{}{}'.format( getattr(Colored, color), s, Colored.RESET @@ -111,16 +130,13 @@ class Colored(object): def red(self, s): print(self.color_str('RED', s, "[ERROR] ")) - def green(self, s): if self.is_debug: print(self.color_str('GREEN', s, "[INFO] ")) - def yellow(self, s): print(self.color_str('YELLOW', s, "[WARNING] ")) - def blue(self, s): return self.color_str('BLUE', s) @@ -133,29 +149,6 @@ class Colored(object): def white(self, s): print(self.color_str('WHITE', s)) - def simple_print(self, s): self.loghook(s) print(s) - - - @staticmethod - def get_fuzz_log_dir(): - return Colored.LOG_DIR - - @staticmethod - def log_task_init(project): - Colored.LOG_TO_FILE = True - Colored.LOG_PROJECT = project - Colored.LOG_DATE = time.strftime("%Y%m%d%H%M%S", time.localtime()) - - if not os.path.exists(Colored.LOG_DIR): - os.mkdir(Colored.LOG_DIR) - - project_log_dir = Colored.get_fuzz_project_log_dir() - if not os.path.exists(project_log_dir): - os.mkdir(project_log_dir) - - current_project_log_dir = Colored.get_fuzz_current_project_log_dir() - if not os.path.exists(current_project_log_dir): - os.mkdir(current_project_log_dir) diff --git a/libs/fuzzlib/tools/run_result.py b/libs/fuzzlib/tools/run_result.py index 8c2490b..662d6ab 100644 --- a/libs/fuzzlib/tools/run_result.py +++ b/libs/fuzzlib/tools/run_result.py @@ -56,10 +56,6 @@ class RunResult(): "report_progress": 0 } - - def get_log(self): - return "code :{}, msg: {}".format(self.code, self.data) - @staticmethod def filter_log(log_str): ansi_escape = re.compile(r''' @@ -76,6 +72,9 @@ class RunResult(): result = ansi_escape.sub('', log_str) return result + def get_log(self): + return "code :{}, msg: {}".format(self.code, self.data) + def analysis(self, result, outdir): pass @@ -87,6 +86,7 @@ class RunResult(): f.write(RunResult.filter_log(render_detail(self.crash_info))) else: f.write(RunResult.filter_log(self.crash_info["backtrace"])) + if __name__ == "__main__": diff --git a/libs/fuzzlib/tools/templates.py b/libs/fuzzlib/tools/templates.py index deb5675..5a3cde3 100644 --- a/libs/fuzzlib/tools/templates.py +++ b/libs/fuzzlib/tools/templates.py @@ -186,7 +186,7 @@ REPORT_CSS_TEMPLATE = """ def render_tbody(data): - res = "" + res = "" for row in data: row_line = "" for row_td in row: diff --git a/localCoverage/keyword_registration/keyword_filter.py b/localCoverage/keyword_registration/keyword_filter.py index 35b3646..778caba 100644 --- a/localCoverage/keyword_registration/keyword_filter.py +++ b/localCoverage/keyword_registration/keyword_filter.py @@ -94,19 +94,6 @@ class KeywordRegistration: self.keyword_file_path = os.path.normcase( os.path.join(os.path.dirname(__file__), "keyword.json")) - def get_keyword_info(self): - """ - 获取报备关键字信息 - """ - try: - with open(self.keyword_file_path, "r") as file: - keyword_dict = json.load(file) - keyword_list = keyword_dict.get("KEYWORD") - return keyword_list - except (FileNotFoundError, AttributeError, FileExistsError): - print(f"获取报备过滤关键字报错") - return [] - @staticmethod def get_coverage_content(file_path): """ @@ -153,6 +140,176 @@ class KeywordRegistration: tag = tag.replace(item, replace_item) return tag + @staticmethod + def get_branch_line_list(keyword_line: int, branch_line_list: list): + """ + 获取大于关键字行号的所有分支行号 + """ + if keyword_line in branch_line_list: + index = branch_line_list.index(keyword_line) + branch_line_list = branch_line_list[index:] + else: + for line in branch_line_list: + if line > keyword_line: + index = branch_line_list.index(line) + branch_line_list = branch_line_list[index:] + break + return branch_line_list + + @staticmethod + def get_keyword_judge_char(keyword, keyword_source_code): + """ + 获取关键字替代字符 + """ + if "&" in keyword: + keyword = keyword.replace("&", "<") + + keyword_index = keyword_source_code.find(keyword) + if keyword_index == -1: + return "" + + try: + keyword_code = keyword_source_code[:keyword_index + len(keyword)] + if " = " in keyword_code: + judge_key = keyword_code.split(" = ")[0].split()[-1] + else: + bracket_index = keyword_code.find("(") + bracket_code = keyword_code[:bracket_index] + judge_key = bracket_code.split()[-1] + return judge_key + except (IndexError, ValueError): + print("获取关键字替代字符失败") + return "" + + @staticmethod + def get_branch_data_by_tag(tag_html: str, symbol_status=None): + """ + 根据前端标签获取分支数据 + """ + if symbol_status: + key = r"#+\-*" + else: + key = r"#+\-" + branch_line_list = re.findall(rf"> ([{key}]) ", tag_html) + + return branch_line_list + + @staticmethod + def get_judge_condition_index(judge_key: str, source_code: str): + """ + 获取判断条件索引 + """ + keyword_index_list = [] + keyword_index_list_append = keyword_index_list.append + + condition_str_list = re.split(rf"\|\||&&", source_code) + for index, code_str in enumerate(condition_str_list): + if judge_key in code_str: + keyword_index_list_append(index) + return keyword_index_list, condition_str_list + + @staticmethod + def update_source_code_tag(html_tag: str): + replace_item_list = ["lineNum", "lineCov", "lineNoCov"] + + for item in replace_item_list: + if item in html_tag: + replace_item = (item + "Update").lower() + html_tag = html_tag.replace(item, replace_item) + + return html_tag + + @staticmethod + def _branch_replace(branch): + """ + 分支符号替换 + """ + if branch == "#": + branch = "> # <" + elif branch == "+": + branch = "> + <" + elif branch == "*": + branch = "> * <" + else: + branch = "> - <" + return branch + + @staticmethod + def _single_condition_modify_html(branch_html, branch_list): + """ + 单条件修改代码块html + """ + line_item = ' ' + line_feed_index = branch_html.find(line_item) + if line_feed_index == -1: + if "+" in branch_list: + update_branch_tag = branch_html.replace("> - <", "> <") + update_branch_tag = update_branch_tag.replace("> # <", "> <") + else: + try: + first_branch = branch_list[0] + first_branch = "> " + first_branch + " <" + first_branch_index = branch_html.find(first_branch) + branch_tag = branch_html[:first_branch_index + 5] + update_branch_tag = branch_html[first_branch_index + 5:] + update_branch_tag = update_branch_tag.replace("> - <", "> <") + update_branch_tag = update_branch_tag.replace("> # <", "> <") + update_branch_tag = branch_tag + update_branch_tag + except ValueError: + return "" + else: + line_feed_index = branch_html.find(line_item) + update_branch_tag = branch_html[:line_feed_index + len(line_item) + 1] + if "-" not in branch_list and "+" not in branch_list: + del_count = update_branch_tag.count("> # <") + update_branch_tag = update_branch_tag.replace("> # <", "> <", del_count - 1) + else: + update_branch_tag = update_branch_tag.replace("> - <", "> <") + update_branch_tag = update_branch_tag.replace("> # <", "> <") + branch_tag = branch_html[line_feed_index + len(line_item) + 1:] + line_feed_index = branch_tag.find(line_item) + if line_feed_index == -1: + branch_tag = branch_tag.replace("> - <", "> <") + branch_tag = branch_tag.replace("> # <", "> <") + update_branch_tag += branch_tag + else: + loop_count = 0 + while line_feed_index + 1: + loop_count += 1 + if loop_count > 200: + continue + try: + update_branch_tag += branch_tag[:line_feed_index + len(line_item) + 1] + update_branch_tag = update_branch_tag.replace("> - <", "> <") + update_branch_tag = update_branch_tag.replace("> # <", "> <") + branch_tag = branch_tag[line_feed_index + len(line_item) + 1:] + line_feed_index = branch_tag.find(line_item) + except ValueError: + return "" + + branch_tag = branch_tag.replace("> - <", "> <") + update_branch_tag = update_branch_tag.replace("> # <", "> <") + update_branch_tag += branch_tag + return update_branch_tag + + @staticmethod + def modify_tag_style(tag, rate): + """ + 修改标签样式 + """ + if 75 <= rate < 90: + tag = tag.replace("headerCovTableEntryLo", "headerCovTableEntryMed") + tag = tag.replace("coverPerLo", "coverPerMed") + tag = tag.replace("coverNumLo", "coverNumMed") + elif rate >= 90: + tag = tag.replace("headerCovTableEntryLo", "headerCovTableEntryHi") + tag = tag.replace("headerCovTableEntryMed", "headerCovTableEntryHi") + tag = tag.replace("coverPerLo", "coverPerHi") + tag = tag.replace("coverNumLo", "coverNumHi") + tag = tag.replace("coverPerMed", "coverPerHi") + tag = tag.replace("coverNumMed", "coverNumHi") + return tag + def get_coverage_lines_by_branch(self, file_path, content=None): """ 获取覆盖率报告中的所有的if分支行号 @@ -311,85 +468,6 @@ class KeywordRegistration: traceback.format_exc()) return "" - @staticmethod - def get_branch_line_list(keyword_line: int, branch_line_list: list): - """ - 获取大于关键字行号的所有分支行号 - """ - if keyword_line in branch_line_list: - index = branch_line_list.index(keyword_line) - branch_line_list = branch_line_list[index:] - else: - for line in branch_line_list: - if line > keyword_line: - index = branch_line_list.index(line) - branch_line_list = branch_line_list[index:] - break - return branch_line_list - - @staticmethod - def get_keyword_judge_char(keyword, keyword_source_code): - """ - 获取关键字替代字符 - """ - if "&" in keyword: - keyword = keyword.replace("&", "<") - - keyword_index = keyword_source_code.find(keyword) - if keyword_index == -1: - return "" - - try: - keyword_code = keyword_source_code[:keyword_index + len(keyword)] - if " = " in keyword_code: - judge_key = keyword_code.split(" = ")[0].split()[-1] - else: - bracket_index = keyword_code.find("(") - bracket_code = keyword_code[:bracket_index] - judge_key = bracket_code.split()[-1] - return judge_key - except (IndexError, ValueError): - print("获取关键字替代字符失败") - return "" - - @staticmethod - def get_branch_data_by_tag(tag_html: str, symbol_status=None): - """ - 根据前端标签获取分支数据 - """ - if symbol_status: - key = r"#+\-*" - else: - key = r"#+\-" - branch_line_list = re.findall(rf"> ([{key}]) ", tag_html) - - return branch_line_list - - @staticmethod - def get_judge_condition_index(judge_key: str, source_code: str): - """ - 获取判断条件索引 - """ - keyword_index_list = [] - keyword_index_list_append = keyword_index_list.append - - condition_str_list = re.split(rf"\|\||&&", source_code) - for index, code_str in enumerate(condition_str_list): - if judge_key in code_str: - keyword_index_list_append(index) - return keyword_index_list, condition_str_list - - @staticmethod - def update_source_code_tag(html_tag: str): - replace_item_list = ["lineNum", "lineCov", "lineNoCov"] - - for item in replace_item_list: - if item in html_tag: - replace_item = (item + "Update").lower() - html_tag = html_tag.replace(item, replace_item) - - return html_tag - def get_break_line_tag(self, content, origin_branch_html, branch_line): """ 获取分支换行的判断条件源码tag @@ -409,24 +487,6 @@ class KeywordRegistration: loop_count += 1 return origin_branch_html - @staticmethod - def modify_tag_style(tag, rate): - """ - 修改标签样式 - """ - if 75 <= rate < 90: - tag = tag.replace("headerCovTableEntryLo", "headerCovTableEntryMed") - tag = tag.replace("coverPerLo", "coverPerMed") - tag = tag.replace("coverNumLo", "coverNumMed") - elif rate >= 90: - tag = tag.replace("headerCovTableEntryLo", "headerCovTableEntryHi") - tag = tag.replace("headerCovTableEntryMed", "headerCovTableEntryHi") - tag = tag.replace("coverPerLo", "coverPerHi") - tag = tag.replace("coverNumLo", "coverNumHi") - tag = tag.replace("coverPerMed", "coverPerHi") - tag = tag.replace("coverNumMed", "coverNumHi") - return tag - def update_coverage_ratio_tag(self, file_path): """ 修改覆盖率比率数据 @@ -619,79 +679,6 @@ class KeywordRegistration: return if_branch_line - @staticmethod - def _branch_replace(branch): - """ - 分支符号替换 - """ - if branch == "#": - branch = "> # <" - elif branch == "+": - branch = "> + <" - elif branch == "*": - branch = "> * <" - else: - branch = "> - <" - return branch - - @staticmethod - def _single_condition_modify_html(branch_html, branch_list): - """ - 单条件修改代码块html - """ - line_item = ' ' - line_feed_index = branch_html.find(line_item) - if line_feed_index == -1: - if "+" in branch_list: - update_branch_tag = branch_html.replace("> - <", "> <") - update_branch_tag = update_branch_tag.replace("> # <", "> <") - else: - try: - first_branch = branch_list[0] - first_branch = "> " + first_branch + " <" - first_branch_index = branch_html.find(first_branch) - branch_tag = branch_html[:first_branch_index + 5] - update_branch_tag = branch_html[first_branch_index + 5:] - update_branch_tag = update_branch_tag.replace("> - <", "> <") - update_branch_tag = update_branch_tag.replace("> # <", "> <") - update_branch_tag = branch_tag + update_branch_tag - except ValueError: - return "" - else: - line_feed_index = branch_html.find(line_item) - update_branch_tag = branch_html[:line_feed_index + len(line_item) + 1] - if "-" not in branch_list and "+" not in branch_list: - del_count = update_branch_tag.count("> # <") - update_branch_tag = update_branch_tag.replace("> # <", "> <", del_count - 1) - else: - update_branch_tag = update_branch_tag.replace("> - <", "> <") - update_branch_tag = update_branch_tag.replace("> # <", "> <") - branch_tag = branch_html[line_feed_index + len(line_item) + 1:] - line_feed_index = branch_tag.find(line_item) - if line_feed_index == -1: - branch_tag = branch_tag.replace("> - <", "> <") - branch_tag = branch_tag.replace("> # <", "> <") - update_branch_tag += branch_tag - else: - loop_count = 0 - while line_feed_index + 1: - loop_count += 1 - if loop_count > 200: - continue - try: - update_branch_tag += branch_tag[:line_feed_index + len(line_item) + 1] - update_branch_tag = update_branch_tag.replace("> - <", "> <") - update_branch_tag = update_branch_tag.replace("> # <", "> <") - branch_tag = branch_tag[line_feed_index + len(line_item) + 1:] - line_feed_index = branch_tag.find(line_item) - except ValueError: - return "" - - branch_tag = branch_tag.replace("> - <", "> <") - update_branch_tag = update_branch_tag.replace("> # <", "> <") - update_branch_tag += branch_tag - return update_branch_tag - def _multi_condition_modify_html(self, branch_html, branch_length, condition_str_list, judge_index_list): """ diff --git a/src/core/build/build_manager.py b/src/core/build/build_manager.py index 3c8ad7a..38ec1aa 100644 --- a/src/core/build/build_manager.py +++ b/src/core/build/build_manager.py @@ -38,6 +38,25 @@ LOG = platform_logger("BuildManager") ############################################################################## class BuildManager(object): + @classmethod + def build_version(cls, project_root_path, product_form): + if BuildTestcases(project_root_path).build_version(product_form): + LOG.info("The version compiled successfully.") + build_result = True + else: + LOG.info("The version compilation failed, please modify.") + build_result = False + return build_result + + @classmethod + def build_gn_file(cls, project_root_path, product_form): + if BuildTestcases(project_root_path).build_gn_file(product_form): + LOG.info("The gn compiled successfully.") + build_result = True + else: + LOG.info("The gn compilation failed, please modify.") + build_result = False + return build_result @classmethod def _make_gn_file(cls, filepath, target_list): @@ -119,7 +138,51 @@ class BuildManager(object): else: LOG.info("Test case compilation failed, please modify.") return build_result + + def build_testcases(self, project_root_path, param): + if not os.path.exists(project_root_path): + LOG.error("%s is not exists." % project_root_path) + return False + + LOG.info("--------------------------------------------------") + LOG.info("Building parameter:") + LOG.info("productform = %s" % param.productform) + LOG.info("testtype = %s" % str(param.testtype)) + LOG.info("partname_list = %s" % str(param.partname_list)) + LOG.info("testmodule = %s" % param.testmodule) + LOG.info("testsuit = %s" % param.testsuit) + LOG.info("testcase = %s" % param.testcase) + LOG.info("--------------------------------------------------") + + LOG.info("") + LOG.info("**************************************************") + LOG.info("*************** Start build testcases ************") + LOG.info("**************************************************") + LOG.info("") + build_xts_result = True + build_result = True + if "partdeps" == param.partdeps: + LOG.info("**********************Start prebuild testcases****************************") + build_deps_files_result = self._compile_deps_files(project_root_path, param) + if build_deps_files_result: + self._compile_part_deps(project_root_path, param) + + if "acts" in param.testtype or "hats" in param.testtype or "hits" in param.testtype: + LOG.info("**********************Start build xts testcases****************************") + build_xts_result = self._compile_xts_test_cases(project_root_path, param) + else: + LOG.info("**********************Start build subsystem testcases****************************") + build_result = self._compile_testcases(project_root_path, param) + + LOG.info("") + LOG.info("**************************************************") + LOG.info("*************** Ended build testcases ************") + LOG.info("**************************************************") + LOG.info("") + + return build_result and build_xts_result + # 编译入口 def _compile_testcases(self, project_root_path, para): # 获取所有支持的产品,3.1Release版本为["DAYU","Hi3516DV300","ohos-arm64","ohos-sdk","rk3568"] @@ -191,70 +254,5 @@ class BuildManager(object): return build_result - @classmethod - def build_version(cls, project_root_path, product_form): - if BuildTestcases(project_root_path).build_version(product_form): - LOG.info("The version compiled successfully.") - build_result = True - else: - LOG.info("The version compilation failed, please modify.") - build_result = False - return build_result - - @classmethod - def build_gn_file(cls, project_root_path, product_form): - if BuildTestcases(project_root_path).build_gn_file(product_form): - LOG.info("The gn compiled successfully.") - build_result = True - else: - LOG.info("The gn compilation failed, please modify.") - build_result = False - return build_result - - def build_testcases(self, project_root_path, param): - if not os.path.exists(project_root_path): - LOG.error("%s is not exists." % project_root_path) - return False - - LOG.info("--------------------------------------------------") - LOG.info("Building parameter:") - LOG.info("productform = %s" % param.productform) - LOG.info("testtype = %s" % str(param.testtype)) - LOG.info("partname_list = %s" % str(param.partname_list)) - LOG.info("testmodule = %s" % param.testmodule) - LOG.info("testsuit = %s" % param.testsuit) - LOG.info("testcase = %s" % param.testcase) - LOG.info("--------------------------------------------------") - - LOG.info("") - LOG.info("**************************************************") - LOG.info("*************** Start build testcases ************") - LOG.info("**************************************************") - LOG.info("") - - build_xts_result = True - build_result = True - if "partdeps" == param.partdeps: - LOG.info("**********************Start prebuild testcases****************************") - build_deps_files_result = self._compile_deps_files(project_root_path, param) - if build_deps_files_result: - self._compile_part_deps(project_root_path, param) - - if "acts" in param.testtype or "hats" in param.testtype or "hits" in param.testtype: - LOG.info("**********************Start build xts testcases****************************") - build_xts_result = self._compile_xts_test_cases(project_root_path, param) - else: - LOG.info("**********************Start build subsystem testcases****************************") - build_result = self._compile_testcases(project_root_path, param) - - LOG.info("") - LOG.info("**************************************************") - LOG.info("*************** Ended build testcases ************") - LOG.info("**************************************************") - LOG.info("") - - return build_result and build_xts_result - - ############################################################################## ############################################################################## diff --git a/src/core/build/build_testcases.py b/src/core/build/build_testcases.py index 24f9ff3..6e12fef 100644 --- a/src/core/build/build_testcases.py +++ b/src/core/build/build_testcases.py @@ -56,7 +56,7 @@ class BuildTestcases(object): "build", "example") self.build_parameter_dic = user_manager.get_user_config( "build", "parameter") - + @classmethod def _copy_folder(cls, source_dir, target_dir): if not os.path.exists(target_dir): @@ -110,6 +110,107 @@ class BuildTestcases(object): if os.path.exists(xts_testcase_out_dir): shutil.rmtree(xts_testcase_out_dir) + def build_fuzz_testcases(self, para): + self._delete_testcase_dir(para.productform) + helper_path = os.path.join("..", "libs", "fuzzlib", "fuzzer_helper.py") + command = [sys.executable, helper_path, 'make', + 'make_temp_test', para.productform] + if subprocess.call(command, shell=False) == 0: + build_result = True + else: + build_result = False + self._merge_testcase_dir(para.productform) + return build_result + + # 编译测试用例(编译命令拼接) + def build_testcases(self, productform, target): + command = [] + if self.is_build_example: + command.append("--gn-args") + command.append("build_example=true") + if isinstance(target, list): + for test in target: + command.append("--build-target") + command.append(test + "_test") + elif isinstance(target, str): + for test in target.split(','): + command.append("--build-target") + command.append(test) + + if productform == "rk3568": + pass + else: + command.append("--abi-type") + command.append("generic_generic_arm_64only") + command.append("--device-type") + command.append(get_output_path().split("/")[-1]) + command.append("--build-variant") + command.append("root") + command.append("--ccache") + self._delete_testcase_dir(productform) + build_result = self._execute_build_command(productform, command) + self._merge_testcase_dir(productform) + return build_result + + # 编译XTS测试用例 + def build_xts_testcases(self, para): + self._delete_xts_testcase_dir(para) + xts_build_command = [] + if para.productform == "rk3568": + False + else: + xts_build_test_command = ["--abi-type", "generic_generic_arm_64only", "--device-type", + get_output_path().split("/")[-1], "--build-variant", "root", "--gn-args", + "build_xts=true", "--export-para", "xts_suitename:" + para.testtype[0]] + if len(para.subsystem) > 0: + input_subsystem = ",".join(para.subsystem) + xts_build_test_command.append("--build-target") + xts_build_test_command.append(input_subsystem) + if para.testsuit != "" and len(para.subsystem) == 0: + LOG.error("Please specify subsystem.") + return False + xts_build_command.extend(xts_build_test_command) + xts_build_command.append("--ccache") + build_result = self._execute_build_xts_command(para, xts_build_command) + return build_result + + def build_deps_files(self, productform): + command = ["--ccache", "--gn-args", "pycache_enable=true", "--gn-args", + "check_deps=true", "--build-only-gn"] + if productform == "rk3568": + pass + else: + command.append("--abi-type") + command.append("generic_generic_arm_64only") + command.append("--device-type") + command.append(get_output_path().split("/")[-1]) + command.append("--build-variant") + command.append("root") + return self._execute_build_deps_files_command(productform, command) + + # 部件间依赖关系预处理,生成part_deps_info.json + def build_part_deps(self, para): + build_part_deps_result = self._execute_build_part_deps_command(para) + return build_part_deps_result + + def build_gn_file(self, productform): + command = [] + if self.is_build_example: + command.append("--gn-args") + command.append("build_example=true") + command.append("--build-only-gn") + command.append("--gn-args") + command.append(BUILD_TARGET_PLATFORM % productform) + return self._execute_build_command(productform, command) + + def build_version(self, productform): + command = [] + command.append("--build-target") + command.append("make_all") + command.append("--gn-args") + command.append(BUILD_TARGET_PLATFORM % productform) + return self._execute_build_command(productform, command) + def _delete_testcase_dir(self, productform): if is_open_source_product(productform): package_out_dir = os.path.join( @@ -299,107 +400,5 @@ class BuildTestcases(object): os.chdir(current_path) return build_result - def build_fuzz_testcases(self, para): - self._delete_testcase_dir(para.productform) - helper_path = os.path.join("..", "libs", "fuzzlib", "fuzzer_helper.py") - command = [sys.executable, helper_path, 'make', - 'make_temp_test', para.productform] - if subprocess.call(command, shell=False) == 0: - build_result = True - else: - build_result = False - self._merge_testcase_dir(para.productform) - return build_result - - # 编译测试用例(编译命令拼接) - def build_testcases(self, productform, target): - command = [] - if self.is_build_example: - command.append("--gn-args") - command.append("build_example=true") - if isinstance(target, list): - for test in target: - command.append("--build-target") - command.append(test + "_test") - elif isinstance(target, str): - for test in target.split(','): - command.append("--build-target") - command.append(test) - - if productform == "rk3568": - pass - else: - command.append("--abi-type") - command.append("generic_generic_arm_64only") - command.append("--device-type") - command.append(get_output_path().split("/")[-1]) - command.append("--build-variant") - command.append("root") - command.append("--ccache") - self._delete_testcase_dir(productform) - build_result = self._execute_build_command(productform, command) - self._merge_testcase_dir(productform) - return build_result - - # 编译XTS测试用例 - def build_xts_testcases(self, para): - self._delete_xts_testcase_dir(para) - xts_build_command = [] - if para.productform == "rk3568": - False - else: - xts_build_test_command = ["--abi-type", "generic_generic_arm_64only", "--device-type", - get_output_path().split("/")[-1], "--build-variant", "root", "--gn-args", - "build_xts=true", "--export-para", "xts_suitename:" + para.testtype[0]] - if len(para.subsystem) > 0: - input_subsystem = ",".join(para.subsystem) - xts_build_test_command.append("--build-target") - xts_build_test_command.append(input_subsystem) - if para.testsuit != "" and len(para.subsystem) == 0: - LOG.error("Please specify subsystem.") - return False - xts_build_command.extend(xts_build_test_command) - xts_build_command.append("--ccache") - build_result = self._execute_build_xts_command(para, xts_build_command) - return build_result - - - def build_deps_files(self, productform): - command = ["--ccache", "--gn-args", "pycache_enable=true", "--gn-args", - "check_deps=true", "--build-only-gn"] - if productform == "rk3568": - pass - else: - command.append("--abi-type") - command.append("generic_generic_arm_64only") - command.append("--device-type") - command.append(get_output_path().split("/")[-1]) - command.append("--build-variant") - command.append("root") - return self._execute_build_deps_files_command(productform, command) - - # 部件间依赖关系预处理,生成part_deps_info.json - def build_part_deps(self, para): - build_part_deps_result = self._execute_build_part_deps_command(para) - return build_part_deps_result - - def build_gn_file(self, productform): - command = [] - if self.is_build_example: - command.append("--gn-args") - command.append("build_example=true") - command.append("--build-only-gn") - command.append("--gn-args") - command.append(BUILD_TARGET_PLATFORM % productform) - return self._execute_build_command(productform, command) - - def build_version(self, productform): - command = [] - command.append("--build-target") - command.append("make_all") - command.append("--gn-args") - command.append(BUILD_TARGET_PLATFORM % productform) - return self._execute_build_command(productform, command) - ############################################################################## ############################################################################## diff --git a/src/core/build/select_targets.py b/src/core/build/select_targets.py index a411232..653a785 100755 --- a/src/core/build/select_targets.py +++ b/src/core/build/select_targets.py @@ -32,18 +32,7 @@ LOG = platform_logger("SelectTargets") class SelectTargets(object): def __init__(self, project_rootpath): self.project_rootpath = project_rootpath - - @classmethod - def _get_mlf_data_from_file(cls, filepath): - data_list = [] - if os.path.exists(filepath): - with open(filepath, 'r') as mlf_file: - data_list = json.load(mlf_file) - if not data_list: - LOG.warning("The %s file load error." % filepath) - data_list = [] - return data_list - + @classmethod def _get_part_path_data(cls, productform): part_path_dic = {} @@ -82,6 +71,66 @@ class SelectTargets(object): part_path_dic[part_name] = part_path_list return part_path_dic + def get_build_targets(self, productform, typelist, partlist, testmodule): + target_list = [] + + if productform == "" or len(typelist) == 0: + LOG.warning("Error: productform or typelist is empty.") + return [] + + if len(partlist) == 0 and testmodule != "": + LOG.warning( + "The part cannot be empty When the module is not empty.") + return [] + # productform不为空,typelist(test type[UT,MST,ST,PERF,ALL])不为空 + # partlist和testmodule为空,通过testtype获取部件列表 + if len(partlist) == 0 and testmodule == "": + target_list = self._get_target_list_by_type(productform, typelist) + return target_list + # productform不为空,typelist(test type[UT,MST,ST,PERF,ALL])不为空 + # partlist不为空,testmodule为空,通过testtype、partlist一起获取部件列表 + if len(partlist) != 0 and testmodule == "": + target_list = self._get_target_list_by_part(productform, typelist, + partlist) + return target_list + # productform不为空,typelist(test type[UT,MST,ST,PERF,ALL])不为空 + # partlist不为空,testmodule不为空,通过testtype、partlist、testmodule一起获取部件列表 + if len(partlist) != 0 and testmodule != "": + target_list = self._get_target_list_by_module(productform, + typelist, + partlist, + testmodule) + + return target_list + + # 通过infos_for_testfwk.json文件获取所有子部件信息编译目录信息: + # [{“部件名1”:[~/OpenHarmony/out/rk3568/module_list_files/部件名1]}] + # 然后遍历这些目录中的mlf文件,获取其中定义的label,返回label集合 + # 遍历时通过testmodule控制遍历的部件指定模块目录,如果不定义,则遍历子部件下面所有模块目录 + # 遍历时通过partlist控制遍历指定部件目录,如果不定义,则遍历infos_for_testfwk.json文件中定义的所有子部件目录 + def filter_build_targets(self, para): + productform = para.productform + typelist = para.testtype + partlist = para.partname_list + testmodule = para.testmodule + + print("partlist = %s" % str(partlist)) + target_list = self.get_build_targets(productform, typelist, + partlist, testmodule) + return target_list + + @classmethod + + def _get_mlf_data_from_file(cls, filepath): + data_list = [] + if os.path.exists(filepath): + with open(filepath, 'r') as mlf_file: + data_list = json.load(mlf_file) + if not data_list: + LOG.warning("The %s file load error." % filepath) + data_list = [] + return data_list + def _get_target_list_from_path(self, typelist, check_path): target_list = [] if os.path.exists(check_path): @@ -146,54 +195,5 @@ class SelectTargets(object): target_list.extend(temp_list) return target_list - def get_build_targets(self, productform, typelist, partlist, testmodule): - target_list = [] - - if productform == "" or len(typelist) == 0: - LOG.warning("Error: productform or typelist is empty.") - return [] - - if len(partlist) == 0 and testmodule != "": - LOG.warning( - "The part cannot be empty When the module is not empty.") - return [] - # productform不为空,typelist(test type[UT,MST,ST,PERF,ALL])不为空 - # partlist和testmodule为空,通过testtype获取部件列表 - if len(partlist) == 0 and testmodule == "": - target_list = self._get_target_list_by_type(productform, typelist) - return target_list - # productform不为空,typelist(test type[UT,MST,ST,PERF,ALL])不为空 - # partlist不为空,testmodule为空,通过testtype、partlist一起获取部件列表 - if len(partlist) != 0 and testmodule == "": - target_list = self._get_target_list_by_part(productform, typelist, - partlist) - return target_list - # productform不为空,typelist(test type[UT,MST,ST,PERF,ALL])不为空 - # partlist不为空,testmodule不为空,通过testtype、partlist、testmodule一起获取部件列表 - if len(partlist) != 0 and testmodule != "": - target_list = self._get_target_list_by_module(productform, - typelist, - partlist, - testmodule) - - return target_list - - # 通过infos_for_testfwk.json文件获取所有子部件信息编译目录信息: - # [{“部件名1”:[~/OpenHarmony/out/rk3568/module_list_files/部件名1]}] - # 然后遍历这些目录中的mlf文件,获取其中定义的label,返回label集合 - # 遍历时通过testmodule控制遍历的部件指定模块目录,如果不定义,则遍历子部件下面所有模块目录 - # 遍历时通过partlist控制遍历指定部件目录,如果不定义,则遍历infos_for_testfwk.json文件中定义的所有子部件目录 - def filter_build_targets(self, para): - productform = para.productform - typelist = para.testtype - partlist = para.partname_list - testmodule = para.testmodule - - print("partlist = %s" % str(partlist)) - target_list = self.get_build_targets(productform, typelist, - partlist, testmodule) - return target_list - - ############################################################################## ############################################################################## diff --git a/src/core/command/console.py b/src/core/command/console.py index 84624f7..924abbd 100755 --- a/src/core/command/console.py +++ b/src/core/command/console.py @@ -66,69 +66,6 @@ class Console(object): def __init__(self): pass - def handler_ctrl_c(self, signalnum, frame): - pass - - def handler_ctrl_z(self, signalnum, frame): - pass - - def console(self, args): - """ - Main xDevice console providing user with the interface to interact - """ - EnvironmentManager() - if args is None or len(args) < 2: - self.wizard_dic = show_wizard_mode() - print(self.wizard_dic) - if self._build_version(self.wizard_dic["productform"]): - self._console() - else: - LOG.error("Build version failed, exit test framework.") - else: - self.command_parser(" ".join(args[1:])) - - # 命令执行总入口 - def _console(self): - if platform.system() != 'Windows': - signal.signal(signal.SIGTSTP, self.handler_ctrl_z) # ctrl+x linux - signal.signal(signal.SIGINT, self.handler_ctrl_c) # ctrl+c - - while True: - try: - # 获取用户命令输入 - usr_input = input(">>> ") - if usr_input == "": - continue - # 用户输入命令解析 - self.command_parser(usr_input) - except SystemExit: - LOG.info("Program exit normally!") - return - except (IOError, EOFError, KeyboardInterrupt) as error: - LOG.exception("Input Error: %s" % error) - - @staticmethod - def _parse_combination_param(combination_value): - # sample: size:xxx1;exclude-annotation:xxx - parse_result = {} - key_value_pairs = str(combination_value).split(";") - for key_value_pair in key_value_pairs: - key, value = key_value_pair.split(":", 1) - if not value: - raise ParamError("'%s' no value" % key) - value_list = str(value).split(",") - exist_list = parse_result.get(key, []) - exist_list.extend(value_list) - parse_result[key] = exist_list - return parse_result - - @classmethod - def _params_post_processing(self, options): - # params post-processing - if options.testargs: - test_args = self._parse_combination_param(options.testargs) - setattr(options, ConfigConst.testargs, test_args) - # 参数解析方法 @classmethod def argument_parser(cls, para_list): @@ -323,48 +260,27 @@ class Console(object): return options, unparsed, valid_param - def command_parser(self, args): - try: - # 将用户输入的指令按空格拆分成字符串数组 - para_list = args.split() - options, _, valid_param = self.argument_parser(para_list) - if options is None or not valid_param: - LOG.warning("options is None.") - return - - # 根据命令行的命令选择不同的方法执行 - command = options.action - if command == "": - LOG.warning("action is empty.") - return - - if "productform" in self.wizard_dic.keys(): - productform = self.wizard_dic["productform"] - options.productform = productform - else: - productform = options.productform - - if command.startswith(ToolCommandType.TOOLCMD_KEY_HELP): - self._process_command_help(para_list) - elif command.startswith(ToolCommandType.TOOLCMD_KEY_SHOW): - self._process_command_show(para_list, productform) - elif command.startswith(ToolCommandType.TOOLCMD_KEY_GEN): - self._process_command_gen(command, options) - elif command.startswith(ToolCommandType.TOOLCMD_KEY_RUN): - # 保存原始控制命令 - options.current_raw_cmd = args - self._process_command_run(command, options) - elif command.startswith(ToolCommandType.TOOLCMD_KEY_QUIT): - self._process_command_quit(command) - elif command.startswith(ToolCommandType.TOOLCMD_KEY_LIST): - self._process_command_device(command) - elif command.startswith(ToolCommandType.TOOLCMD_KEY_VERSION): - self._process_command_version(command) - else: - print("The %s command is not supported." % command) - except (AttributeError, IOError, IndexError, ImportError, NameError, - RuntimeError, SystemError, TypeError, ValueError) as exception: - LOG.exception(exception, exc_info=False) + @staticmethod + def _parse_combination_param(combination_value): + # sample: size:xxx1;exclude-annotation:xxx + parse_result = {} + key_value_pairs = str(combination_value).split(";") + for key_value_pair in key_value_pairs: + key, value = key_value_pair.split(":", 1) + if not value: + raise ParamError("'%s' no value" % key) + value_list = str(value).split(",") + exist_list = parse_result.get(key, []) + exist_list.extend(value_list) + parse_result[key] = exist_list + return parse_result + + @classmethod + def _params_post_processing(self, options): + # params post-processing + if options.testargs: + test_args = self._parse_combination_param(options.testargs) + setattr(options, ConfigConst.testargs, test_args) @classmethod def _params_pre_processing(cls, para_list): @@ -395,13 +311,11 @@ class Console(object): parse_result[key] = exist_list return parse_result - @classmethod def _process_command_version(cls, para_list): display_version_info(para_list) return - @classmethod def _process_command_help(cls, para_list): if para_list[0] == ToolCommandType.TOOLCMD_KEY_HELP: @@ -476,7 +390,91 @@ class Console(object): build_result = build_manager.build_version(project_root_path, product_form) return build_result + + def handler_ctrl_c(self, signalnum, frame): + pass + + def handler_ctrl_z(self, signalnum, frame): + pass + + def console(self, args): + """ + Main xDevice console providing user with the interface to interact + """ + EnvironmentManager() + if args is None or len(args) < 2: + self.wizard_dic = show_wizard_mode() + print(self.wizard_dic) + if self._build_version(self.wizard_dic["productform"]): + self._console() + else: + LOG.error("Build version failed, exit test framework.") + else: + self.command_parser(" ".join(args[1:])) + + def command_parser(self, args): + try: + # 将用户输入的指令按空格拆分成字符串数组 + para_list = args.split() + options, _, valid_param = self.argument_parser(para_list) + if options is None or not valid_param: + LOG.warning("options is None.") + return + + # 根据命令行的命令选择不同的方法执行 + command = options.action + if command == "": + LOG.warning("action is empty.") + return + + if "productform" in self.wizard_dic.keys(): + productform = self.wizard_dic["productform"] + options.productform = productform + else: + productform = options.productform + if command.startswith(ToolCommandType.TOOLCMD_KEY_HELP): + self._process_command_help(para_list) + elif command.startswith(ToolCommandType.TOOLCMD_KEY_SHOW): + self._process_command_show(para_list, productform) + elif command.startswith(ToolCommandType.TOOLCMD_KEY_GEN): + self._process_command_gen(command, options) + elif command.startswith(ToolCommandType.TOOLCMD_KEY_RUN): + # 保存原始控制命令 + options.current_raw_cmd = args + self._process_command_run(command, options) + elif command.startswith(ToolCommandType.TOOLCMD_KEY_QUIT): + self._process_command_quit(command) + elif command.startswith(ToolCommandType.TOOLCMD_KEY_LIST): + self._process_command_device(command) + elif command.startswith(ToolCommandType.TOOLCMD_KEY_VERSION): + self._process_command_version(command) + else: + print("The %s command is not supported." % command) + except (AttributeError, IOError, IndexError, ImportError, NameError, + RuntimeError, SystemError, TypeError, ValueError) as exception: + LOG.exception(exception, exc_info=False) + + # 命令执行总入口 + def _console(self): + if platform.system() != 'Windows': + signal.signal(signal.SIGTSTP, self.handler_ctrl_z) # ctrl+x linux + signal.signal(signal.SIGINT, self.handler_ctrl_c) # ctrl+c + + while True: + try: + # 获取用户命令输入 + usr_input = input(">>> ") + if usr_input == "": + continue + # 用户输入命令解析 + self.command_parser(usr_input) + except SystemExit: + LOG.info("Program exit normally!") + return + except (IOError, EOFError, KeyboardInterrupt) as error: + LOG.exception("Input Error: %s" % error) + @dataclass class ConfigConst(object): diff --git a/src/core/command/gen.py b/src/core/command/gen.py index 332ed40..dfecea4 100644 --- a/src/core/command/gen.py +++ b/src/core/command/gen.py @@ -28,7 +28,22 @@ MODES = stat.S_IWUSR | stat.S_IRUSR LOG = platform_logger("Gen") + class Gen(object): + @classmethod + def fuzz_dir_generation(cls, options): + helper_path = os.path.join("..", "libs", "fuzzlib", "fuzzer_helper.py") + fuzz_path = os.path.join(sys.source_code_root_path, options.dirpath) + LOG.info("fuzz_path = %s" % fuzz_path) + if not os.path.exists(fuzz_path): + os.makedirs(fuzz_path) + LOG.info("make folder %s" % fuzz_path) + + command = [sys.executable, helper_path, 'generate', + options.fuzzername, fuzz_path] + LOG.info("command %s" % command) + subprocess.call(command, shell=False) + def process_command_gen(self, options): if (len(options.testtype) != 1) or (options.dirpath == "") or \ (options.fuzzername == ""): @@ -53,16 +68,4 @@ class Gen(object): if target: gn_file.write("\"%s\",\n" % target) - @classmethod - def fuzz_dir_generation(cls, options): - helper_path = os.path.join("..", "libs", "fuzzlib", "fuzzer_helper.py") - fuzz_path = os.path.join(sys.source_code_root_path, options.dirpath) - LOG.info("fuzz_path = %s" % fuzz_path) - if not os.path.exists(fuzz_path): - os.makedirs(fuzz_path) - LOG.info("make folder %s" % fuzz_path) - - command = [sys.executable, helper_path, 'generate', - options.fuzzername, fuzz_path] - LOG.info("command %s" % command) - subprocess.call(command, shell=False) \ No newline at end of file + \ No newline at end of file diff --git a/src/core/command/run.py b/src/core/command/run.py index 1e33641..887b507 100644 --- a/src/core/command/run.py +++ b/src/core/command/run.py @@ -49,10 +49,6 @@ class Run(object): history_cmd_list = [] - @classmethod - def get_history(self): - return self.history_cmd_list - def process_command_run(self, command, options): current_raw_cmd = ",".join(list(map(str, options.current_raw_cmd.split(" ")))) if options.coverage and platform.system() != "Windows": @@ -138,10 +134,9 @@ class Run(object): #打印历史记录 if options.historylist: print("The latest command history is: %d" % len(self.history_cmd_list)) - for index in range(0, len(self.history_cmd_list)): - cmd_record = self.history_cmd_list[index] + for index, cmd_record in enumerate(self.history_cmd_list): print("%d. [%s] - [%s]::[%s]" % (index + 1, cmd_record["time"], - cmd_record["raw_cmd"], cmd_record["result"])) + cmd_record["raw_cmd"], cmd_record["result"])) return #重新运行历史里的一条命令 if options.runhistory > 0: @@ -233,7 +228,7 @@ class Run(object): if not check_ditributetest_environment(): return - output_test = get_test_case(test_dict["CXX"]) + output_test = get_test_case(test_dict.get("CXX", None)) if not output_test: return @@ -315,10 +310,14 @@ class Run(object): else: print(f"{cov_main_file_path} not exists.") return - + ############################################################## ############################################################## + @classmethod + def get_history(self): + return self.history_cmd_list + @classmethod def get_target_out_path(cls, product_form): target_out_path = UserConfigManager().get_test_cases_dir() @@ -330,33 +329,6 @@ class Run(object): target_out_path = os.path.abspath(target_out_path) return target_out_path - @classmethod - def _build_test_cases(cls, options): - if options.coverage: - LOG.info("Coverage testing, no need to compile testcases") - return True - - is_build_testcase = UserConfigManager().get_user_config_flag( - "build", "testcase") - project_root_path = sys.source_code_root_path - if is_build_testcase and project_root_path != "": - from core.build.build_manager import BuildManager - build_manager = BuildManager() - return build_manager.build_testcases(project_root_path, options) - else: - return True - - @classmethod - def _check_test_dictionary(cls, test_dictionary): - is_valid_status = False - key_list = sorted(test_dictionary.keys()) - for key in key_list: - file_list = test_dictionary[key] - if len(file_list) > 0: - is_valid_status = True - break - return is_valid_status - @classmethod def get_tests_out_path(cls, product_form): testcase_path = UserConfigManager().get_test_cases_dir() @@ -417,6 +389,33 @@ class Run(object): external_deps_path_list = TestCaseManager().get_part_deps_files(external_deps_path, testpart) return external_deps_path_list + @classmethod + def _build_test_cases(cls, options): + if options.coverage: + LOG.info("Coverage testing, no need to compile testcases") + return True + + is_build_testcase = UserConfigManager().get_user_config_flag( + "build", "testcase") + project_root_path = sys.source_code_root_path + if is_build_testcase and project_root_path != "": + from core.build.build_manager import BuildManager + build_manager = BuildManager() + return build_manager.build_testcases(project_root_path, options) + else: + return True + + @classmethod + def _check_test_dictionary(cls, test_dictionary): + is_valid_status = False + key_list = sorted(test_dictionary.keys()) + for key in key_list: + file_list = test_dictionary[key] + if len(file_list) > 0: + is_valid_status = True + break + return is_valid_status + def get_xts_test_dict(self, options): # 获取XTS测试用例编译结果路径 xts_test_case_path = self.get_xts_tests_out_path(options.productform, options.testtype) @@ -435,5 +434,4 @@ class Run(object): test_dict = TestCaseManager().get_test_files(test_case_path, options) return test_dict - - + \ No newline at end of file diff --git a/src/core/config/config_manager.py b/src/core/config/config_manager.py index b9d12fa..d63e9b9 100755 --- a/src/core/config/config_manager.py +++ b/src/core/config/config_manager.py @@ -175,6 +175,17 @@ class UserConfigManager(object): self.filepath = os.path.abspath( os.path.join(CONFIG_PATH, config_file)) + @classmethod + def content_strip(cls, content): + return content.strip() + + @classmethod + def _verify_duplicate(cls, items): + if len(set(items)) != len(items): + LOG.warning("find duplicate sn config, configuration incorrect") + return False + return True + def get_user_config_list(self, tag_name): data_dic = {} try: @@ -189,25 +200,6 @@ class UserConfigManager(object): LOG.error(("Parse %s fail!" % self.filepath) + xml_exception.args) return data_dic - @classmethod - def content_strip(cls, content): - return content.strip() - - @classmethod - def _verify_duplicate(cls, items): - if len(set(items)) != len(items): - LOG.warning("find duplicate sn config, configuration incorrect") - return False - return True - - def _handle_str(self, content): - config_list = map(self.content_strip, content.split(';')) - config_list = [item for item in config_list if item] - if config_list: - if not self._verify_duplicate(config_list): - return [] - return config_list - def get_sn_list(self): sn_select_list = [] try: @@ -280,6 +272,14 @@ class UserConfigManager(object): if testcase_path != "": testcase_path = os.path.abspath(testcase_path) return testcase_path + + def _handle_str(self, content): + config_list = map(self.content_strip, content.split(';')) + config_list = [item for item in config_list if item] + if config_list: + if not self._verify_duplicate(config_list): + return [] + return config_list class BuildConfigManager(object): diff --git a/src/core/config/resource_manager.py b/src/core/config/resource_manager.py index 9e69991..30f84e7 100755 --- a/src/core/config/resource_manager.py +++ b/src/core/config/resource_manager.py @@ -32,63 +32,75 @@ LOG = platform_logger("ResourceManager") class ResourceManager(object): def __init__(self): pass + + @classmethod + def get_env_data(cls, environment_list): + env_data_dic = {} + device_name = "" + option_dic = {} - def get_resource_data_dic(self, testsuit_filepath): - resource_dir = "" - data_dic = {} - - target_name, _ = self._get_file_name_extension(testsuit_filepath) - xml_filepath = self.get_resource_xml_file_path(testsuit_filepath) - if not os.path.exists(xml_filepath): - return data_dic, resource_dir - - data_dic = self.get_resource_data(xml_filepath, target_name) - resource_dir = os.path.abspath(os.path.dirname(xml_filepath)) - return data_dic, resource_dir - - def get_resource_data(self, xml_filepath, target_name): - data_dic = {} - if os.path.exists(xml_filepath): - data_dic = self._parse_resource_test_xml_file( - xml_filepath, target_name) - return data_dic - - def _parse_resource_test_xml_file(self, filepath, targetname): - data_dic = {} + for item in environment_list: + if "type" in item.keys(): + if device_name != "": + temp_dic = option_dic.copy() + env_data_dic[device_name] = temp_dic + device_name = "" + option_dic.clear() + device_name = item["type"] - node = self.find_node_by_target(filepath, targetname) - if node: - target_attrib_list = [] - target_attrib_list.append(node.attrib) - environment_data_list = [] - env_node = node.find("environment") - if env_node: - environment_data_list.append(env_node.attrib) - for element in env_node.findall("device"): - environment_data_list.append(element.attrib) - for option_element in element.findall("option"): - environment_data_list.append(option_element.attrib) + if "name" in item.keys(): + name = item["name"] + value = item["value"] + option_dic[name] = value - preparer_data_list = [] - pre_node = node.find("preparer") - if pre_node: - preparer_data_list.append(pre_node.attrib) - for element in pre_node.findall("option"): - preparer_data_list.append(element.attrib) + if device_name != "": + temp_dic = option_dic.copy() + env_data_dic[device_name] = temp_dic + device_name = "" + option_dic.clear() + LOG.debug("get environment data finish") + return env_data_dic - cleaner_data_list = [] - clr_node = node.find("cleaner") - if clr_node: - cleaner_data_list.append(clr_node.attrib) - for element in clr_node.findall("option"): - cleaner_data_list.append(element.attrib) + @staticmethod + def get_resource_xml_file_path(test_suit_file_path): + current_dir = os.path.dirname(test_suit_file_path) + while True: + if current_dir.endswith(os.sep + "tests"): + current_dir = "" + break + if current_dir == "/" or current_dir.endswith(":\\"): + current_dir = "" + break + if os.path.exists(os.path.join(current_dir, "resource")): + break + current_dir = os.path.dirname(current_dir) - data_dic["nodeattrib"] = target_attrib_list - data_dic["environment"] = environment_data_list - data_dic["preparer"] = preparer_data_list - data_dic["cleaner"] = cleaner_data_list + if current_dir != "": + xml_filepath = os.path.join( + current_dir, + "resource", + ConfigFileConst.RESOURCECONFIG_FILEPATH) + if not os.path.exists(xml_filepath): + xml_filepath = os.path.join( + current_dir, + "resource", + ConfigFileConst.CASE_RESOURCE_FILEPATH) + else: + xml_filepath = "" + LOG.info("xml_filepath = %s" % xml_filepath) + return xml_filepath - return data_dic + @classmethod + def get_nodeattrib_data(cls, data_dic): + curr_timeout = "" + if "nodeattrib" in data_dic.keys(): + LOG.info("++++++++++++++nodeattrib+++++++++++++++") + nodeattrib_list = data_dic["nodeattrib"] + if len(nodeattrib_list) != 0: + node_item_dic = nodeattrib_list[0] + if "timeout" in node_item_dic: + curr_timeout = node_item_dic["timeout"] + return curr_timeout @staticmethod def find_node_by_target(file_path, targe_tname): @@ -128,6 +140,26 @@ class ResourceManager(object): dir_name = dir_name_list[-1] return dir_name + def get_resource_data_dic(self, testsuit_filepath): + resource_dir = "" + data_dic = {} + + target_name, _ = self._get_file_name_extension(testsuit_filepath) + xml_filepath = self.get_resource_xml_file_path(testsuit_filepath) + if not os.path.exists(xml_filepath): + return data_dic, resource_dir + + data_dic = self.get_resource_data(xml_filepath, target_name) + resource_dir = os.path.abspath(os.path.dirname(xml_filepath)) + return data_dic, resource_dir + + def get_resource_data(self, xml_filepath, target_name): + data_dic = {} + if os.path.exists(xml_filepath): + data_dic = self._parse_resource_test_xml_file( + xml_filepath, target_name) + return data_dic + def process_resource_file(self, resource_dir, preparer_list, device): for item in preparer_list: if "name" not in item.keys(): @@ -160,6 +192,43 @@ class ResourceManager(object): command = command.strip() device.connector_command(command) + def _parse_resource_test_xml_file(self, filepath, targetname): + data_dic = {} + + node = self.find_node_by_target(filepath, targetname) + if node: + target_attrib_list = [] + target_attrib_list.append(node.attrib) + environment_data_list = [] + env_node = node.find("environment") + if env_node: + environment_data_list.append(env_node.attrib) + for element in env_node.findall("device"): + environment_data_list.append(element.attrib) + for option_element in element.findall("option"): + environment_data_list.append(option_element.attrib) + + preparer_data_list = [] + pre_node = node.find("preparer") + if pre_node: + preparer_data_list.append(pre_node.attrib) + for element in pre_node.findall("option"): + preparer_data_list.append(element.attrib) + + cleaner_data_list = [] + clr_node = node.find("cleaner") + if clr_node: + cleaner_data_list.append(clr_node.attrib) + for element in clr_node.findall("option"): + cleaner_data_list.append(element.attrib) + + data_dic["nodeattrib"] = target_attrib_list + data_dic["environment"] = environment_data_list + data_dic["preparer"] = preparer_data_list + data_dic["cleaner"] = cleaner_data_list + + return data_dic + def lite_process_resource_file(self, resource_dir, preparer_list): for item in preparer_list: if "name" not in item.keys(): @@ -185,75 +254,7 @@ class ResourceManager(object): command = command.strip() self.lite_device.execute_command_with_timeout(command, case_type=DeviceTestType.lite_cpp_test) - @classmethod - def get_env_data(cls, environment_list): - env_data_dic = {} - device_name = "" - option_dic = {} - - for item in environment_list: - if "type" in item.keys(): - if device_name != "": - temp_dic = option_dic.copy() - env_data_dic[device_name] = temp_dic - device_name = "" - option_dic.clear() - device_name = item["type"] - - if "name" in item.keys(): - name = item["name"] - value = item["value"] - option_dic[name] = value - - if device_name != "": - temp_dic = option_dic.copy() - env_data_dic[device_name] = temp_dic - device_name = "" - option_dic.clear() - LOG.debug("get environment data finish") - return env_data_dic - - @staticmethod - def get_resource_xml_file_path(test_suit_file_path): - current_dir = os.path.dirname(test_suit_file_path) - while True: - if current_dir.endswith(os.sep + "tests"): - current_dir = "" - break - if current_dir == "/" or current_dir.endswith(":\\"): - current_dir = "" - break - if os.path.exists(os.path.join(current_dir, "resource")): - break - current_dir = os.path.dirname(current_dir) - - if current_dir != "": - xml_filepath = os.path.join( - current_dir, - "resource", - ConfigFileConst.RESOURCECONFIG_FILEPATH) - if not os.path.exists(xml_filepath): - xml_filepath = os.path.join( - current_dir, - "resource", - ConfigFileConst.CASE_RESOURCE_FILEPATH) - else: - xml_filepath = "" - LOG.info("xml_filepath = %s" % xml_filepath) - return xml_filepath - - @classmethod - def get_nodeattrib_data(cls, data_dic): - curr_timeout = "" - if "nodeattrib" in data_dic.keys(): - LOG.info("++++++++++++++nodeattrib+++++++++++++++") - nodeattrib_list = data_dic["nodeattrib"] - if len(nodeattrib_list) != 0: - node_item_dic = nodeattrib_list[0] - if "timeout" in node_item_dic: - curr_timeout = node_item_dic["timeout"] - return curr_timeout - + def get_environment_data(self, data_dic): env_data_dic = {} if "environment" in data_dic.keys(): diff --git a/src/core/driver/drivers.py b/src/core/driver/drivers.py index 57e6bfa..e5a41a9 100644 --- a/src/core/driver/drivers.py +++ b/src/core/driver/drivers.py @@ -87,18 +87,6 @@ class DisplayOutputReceiver: self.output = "" self.unfinished_line = "" - def _process_output(self, output, end_mark="\n"): - content = output - if self.unfinished_line: - content = "".join((self.unfinished_line, content)) - self.unfinished_line = "" - lines = content.split(end_mark) - if content.endswith(end_mark): - return lines[:-1] - else: - self.unfinished_line = lines[-1] - return lines[:-1] - def __read__(self, output): self.output = "%s%s" % (self.output, output) lines = self._process_output(output) @@ -112,6 +100,18 @@ class DisplayOutputReceiver: def __done__(self, result_code="", message=""): pass + + def _process_output(self, output, end_mark="\n"): + content = output + if self.unfinished_line: + content = "".join((self.unfinished_line, content)) + self.unfinished_line = "" + lines = content.split(end_mark) + if content.endswith(end_mark): + return lines[:-1] + else: + self.unfinished_line = lines[-1] + return lines[:-1] @dataclass @@ -369,32 +369,6 @@ class ResultManager(object): return result_file_path - def _obtain_fuzz_corpus(self): - command = f"cd {DEFAULT_TEST_PATH}; tar czf {self.testsuite_name}_corpus.tar.gz corpus;" - self.config.device.execute_shell_command(command) - result_save_path = get_result_savepath(self.testsuite_path, self.result_rootpath) - LOG.info(f"fuzz_dir = {result_save_path}") - self.device.pull_file(f"{DEFAULT_TEST_PATH}/{self.testsuite_name}_corpus.tar.gz", result_save_path) - - def _obtain_benchmark_result(self): - benchmark_root_dir = os.path.abspath( - os.path.join(self.result_rootpath, "benchmark")) - benchmark_dir = os.path.abspath( - os.path.join(benchmark_root_dir, - self.get_result_sub_save_path(), - self.testsuite_name)) - - if not os.path.exists(benchmark_dir): - os.makedirs(benchmark_dir) - - LOG.info("benchmark_dir = %s" % benchmark_dir) - self.device.pull_file(os.path.join(self.device_testpath, - "%s.json" % self.testsuite_name), benchmark_dir) - if not os.path.exists(os.path.join(benchmark_dir, - "%s.json" % self.testsuite_name)): - os.rmdir(benchmark_dir) - return benchmark_dir - def get_result_sub_save_path(self): find_key = os.sep + "benchmark" + os.sep file_dir, _ = os.path.split(self.testsuite_path) @@ -511,6 +485,32 @@ class ResultManager(object): if target_name != OBJ: subprocess.Popen("mv %s %s" % (os.path.join(cxx_cov_path, target_name), os.path.join(cxx_cov_path, OBJ)), shell=True).communicate() + + def _obtain_fuzz_corpus(self): + command = f"cd {DEFAULT_TEST_PATH}; tar czf {self.testsuite_name}_corpus.tar.gz corpus;" + self.config.device.execute_shell_command(command) + result_save_path = get_result_savepath(self.testsuite_path, self.result_rootpath) + LOG.info(f"fuzz_dir = {result_save_path}") + self.device.pull_file(f"{DEFAULT_TEST_PATH}/{self.testsuite_name}_corpus.tar.gz", result_save_path) + + def _obtain_benchmark_result(self): + benchmark_root_dir = os.path.abspath( + os.path.join(self.result_rootpath, "benchmark")) + benchmark_dir = os.path.abspath( + os.path.join(benchmark_root_dir, + self.get_result_sub_save_path(), + self.testsuite_name)) + + if not os.path.exists(benchmark_dir): + os.makedirs(benchmark_dir) + + LOG.info("benchmark_dir = %s" % benchmark_dir) + self.device.pull_file(os.path.join(self.device_testpath, + "%s.json" % self.testsuite_name), benchmark_dir) + if not os.path.exists(os.path.join(benchmark_dir, + "%s.json" % self.testsuite_name)): + os.rmdir(benchmark_dir) + return benchmark_dir ############################################################################## @@ -569,6 +569,31 @@ class CppTestDriver(IDriver): log_tar_file_name = "{}_{}".format(request.get_module_name(), str(serial).replace( ":", "_")) self.config.device.device_log_collector.stop_hilog_task(log_tar_file_name) + + @staticmethod + def _alter_init(name): + with open(name, "rb") as f: + lines = f.read() + str_content = lines.decode("utf-8") + + pattern_sharp = '^\s*#.*$(\n|\r\n)' + pattern_star = '/\*.*?\*/(\n|\r\n)+' + pattern_xml = '(\n|\r\n)+' + + if re.match(pattern_sharp, str_content, flags=re.M): + striped_content = re.sub(pattern_sharp, '', str_content, flags=re.M) + elif re.findall(pattern_star, str_content, flags=re.S): + striped_content = re.sub(pattern_star, '', str_content, flags=re.S) + elif re.findall(pattern_xml, str_content, flags=re.S): + striped_content = re.sub(pattern_xml, '', str_content, flags=re.S) + else: + striped_content = str_content + + striped_bt = striped_content.encode("utf-8") + if os.path.exists(name): + os.remove(name) + with os.fdopen(os.open(name, FLAGS, MODES), 'wb') as f: + f.write(striped_bt) def _init_gtest(self): self.config.device.connector_command("target mount") @@ -686,31 +711,6 @@ class CppTestDriver(IDriver): resource_dir, self.config.device) - @staticmethod - def _alter_init(name): - with open(name, "rb") as f: - lines = f.read() - str_content = lines.decode("utf-8") - - pattern_sharp = '^\s*#.*$(\n|\r\n)' - pattern_star = '/\*.*?\*/(\n|\r\n)+' - pattern_xml = '(\n|\r\n)+' - - if re.match(pattern_sharp, str_content, flags=re.M): - striped_content = re.sub(pattern_sharp, '', str_content, flags=re.M) - elif re.findall(pattern_star, str_content, flags=re.S): - striped_content = re.sub(pattern_star, '', str_content, flags=re.S) - elif re.findall(pattern_xml, str_content, flags=re.S): - striped_content = re.sub(pattern_xml, '', str_content, flags=re.S) - else: - striped_content = str_content - - striped_bt = striped_content.encode("utf-8") - if os.path.exists(name): - os.remove(name) - with os.fdopen(os.open(name, FLAGS, MODES), 'wb') as f: - f.write(striped_bt) - def _push_corpus_cov_if_exist(self, suite_file): cov_file = suite_file + "_corpus.tar.gz" LOG.info("corpus_cov file :%s" % str(cov_file)) @@ -871,161 +871,7 @@ class JSUnitTestDriver(IDriver): finally: self.config.device.device_log_collector.remove_log_address(None, self.hilog) self.config.device.device_log_collector.stop_catch_device_log(self.hilog_proc) - - def _init_jsunit_test(self): - self.config.device.connector_command("target mount") - self.config.device.execute_shell_command( - "rm -rf %s" % self.config.target_test_path) - self.config.device.execute_shell_command( - "mkdir -p %s" % self.config.target_test_path) - self.config.device.execute_shell_command( - "mount -o rw,remount,rw /") - - def _run_jsunit(self, suite_file, device_log_file): - filename = os.path.basename(suite_file) - _, suffix_name = os.path.splitext(filename) - - resource_manager = ResourceManager() - resource_data_dic, resource_dir = resource_manager.get_resource_data_dic(suite_file) - if suffix_name == ".hap": - json_file_path = suite_file.replace(".hap", ".json") - if os.path.exists(json_file_path): - timeout = self._get_json_shell_timeout(json_file_path) - else: - timeout = ResourceManager.get_nodeattrib_data(resource_data_dic) - else: - timeout = ResourceManager.get_nodeattrib_data(resource_data_dic) - resource_manager.process_preparer_data(resource_data_dic, resource_dir, self.config.device) - main_result = self._install_hap(suite_file) - result = ResultManager(suite_file, self.config) - if main_result: - self._execute_hapfile_jsunittest() - try: - status = False - actiontime = JS_TIMEOUT - times = CYCLE_TIMES - if timeout: - actiontime = timeout - times = 1 - device_log_file_open = os.open(device_log_file, os.O_RDONLY, stat.S_IWUSR | stat.S_IRUSR) - with os.fdopen(device_log_file_open, "r", encoding='utf-8') \ - as file_read_pipe: - for i in range(0, times): - if status: - break - else: - time.sleep(float(actiontime)) - start_time = int(time.time()) - while True: - data = file_read_pipe.readline() - if data.find("JSApp:") != -1 and data.find("[end] run suites end") != -1: - LOG.info("execute testcase successfully.") - status = True - break - if int(time.time()) - start_time > 5: - break - finally: - _lock_screen(self.config.device) - self._uninstall_hap(self.package_name) - else: - self.result = result.get_test_results("Error: install hap failed") - LOG.error("Error: install hap failed") - - resource_manager.process_cleaner_data(resource_data_dic, resource_dir, self.config.device) - - def generate_console_output(self, device_log_file, request): - result_message = self.read_device_log(device_log_file) - - report_name = request.get_module_name() - parsers = get_plugin( - Plugin.PARSER, CommonParserType.jsunit) - if parsers: - parsers = parsers[:1] - for listener in request.listeners: - listener.device_sn = self.config.device.device_sn - parser_instances = [] - - for parser in parsers: - parser_instance = parser.__class__() - parser_instance.suites_name = report_name - parser_instance.suite_name = report_name - parser_instance.listeners = request.listeners - parser_instances.append(parser_instance) - handler = ShellHandler(parser_instances) - process_command_ret(result_message, handler) - - def read_device_log(self, device_log_file): - device_log_file_open = os.open(device_log_file, os.O_RDONLY, - stat.S_IWUSR | stat.S_IRUSR) - - result_message = "" - with os.fdopen(device_log_file_open, "r", encoding='utf-8') \ - as file_read_pipe: - while True: - data = file_read_pipe.readline() - if not data: - break - # only filter JSApp log - if data.find("JSApp:") != -1: - result_message += data - if data.find("[end] run suites end") != -1: - break - return result_message - - def _execute_hapfile_jsunittest(self): - _unlock_screen(self.config.device) - _unlock_device(self.config.device) - - try: - return_message = self.start_hap_execute() - except (ExecuteTerminate, DeviceError) as exception: - return_message = str(exception.args) - - return return_message - - def _install_hap(self, suite_file): - message = self.config.device.connector_command("install %s" % suite_file) - message = str(message).rstrip() - if message == "" or "success" in message: - return_code = True - if message != "": - LOG.info(message) - else: - return_code = False - if message != "": - LOG.warning(message) - - _sleep_according_to_result(return_code) - return return_code - - def start_hap_execute(self): - try: - command = "aa start -d 123 -a %s.MainAbility -b %s" \ - % (self.package_name, self.package_name) - self.start_time = time.time() - result_value = self.config.device.execute_shell_command( - command, timeout=TIME_OUT) - - if "success" in str(result_value).lower(): - LOG.info("execute %s's testcase success. result value=%s" - % (self.package_name, result_value)) - else: - LOG.info("execute %s's testcase failed. result value=%s" - % (self.package_name, result_value)) - - _sleep_according_to_result(result_value) - return_message = result_value - except (ExecuteTerminate, DeviceError) as exception: - return_message = exception.args - - return return_message - - def _uninstall_hap(self, package_name): - return_message = self.config.device.execute_shell_command( - "bm uninstall -n %s" % package_name) - _sleep_according_to_result(return_message) - return return_message - + @staticmethod def _get_acts_test_para(testcase, testlevel, @@ -1144,6 +990,160 @@ class JSUnitTestDriver(IDriver): print("file %s not exist" % hap_filepath) return package_name, ability_name + def start_hap_execute(self): + try: + command = "aa start -d 123 -a %s.MainAbility -b %s" \ + % (self.package_name, self.package_name) + self.start_time = time.time() + result_value = self.config.device.execute_shell_command( + command, timeout=TIME_OUT) + + if "success" in str(result_value).lower(): + LOG.info("execute %s's testcase success. result value=%s" + % (self.package_name, result_value)) + else: + LOG.info("execute %s's testcase failed. result value=%s" + % (self.package_name, result_value)) + + _sleep_according_to_result(result_value) + return_message = result_value + except (ExecuteTerminate, DeviceError) as exception: + return_message = exception.args + + return return_message + + def generate_console_output(self, device_log_file, request): + result_message = self.read_device_log(device_log_file) + + report_name = request.get_module_name() + parsers = get_plugin( + Plugin.PARSER, CommonParserType.jsunit) + if parsers: + parsers = parsers[:1] + for listener in request.listeners: + listener.device_sn = self.config.device.device_sn + parser_instances = [] + + for parser in parsers: + parser_instance = parser.__class__() + parser_instance.suites_name = report_name + parser_instance.suite_name = report_name + parser_instance.listeners = request.listeners + parser_instances.append(parser_instance) + handler = ShellHandler(parser_instances) + process_command_ret(result_message, handler) + + def read_device_log(self, device_log_file): + device_log_file_open = os.open(device_log_file, os.O_RDONLY, + stat.S_IWUSR | stat.S_IRUSR) + + result_message = "" + with os.fdopen(device_log_file_open, "r", encoding='utf-8') \ + as file_read_pipe: + while True: + data = file_read_pipe.readline() + if not data: + break + # only filter JSApp log + if data.find("JSApp:") != -1: + result_message += data + if data.find("[end] run suites end") != -1: + break + return result_message + + def _init_jsunit_test(self): + self.config.device.connector_command("target mount") + self.config.device.execute_shell_command( + "rm -rf %s" % self.config.target_test_path) + self.config.device.execute_shell_command( + "mkdir -p %s" % self.config.target_test_path) + self.config.device.execute_shell_command( + "mount -o rw,remount,rw /") + + def _run_jsunit(self, suite_file, device_log_file): + filename = os.path.basename(suite_file) + _, suffix_name = os.path.splitext(filename) + + resource_manager = ResourceManager() + resource_data_dic, resource_dir = resource_manager.get_resource_data_dic(suite_file) + if suffix_name == ".hap": + json_file_path = suite_file.replace(".hap", ".json") + if os.path.exists(json_file_path): + timeout = self._get_json_shell_timeout(json_file_path) + else: + timeout = ResourceManager.get_nodeattrib_data(resource_data_dic) + else: + timeout = ResourceManager.get_nodeattrib_data(resource_data_dic) + resource_manager.process_preparer_data(resource_data_dic, resource_dir, self.config.device) + main_result = self._install_hap(suite_file) + result = ResultManager(suite_file, self.config) + if main_result: + self._execute_hapfile_jsunittest() + try: + status = False + actiontime = JS_TIMEOUT + times = CYCLE_TIMES + if timeout: + actiontime = timeout + times = 1 + device_log_file_open = os.open(device_log_file, os.O_RDONLY, stat.S_IWUSR | stat.S_IRUSR) + with os.fdopen(device_log_file_open, "r", encoding='utf-8') \ + as file_read_pipe: + for i in range(0, times): + if status: + break + else: + time.sleep(float(actiontime)) + start_time = int(time.time()) + while True: + data = file_read_pipe.readline() + if data.find("JSApp:") != -1 and data.find("[end] run suites end") != -1: + LOG.info("execute testcase successfully.") + status = True + break + if int(time.time()) - start_time > 5: + break + finally: + _lock_screen(self.config.device) + self._uninstall_hap(self.package_name) + else: + self.result = result.get_test_results("Error: install hap failed") + LOG.error("Error: install hap failed") + + resource_manager.process_cleaner_data(resource_data_dic, resource_dir, self.config.device) + + def _execute_hapfile_jsunittest(self): + _unlock_screen(self.config.device) + _unlock_device(self.config.device) + + try: + return_message = self.start_hap_execute() + except (ExecuteTerminate, DeviceError) as exception: + return_message = str(exception.args) + + return return_message + + def _install_hap(self, suite_file): + message = self.config.device.connector_command("install %s" % suite_file) + message = str(message).rstrip() + if message == "" or "success" in message: + return_code = True + if message != "": + LOG.info(message) + else: + return_code = False + if message != "": + LOG.warning(message) + + _sleep_according_to_result(return_code) + return return_code + + def _uninstall_hap(self, package_name): + return_message = self.config.device.execute_shell_command( + "bm uninstall -n %s" % package_name) + _sleep_according_to_result(return_message) + return return_message + @Plugin(type=Plugin.DRIVER, id=DeviceTestType.oh_rust_test) class OHRustTestDriver(IDriver): @@ -1194,6 +1194,9 @@ class OHRustTestDriver(IDriver): log_tar_file_name) self.result = check_result_report( request.config.report_path, self.result, self.error_message) + + def __result__(self): + return self.result if os.path.exists(self.result) else "" def _init_oh_rust(self): self.config.device.connector_command("target mount") @@ -1234,6 +1237,3 @@ class OHRustTestDriver(IDriver): result.obtain_coverage_data() resource_manager.process_cleaner_data(resource_data_dict, resource_dir, self.config.device) - - def __result__(self): - return self.result if os.path.exists(self.result) else "" diff --git a/src/core/driver/lite_driver.py b/src/core/driver/lite_driver.py index 024db50..f4cd7af 100755 --- a/src/core/driver/lite_driver.py +++ b/src/core/driver/lite_driver.py @@ -124,6 +124,23 @@ class LiteUnitTest(IDriver): return self.log.info("lite device execute request success") + def __result__(self): + pass + + def show_help_info(self): + """ + show help info. + """ + self.log.info("this is test driver for cpp test") + return + + def show_driver_info(self): + """ + show driver info. + """ + self.log.info("this is test driver for cpp test") + return + def _mount_nfs_server(self): #before execute each suits bin, mount nfs self.mnt_cmd = "mount {}".format(UserConfigManager().get_user_config( @@ -287,23 +304,6 @@ class LiteUnitTest(IDriver): time.sleep(5) return False - def show_help_info(self): - """ - show help info. - """ - self.log.info("this is test driver for cpp test") - return - - def show_driver_info(self): - """ - show driver info. - """ - self.log.info("this is test driver for cpp test") - return - - def __result__(self): - pass - @Plugin(type=Plugin.DRIVER, id=DeviceTestType.ctest_lite) class CTestDriver(IDriver): @@ -364,6 +364,9 @@ class CTestDriver(IDriver): self.result, self.error_message, report_name) + + def __result__(self): + return self.result if os.path.exists(self.result) else "" def _run_ctest(self, source=None, request=None): if not source: @@ -435,10 +438,6 @@ class CTestDriver(IDriver): reset_cmd = [int(item, 16) for item in reset_cmd] return reset_cmd - def __result__(self): - return self.result if os.path.exists(self.result) else "" - - @Plugin(type=Plugin.DRIVER, id=DeviceTestType.jsunit_test_lite) class JSUnitTestLiteDriver(IDriver): @@ -457,23 +456,7 @@ class JSUnitTestLiteDriver(IDriver): def __check_config__(self, config): pass - - def _get_driver_config(self, json_config): - bundle_name = get_config_value('bundle-name', - json_config.get_driver(), False) - if not bundle_name: - raise ParamError("Can't find bundle-name in config file.", - error_no="00108") - else: - self.config.bundle_name = bundle_name - - ability = get_config_value('ability', - json_config.get_driver(), False) - if not ability: - self.config.ability = "default" - else: - self.config.ability = ability - + def __execute__(self, request): try: LOG.debug("Start execute xdevice extension JSUnit Test") @@ -536,6 +519,25 @@ class JSUnitTestLiteDriver(IDriver): self.config.device.close() + def __result__(self): + return self.result if os.path.exists(self.result) else "" + + def _get_driver_config(self, json_config): + bundle_name = get_config_value('bundle-name', + json_config.get_driver(), False) + if not bundle_name: + raise ParamError("Can't find bundle-name in config file.", + error_no="00108") + else: + self.config.bundle_name = bundle_name + + ability = get_config_value('ability', + json_config.get_driver(), False) + if not ability: + self.config.ability = "default" + else: + self.config.ability = ability + def _run_jsunit(self, request): parser_instances = [] parsers = get_plugin(Plugin.PARSER, ParserType.jsuit_test_lite) @@ -563,6 +565,3 @@ class JSUnitTestLiteDriver(IDriver): file_name.write("{}{}".format( "\n".join(result.split("\n")[0:-1]), "\n")) file_name.flush() - - def __result__(self): - return self.result if os.path.exists(self.result) else "" \ No newline at end of file diff --git a/src/core/testcase/testcase_manager.py b/src/core/testcase/testcase_manager.py index 41cb2e1..27a7ecb 100644 --- a/src/core/testcase/testcase_manager.py +++ b/src/core/testcase/testcase_manager.py @@ -47,6 +47,137 @@ FILTER_SUFFIX_NAME_LIST = [".TOC", ".info", ".pyc"] class TestCaseManager(object): + @classmethod + def get_valid_suite_file(cls, test_case_out_path, suite_file, options): + partlist = options.partname_list + testmodule = options.testmodule + testsuit = options.testsuit + + if not suite_file.startswith(test_case_out_path): + return False + + if testsuit != "": + short_name, _ = os.path.splitext(os.path.basename(suite_file)) + testsuit_list = testsuit.split(',') + for test in testsuit_list: + if short_name.startswith(test) or \ + testsuit.startswith(short_name): + return True + return False + + is_valid_status = False + suitfile_subpath = suite_file.replace(test_case_out_path, "") + suitfile_subpath = suitfile_subpath.strip(os.sep) + if len(partlist) == 0: + if testmodule != "": + temp_list = suitfile_subpath.split(os.sep) + if len(temp_list) > 2 and testmodule == temp_list[1]: + is_valid_status = True + else: + is_valid_status = True + else: + for partname in partlist: + if testmodule != "": + if suitfile_subpath.startswith( + partname + os.sep + testmodule + os.sep): + is_valid_status = True + break + else: + if suitfile_subpath.startswith(partname + os.sep): + is_valid_status = True + break + return is_valid_status + + @classmethod + def check_python_test_file(cls, suite_file): + if suite_file.endswith(".py"): + filename = os.path.basename(suite_file) + if filename.startswith("test_"): + return True + return False + + @classmethod + def check_hap_test_file(cls, hap_file_path): + try: + if hap_file_path.endswith(".hap"): + json_file_path = hap_file_path.replace(".hap", ".json") + if os.path.exists(json_file_path): + with open(json_file_path, 'r') as json_file: + data_dic = json.load(json_file) + if not data_dic: + return False + else: + if "kits" in data_dic.keys(): + kits_list = data_dic.get("kits") + if len(kits_list) > 0: + for kits_dict in kits_list: + if "test-file-name" not in kits_dict.keys(): + continue + else: + return True + else: + return False + return False + except JSONDecodeError: + return False + finally: + print(" check hap test file finally") + + @classmethod + def get_hap_test_driver(cls, hap_file_path): + data_dic = cls.get_hap_json(hap_file_path) + if not data_dic: + return "" + else: + if "driver" in data_dic.keys(): + driver_dict = data_dic.get("driver") + if bool(driver_dict): + driver_type = driver_dict.get("type") + return driver_type + else: + LOG.error("%s has not set driver." % hap_file_path) + return "" + else: + return "" + + @classmethod + def get_hap_json(cls, hap_file_path): + if hap_file_path.endswith(".hap"): + json_file_path = hap_file_path.replace(".hap", ".json") + if os.path.exists(json_file_path): + with open(json_file_path, 'r') as json_file: + data_dic = json.load(json_file) + return data_dic + else: + return {} + else: + return {} + + @classmethod + def get_hap_part_json(cls, hap_file_path): + if hap_file_path.endswith(".hap"): + json_file_path = hap_file_path.replace(".hap", ".moduleInfo") + if os.path.exists(json_file_path): + with open(json_file_path, 'r') as json_file: + data_dic = json.load(json_file) + return data_dic + else: + return {} + else: + return {} + + @classmethod + def get_part_name_test_file(cls, hap_file_path): + data_dic = cls.get_hap_part_json(hap_file_path) + if not data_dic: + return "" + else: + if "part" in data_dic.keys(): + part_name = data_dic["part"] + return part_name + else: + return "" + def get_test_files(self, test_case_path, options): LOG.info("test case path: " + test_case_path) LOG.info("test type list: " + str(options.testtype)) @@ -215,134 +346,3 @@ class TestCaseManager(object): if self.get_hap_test_driver(xts_suite_file) == "JSUnitTest": xts_suit_file_dic.get("JST").append(xts_suite_file) return xts_suit_file_dic - - @classmethod - def get_valid_suite_file(cls, test_case_out_path, suite_file, options): - partlist = options.partname_list - testmodule = options.testmodule - testsuit = options.testsuit - - if not suite_file.startswith(test_case_out_path): - return False - - if testsuit != "": - short_name, _ = os.path.splitext(os.path.basename(suite_file)) - testsuit_list = testsuit.split(',') - for test in testsuit_list: - if short_name.startswith(test) or \ - testsuit.startswith(short_name): - return True - return False - - is_valid_status = False - suitfile_subpath = suite_file.replace(test_case_out_path, "") - suitfile_subpath = suitfile_subpath.strip(os.sep) - if len(partlist) == 0: - if testmodule != "": - temp_list = suitfile_subpath.split(os.sep) - if len(temp_list) > 2 and testmodule == temp_list[1]: - is_valid_status = True - else: - is_valid_status = True - else: - for partname in partlist: - if testmodule != "": - if suitfile_subpath.startswith( - partname + os.sep + testmodule + os.sep): - is_valid_status = True - break - else: - if suitfile_subpath.startswith(partname + os.sep): - is_valid_status = True - break - return is_valid_status - - @classmethod - def check_python_test_file(cls, suite_file): - if suite_file.endswith(".py"): - filename = os.path.basename(suite_file) - if filename.startswith("test_"): - return True - return False - - @classmethod - def check_hap_test_file(cls, hap_file_path): - try: - if hap_file_path.endswith(".hap"): - json_file_path = hap_file_path.replace(".hap", ".json") - if os.path.exists(json_file_path): - with open(json_file_path, 'r') as json_file: - data_dic = json.load(json_file) - if not data_dic: - return False - else: - if "kits" in data_dic.keys(): - kits_list = data_dic.get("kits") - if len(kits_list) > 0: - for kits_dict in kits_list: - if "test-file-name" not in kits_dict.keys(): - continue - else: - return True - else: - return False - return False - except JSONDecodeError: - return False - finally: - print(" check hap test file finally") - - @classmethod - def get_hap_test_driver(cls, hap_file_path): - data_dic = cls.get_hap_json(hap_file_path) - if not data_dic: - return "" - else: - if "driver" in data_dic.keys(): - driver_dict = data_dic.get("driver") - if bool(driver_dict): - driver_type = driver_dict.get("type") - return driver_type - else: - LOG.error("%s has not set driver." % hap_file_path) - return "" - else: - return "" - - @classmethod - def get_hap_json(cls, hap_file_path): - if hap_file_path.endswith(".hap"): - json_file_path = hap_file_path.replace(".hap", ".json") - if os.path.exists(json_file_path): - with open(json_file_path, 'r') as json_file: - data_dic = json.load(json_file) - return data_dic - else: - return {} - else: - return {} - - @classmethod - def get_hap_part_json(cls, hap_file_path): - if hap_file_path.endswith(".hap"): - json_file_path = hap_file_path.replace(".hap", ".moduleInfo") - if os.path.exists(json_file_path): - with open(json_file_path, 'r') as json_file: - data_dic = json.load(json_file) - return data_dic - else: - return {} - else: - return {} - - @classmethod - def get_part_name_test_file(cls, hap_file_path): - data_dic = cls.get_hap_part_json(hap_file_path) - if not data_dic: - return "" - else: - if "part" in data_dic.keys(): - part_name = data_dic["part"] - return part_name - else: - return "" diff --git a/src/core/testkit/kit_lite.py b/src/core/testkit/kit_lite.py index 35fafde..f4af61b 100755 --- a/src/core/testkit/kit_lite.py +++ b/src/core/testkit/kit_lite.py @@ -63,6 +63,56 @@ class DeployKit(ITestKit): "burn_file:{}".format(self.timeout, self.burn_file) raise ParamError(msg, error_no="00108") + def __setup__(self, device, **kwargs): + """ + Execute reset command on the device by cmd serial port and then upload + patch file by deploy tool. + Parameters: + device: the instance of LocalController with one or more + ComController + """ + args = kwargs + source_file = args.get("source_file", None) + self._reset(device) + self._send_file(device, source_file) + + def __teardown__(self, device): + pass + + def copy_file_as_temp(self, original_file, str_length): + """ + To obtain a random string with specified length + Parameters: + original_file : the original file path + str_length: the length of random string + """ + if os.path.isfile(original_file): + random_str = random.sample(string.ascii_letters + string.digits, + str_length) + new_temp_tool_path = '{}_{}{}'.format( + os.path.splitext(original_file)[0], "".join(random_str), + os.path.splitext(original_file)[1]) + return shutil.copyfile(original_file, new_temp_tool_path) + else: + return "" + def copy_file_as_temp(self, original_file, str_length): + """ + To obtain a random string with specified length + Parameters: + original_file : the original file path + str_length: the length of random string + """ + if os.path.isfile(original_file): + random_str = random.sample(string.ascii_letters + string.digits, + str_length) + new_temp_tool_path = '{}_{}{}'.format( + os.path.splitext(original_file)[0], "".join(random_str), + os.path.splitext(original_file)[1]) + return shutil.copyfile(original_file, new_temp_tool_path) + else: + return "" + + def _reset(self, device): cmd_com = device.device.com_dict.get(ComType.cmd_com) try: @@ -112,36 +162,3 @@ class DeployKit(ITestKit): device.device_allocation_state = DeviceAllocationState.unusable raise LiteDeviceError("%s port set_up wifiiot failed" % deploy_serial_port, error_no="00402") - - def __setup__(self, device, **kwargs): - """ - Execute reset command on the device by cmd serial port and then upload - patch file by deploy tool. - Parameters: - device: the instance of LocalController with one or more - ComController - """ - args = kwargs - source_file = args.get("source_file", None) - self._reset(device) - self._send_file(device, source_file) - - def __teardown__(self, device): - pass - - def copy_file_as_temp(self, original_file, str_length): - """ - To obtain a random string with specified length - Parameters: - original_file : the original file path - str_length: the length of random string - """ - if os.path.isfile(original_file): - random_str = random.sample(string.ascii_letters + string.digits, - str_length) - new_temp_tool_path = '{}_{}{}'.format( - os.path.splitext(original_file)[0], "".join(random_str), - os.path.splitext(original_file)[1]) - return shutil.copyfile(original_file, new_temp_tool_path) - else: - return "" -- Gitee From 385e22fe7f1599bdb53be9fdc1566598abeb801d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=9B=BD=E8=BE=89?= Date: Tue, 30 Jul 2024 14:59:56 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Signed-off-by:=E9=BB=84=E5=9B=BD=E8=BE=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {localCoverage => local_coverage}/__init__.py | 0 .../all_subsystem_config.json | 2512 ++++++++--------- .../code_coverage}/__init__.py | 0 .../code_coverage/code_coverage_gcov_lcov.py | 598 ++-- .../coverage_rc/lcovrc_cov_template | 0 .../code_coverage}/llvm-gcov.sh | 2 +- .../multiprocess_code_coverage.py | 790 +++--- .../coverage_tools.py | 406 +-- .../interface_coverage}/__init__.py | 0 .../interface_coverage}/get_innerkits_json.py | 160 +- .../interface_coverage_gcov_lcov.py | 6 +- .../interface_coverage}/make_report.py | 0 .../interface_kits/coverage_summary_file.xml | 0 .../ohos_interfaceCoverage.html | 0 .../keyword_registration/keyword.json | 0 .../keyword_registration/keyword_filter.py | 254 +- .../push_coverage_so/__init__.py | 0 .../push_coverage_so/push_coverage.py | 4 +- .../resident_service/config/ams/ams.cfg | 98 +- .../resident_service/config/ams/ams.xml | 126 +- .../config/ams/foundation.xml | 254 +- .../resident_service/config/bms/bms.cfg | 98 +- .../resident_service/config/bms/bms.xml | 66 +- .../config/bms/foundation.xml | 310 +- .../resident_service/config/call/call.cfg | 98 +- .../resident_service/config/call/call.xml | 62 +- .../config/call/foundation.xml | 312 +- .../resident_service/config/fms/fms.cfg | 98 +- .../resident_service/config/fms/fms.xml | 64 +- .../config/fms/foundation.xml | 310 +- .../config/notification/foundation.xml | 286 +- .../config/notification/notification.cfg | 98 +- .../config/notification/notification.xml | 86 +- .../config/power/foundation.xml | 276 +- .../resident_service/config/power/power.cfg | 98 +- .../resident_service/config/power/power.xml | 126 +- .../config/state/foundation.xml | 312 +- .../resident_service/config/state/state.cfg | 98 +- .../resident_service/config/state/state.xml | 62 +- .../config/wms/foundation.xml | 290 +- .../resident_service/config/wms/wms.cfg | 98 +- .../resident_service/config/wms/wms.xml | 88 +- .../resident_service/init_gcov.py | 730 ++--- .../resident_service/public_method.py | 286 +- .../resident_service/pull_service_gcda.py | 322 +-- .../resident_service/resources/gcov_flush.sh | 0 .../resident_service/system_part_service.json | 228 +- .../restore_comment/__init__.py | 0 .../restore_comment/after_lcov_branch.py | 170 +- .../restore_comment/build_before_generate.py | 4 +- .../restore_comment/restore_source_code.py | 92 +- {localCoverage => local_coverage}/utils.py | 0 src/core/command/run.py | 8 +- 53 files changed, 5193 insertions(+), 5193 deletions(-) rename {localCoverage => local_coverage}/__init__.py (100%) rename {localCoverage => local_coverage}/all_subsystem_config.json (95%) rename {localCoverage/codeCoverage => local_coverage/code_coverage}/__init__.py (100%) rename localCoverage/codeCoverage/codeCoverage_gcov_lcov.py => local_coverage/code_coverage/code_coverage_gcov_lcov.py (94%) rename {localCoverage/codeCoverage => local_coverage/code_coverage}/coverage_rc/lcovrc_cov_template (100%) rename {localCoverage/codeCoverage => local_coverage/code_coverage}/llvm-gcov.sh (90%) rename localCoverage/codeCoverage/mutilProcess_CodeCoverage.py => local_coverage/code_coverage/multiprocess_code_coverage.py (92%) rename {localCoverage => local_coverage}/coverage_tools.py (83%) rename {localCoverage/interfaceCoverage => local_coverage/interface_coverage}/__init__.py (100%) rename {localCoverage/interfaceCoverage => local_coverage/interface_coverage}/get_innerkits_json.py (93%) rename localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py => local_coverage/interface_coverage/interface_coverage_gcov_lcov.py (98%) rename {localCoverage/interfaceCoverage => local_coverage/interface_coverage}/make_report.py (100%) rename {localCoverage/interfaceCoverage => local_coverage/interface_coverage}/results/coverage/interface_kits/coverage_summary_file.xml (100%) rename {localCoverage/interfaceCoverage => local_coverage/interface_coverage}/results/coverage/interface_kits/ohos_interfaceCoverage.html (100%) rename {localCoverage => local_coverage}/keyword_registration/keyword.json (100%) rename {localCoverage => local_coverage}/keyword_registration/keyword_filter.py (99%) rename {localCoverage => local_coverage}/push_coverage_so/__init__.py (100%) rename {localCoverage => local_coverage}/push_coverage_so/push_coverage.py (97%) rename {localCoverage => local_coverage}/resident_service/config/ams/ams.cfg (97%) rename {localCoverage => local_coverage}/resident_service/config/ams/ams.xml (96%) rename {localCoverage => local_coverage}/resident_service/config/ams/foundation.xml (97%) rename {localCoverage => local_coverage}/resident_service/config/bms/bms.cfg (97%) rename {localCoverage => local_coverage}/resident_service/config/bms/bms.xml (97%) rename {localCoverage => local_coverage}/resident_service/config/bms/foundation.xml (96%) rename {localCoverage => local_coverage}/resident_service/config/call/call.cfg (97%) rename {localCoverage => local_coverage}/resident_service/config/call/call.xml (97%) rename {localCoverage => local_coverage}/resident_service/config/call/foundation.xml (97%) rename {localCoverage => local_coverage}/resident_service/config/fms/fms.cfg (97%) rename {localCoverage => local_coverage}/resident_service/config/fms/fms.xml (97%) rename {localCoverage => local_coverage}/resident_service/config/fms/foundation.xml (97%) rename {localCoverage => local_coverage}/resident_service/config/notification/foundation.xml (97%) rename {localCoverage => local_coverage}/resident_service/config/notification/notification.cfg (97%) rename {localCoverage => local_coverage}/resident_service/config/notification/notification.xml (97%) rename {localCoverage => local_coverage}/resident_service/config/power/foundation.xml (97%) rename {localCoverage => local_coverage}/resident_service/config/power/power.cfg (97%) rename {localCoverage => local_coverage}/resident_service/config/power/power.xml (97%) rename {localCoverage => local_coverage}/resident_service/config/state/foundation.xml (97%) rename {localCoverage => local_coverage}/resident_service/config/state/state.cfg (97%) rename {localCoverage => local_coverage}/resident_service/config/state/state.xml (97%) rename {localCoverage => local_coverage}/resident_service/config/wms/foundation.xml (97%) rename {localCoverage => local_coverage}/resident_service/config/wms/wms.cfg (97%) rename {localCoverage => local_coverage}/resident_service/config/wms/wms.xml (96%) rename {localCoverage => local_coverage}/resident_service/init_gcov.py (95%) rename {localCoverage => local_coverage}/resident_service/public_method.py (96%) rename {localCoverage => local_coverage}/resident_service/pull_service_gcda.py (95%) rename {localCoverage => local_coverage}/resident_service/resources/gcov_flush.sh (100%) rename {localCoverage => local_coverage}/resident_service/system_part_service.json (98%) rename {localCoverage => local_coverage}/restore_comment/__init__.py (100%) rename {localCoverage => local_coverage}/restore_comment/after_lcov_branch.py (94%) rename {localCoverage => local_coverage}/restore_comment/build_before_generate.py (97%) rename {localCoverage => local_coverage}/restore_comment/restore_source_code.py (92%) rename {localCoverage => local_coverage}/utils.py (100%) diff --git a/localCoverage/__init__.py b/local_coverage/__init__.py similarity index 100% rename from localCoverage/__init__.py rename to local_coverage/__init__.py diff --git a/localCoverage/all_subsystem_config.json b/local_coverage/all_subsystem_config.json similarity index 95% rename from localCoverage/all_subsystem_config.json rename to local_coverage/all_subsystem_config.json index 46f86d0..2980779 100644 --- a/localCoverage/all_subsystem_config.json +++ b/local_coverage/all_subsystem_config.json @@ -1,1256 +1,1256 @@ -{ - "bundle_framework": { - "name": "bundle_framework", - "path": [ - "foundation/bundlemanager/bundle_framework" - ] - }, - "bundle_framework_lite": { - "name": "bundle_framework_lite", - "path": [ - "foundation/bundlemanager/bundle_framework_lite" - ] - }, - "packing_tool": { - "name": "packing_tool", - "path": [ - "developtools/packing_tool" - ] - }, - "appverify": { - "name": "appverify", - "path": [ - "base/security/appverify" - ] - }, - "zlib": { - "name": "zlib", - "path": [ - "third_party/zlib" - ] - }, - "ability_lite": { - "name": "ability_lite", - "path": [ - "foundation/ability/ability_lite" - ] - }, - "ability_base": { - "name": "ability_base", - "path": [ - "foundation/ability/ability_base" - ] - }, - "ability_runtime": { - "name": "ability_runtime", - "path": [ - "foundation/ability/ability_runtime" - ] - }, - "ability_tool": { - "name": "ability_tool", - "path": [ - "foundation/ability/ability_runtime/tools" - ] - }, - "idl_tool": { - "name": "idl_tool", - "path": [ - "foundation/ability/idl_tool" - ] - }, - "form_fwk": { - "name": "form_fwk", - "path": [ - "foundation/ability/form_fwk" - ] - }, - "window_manager_lite": { - "name": "window_manager_lite", - "path": [ - "foundation/window/window_manager_lite" - ] - }, - "ui_lite": { - "name": "ui_lite", - "path": [ - "foundation/arkui/ui_lite" - ] - }, - "graphic_utils_lite": { - "name": "graphic_utils_lite", - "path": [ - "foundation/graphic/graphic_utils_lite" - ] - }, - "graphic_2d": { - "name": "graphic_2d", - "path": [ - "foundation/graphic/graphic_2d" - ] - }, - "image_framework": { - "name": "image_framework", - "path": [ - "foundation/multimedia/image_framework" - ] - }, - "background_task_mgr": { - "name": "background_task_mgr", - "path": [ - "foundation/resourceschedule/background_task_mgr" - ] - }, - "work_scheduler": { - "name": "work_scheduler", - "path": [ - "foundation/resourceschedule/work_scheduler" - ] - }, - "device_usage_statistics": { - "name": "device_usage_statistics", - "path": [ - "foundation/resourceschedule/device_usage_statistics" - ] - }, - "resource_schedule_service": { - "name": "resource_schedule_service", - "path": [ - "foundation/resourceschedule/resource_schedule_service" - ] - }, - "schedule_ext": { - "name": "schedule_ext", - "path": [ - "foundation/resourceschedule/resource_schedule_service/schedule_ext" - ] - }, - "efficiency_manager": { - "name": "efficiency_manager", - "path": [ - "foundation/resourceschedule/efficiency_manager" - ] - }, - "efficiency_manager_ext": { - "name": "efficiency_manager_ext", - "path": [ - "foundation/resourceschedule/efficiency_manager_ext" - ] - }, - "preferences": { - "name": "preferences", - "path": [ - "foundation/distributeddatamgr/preferences" - ] - }, - "relational_store": { - "name": "relational_store", - "path": [ - "foundation/distributeddatamgr/relational_store" - ] - }, - "data_share": { - "name": "data_share", - "path": [ - "foundation/distributeddatamgr/data_share" - ] - }, - "kv_store": { - "name": "kv_store", - "path": [ - "foundation/distributeddatamgr/kv_store" - ] - }, - "datamgr_service": { - "name": "datamgr_service", - "path": [ - "foundation/distributeddatamgr/distributeddatamgr" - ] - }, - "data_object": { - "name": "data_object", - "path": [ - "foundation/distributeddatamgr/data_object" - ] - }, - "pasteboard": { - "name": "pasteboard", - "path": [ - "foundation/distributeddatamgr/pasteboard" - ] - }, - "ipc": { - "name": "ipc", - "path": [ - "foundation/communication/ipc" - ] - }, - "dsoftbus_standard": { - "name": "dsoftbus_standard", - "path": [ - "foundation/communication/dsoftbus" - ] - }, - "device_manager": { - "name": "device_manager", - "path": [ - "foundation/distributedhardware/device_manager" - ] - }, - "distributed_hardware_fwk": { - "name": "distributed_hardware_fwk", - "path": [ - "foundation/distributedhardware/distributed_hardware_fwk" - ] - }, - "distributed_camera": { - "name": "distributed_camera", - "path": [ - "foundation/distributedhardware/distributed_camera" - ] - }, - "distributed_audio": { - "name": "distributed_audio", - "path": [ - "foundation/distributedhardware/distributed_audio" - ] - }, - "distributed_screen": { - "name": "distributed_screen", - "path": [ - "foundation/distributedhardware/distributed_screen" - ] - }, - "distributed_input": { - "name": "distributed_input", - "path": [ - "foundation/distributedhardware/distributed_input" - ] - }, - "input": { - "name": "input", - "path": [ - "foundation/multimodalinput/input" - ] - }, - "audio_framework": { - "name": "audio_framework", - "path": [ - "foundation/multimedia/audio_framework" - ] - }, - "audio_manager_lite": { - "name": "audio_manager_lite", - "path": [ - "foundation/multimedia/audio_lite" - ] - }, - "camera_lite": { - "name": "camera_lite", - "path": [ - "foundation/multimedia/camera_lite" - ] - }, - "camera_framework": { - "name": "camera_framework", - "path": [ - "foundation/multimedia/camera_standard" - ] - }, - "media_lite": { - "name": "media_lite", - "path": [ - "foundation/multimedia/media_lite" - ] - }, - "multimedia_av_session": { - "name": "multimedia_av_session", - "path": [ - "foundation/multimedia/av_session" - ] - }, - "utils": { - "name": "utils", - "path": [ - "foundation/multimedia/utils" - ] - }, - "omx_adapter": { - "name": "omx_adapter", - "path": [ - "foundation/multimedia/omx_adapter" - ] - }, - "histreamer": { - "name": "histreamer", - "path": [ - "foundation/multimedia/histreamer" - ] - }, - "player_framework": { - "name": "player_framework", - "path": [ - "foundation/multimedia/player_framework" - ] - }, - "neural_network_runtime": { - "name": "neural_network_runtime", - "path": [ - "foundation/ai/neural_network_runtime" - ] - }, - "ai_engine": { - "name": "ai_engine", - "path": [ - "foundation/ai/ai_engine" - ] - }, - "decision": { - "name": "decision", - "path": [ - "foundation/ai/decision" - ] - }, - "mindspore": { - "name": "mindspore", - "path": [ - "third_party/mindspore" - ] - }, - "core_service": { - "name": "core_service", - "path": [ - "base/telephony/core_service" - ] - }, - "call_manager": { - "name": "call_manager", - "path": [ - "base/telephony/call_manager" - ] - }, - "data_storage": { - "name": "data_storage", - "path": [ - "base/telephony/data_storage" - ] - }, - "sms_mms": { - "name": "sms_mms", - "path": [ - "base/telephony/sms_mms" - ] - }, - "cellular_call": { - "name": "cellular_call", - "path": [ - "base/telephony/cellular_call" - ] - }, - "cellular_data": { - "name": "cellular_data", - "path": [ - "base/telephony/cellular_data" - ] - }, - "state_registry": { - "name": "state_registry", - "path": [ - "base/telephony/state_registry" - ] - }, - "ril_adapter": { - "name": "ril_adapter", - "path": [ - "base/telephony/ril_adapter" - ] - }, - "ims_service": { - "name": "ims_service", - "path": [ - "vendor/huawei/base/telephony/ims_service" - ] - }, - "ril_adapter_ext": { - "name": "ril_adapter_ext", - "path": [ - "vendor/huawei/base/telephony/ril_adapter_ext" - ] - }, - "certificate_manager": { - "name": "certificate_manager", - "path": [ - "base/security/certificate_manager" - ] - }, - "crypto_framework": { - "name": "crypto_framework", - "path": [ - "base/security/crypto_framework" - ] - }, - "dataclassification": { - "name": "dataclassification", - "path": [ - "base/security/dataclassification" - ] - }, - "device_auth": { - "name": "device_auth", - "path": [ - "base/security/device_auth" - ] - }, - "device_security_level": { - "name": "device_security_level", - "path": [ - "base/security/device_security_level" - ] - }, - "device_threat_detection": { - "name": "device_threat_detection", - "path": [ - "base/security/device_threat_detection" - ] - }, - "hapsigner": { - "name": "hapsigner", - "path": [ - "developtools/hapsigner" - ] - }, - "huks": { - "name": "huks", - "path": [ - "base/security/huks" - ] - }, - "appspawn": { - "name": "appspawn", - "path": [ - "base/startup/appspawn" - ] - }, - "bootstrap_lite": { - "name": "bootstrap_lite", - "path": [ - "base/startup/bootstrap_lite" - ] - }, - "init": { - "name": "init", - "path": [ - "base/startup/init" - ] - }, - "notification": { - "name": "notification", - "path": [ - "base/notification/common_event_service", - "base/notification/distributed_notification_service", - "base/notification/eventhandler" - ] - }, - "hilog": { - "name": "hilog", - "path": [ - "base/hiviewdfx/hilog" - ] - }, - "hilog_lite": { - "name": "hilog_lite", - "path": [ - "base/hiviewdfx/hilog_lite" - ] - }, - "hitrace": { - "name": "hitrace", - "path": [ - "base/hiviewdfx/hitrace" - ] - }, - "hiview": { - "name": "hiview", - "path": [ - "base/hiviewdfx/hiview/adapter", - "base/hiviewdfx/hiview/build", - "base/hiviewdfx/hiview/base", - "base/hiviewdfx/hiview/core", - "base/hiviewdfx/hiview/figures", - "base/hiviewdfx/hiview/include", - "base/hiviewdfx/hiview/service", - "base/hiviewdfx/hiview/utility", - "base/hiviewdfx/hiview/test", - "base/hiviewdfx/hiview/plugins/eventlogger", - "base/hiviewdfx/hiview/plugins/eventservice", - "base/hiviewdfx/hiview/plugins/faultlogger", - "base/hiviewdfx/hiview/plugins/freeze_detector", - "base/hiviewdfx/hiview/plugins/hicollie_collector", - "base/hiviewdfx/hiview/plugins/usage_event_report", - "base/hiviewdfx/hiview/plugins/huawei_proprietary/leak_detectors", - "base/hiviewdfx/hiview/plugins/huawei_proprietary/test" - ] - }, - "hiview_lite": { - "name": "hiview_lite", - "path": [ - "base/hiviewdfx/hiview_lite" - ] - }, - "hichecker": { - "name": "hichecker", - "path": [ - "base/hiviewdfx/hichecker" - ] - }, - "hicollie": { - "name": "hicollie", - "path": [ - "base/hiviewdfx/hicollie" - ] - }, - "hiappevent": { - "name": "hiappevent", - "path": [ - "base/hiviewdfx/hiappevent" - ] - }, - "hisysevent": { - "name": "hisysevent", - "path": [ - "base/hiviewdfx/hisysevent" - ] - }, - "hievent_lite": { - "name": "hievent_lite", - "path": [ - "base/hiviewdfx/hievent_lite" - ] - }, - "faultloggerd": { - "name": "faultloggerd", - "path": [ - "base/hiviewdfx/faultloggerd" - ] - }, - "profiler": { - "name": "profiler", - "path": [ - "developtools/profiler" - ] - }, - "hiperf": { - "name": "hiperf", - "path": [ - "developtools/hiperf" - ] - }, - "bytrace": { - "name": "bytrace", - "path": [ - "developtools/bytrace" - ] - }, - "hidumper_lite": { - "name": "hidumper_lite", - "path": [ - "base/hiviewdfx/hidumper_lite" - ] - }, - "blackbox": { - "name": "blackbox", - "path": [ - "base/hiviewdfx/blackbox" - ] - }, - "hidumper": { - "name": "hidumper", - "path": [ - "base/hiviewdfx/hidumper" - ] - }, - "bluetooth": { - "name": "bluetooth", - "path": [ - "foundation/communication/bluetooth" - ] - }, - "nfc": { - "name": "nfc", - "path": [ - "foundation/communication/nfc/nfc_core" - ] - }, - "connected_tag": { - "name": "connected_tag", - "path": [ - "foundation/communication/nfc/connected_tag" - ] - }, - "wifi": { - "name": "wifi", - "path": [ - "foundation/communication/wifi/wifi" - ] - }, - "dhcp": { - "name": "dhcp", - "path": [ - "foundation/communication/wifi/dhcp" - ] - }, - "wifi_aware": { - "name": "wifi_aware", - "path": [ - "foundation/communication/wifi_aware" - ] - }, - "wifi_lite": { - "name": "wifi_lite", - "path": [ - "foundation/communication/wifi_lite" - ] - }, - "algorithm": { - "name": "algorithm", - "path": [ - "base/msdp/algorithm" - ] - }, - "geofence": { - "name": "geofence", - "path": [ - "base/msdp/geofence" - ] - }, - "motion": { - "name": "motion", - "path": [ - "base/msdp/motion" - ] - }, - "movement": { - "name": "movement", - "path": [ - "base/msdp/movement" - ] - }, - "spatial_awareness": { - "name": "spatial_awareness", - "path": [ - "base/msdp/spatial_awareness" - ] - }, - "timeline": { - "name": "timeline", - "path": [ - "base/msdp/timeline" - ] - }, - "device_status": { - "name": "device_status", - "path": [ - "base/msdp/device_status" - ] - }, - "os_account": { - "name": "os_account", - "path": [ - "base/account/os_account" - ] - }, - "i18n": { - "name": "i18n", - "path": [ - "base/global/i18n" - ] - }, - "i18n_lite": { - "name": "i18n_lite", - "path": [ - "base/global/i18n_lite" - ] - }, - "system_resources": { - "name": "system_resources", - "path": [ - "utils/system_resources" - ] - }, - "jsoncpp": { - "name": "jsoncpp", - "path": [ - "third_party/jsoncpp" - ] - }, - "libxml2": { - "name": "libxml2", - "path": [ - "third_party/libxml2" - ] - }, - "global_resource_tool": { - "name": "global_resource_tool", - "path": [ - "developtools/global_resource_tool" - ] - }, - "resource_management": { - "name": "resource_management", - "path": [ - "base/global/resource_management" - ] - }, - "resource_management_lite": { - "name": "resource_management_lite", - "path": [ - "base/global/resource_management_lite" - ] - }, - "time_zone": { - "name": "time_zone", - "path": [ - "base/global/time_zone" - ] - }, - "accessibility": { - "name": "accessibility", - "path": [ - "foundation/barrierfree/accessibility" - ] - }, - "time_service": { - "name": "time_service", - "path": [ - "base/time/time_service" - ] - }, - "imf": { - "name": "imf", - "path": [ - "base/inputmethod/imf" - ] - }, - "theme": { - "name": "theme", - "path": [ - "base/theme" - ] - }, - "request": { - "name": "request", - "path": [ - "base/request" - ] - }, - "battery_manager": { - "name": "battery_manager", - "path": [ - "base/powermgr/battery_manager" - ] - }, - "display_manager": { - "name": "display_manager", - "path": [ - "base/powermgr/display_manager" - ] - }, - "powermgr_lite": { - "name": "powermgr_lite", - "path": [ - "base/powermgr/powermgr_lite" - ] - }, - "battery_lite": { - "name": "battery_lite", - "path": [ - "base/powermgr/battery_lite" - ] - }, - "battery_statistics": { - "name": "battery_statistics", - "path": [ - "base/powermgr/battery_statistics" - ] - }, - "power_manager": { - "name": "power_manager", - "path": [ - "base/powermgr/power_manager" - ] - }, - "thermal_manager": { - "name": "thermal_manager", - "path": [ - "base/powermgr/thermal_manager" - ] - }, - "sensor": { - "name": "sensor", - "path": [ - "base/sensors/sensor" - ] - }, - "miscdevice": { - "name": "miscdevice", - "path": [ - "base/sensors/miscdevice" - ] - }, - "sensor_lite": { - "name": "sensor_lite", - "path": [ - "base/sensors/sensor_lite" - ] - }, - "miscdevice_lite": { - "name": "miscdevice_lite", - "path": [ - "base/sensors/miscdevice_lite" - ] - }, - "start": { - "name": "start", - "path": [ - "base/sensors/start" - ] - }, - "user_auth_framework": { - "name": "user_auth_framework", - "path": [ - "base/useriam/user_auth_framework" - ] - }, - "pin_auth": { - "name": "pin_auth", - "path": [ - "base/useriam/pin_auth" - ] - }, - "face_auth": { - "name": "face_auth", - "path": [ - "base/useriam/face_auth" - ] - }, - "fingerprint_auth": { - "name": "fingerprint_auth", - "path": [ - "base/useriam/fingerprint_auth" - ] - }, - "peripheral": { - "name": "peripheral", - "path": [ - "drivers/peripheral/pin_auth", - "drivers/peripheral/face_auth", - "drivers/peripheral/user_auth", - "drivers/peripheral/fingerprint_auth" - ] - }, - "location": { - "name": "location", - "path": [ - "base/location" - ] - }, - "usb_manager": { - "name": "usb_manager", - "path": [ - "base/usb/usb_manager" - ] - }, - "build": { - "name": "build", - "path": [ - "build" - ] - }, - "gn": { - "name": "gn", - "path": [ - "third_party/gn" - ] - }, - "ninja": { - "name": "ninja", - "path": [ - "third_party/ninja" - ] - }, - "hidl_adapter": { - "name": "hidl_adapter", - "path": [ - "drivers/peripheral/adapter/activity_recognition", - "drivers/peripheral/adapter/audio", - "drivers/peripheral/adapter/camera", - "drivers/peripheral/adapter/gralloc", - "drivers/peripheral/adapter/hwc", - "drivers/peripheral/adapter/input", - "drivers/peripheral/adapter/motion", - "drivers/peripheral/adapter/sensor", - "drivers/peripheral/adapter/thermal" - ] - }, - "hdf_core": { - "name": "hdf_core", - "path": [ - "drivers/hdf_core/adapter/uhdf2", - "drivers/hdf_core/framework/core/common", - "drivers/hdf_core/framework/core/host", - "drivers/hdf_core/framework/core/manager", - "drivers/hdf_core/framework/core/shared", - "drivers/hdf_core/framework/support/posix/" - ] - }, - "filemanagement_app_file_service": { - "name": "filemanagement_app_file_service", - "path": [ - "foundation/filemanagement/app_file_service" - ] - }, - "filemanagement_backup": { - "name": "filemanagement_backup", - "path": [ - "foundation/filemanagement/backup" - ] - }, - "filemanagement_dfs_service": { - "name": "filemanagement_dfs_service", - "path": [ - "foundation/filemanagement/dfs_service" - ] - }, - "filemanagement_file_api": { - "name": "filemanagement_file_api", - "path": [ - "foundation/filemanagement/file_api" - ] - }, - "filemanagement_storage_service": { - "name": "filemanagement_storage_service", - "path": [ - "foundation/filemanagement/storage_service" - ] - }, - "filemanagement_user_file_service": { - "name": "filemanagement_user_file_service", - "path": [ - "foundation/filemanagement/user_file_service" - ] - }, - "media_library": { - "name": "media_library", - "path": [ - "foundation/multimedia/media_library" - ] - }, - "netmanager_base": { - "name": "netmanager_base", - "path": [ - "foundation/communication/netmanager_base" - ] - }, - "netmanager_ext": { - "name": "netmanager_ext", - "path": [ - "foundation/communication/netmanager_ext" - ] - }, - "netstack": { - "name": "netstack", - "path": [ - "foundation/communication/netstack" - ] - }, - "webview": { - "name": "webview", - "path": [ - "base/web/webview/ohos_adapter", - "base/web/webview/ohos_nweb" - ] - }, - "tee_client": { - "name": "tee_client", - "path": [ - "base/tee/tee_client" - ] - }, - "tee_os_framework": { - "name": "tee_os_framework", - "path": [ - "base/tee/tee_os_framework" - ] - }, - "tee_dev_kit": { - "name": "tee_dev_kit", - "path": [ - "base/tee/tee_dev_kit" - ] - }, - "tee_tzdriver": { - "name": "tee_tzdriver", - "path": [ - "base/tee/tee_tzdriver" - ] - }, - "tee_os_kernel": { - "name": "tee_os_kernel", - "path": [ - "base/tee/tee_os_kernel" - ] - }, - "device_info_manager": { - "name": "device_info_manager", - "path": [ - "foundation/deviceprofile" - ] - }, - "enterprise_device_management": { - "name": "enterprise_device_management", - "path": [ - "base/customization/enterprise_device_management" - ] - }, - "config_policy": { - "name": "config_policy", - "path": [ - "base/customization/config_policy" - ] - }, - "toolchain": { - "name": "toolchain", - "path": [ - "arkcompiler/toolchain" - ] - }, - "runtime_core": { - "name": "runtime_core", - "path": [ - "arkcompiler/runtime_core" - ] - }, - "ets_frontend": { - "name": "ets_frontend", - "path": [ - "arkcompiler/ets_frontend" - ] - }, - "ets_runtime": { - "name": "ets_runtime", - "path": [ - "arkcompiler/ets_runtime" - ] - }, - "jerryscript": { - "name": "jerryscript", - "path": [ - "third_party/jerryscript" - ] - }, - "safwk": { - "name": "safwk", - "path": [ - "foundation/systemabilitymgr/safwk" - ] - }, - "safwk_lite": { - "name": "safwk_lite", - "path": [ - "foundation/systemabilitymgr/safwk_lite" - ] - }, - "samgr_lite": { - "name": "samgr_lite", - "path": [ - "foundation/systemabilitymgr/samgr_lite" - ] - }, - "samgr": { - "name": "samgr", - "path": [ - "foundation/systemabilitymgr/samgr" - ] - }, - "dmsfwk": { - "name": "dmsfwk", - "path": [ - "foundation/ability/dmsfwk" - ] - }, - "dmsfwk_lite": { - "name": "dmsfwk_lite", - "path": [ - "foundation/ability/dmsfwk_lite" - ] - }, - "window_manager": { - "name": "window_manager", - "path": [ - "foundation/window/window_manager" - ] - }, - "utils_lite": { - "name": "utils_lite", - "path": [ - "commonlibrary/utils_lite" - ] - }, - "c_utils": { - "name": "c_utils", - "path": [ - "commonlibrary/c_utils" - ] - }, - "ets_utils": { - "name": "ets_utils", - "path": [ - "commonlibrary/ets_utils" - ] - }, - "selinux_adapter": { - "name": "selinux_adapter", - "path": [ - "base/security/selinux_adapter" - ] - }, - "access_token": { - "name": "access_token", - "path": [ - "base/security/access_token" - ] - }, - "permission_lite": { - "name": "permission_lite", - "path": [ - "base/security/permission_lite" - ] - }, - "dlp_permission_service": { - "name": "dlp_permission_service", - "path": [ - "base/security/dlp_permission_service" - ] - }, - "dlp_credential_service": { - "name": "dlp_credential_service", - "path": [ - "base/security/dlp_credential_service" - ] - }, - "memmgr": { - "name": "memmgr", - "path": [ - "foundation/resourceschedule/memmgr_plugin" - ] - }, - "utils_memory": { - "name": "utils_memory", - "path": [ - "utils/memory" - ] - }, - "frame_aware_sched": { - "name": "frame_aware_sched", - "path": [ - "foundation/resourceschedule/frame_aware_sched" - ] - }, - "sys_installer": { - "name": "sys_installer", - "path": [ - "base/update/sys_installer" - ] - }, - "updater": { - "name": "updater", - "path": [ - "base/update/updater" - ] - }, - "dupdate_engine": { - "name": "dupdate_engine", - "path": [ - "base/update/dupdate_engine" - ] - }, - "memory_utils": { - "name": "memory_utils", - "path": [ - "commonlibrary/memory_utils" - ] - }, - "resourceschedule_ffrt_core": { - "name": "resourceschedule_ffrt_core", - "path": [ - "foundation/resourceschedule/ffrt_core" - ] - }, - "resourceschedule_ffrt_sched_override": { - "name": "resourceschedule_ffrt_sched_override", - "path": [ - "vendor/huawei/foundation/resourceschedule/ffrt_sched_override" - ] - }, - "ace_engine": { - "name": "ace_engine", - "path": [ - "foundation/arkui/ace_engine/frameworks/base/geometry", - "foundation/arkui/ace_engine/frameworks/base/json", - "foundation/arkui/ace_engine/frameworks/base/utils", - "foundation/arkui/ace_engine/frameworks/bridge/card_frontend", - "foundation/arkui/ace_engine/frameworks/bridge/common/manifest", - "foundation/arkui/ace_engine/frameworks/bridge/common/media_query", - "foundation/arkui/ace_engine/frameworks/bridge/common/plugin_adapter", - "foundation/arkui/ace_engine/frameworks/bridge/common/utils", - "foundation/arkui/ace_engine/frameworks/bridge/plugin_frontend", - "foundation/arkui/ace_engine/interfaces" - ] - }, - "ace_engine_core": { - "name": "ace_engine_core", - "path": [ - "foundation/arkui/ace_engine/frameworks/core/accessibility", - "foundation/arkui/ace_engine/frameworks/core/common", - "foundation/arkui/ace_engine/frameworks/core/components_ng", - "foundation/arkui/ace_engine/frameworks/core/pipeline_ng" - ] - }, - "container_linux_service_broker": { - "name": "container_linux_service_broker", - "path": [ - "vendor/huawei/virt_service/linux_fusion_service" - ] - }, - "container_manager": { - "name": "container_manager", - "path": [ - "vendor/huawei/virt_service/container_manager" - ] - }, - "container_comm": { - "name": "container_comm", - "path": [ - "vendor/huawei/virt_service/container_comm" - ] - } -} - - - - - - - - - - - - - - - - - - - +{ + "bundle_framework": { + "name": "bundle_framework", + "path": [ + "foundation/bundlemanager/bundle_framework" + ] + }, + "bundle_framework_lite": { + "name": "bundle_framework_lite", + "path": [ + "foundation/bundlemanager/bundle_framework_lite" + ] + }, + "packing_tool": { + "name": "packing_tool", + "path": [ + "developtools/packing_tool" + ] + }, + "appverify": { + "name": "appverify", + "path": [ + "base/security/appverify" + ] + }, + "zlib": { + "name": "zlib", + "path": [ + "third_party/zlib" + ] + }, + "ability_lite": { + "name": "ability_lite", + "path": [ + "foundation/ability/ability_lite" + ] + }, + "ability_base": { + "name": "ability_base", + "path": [ + "foundation/ability/ability_base" + ] + }, + "ability_runtime": { + "name": "ability_runtime", + "path": [ + "foundation/ability/ability_runtime" + ] + }, + "ability_tool": { + "name": "ability_tool", + "path": [ + "foundation/ability/ability_runtime/tools" + ] + }, + "idl_tool": { + "name": "idl_tool", + "path": [ + "foundation/ability/idl_tool" + ] + }, + "form_fwk": { + "name": "form_fwk", + "path": [ + "foundation/ability/form_fwk" + ] + }, + "window_manager_lite": { + "name": "window_manager_lite", + "path": [ + "foundation/window/window_manager_lite" + ] + }, + "ui_lite": { + "name": "ui_lite", + "path": [ + "foundation/arkui/ui_lite" + ] + }, + "graphic_utils_lite": { + "name": "graphic_utils_lite", + "path": [ + "foundation/graphic/graphic_utils_lite" + ] + }, + "graphic_2d": { + "name": "graphic_2d", + "path": [ + "foundation/graphic/graphic_2d" + ] + }, + "image_framework": { + "name": "image_framework", + "path": [ + "foundation/multimedia/image_framework" + ] + }, + "background_task_mgr": { + "name": "background_task_mgr", + "path": [ + "foundation/resourceschedule/background_task_mgr" + ] + }, + "work_scheduler": { + "name": "work_scheduler", + "path": [ + "foundation/resourceschedule/work_scheduler" + ] + }, + "device_usage_statistics": { + "name": "device_usage_statistics", + "path": [ + "foundation/resourceschedule/device_usage_statistics" + ] + }, + "resource_schedule_service": { + "name": "resource_schedule_service", + "path": [ + "foundation/resourceschedule/resource_schedule_service" + ] + }, + "schedule_ext": { + "name": "schedule_ext", + "path": [ + "foundation/resourceschedule/resource_schedule_service/schedule_ext" + ] + }, + "efficiency_manager": { + "name": "efficiency_manager", + "path": [ + "foundation/resourceschedule/efficiency_manager" + ] + }, + "efficiency_manager_ext": { + "name": "efficiency_manager_ext", + "path": [ + "foundation/resourceschedule/efficiency_manager_ext" + ] + }, + "preferences": { + "name": "preferences", + "path": [ + "foundation/distributeddatamgr/preferences" + ] + }, + "relational_store": { + "name": "relational_store", + "path": [ + "foundation/distributeddatamgr/relational_store" + ] + }, + "data_share": { + "name": "data_share", + "path": [ + "foundation/distributeddatamgr/data_share" + ] + }, + "kv_store": { + "name": "kv_store", + "path": [ + "foundation/distributeddatamgr/kv_store" + ] + }, + "datamgr_service": { + "name": "datamgr_service", + "path": [ + "foundation/distributeddatamgr/distributeddatamgr" + ] + }, + "data_object": { + "name": "data_object", + "path": [ + "foundation/distributeddatamgr/data_object" + ] + }, + "pasteboard": { + "name": "pasteboard", + "path": [ + "foundation/distributeddatamgr/pasteboard" + ] + }, + "ipc": { + "name": "ipc", + "path": [ + "foundation/communication/ipc" + ] + }, + "dsoftbus_standard": { + "name": "dsoftbus_standard", + "path": [ + "foundation/communication/dsoftbus" + ] + }, + "device_manager": { + "name": "device_manager", + "path": [ + "foundation/distributedhardware/device_manager" + ] + }, + "distributed_hardware_fwk": { + "name": "distributed_hardware_fwk", + "path": [ + "foundation/distributedhardware/distributed_hardware_fwk" + ] + }, + "distributed_camera": { + "name": "distributed_camera", + "path": [ + "foundation/distributedhardware/distributed_camera" + ] + }, + "distributed_audio": { + "name": "distributed_audio", + "path": [ + "foundation/distributedhardware/distributed_audio" + ] + }, + "distributed_screen": { + "name": "distributed_screen", + "path": [ + "foundation/distributedhardware/distributed_screen" + ] + }, + "distributed_input": { + "name": "distributed_input", + "path": [ + "foundation/distributedhardware/distributed_input" + ] + }, + "input": { + "name": "input", + "path": [ + "foundation/multimodalinput/input" + ] + }, + "audio_framework": { + "name": "audio_framework", + "path": [ + "foundation/multimedia/audio_framework" + ] + }, + "audio_manager_lite": { + "name": "audio_manager_lite", + "path": [ + "foundation/multimedia/audio_lite" + ] + }, + "camera_lite": { + "name": "camera_lite", + "path": [ + "foundation/multimedia/camera_lite" + ] + }, + "camera_framework": { + "name": "camera_framework", + "path": [ + "foundation/multimedia/camera_standard" + ] + }, + "media_lite": { + "name": "media_lite", + "path": [ + "foundation/multimedia/media_lite" + ] + }, + "multimedia_av_session": { + "name": "multimedia_av_session", + "path": [ + "foundation/multimedia/av_session" + ] + }, + "utils": { + "name": "utils", + "path": [ + "foundation/multimedia/utils" + ] + }, + "omx_adapter": { + "name": "omx_adapter", + "path": [ + "foundation/multimedia/omx_adapter" + ] + }, + "histreamer": { + "name": "histreamer", + "path": [ + "foundation/multimedia/histreamer" + ] + }, + "player_framework": { + "name": "player_framework", + "path": [ + "foundation/multimedia/player_framework" + ] + }, + "neural_network_runtime": { + "name": "neural_network_runtime", + "path": [ + "foundation/ai/neural_network_runtime" + ] + }, + "ai_engine": { + "name": "ai_engine", + "path": [ + "foundation/ai/ai_engine" + ] + }, + "decision": { + "name": "decision", + "path": [ + "foundation/ai/decision" + ] + }, + "mindspore": { + "name": "mindspore", + "path": [ + "third_party/mindspore" + ] + }, + "core_service": { + "name": "core_service", + "path": [ + "base/telephony/core_service" + ] + }, + "call_manager": { + "name": "call_manager", + "path": [ + "base/telephony/call_manager" + ] + }, + "data_storage": { + "name": "data_storage", + "path": [ + "base/telephony/data_storage" + ] + }, + "sms_mms": { + "name": "sms_mms", + "path": [ + "base/telephony/sms_mms" + ] + }, + "cellular_call": { + "name": "cellular_call", + "path": [ + "base/telephony/cellular_call" + ] + }, + "cellular_data": { + "name": "cellular_data", + "path": [ + "base/telephony/cellular_data" + ] + }, + "state_registry": { + "name": "state_registry", + "path": [ + "base/telephony/state_registry" + ] + }, + "ril_adapter": { + "name": "ril_adapter", + "path": [ + "base/telephony/ril_adapter" + ] + }, + "ims_service": { + "name": "ims_service", + "path": [ + "vendor/huawei/base/telephony/ims_service" + ] + }, + "ril_adapter_ext": { + "name": "ril_adapter_ext", + "path": [ + "vendor/huawei/base/telephony/ril_adapter_ext" + ] + }, + "certificate_manager": { + "name": "certificate_manager", + "path": [ + "base/security/certificate_manager" + ] + }, + "crypto_framework": { + "name": "crypto_framework", + "path": [ + "base/security/crypto_framework" + ] + }, + "dataclassification": { + "name": "dataclassification", + "path": [ + "base/security/dataclassification" + ] + }, + "device_auth": { + "name": "device_auth", + "path": [ + "base/security/device_auth" + ] + }, + "device_security_level": { + "name": "device_security_level", + "path": [ + "base/security/device_security_level" + ] + }, + "device_threat_detection": { + "name": "device_threat_detection", + "path": [ + "base/security/device_threat_detection" + ] + }, + "hapsigner": { + "name": "hapsigner", + "path": [ + "developtools/hapsigner" + ] + }, + "huks": { + "name": "huks", + "path": [ + "base/security/huks" + ] + }, + "appspawn": { + "name": "appspawn", + "path": [ + "base/startup/appspawn" + ] + }, + "bootstrap_lite": { + "name": "bootstrap_lite", + "path": [ + "base/startup/bootstrap_lite" + ] + }, + "init": { + "name": "init", + "path": [ + "base/startup/init" + ] + }, + "notification": { + "name": "notification", + "path": [ + "base/notification/common_event_service", + "base/notification/distributed_notification_service", + "base/notification/eventhandler" + ] + }, + "hilog": { + "name": "hilog", + "path": [ + "base/hiviewdfx/hilog" + ] + }, + "hilog_lite": { + "name": "hilog_lite", + "path": [ + "base/hiviewdfx/hilog_lite" + ] + }, + "hitrace": { + "name": "hitrace", + "path": [ + "base/hiviewdfx/hitrace" + ] + }, + "hiview": { + "name": "hiview", + "path": [ + "base/hiviewdfx/hiview/adapter", + "base/hiviewdfx/hiview/build", + "base/hiviewdfx/hiview/base", + "base/hiviewdfx/hiview/core", + "base/hiviewdfx/hiview/figures", + "base/hiviewdfx/hiview/include", + "base/hiviewdfx/hiview/service", + "base/hiviewdfx/hiview/utility", + "base/hiviewdfx/hiview/test", + "base/hiviewdfx/hiview/plugins/eventlogger", + "base/hiviewdfx/hiview/plugins/eventservice", + "base/hiviewdfx/hiview/plugins/faultlogger", + "base/hiviewdfx/hiview/plugins/freeze_detector", + "base/hiviewdfx/hiview/plugins/hicollie_collector", + "base/hiviewdfx/hiview/plugins/usage_event_report", + "base/hiviewdfx/hiview/plugins/huawei_proprietary/leak_detectors", + "base/hiviewdfx/hiview/plugins/huawei_proprietary/test" + ] + }, + "hiview_lite": { + "name": "hiview_lite", + "path": [ + "base/hiviewdfx/hiview_lite" + ] + }, + "hichecker": { + "name": "hichecker", + "path": [ + "base/hiviewdfx/hichecker" + ] + }, + "hicollie": { + "name": "hicollie", + "path": [ + "base/hiviewdfx/hicollie" + ] + }, + "hiappevent": { + "name": "hiappevent", + "path": [ + "base/hiviewdfx/hiappevent" + ] + }, + "hisysevent": { + "name": "hisysevent", + "path": [ + "base/hiviewdfx/hisysevent" + ] + }, + "hievent_lite": { + "name": "hievent_lite", + "path": [ + "base/hiviewdfx/hievent_lite" + ] + }, + "faultloggerd": { + "name": "faultloggerd", + "path": [ + "base/hiviewdfx/faultloggerd" + ] + }, + "profiler": { + "name": "profiler", + "path": [ + "developtools/profiler" + ] + }, + "hiperf": { + "name": "hiperf", + "path": [ + "developtools/hiperf" + ] + }, + "bytrace": { + "name": "bytrace", + "path": [ + "developtools/bytrace" + ] + }, + "hidumper_lite": { + "name": "hidumper_lite", + "path": [ + "base/hiviewdfx/hidumper_lite" + ] + }, + "blackbox": { + "name": "blackbox", + "path": [ + "base/hiviewdfx/blackbox" + ] + }, + "hidumper": { + "name": "hidumper", + "path": [ + "base/hiviewdfx/hidumper" + ] + }, + "bluetooth": { + "name": "bluetooth", + "path": [ + "foundation/communication/bluetooth" + ] + }, + "nfc": { + "name": "nfc", + "path": [ + "foundation/communication/nfc/nfc_core" + ] + }, + "connected_tag": { + "name": "connected_tag", + "path": [ + "foundation/communication/nfc/connected_tag" + ] + }, + "wifi": { + "name": "wifi", + "path": [ + "foundation/communication/wifi/wifi" + ] + }, + "dhcp": { + "name": "dhcp", + "path": [ + "foundation/communication/wifi/dhcp" + ] + }, + "wifi_aware": { + "name": "wifi_aware", + "path": [ + "foundation/communication/wifi_aware" + ] + }, + "wifi_lite": { + "name": "wifi_lite", + "path": [ + "foundation/communication/wifi_lite" + ] + }, + "algorithm": { + "name": "algorithm", + "path": [ + "base/msdp/algorithm" + ] + }, + "geofence": { + "name": "geofence", + "path": [ + "base/msdp/geofence" + ] + }, + "motion": { + "name": "motion", + "path": [ + "base/msdp/motion" + ] + }, + "movement": { + "name": "movement", + "path": [ + "base/msdp/movement" + ] + }, + "spatial_awareness": { + "name": "spatial_awareness", + "path": [ + "base/msdp/spatial_awareness" + ] + }, + "timeline": { + "name": "timeline", + "path": [ + "base/msdp/timeline" + ] + }, + "device_status": { + "name": "device_status", + "path": [ + "base/msdp/device_status" + ] + }, + "os_account": { + "name": "os_account", + "path": [ + "base/account/os_account" + ] + }, + "i18n": { + "name": "i18n", + "path": [ + "base/global/i18n" + ] + }, + "i18n_lite": { + "name": "i18n_lite", + "path": [ + "base/global/i18n_lite" + ] + }, + "system_resources": { + "name": "system_resources", + "path": [ + "utils/system_resources" + ] + }, + "jsoncpp": { + "name": "jsoncpp", + "path": [ + "third_party/jsoncpp" + ] + }, + "libxml2": { + "name": "libxml2", + "path": [ + "third_party/libxml2" + ] + }, + "global_resource_tool": { + "name": "global_resource_tool", + "path": [ + "developtools/global_resource_tool" + ] + }, + "resource_management": { + "name": "resource_management", + "path": [ + "base/global/resource_management" + ] + }, + "resource_management_lite": { + "name": "resource_management_lite", + "path": [ + "base/global/resource_management_lite" + ] + }, + "time_zone": { + "name": "time_zone", + "path": [ + "base/global/time_zone" + ] + }, + "accessibility": { + "name": "accessibility", + "path": [ + "foundation/barrierfree/accessibility" + ] + }, + "time_service": { + "name": "time_service", + "path": [ + "base/time/time_service" + ] + }, + "imf": { + "name": "imf", + "path": [ + "base/inputmethod/imf" + ] + }, + "theme": { + "name": "theme", + "path": [ + "base/theme" + ] + }, + "request": { + "name": "request", + "path": [ + "base/request" + ] + }, + "battery_manager": { + "name": "battery_manager", + "path": [ + "base/powermgr/battery_manager" + ] + }, + "display_manager": { + "name": "display_manager", + "path": [ + "base/powermgr/display_manager" + ] + }, + "powermgr_lite": { + "name": "powermgr_lite", + "path": [ + "base/powermgr/powermgr_lite" + ] + }, + "battery_lite": { + "name": "battery_lite", + "path": [ + "base/powermgr/battery_lite" + ] + }, + "battery_statistics": { + "name": "battery_statistics", + "path": [ + "base/powermgr/battery_statistics" + ] + }, + "power_manager": { + "name": "power_manager", + "path": [ + "base/powermgr/power_manager" + ] + }, + "thermal_manager": { + "name": "thermal_manager", + "path": [ + "base/powermgr/thermal_manager" + ] + }, + "sensor": { + "name": "sensor", + "path": [ + "base/sensors/sensor" + ] + }, + "miscdevice": { + "name": "miscdevice", + "path": [ + "base/sensors/miscdevice" + ] + }, + "sensor_lite": { + "name": "sensor_lite", + "path": [ + "base/sensors/sensor_lite" + ] + }, + "miscdevice_lite": { + "name": "miscdevice_lite", + "path": [ + "base/sensors/miscdevice_lite" + ] + }, + "start": { + "name": "start", + "path": [ + "base/sensors/start" + ] + }, + "user_auth_framework": { + "name": "user_auth_framework", + "path": [ + "base/useriam/user_auth_framework" + ] + }, + "pin_auth": { + "name": "pin_auth", + "path": [ + "base/useriam/pin_auth" + ] + }, + "face_auth": { + "name": "face_auth", + "path": [ + "base/useriam/face_auth" + ] + }, + "fingerprint_auth": { + "name": "fingerprint_auth", + "path": [ + "base/useriam/fingerprint_auth" + ] + }, + "peripheral": { + "name": "peripheral", + "path": [ + "drivers/peripheral/pin_auth", + "drivers/peripheral/face_auth", + "drivers/peripheral/user_auth", + "drivers/peripheral/fingerprint_auth" + ] + }, + "location": { + "name": "location", + "path": [ + "base/location" + ] + }, + "usb_manager": { + "name": "usb_manager", + "path": [ + "base/usb/usb_manager" + ] + }, + "build": { + "name": "build", + "path": [ + "build" + ] + }, + "gn": { + "name": "gn", + "path": [ + "third_party/gn" + ] + }, + "ninja": { + "name": "ninja", + "path": [ + "third_party/ninja" + ] + }, + "hidl_adapter": { + "name": "hidl_adapter", + "path": [ + "drivers/peripheral/adapter/activity_recognition", + "drivers/peripheral/adapter/audio", + "drivers/peripheral/adapter/camera", + "drivers/peripheral/adapter/gralloc", + "drivers/peripheral/adapter/hwc", + "drivers/peripheral/adapter/input", + "drivers/peripheral/adapter/motion", + "drivers/peripheral/adapter/sensor", + "drivers/peripheral/adapter/thermal" + ] + }, + "hdf_core": { + "name": "hdf_core", + "path": [ + "drivers/hdf_core/adapter/uhdf2", + "drivers/hdf_core/framework/core/common", + "drivers/hdf_core/framework/core/host", + "drivers/hdf_core/framework/core/manager", + "drivers/hdf_core/framework/core/shared", + "drivers/hdf_core/framework/support/posix/" + ] + }, + "filemanagement_app_file_service": { + "name": "filemanagement_app_file_service", + "path": [ + "foundation/filemanagement/app_file_service" + ] + }, + "filemanagement_backup": { + "name": "filemanagement_backup", + "path": [ + "foundation/filemanagement/backup" + ] + }, + "filemanagement_dfs_service": { + "name": "filemanagement_dfs_service", + "path": [ + "foundation/filemanagement/dfs_service" + ] + }, + "filemanagement_file_api": { + "name": "filemanagement_file_api", + "path": [ + "foundation/filemanagement/file_api" + ] + }, + "filemanagement_storage_service": { + "name": "filemanagement_storage_service", + "path": [ + "foundation/filemanagement/storage_service" + ] + }, + "filemanagement_user_file_service": { + "name": "filemanagement_user_file_service", + "path": [ + "foundation/filemanagement/user_file_service" + ] + }, + "media_library": { + "name": "media_library", + "path": [ + "foundation/multimedia/media_library" + ] + }, + "netmanager_base": { + "name": "netmanager_base", + "path": [ + "foundation/communication/netmanager_base" + ] + }, + "netmanager_ext": { + "name": "netmanager_ext", + "path": [ + "foundation/communication/netmanager_ext" + ] + }, + "netstack": { + "name": "netstack", + "path": [ + "foundation/communication/netstack" + ] + }, + "webview": { + "name": "webview", + "path": [ + "base/web/webview/ohos_adapter", + "base/web/webview/ohos_nweb" + ] + }, + "tee_client": { + "name": "tee_client", + "path": [ + "base/tee/tee_client" + ] + }, + "tee_os_framework": { + "name": "tee_os_framework", + "path": [ + "base/tee/tee_os_framework" + ] + }, + "tee_dev_kit": { + "name": "tee_dev_kit", + "path": [ + "base/tee/tee_dev_kit" + ] + }, + "tee_tzdriver": { + "name": "tee_tzdriver", + "path": [ + "base/tee/tee_tzdriver" + ] + }, + "tee_os_kernel": { + "name": "tee_os_kernel", + "path": [ + "base/tee/tee_os_kernel" + ] + }, + "device_info_manager": { + "name": "device_info_manager", + "path": [ + "foundation/deviceprofile" + ] + }, + "enterprise_device_management": { + "name": "enterprise_device_management", + "path": [ + "base/customization/enterprise_device_management" + ] + }, + "config_policy": { + "name": "config_policy", + "path": [ + "base/customization/config_policy" + ] + }, + "toolchain": { + "name": "toolchain", + "path": [ + "arkcompiler/toolchain" + ] + }, + "runtime_core": { + "name": "runtime_core", + "path": [ + "arkcompiler/runtime_core" + ] + }, + "ets_frontend": { + "name": "ets_frontend", + "path": [ + "arkcompiler/ets_frontend" + ] + }, + "ets_runtime": { + "name": "ets_runtime", + "path": [ + "arkcompiler/ets_runtime" + ] + }, + "jerryscript": { + "name": "jerryscript", + "path": [ + "third_party/jerryscript" + ] + }, + "safwk": { + "name": "safwk", + "path": [ + "foundation/systemabilitymgr/safwk" + ] + }, + "safwk_lite": { + "name": "safwk_lite", + "path": [ + "foundation/systemabilitymgr/safwk_lite" + ] + }, + "samgr_lite": { + "name": "samgr_lite", + "path": [ + "foundation/systemabilitymgr/samgr_lite" + ] + }, + "samgr": { + "name": "samgr", + "path": [ + "foundation/systemabilitymgr/samgr" + ] + }, + "dmsfwk": { + "name": "dmsfwk", + "path": [ + "foundation/ability/dmsfwk" + ] + }, + "dmsfwk_lite": { + "name": "dmsfwk_lite", + "path": [ + "foundation/ability/dmsfwk_lite" + ] + }, + "window_manager": { + "name": "window_manager", + "path": [ + "foundation/window/window_manager" + ] + }, + "utils_lite": { + "name": "utils_lite", + "path": [ + "commonlibrary/utils_lite" + ] + }, + "c_utils": { + "name": "c_utils", + "path": [ + "commonlibrary/c_utils" + ] + }, + "ets_utils": { + "name": "ets_utils", + "path": [ + "commonlibrary/ets_utils" + ] + }, + "selinux_adapter": { + "name": "selinux_adapter", + "path": [ + "base/security/selinux_adapter" + ] + }, + "access_token": { + "name": "access_token", + "path": [ + "base/security/access_token" + ] + }, + "permission_lite": { + "name": "permission_lite", + "path": [ + "base/security/permission_lite" + ] + }, + "dlp_permission_service": { + "name": "dlp_permission_service", + "path": [ + "base/security/dlp_permission_service" + ] + }, + "dlp_credential_service": { + "name": "dlp_credential_service", + "path": [ + "base/security/dlp_credential_service" + ] + }, + "memmgr": { + "name": "memmgr", + "path": [ + "foundation/resourceschedule/memmgr_plugin" + ] + }, + "utils_memory": { + "name": "utils_memory", + "path": [ + "utils/memory" + ] + }, + "frame_aware_sched": { + "name": "frame_aware_sched", + "path": [ + "foundation/resourceschedule/frame_aware_sched" + ] + }, + "sys_installer": { + "name": "sys_installer", + "path": [ + "base/update/sys_installer" + ] + }, + "updater": { + "name": "updater", + "path": [ + "base/update/updater" + ] + }, + "dupdate_engine": { + "name": "dupdate_engine", + "path": [ + "base/update/dupdate_engine" + ] + }, + "memory_utils": { + "name": "memory_utils", + "path": [ + "commonlibrary/memory_utils" + ] + }, + "resourceschedule_ffrt_core": { + "name": "resourceschedule_ffrt_core", + "path": [ + "foundation/resourceschedule/ffrt_core" + ] + }, + "resourceschedule_ffrt_sched_override": { + "name": "resourceschedule_ffrt_sched_override", + "path": [ + "vendor/huawei/foundation/resourceschedule/ffrt_sched_override" + ] + }, + "ace_engine": { + "name": "ace_engine", + "path": [ + "foundation/arkui/ace_engine/frameworks/base/geometry", + "foundation/arkui/ace_engine/frameworks/base/json", + "foundation/arkui/ace_engine/frameworks/base/utils", + "foundation/arkui/ace_engine/frameworks/bridge/card_frontend", + "foundation/arkui/ace_engine/frameworks/bridge/common/manifest", + "foundation/arkui/ace_engine/frameworks/bridge/common/media_query", + "foundation/arkui/ace_engine/frameworks/bridge/common/plugin_adapter", + "foundation/arkui/ace_engine/frameworks/bridge/common/utils", + "foundation/arkui/ace_engine/frameworks/bridge/plugin_frontend", + "foundation/arkui/ace_engine/interfaces" + ] + }, + "ace_engine_core": { + "name": "ace_engine_core", + "path": [ + "foundation/arkui/ace_engine/frameworks/core/accessibility", + "foundation/arkui/ace_engine/frameworks/core/common", + "foundation/arkui/ace_engine/frameworks/core/components_ng", + "foundation/arkui/ace_engine/frameworks/core/pipeline_ng" + ] + }, + "container_linux_service_broker": { + "name": "container_linux_service_broker", + "path": [ + "vendor/huawei/virt_service/linux_fusion_service" + ] + }, + "container_manager": { + "name": "container_manager", + "path": [ + "vendor/huawei/virt_service/container_manager" + ] + }, + "container_comm": { + "name": "container_comm", + "path": [ + "vendor/huawei/virt_service/container_comm" + ] + } +} + + + + + + + + + + + + + + + + + + + diff --git a/localCoverage/codeCoverage/__init__.py b/local_coverage/code_coverage/__init__.py similarity index 100% rename from localCoverage/codeCoverage/__init__.py rename to local_coverage/code_coverage/__init__.py diff --git a/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py b/local_coverage/code_coverage/code_coverage_gcov_lcov.py similarity index 94% rename from localCoverage/codeCoverage/codeCoverage_gcov_lcov.py rename to local_coverage/code_coverage/code_coverage_gcov_lcov.py index ae82dbb..4ec40f9 100644 --- a/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py +++ b/local_coverage/code_coverage/code_coverage_gcov_lcov.py @@ -1,299 +1,299 @@ -#!/usr/bin/env python3 -# coding=utf-8 - -# -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -import os -import json -import shutil -import shlex -import subprocess -import sys -import stat - -FLAGS = os.O_WRONLY | os.O_APPEND | os.O_CREAT -MODES = stat.S_IWUSR | stat.S_IRUSR - -# 子系统json目录 -SYSTEM_JSON = "build/subsystem_config.json" -# 覆盖率gcda -COVERAGE_GCDA_RESULTS = "test/localCoverage/codeCoverage/results/coverage/data/cxx" -# 报告路径 -REPORT_PATH = "test/localCoverage/codeCoverage/results/coverage/reports/cxx" -# llvm-gcov.sh -LLVM_GCOV = "test/localCoverage/codeCoverage/llvm-gcov.sh" - - -def _init_sys_config(): - sys.localcoverage_path = os.path.join(current_path, "..") - sys.path.insert(0, sys.localcoverage_path) - - -def call(cmd_list, is_show_cmd=False, out=None, err=None): - return_flag = False - try: - if is_show_cmd: - print("execute command: {}".format(" ".join(cmd_list))) - if 0 == subprocess.call(cmd_list, shell=False, stdout=out, stderr=err): - return_flag = True - except Exception: - print("Error : command {} execute faild!".format(cmd_list)) - return_flag = False - return return_flag - - -def execute_command(command, printflag=False): - try: - cmd_list = shlex.split(command) - coverage_log_path = os.path.join( - CODEPATH, "test/testfwk/developer_test/localCoverage", "coverage.log") - with os.fdopen(os.open(coverage_log_path, FLAGS, MODES), 'a') as fd: - call(cmd_list, printflag, fd, fd) - except IOError: - print("Error: Exception occur in open err") - - -def get_subsystem_config_info(): - subsystem_info_dic = {} - subsystem_config_filepath = os.path.join(CODEPATH, SYSTEM_JSON) - if os.path.exists(subsystem_config_filepath): - data = None - with open(subsystem_config_filepath, 'r') as f: - data = json.load(f) - if not data: - print("subsystem config file error.") - for value in data.values(): - subsystem_name = value.get('name') - subsystem_dir = value.get('dir') - subsystem_path = value.get('path') - subsystem_project = value.get('project') - subsystem_rootpath = os.path.join(CODEPATH, subsystem_path) - subsystem_info_dic[subsystem_name] = [ - subsystem_project, subsystem_dir, - subsystem_path, subsystem_rootpath - ] - return subsystem_info_dic - - -def get_subsystem_name_list(): - subsystem_name_list = [] - subsystem_info_dic = get_subsystem_config_info() - for key in subsystem_info_dic.keys(): - subsystem_rootpath = subsystem_info_dic[key][3] - if os.path.exists(subsystem_rootpath): - subsystem_name_list.append(key) - return subsystem_name_list - - -def get_subsystem_rootpath(subsystem_name): - subsystem_path = "" - subsystem_rootpath = "" - subsystem_info_dic = get_subsystem_config_info() - for key in subsystem_info_dic.keys(): - if key == subsystem_name: - subsystem_path = subsystem_info_dic[key][2] - subsystem_rootpath = subsystem_info_dic[key][3] - break - return subsystem_path, subsystem_rootpath - - -def is_filterout_dir(ignore_prefix, check_path): - # 屏蔽列表 - filter_out_list = ["unittest", "third_party", "test"] - for item in filter_out_list: - check_list = check_path[len(ignore_prefix):].split("/") - if item in check_list: - return True - return False - - -def rm_unnecessary_dir(cov_path): - topdir = os.path.join(cov_path, "obj") - for root, dirs, files in os.walk(topdir): - if is_filterout_dir(topdir, root): - shutil.rmtree(root) - - -def get_files_from_dir(find_path, postfix=None): - names = os.listdir(find_path) - file_list = [] - for fn in names: - if not os.path.isfile(os.path.join(find_path, fn)): - continue - if postfix is not None: - if fn.endswith(postfix): - file_list.append(fn) - else: - file_list.append(fn) - return file_list - - -def get_gcno_files(cov_path, dir_name): - gcda_strip_path = dir_name[len(cov_path) + 1:] - gcda_list = get_files_from_dir(dir_name, ".gcda") - for file_name in gcda_list: - gcno_name = f"{os.path.splitext(file_name)[0]}.gcno" - gcno_path = os.path.join( - os.path.join(CODEPATH, OUTPUT), gcda_strip_path, gcno_name) - if os.path.exists(gcno_path): - if os.path.exists(gcno_path): - shutil.copy(gcno_path, dir_name) - else: - print("%s not exists!", gcno_path) - - -def get_module_gcno_files(cov_path, dir_name): - for root, dirs, files in os.walk(dir_name): - get_gcno_files(cov_path, root) - - -def gen_subsystem_trace_info(subsystem, data_dir, test_dir): - src_dir = os.path.join(CODEPATH, OUTPUT) - single_info_path = os.path.join( - CODEPATH, REPORT_PATH, "single_test", test_dir) - if not os.path.exists(single_info_path): - os.makedirs(single_info_path) - output_name = os.path.join( - CODEPATH, single_info_path, f"{subsystem}_output.info") - if not os.path.exists(src_dir): - print("Sours path %s not exist!", src_dir) - return - cmd = "lcov -c -b {} -d {} --gcov-tool {} -o {} --ignore-errors source,gcov".format( - src_dir, data_dir, os.path.join(CODEPATH, LLVM_GCOV), output_name) - print(f"single_test**{cmd}") - execute_command(cmd) - - -def cut_info(subsystem, test_dir): - trace_file = os.path.join( - CODEPATH, REPORT_PATH, "single_test", - test_dir, f"{subsystem}_output.info") - output_name = os.path.join( - CODEPATH, REPORT_PATH, "single_test", - test_dir, f"{subsystem}_strip.info") - remove = r"'*/unittest/*' '*/third_party/*' 'sdk/android-arm64/*'" - if not os.path.exists(trace_file): - print("Error: trace file %s not exisit!", trace_file) - return - cmd = "lcov --remove {} {} -o {}".format(trace_file, remove, output_name) - execute_command(cmd) - - -def gen_info(cov_path, test_dir, subsystem_list): - if len(subsystem_list) == 0: - return - for subsystem in subsystem_list: - (subsystem_path, subsystem_rootpath) = get_subsystem_rootpath(subsystem) - subsystem_data_abspath = os.path.join(cov_path, "obj", subsystem_path) - if not os.path.exists(subsystem_data_abspath): - continue - get_module_gcno_files(cov_path, subsystem_data_abspath) - gen_subsystem_trace_info(subsystem, subsystem_data_abspath, test_dir) - cut_info(subsystem, test_dir) - - -def gen_all_test_info(subsystem_list): - cov_path = os.path.join(CODEPATH, COVERAGE_GCDA_RESULTS) - single_test_dir_list = [] - for root, dirs, files in os.walk(cov_path): - single_test_dir_list = dirs - break - for index, cur_test_dir in enumerate(single_test_dir_list): - cur_test_abs_dir = os.path.join(cov_path, cur_test_dir) - rm_unnecessary_dir(cur_test_abs_dir) - gen_info(cur_test_abs_dir, cur_test_dir, subsystem_list) - - -def merge_subsystem_info_from_all_test(subsystem): - single_test_info_path = os.path.join(CODEPATH, REPORT_PATH, "single_test") - subsystem_info_list = [] - subsystem_info_name = f"{subsystem}_strip.info" - for root, dirs, files in os.walk(single_test_info_path): - if subsystem_info_name in files: - subsystem_info_path_tmp = os.path.join( - single_test_info_path, root, subsystem_info_name) - subsystem_info_list.append(subsystem_info_path_tmp) - if len(subsystem_info_list) == 0: - return - info_output_name = os.path.join( - CODEPATH, REPORT_PATH, subsystem_info_name) - cmd = "lcov -a {} -o {}".format( - " -a ".join(subsystem_info_list), info_output_name) - execute_command(cmd) - - -def merge_all_test_subsystem_info(subsystem_list): - single_test_info_path = os.path.join( - CODEPATH, REPORT_PATH, "single_test") - if not os.path.exists(single_test_info_path): - print("Error: the single test info path %s not exist", - single_test_info_path) - return - for subsystem in subsystem_list: - print("Merging all %s info from test data......", subsystem) - merge_subsystem_info_from_all_test(subsystem) - - -def merge_info(report_dir): - if not os.path.exists(report_dir): - print("Error: report dir %s not exist", report_dir) - return - subsystem_name_list = get_files_from_dir(report_dir, "_strip.info") - if len(subsystem_name_list) == 0: - print("Error: get subsytem trace files in \report directory failed.") - return - trace_file_list = [] - for subsystem in subsystem_name_list: - trace_file_name = os.path.join(report_dir, subsystem) - trace_file_list.append(trace_file_name) - cmd = "lcov -a {} -o {}".format( - " -a ".join(trace_file_list), os.path.join(report_dir, "ohos_codeCoverage.info")) - execute_command(cmd) - - -def merge_all_subsystem_info(): - print("Merging all the sysbsystem trace files......") - merge_info(os.path.join(CODEPATH, REPORT_PATH)) - - -def gen_html(cov_path): - tracefile = os.path.join(CODEPATH, REPORT_PATH, "ohos_codeCoverage.info") - if not os.path.exists(tracefile): - print("Error: the trace file %s not exist", tracefile) - return - cmd = "genhtml --branch-coverage --demangle-cpp -o {} -p {} --ignore-errors source {}".format( - os.path.join(CODEPATH, REPORT_PATH, "html"), CODEPATH, tracefile) - execute_command(cmd) - - -def gen_final_report(cov_path): - print("Generating the html report......") - gen_html(cov_path) - - -if __name__ == "__main__": - current_path = os.path.abspath(os.path.dirname(__name__)) - CODEPATH = current_path.split("/test/testfwk/developer_test")[0] - _init_sys_config() - from localCoverage.utils import get_product_name - # 编译生成的out路径 - OUTPUT = "out/{}".format(get_product_name(CODEPATH)) - - gen_all_test_info(subsystem_list=get_subsystem_name_list()) - merge_all_test_subsystem_info(subsystem_list=get_subsystem_name_list()) - merge_all_subsystem_info() - gen_final_report(os.path.join(CODEPATH, COVERAGE_GCDA_RESULTS)) +#!/usr/bin/env python3 +# coding=utf-8 + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +import os +import json +import shutil +import shlex +import subprocess +import sys +import stat + +FLAGS = os.O_WRONLY | os.O_APPEND | os.O_CREAT +MODES = stat.S_IWUSR | stat.S_IRUSR + +# 子系统json目录 +SYSTEM_JSON = "build/subsystem_config.json" +# 覆盖率gcda +COVERAGE_GCDA_RESULTS = "test/local_coverage/code_coverage/results/coverage/data/cxx" +# 报告路径 +REPORT_PATH = "test/local_coverage/code_coverage/results/coverage/reports/cxx" +# llvm-gcov.sh +LLVM_GCOV = "test/local_coverage/code_coverage/llvm-gcov.sh" + + +def _init_sys_config(): + sys.localcoverage_path = os.path.join(current_path, "..") + sys.path.insert(0, sys.localcoverage_path) + + +def call(cmd_list, is_show_cmd=False, out=None, err=None): + return_flag = False + try: + if is_show_cmd: + print("execute command: {}".format(" ".join(cmd_list))) + if 0 == subprocess.call(cmd_list, shell=False, stdout=out, stderr=err): + return_flag = True + except Exception: + print("Error : command {} execute faild!".format(cmd_list)) + return_flag = False + return return_flag + + +def execute_command(command, printflag=False): + try: + cmd_list = shlex.split(command) + coverage_log_path = os.path.join( + CODEPATH, "test/testfwk/developer_test/local_coverage", "coverage.log") + with os.fdopen(os.open(coverage_log_path, FLAGS, MODES), 'a') as fd: + call(cmd_list, printflag, fd, fd) + except IOError: + print("Error: Exception occur in open err") + + +def get_subsystem_config_info(): + subsystem_info_dic = {} + subsystem_config_filepath = os.path.join(CODEPATH, SYSTEM_JSON) + if os.path.exists(subsystem_config_filepath): + data = None + with open(subsystem_config_filepath, 'r') as f: + data = json.load(f) + if not data: + print("subsystem config file error.") + for value in data.values(): + subsystem_name = value.get('name') + subsystem_dir = value.get('dir') + subsystem_path = value.get('path') + subsystem_project = value.get('project') + subsystem_rootpath = os.path.join(CODEPATH, subsystem_path) + subsystem_info_dic[subsystem_name] = [ + subsystem_project, subsystem_dir, + subsystem_path, subsystem_rootpath + ] + return subsystem_info_dic + + +def get_subsystem_name_list(): + subsystem_name_list = [] + subsystem_info_dic = get_subsystem_config_info() + for key in subsystem_info_dic.keys(): + subsystem_rootpath = subsystem_info_dic[key][3] + if os.path.exists(subsystem_rootpath): + subsystem_name_list.append(key) + return subsystem_name_list + + +def get_subsystem_rootpath(subsystem_name): + subsystem_path = "" + subsystem_rootpath = "" + subsystem_info_dic = get_subsystem_config_info() + for key in subsystem_info_dic.keys(): + if key == subsystem_name: + subsystem_path = subsystem_info_dic[key][2] + subsystem_rootpath = subsystem_info_dic[key][3] + break + return subsystem_path, subsystem_rootpath + + +def is_filterout_dir(ignore_prefix, check_path): + # 屏蔽列表 + filter_out_list = ["unittest", "third_party", "test"] + for item in filter_out_list: + check_list = check_path[len(ignore_prefix):].split("/") + if item in check_list: + return True + return False + + +def rm_unnecessary_dir(cov_path): + topdir = os.path.join(cov_path, "obj") + for root, dirs, files in os.walk(topdir): + if is_filterout_dir(topdir, root): + shutil.rmtree(root) + + +def get_files_from_dir(find_path, postfix=None): + names = os.listdir(find_path) + file_list = [] + for fn in names: + if not os.path.isfile(os.path.join(find_path, fn)): + continue + if postfix is not None: + if fn.endswith(postfix): + file_list.append(fn) + else: + file_list.append(fn) + return file_list + + +def get_gcno_files(cov_path, dir_name): + gcda_strip_path = dir_name[len(cov_path) + 1:] + gcda_list = get_files_from_dir(dir_name, ".gcda") + for file_name in gcda_list: + gcno_name = f"{os.path.splitext(file_name)[0]}.gcno" + gcno_path = os.path.join( + os.path.join(CODEPATH, OUTPUT), gcda_strip_path, gcno_name) + if os.path.exists(gcno_path): + if os.path.exists(gcno_path): + shutil.copy(gcno_path, dir_name) + else: + print("%s not exists!", gcno_path) + + +def get_module_gcno_files(cov_path, dir_name): + for root, dirs, files in os.walk(dir_name): + get_gcno_files(cov_path, root) + + +def gen_subsystem_trace_info(subsystem, data_dir, test_dir): + src_dir = os.path.join(CODEPATH, OUTPUT) + single_info_path = os.path.join( + CODEPATH, REPORT_PATH, "single_test", test_dir) + if not os.path.exists(single_info_path): + os.makedirs(single_info_path) + output_name = os.path.join( + CODEPATH, single_info_path, f"{subsystem}_output.info") + if not os.path.exists(src_dir): + print("Sours path %s not exist!", src_dir) + return + cmd = "lcov -c -b {} -d {} --gcov-tool {} -o {} --ignore-errors source,gcov".format( + src_dir, data_dir, os.path.join(CODEPATH, LLVM_GCOV), output_name) + print(f"single_test**{cmd}") + execute_command(cmd) + + +def cut_info(subsystem, test_dir): + trace_file = os.path.join( + CODEPATH, REPORT_PATH, "single_test", + test_dir, f"{subsystem}_output.info") + output_name = os.path.join( + CODEPATH, REPORT_PATH, "single_test", + test_dir, f"{subsystem}_strip.info") + remove = r"'*/unittest/*' '*/third_party/*' 'sdk/android-arm64/*'" + if not os.path.exists(trace_file): + print("Error: trace file %s not exisit!", trace_file) + return + cmd = "lcov --remove {} {} -o {}".format(trace_file, remove, output_name) + execute_command(cmd) + + +def gen_info(cov_path, test_dir, subsystem_list): + if len(subsystem_list) == 0: + return + for subsystem in subsystem_list: + (subsystem_path, subsystem_rootpath) = get_subsystem_rootpath(subsystem) + subsystem_data_abspath = os.path.join(cov_path, "obj", subsystem_path) + if not os.path.exists(subsystem_data_abspath): + continue + get_module_gcno_files(cov_path, subsystem_data_abspath) + gen_subsystem_trace_info(subsystem, subsystem_data_abspath, test_dir) + cut_info(subsystem, test_dir) + + +def gen_all_test_info(subsystem_list): + cov_path = os.path.join(CODEPATH, COVERAGE_GCDA_RESULTS) + single_test_dir_list = [] + for root, dirs, files in os.walk(cov_path): + single_test_dir_list = dirs + break + for index, cur_test_dir in enumerate(single_test_dir_list): + cur_test_abs_dir = os.path.join(cov_path, cur_test_dir) + rm_unnecessary_dir(cur_test_abs_dir) + gen_info(cur_test_abs_dir, cur_test_dir, subsystem_list) + + +def merge_subsystem_info_from_all_test(subsystem): + single_test_info_path = os.path.join(CODEPATH, REPORT_PATH, "single_test") + subsystem_info_list = [] + subsystem_info_name = f"{subsystem}_strip.info" + for root, dirs, files in os.walk(single_test_info_path): + if subsystem_info_name in files: + subsystem_info_path_tmp = os.path.join( + single_test_info_path, root, subsystem_info_name) + subsystem_info_list.append(subsystem_info_path_tmp) + if len(subsystem_info_list) == 0: + return + info_output_name = os.path.join( + CODEPATH, REPORT_PATH, subsystem_info_name) + cmd = "lcov -a {} -o {}".format( + " -a ".join(subsystem_info_list), info_output_name) + execute_command(cmd) + + +def merge_all_test_subsystem_info(subsystem_list): + single_test_info_path = os.path.join( + CODEPATH, REPORT_PATH, "single_test") + if not os.path.exists(single_test_info_path): + print("Error: the single test info path %s not exist", + single_test_info_path) + return + for subsystem in subsystem_list: + print("Merging all %s info from test data......", subsystem) + merge_subsystem_info_from_all_test(subsystem) + + +def merge_info(report_dir): + if not os.path.exists(report_dir): + print("Error: report dir %s not exist", report_dir) + return + subsystem_name_list = get_files_from_dir(report_dir, "_strip.info") + if len(subsystem_name_list) == 0: + print("Error: get subsytem trace files in \report directory failed.") + return + trace_file_list = [] + for subsystem in subsystem_name_list: + trace_file_name = os.path.join(report_dir, subsystem) + trace_file_list.append(trace_file_name) + cmd = "lcov -a {} -o {}".format( + " -a ".join(trace_file_list), os.path.join(report_dir, "ohos_codeCoverage.info")) + execute_command(cmd) + + +def merge_all_subsystem_info(): + print("Merging all the sysbsystem trace files......") + merge_info(os.path.join(CODEPATH, REPORT_PATH)) + + +def gen_html(cov_path): + tracefile = os.path.join(CODEPATH, REPORT_PATH, "ohos_codeCoverage.info") + if not os.path.exists(tracefile): + print("Error: the trace file %s not exist", tracefile) + return + cmd = "genhtml --branch-coverage --demangle-cpp -o {} -p {} --ignore-errors source {}".format( + os.path.join(CODEPATH, REPORT_PATH, "html"), CODEPATH, tracefile) + execute_command(cmd) + + +def gen_final_report(cov_path): + print("Generating the html report......") + gen_html(cov_path) + + +if __name__ == "__main__": + current_path = os.path.abspath(os.path.dirname(__name__)) + CODEPATH = current_path.split("/test/testfwk/developer_test")[0] + _init_sys_config() + from local_coverage.utils import get_product_name + # 编译生成的out路径 + OUTPUT = "out/{}".format(get_product_name(CODEPATH)) + + gen_all_test_info(subsystem_list=get_subsystem_name_list()) + merge_all_test_subsystem_info(subsystem_list=get_subsystem_name_list()) + merge_all_subsystem_info() + gen_final_report(os.path.join(CODEPATH, COVERAGE_GCDA_RESULTS)) diff --git a/localCoverage/codeCoverage/coverage_rc/lcovrc_cov_template b/local_coverage/code_coverage/coverage_rc/lcovrc_cov_template similarity index 100% rename from localCoverage/codeCoverage/coverage_rc/lcovrc_cov_template rename to local_coverage/code_coverage/coverage_rc/lcovrc_cov_template diff --git a/localCoverage/codeCoverage/llvm-gcov.sh b/local_coverage/code_coverage/llvm-gcov.sh similarity index 90% rename from localCoverage/codeCoverage/llvm-gcov.sh rename to local_coverage/code_coverage/llvm-gcov.sh index 21b2409..23d7c50 100644 --- a/localCoverage/codeCoverage/llvm-gcov.sh +++ b/local_coverage/code_coverage/llvm-gcov.sh @@ -16,5 +16,5 @@ # This file is autogenerated by c_coverage_mgr.py, do not edit manually . current_path=$(cd $(dirname $0);pwd) -root_path=${current_path%%/test/testfwk/developer_test/localCoverage/codeCoverage} +root_path=${current_path%%/test/testfwk/developer_test/local_coverage/code_coverage} exec $root_path/prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-cov gcov "$@" diff --git a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py b/local_coverage/code_coverage/multiprocess_code_coverage.py similarity index 92% rename from localCoverage/codeCoverage/mutilProcess_CodeCoverage.py rename to local_coverage/code_coverage/multiprocess_code_coverage.py index 753b43b..fc3efcd 100644 --- a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py +++ b/local_coverage/code_coverage/multiprocess_code_coverage.py @@ -1,395 +1,395 @@ -#!/usr/bin/env python3 -# coding=utf-8 - -# -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import os -import json -import shutil -import shlex -import subprocess -import multiprocessing -import sys -import stat - -from multiprocessing import Process - -FLAGS = os.O_WRONLY | os.O_APPEND | os.O_CREAT -MODES = stat.S_IWUSR | stat.S_IRUSR - -# 子系统json目录 -SYSTEM_JSON = "test/testfwk/developer_test/localCoverage/codeCoverage/subsystem_config.json" -# 覆盖率gcda -COVERAGE_GCDA_RESULTS = "test/testfwk/developer_test/localCoverage/codeCoverage/results/coverage/data/cxx" -# 报告路径 -REPORT_PATH = "test/testfwk/developer_test/localCoverage/codeCoverage/results/coverage/reports/cxx" -# llvm-gcov.sh -LLVM_GCOV = "test/testfwk/developer_test/localCoverage/codeCoverage/llvm-gcov.sh" -# 测试套划分步长 -STEP_SIZE = 10 - - -def _init_sys_config(): - sys.localcoverage_path = os.path.join(current_path, "..") - sys.path.insert(0, sys.localcoverage_path) - - -def call(cmd_list, is_show_cmd=False, out=None, err=None): - return_flag = False - try: - if is_show_cmd: - print("execute command: {}".format(" ".join(cmd_list))) - if 0 == subprocess.call(cmd_list, shell=False, stdout=out, stderr=err): - return_flag = True - except IOError: - print("Error : command {} execute faild!".format(cmd_list)) - return_flag = False - - return return_flag - - -def execute_command(command, printflag=False): - try: - cmd_list = shlex.split(command) - coverage_log_path = os.path.join( - CODEPATH, "test/testfwk/developer_test/localCoverage", "coverage.log") - with os.fdopen(os.open(coverage_log_path, FLAGS, MODES), 'a') as fd: - call(cmd_list, printflag, fd, fd) - except IOError: - print("Error: Exception occur in open error") - - -def get_subsystem_config_info(): - filter_subsystem_name_list = [ - "subsystem_examples", - ] - subsystem_info_dic = {} - subsystem_config_filepath = os.path.join(CODEPATH, SYSTEM_JSON) - if os.path.exists(subsystem_config_filepath): - data = None - with open(subsystem_config_filepath, "r", encoding="utf-8") as f: - data = json.load(f) - if not data: - print("subsystem config file error.") - for value in data.values(): - subsystem_name = value.get("name") - if subsystem_name in filter_subsystem_name_list: - continue - subsystem_dir = value.get('dir') - subsystem_path = value.get('path') - subsystem_project = value.get('project') - subsystem_rootpath = [] - for path in subsystem_path: - subsystem_rootpath.append(os.path.join(CODEPATH, path)) - subsystem_info_dic[subsystem_name] = [ - subsystem_project, subsystem_dir, - subsystem_path, subsystem_rootpath - ] - return subsystem_info_dic - - -def get_subsystem_name_list(): - subsystem_name_list = [] - subsystem_info_dic = get_subsystem_config_info() - for key in subsystem_info_dic.keys(): - subsystem_rootpath = subsystem_info_dic[key][3] - for subsystem_rootpath_item in subsystem_rootpath: - if os.path.exists(subsystem_rootpath_item): - subsystem_name_list.append(key) - - return subsystem_name_list - - -def get_subsystem_rootpath(subsystem_name): - subsystem_path = "" - subsystem_rootpath = "" - subsystem_info_dic = get_subsystem_config_info() - for key in subsystem_info_dic.keys(): - if key == subsystem_name: - subsystem_path = subsystem_info_dic[key][2] - subsystem_rootpath = subsystem_info_dic[key][3] - break - - return subsystem_path, subsystem_rootpath - - -def is_filterout_dir(ignore_prefix, check_path): - filter_out_list = ["unittest", "third_party", "test"] - for item in filter_out_list: - check_list = check_path[len(ignore_prefix):].split("/") - if item in check_list: - return True - - return False - - -def rm_unnecessary_dir(cov_path): - topdir = os.path.join(cov_path, "obj") - for root, dirs, files in os.walk(topdir): - if is_filterout_dir(topdir, root): - shutil.rmtree(root) - - -def get_files_from_dir(find_path, postfix=None): - names = os.listdir(find_path) - file_list = [] - for fn in names: - if not os.path.isfile(os.path.join(find_path, fn)): - continue - if postfix is not None: - if fn.endswith(postfix): - file_list.append(fn) - else: - file_list.append(fn) - - return file_list - - -def get_gcno_files(cov_path, dir_name): - gcda_strip_path = dir_name[len(cov_path) + 1:] - gcda_list = get_files_from_dir(dir_name, ".gcda") - for file_name in gcda_list: - gcno_name = f"{os.path.splitext(file_name)[0]}.gcno" - gcno_path = os.path.join( - os.path.join(CODEPATH, OUTPUT), gcda_strip_path, gcno_name - ) - if os.path.exists(gcno_path): - shutil.copy(gcno_path, dir_name) - else: - print(f"{gcno_path} not exists!") - - -def get_module_gcno_files(cov_path, dir_name): - for root, dirs, files in os.walk(dir_name): - get_gcno_files(cov_path, root) - - -def gen_subsystem_trace_info(subsystem, data_dir, test_dir, lcovrc_path): - src_dir = os.path.join(CODEPATH, OUTPUT) - single_info_path = os.path.join( - CODEPATH, REPORT_PATH, "single_test", test_dir - ) - if not os.path.exists(single_info_path): - os.makedirs(single_info_path) - output_name = os.path.join( - CODEPATH, single_info_path, f"{subsystem}_output.info" - ) - if not os.path.exists(src_dir): - print(f"Sours path {src_dir} not exists!") - return - - cmd = "lcov -c -b {} -d {} --gcov-tool {} --config-file {} -o {} --ignore-errors source,gcov".format( - src_dir, data_dir, os.path.join(CODEPATH, LLVM_GCOV), lcovrc_path, output_name) - print("single_test**##father_pid:%s##child_pid:%s cmd:%s config file:%s" % ( - os.getpid(), os.getppid(), cmd, lcovrc_path - )) - execute_command(cmd) - - -def cut_info(subsystem, test_dir): - trace_file = os.path.join( - CODEPATH, REPORT_PATH, "single_test", - test_dir, f"{subsystem}_output.info" - ) - output_name = os.path.join( - CODEPATH, REPORT_PATH, "single_test", - test_dir, f"{subsystem}_strip.info" - ) - - remove = r"'*/third_party/*' 'sdk/android-arm64/*'" - if not os.path.exists(trace_file): - print(f"Error: trace file {trace_file} not exists!") - return - - cmd = "lcov --remove {} {} -o {}".format(trace_file, remove, output_name) - execute_command(cmd) - - -def gen_info(cov_path, test_dir, subsystem_list, lcovrc_path): - if len(subsystem_list) == 0: - print("Error: get subsystem list failed, can not generate trace info") - return - - loop = 0 - for subsystem in list(set(subsystem_list)): - subsystem_path, subsystem_rootpath = get_subsystem_rootpath(subsystem) - for subsys_path in subsystem_path: - subsystem_data_abspath = os.path.join(cov_path, "obj", subsys_path) - # check id subsystem data is exists - if not os.path.exists(subsystem_data_abspath): - continue - - # copy gcno to the gcda same directory - get_module_gcno_files(cov_path, subsystem_data_abspath) - - # generate coverage info for each subsystem - gen_subsystem_trace_info( - f"{subsystem}#{subsys_path.replace('/', '_')}#{ str(loop)}", - subsystem_data_abspath, test_dir, lcovrc_path - ) - - # remove some type which useless - cut_info(f"{subsystem}#{subsys_path.replace('/', '_')}#{str(loop)}", test_dir) - - loop += 1 - - -def generate_coverage_info(single_test_dir_list, lcovrc_path, subsystem_list): - cov_path = os.path.join(CODEPATH, COVERAGE_GCDA_RESULTS) - for index, cur_test_dir in enumerate(single_test_dir_list): - cur_test_abs_dir = os.path.join(cov_path, cur_test_dir) - gen_info(cur_test_abs_dir, cur_test_dir, subsystem_list, lcovrc_path) - - -def gen_all_test_info(subsystem_list): - cov_path = os.path.join(CODEPATH, COVERAGE_GCDA_RESULTS) - print(os.getpid(), os.getppid()) - single_test_dir_list = [] - for root, dirs, files in os.walk(cov_path): - single_test_dir_list = dirs - break - - return single_test_dir_list - - -def merge_subsystem_info_from_all_test(subsystem): - single_test_info_path = os.path.join( - CODEPATH, REPORT_PATH, "single_test" - ) - subsystem_info_list = [] - subsystem_info_name = f"{subsystem}_strip.info" - for root, dirs, files in os.walk(single_test_info_path): - for file in files: - if file.startswith(subsystem) and file.endswith("_strip.info"): - subsystem_info_path_tmp = os.path.join( - single_test_info_path, root, file - ) - print(f"##{subsystem_info_path_tmp}") - subsystem_info_list.append(subsystem_info_path_tmp) - - if len(subsystem_info_list) == 0: - return - - info_output_name = os.path.join( - CODEPATH, REPORT_PATH, subsystem_info_name - ) - cmd = "lcov -a {} -o {}".format( - " -a ".join(subsystem_info_list), info_output_name - ) - execute_command(cmd) - - -def merge_all_test_subsystem_info(subsystem_list): - single_test_info_path = os.path.join( - CODEPATH, REPORT_PATH, "single_test" - ) - if not os.path.exists(single_test_info_path): - print(f"Error: the single test info path " - f"{single_test_info_path} not exist") - return - - for subsystem in subsystem_list: - print(f"Merging all {subsystem} info from test data") - merge_subsystem_info_from_all_test(subsystem) - - -def merge_info(report_dir): - if not os.path.exists(report_dir): - print(f"Error: report dir {report_dir} not exists!") - return - - subsystem_name_list = get_files_from_dir(report_dir, "_strip.info") - if len(subsystem_name_list) == 0: - print("Error: get subsystem trace files in report directory failed.") - return - - trace_file_list = [] - for subsystem in subsystem_name_list: - trace_file_name = os.path.join(report_dir, subsystem) - trace_file_list.append(trace_file_name) - - cmd = "lcov -a {} -o {}".format( - " -a ".join(trace_file_list), os.path.join(report_dir, "ohos_codeCoverage.info") - ) - execute_command(cmd) - - -def merge_all_subsystem_info(): - print("Merging all the subsystem trace files") - merge_info(os.path.join(CODEPATH, REPORT_PATH)) - - -def gen_html(cov_path): - tracefile = os.path.join(CODEPATH, REPORT_PATH, "ohos_codeCoverage.info") - if not os.path.exists(tracefile): - print(f"Error: the trace file {tracefile} not exists!") - return - - cmd = "genhtml --branch-coverage --demangle-cpp -o {} -p {} --ignore-errors source {}".format( - os.path.join(CODEPATH, REPORT_PATH, "html"), CODEPATH, tracefile) - execute_command(cmd) - - -def gen_final_report(cov_path): - print("Generating the html report") - gen_html(cov_path) - - -if __name__ == '__main__': - current_path = os.path.abspath(os.path.dirname(__name__)) - CODEPATH = current_path.split("/test/testfwk/developer_test")[0] - # lcovrc配置文件集合 - LCOVRC_SET = f"{CODEPATH}/test/testfwk/developer_test/localCoverage/codeCoverage/coverage_rc" - _init_sys_config() - from localCoverage.utils import get_product_name - # 编译生成的out路径 - OUTPUT = "out/{}".format(get_product_name(CODEPATH)) - - case_list = gen_all_test_info(subsystem_list=get_subsystem_name_list()) - multiprocessing.set_start_method("fork") # fork spawn forkserver - start = end = 0 - Tag = False - process_list = [] - for i in range(len(case_list)): - lcov_path = f"{LCOVRC_SET}/lcovrc_cov_{str(i)}" - print(lcov_path) - if os.path.exists(lcov_path): - print(f"{lcov_path}{'@' * 20}yes") - else: - raise Exception("mutilProcess have error -rc path not existed. " - "please fix add run") - - start = end - end += STEP_SIZE - if end >= len(case_list): - end = len(case_list) - Tag = True - - p = Process(target=generate_coverage_info, - args=(case_list[start:end], lcov_path, - get_subsystem_name_list())) - p.daemon = True - p.start() - process_list.append(p) - if Tag: - break - - for i in process_list: - i.join() - - merge_all_test_subsystem_info(subsystem_list=get_subsystem_name_list()) - merge_all_subsystem_info() - gen_final_report(os.path.join(CODEPATH, COVERAGE_GCDA_RESULTS)) +#!/usr/bin/env python3 +# coding=utf-8 + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import json +import shutil +import shlex +import subprocess +import multiprocessing +import sys +import stat + +from multiprocessing import Process + +FLAGS = os.O_WRONLY | os.O_APPEND | os.O_CREAT +MODES = stat.S_IWUSR | stat.S_IRUSR + +# 子系统json目录 +SYSTEM_JSON = "test/testfwk/developer_test/local_coverage/code_coverage/subsystem_config.json" +# 覆盖率gcda +COVERAGE_GCDA_RESULTS = "test/testfwk/developer_test/local_coverage/code_coverage/results/coverage/data/cxx" +# 报告路径 +REPORT_PATH = "test/testfwk/developer_test/local_coverage/code_coverage/results/coverage/reports/cxx" +# llvm-gcov.sh +LLVM_GCOV = "test/testfwk/developer_test/local_coverage/code_coverage/llvm-gcov.sh" +# 测试套划分步长 +STEP_SIZE = 10 + + +def _init_sys_config(): + sys.localcoverage_path = os.path.join(current_path, "..") + sys.path.insert(0, sys.localcoverage_path) + + +def call(cmd_list, is_show_cmd=False, out=None, err=None): + return_flag = False + try: + if is_show_cmd: + print("execute command: {}".format(" ".join(cmd_list))) + if 0 == subprocess.call(cmd_list, shell=False, stdout=out, stderr=err): + return_flag = True + except IOError: + print("Error : command {} execute faild!".format(cmd_list)) + return_flag = False + + return return_flag + + +def execute_command(command, printflag=False): + try: + cmd_list = shlex.split(command) + coverage_log_path = os.path.join( + CODEPATH, "test/testfwk/developer_test/local_coverage", "coverage.log") + with os.fdopen(os.open(coverage_log_path, FLAGS, MODES), 'a') as fd: + call(cmd_list, printflag, fd, fd) + except IOError: + print("Error: Exception occur in open error") + + +def get_subsystem_config_info(): + filter_subsystem_name_list = [ + "subsystem_examples", + ] + subsystem_info_dic = {} + subsystem_config_filepath = os.path.join(CODEPATH, SYSTEM_JSON) + if os.path.exists(subsystem_config_filepath): + data = None + with open(subsystem_config_filepath, "r", encoding="utf-8") as f: + data = json.load(f) + if not data: + print("subsystem config file error.") + for value in data.values(): + subsystem_name = value.get("name") + if subsystem_name in filter_subsystem_name_list: + continue + subsystem_dir = value.get('dir') + subsystem_path = value.get('path') + subsystem_project = value.get('project') + subsystem_rootpath = [] + for path in subsystem_path: + subsystem_rootpath.append(os.path.join(CODEPATH, path)) + subsystem_info_dic[subsystem_name] = [ + subsystem_project, subsystem_dir, + subsystem_path, subsystem_rootpath + ] + return subsystem_info_dic + + +def get_subsystem_name_list(): + subsystem_name_list = [] + subsystem_info_dic = get_subsystem_config_info() + for key in subsystem_info_dic.keys(): + subsystem_rootpath = subsystem_info_dic[key][3] + for subsystem_rootpath_item in subsystem_rootpath: + if os.path.exists(subsystem_rootpath_item): + subsystem_name_list.append(key) + + return subsystem_name_list + + +def get_subsystem_rootpath(subsystem_name): + subsystem_path = "" + subsystem_rootpath = "" + subsystem_info_dic = get_subsystem_config_info() + for key in subsystem_info_dic.keys(): + if key == subsystem_name: + subsystem_path = subsystem_info_dic[key][2] + subsystem_rootpath = subsystem_info_dic[key][3] + break + + return subsystem_path, subsystem_rootpath + + +def is_filterout_dir(ignore_prefix, check_path): + filter_out_list = ["unittest", "third_party", "test"] + for item in filter_out_list: + check_list = check_path[len(ignore_prefix):].split("/") + if item in check_list: + return True + + return False + + +def rm_unnecessary_dir(cov_path): + topdir = os.path.join(cov_path, "obj") + for root, dirs, files in os.walk(topdir): + if is_filterout_dir(topdir, root): + shutil.rmtree(root) + + +def get_files_from_dir(find_path, postfix=None): + names = os.listdir(find_path) + file_list = [] + for fn in names: + if not os.path.isfile(os.path.join(find_path, fn)): + continue + if postfix is not None: + if fn.endswith(postfix): + file_list.append(fn) + else: + file_list.append(fn) + + return file_list + + +def get_gcno_files(cov_path, dir_name): + gcda_strip_path = dir_name[len(cov_path) + 1:] + gcda_list = get_files_from_dir(dir_name, ".gcda") + for file_name in gcda_list: + gcno_name = f"{os.path.splitext(file_name)[0]}.gcno" + gcno_path = os.path.join( + os.path.join(CODEPATH, OUTPUT), gcda_strip_path, gcno_name + ) + if os.path.exists(gcno_path): + shutil.copy(gcno_path, dir_name) + else: + print(f"{gcno_path} not exists!") + + +def get_module_gcno_files(cov_path, dir_name): + for root, dirs, files in os.walk(dir_name): + get_gcno_files(cov_path, root) + + +def gen_subsystem_trace_info(subsystem, data_dir, test_dir, lcovrc_path): + src_dir = os.path.join(CODEPATH, OUTPUT) + single_info_path = os.path.join( + CODEPATH, REPORT_PATH, "single_test", test_dir + ) + if not os.path.exists(single_info_path): + os.makedirs(single_info_path) + output_name = os.path.join( + CODEPATH, single_info_path, f"{subsystem}_output.info" + ) + if not os.path.exists(src_dir): + print(f"Sours path {src_dir} not exists!") + return + + cmd = "lcov -c -b {} -d {} --gcov-tool {} --config-file {} -o {} --ignore-errors source,gcov".format( + src_dir, data_dir, os.path.join(CODEPATH, LLVM_GCOV), lcovrc_path, output_name) + print("single_test**##father_pid:%s##child_pid:%s cmd:%s config file:%s" % ( + os.getpid(), os.getppid(), cmd, lcovrc_path + )) + execute_command(cmd) + + +def cut_info(subsystem, test_dir): + trace_file = os.path.join( + CODEPATH, REPORT_PATH, "single_test", + test_dir, f"{subsystem}_output.info" + ) + output_name = os.path.join( + CODEPATH, REPORT_PATH, "single_test", + test_dir, f"{subsystem}_strip.info" + ) + + remove = r"'*/third_party/*' 'sdk/android-arm64/*'" + if not os.path.exists(trace_file): + print(f"Error: trace file {trace_file} not exists!") + return + + cmd = "lcov --remove {} {} -o {}".format(trace_file, remove, output_name) + execute_command(cmd) + + +def gen_info(cov_path, test_dir, subsystem_list, lcovrc_path): + if len(subsystem_list) == 0: + print("Error: get subsystem list failed, can not generate trace info") + return + + loop = 0 + for subsystem in list(set(subsystem_list)): + subsystem_path, subsystem_rootpath = get_subsystem_rootpath(subsystem) + for subsys_path in subsystem_path: + subsystem_data_abspath = os.path.join(cov_path, "obj", subsys_path) + # check id subsystem data is exists + if not os.path.exists(subsystem_data_abspath): + continue + + # copy gcno to the gcda same directory + get_module_gcno_files(cov_path, subsystem_data_abspath) + + # generate coverage info for each subsystem + gen_subsystem_trace_info( + f"{subsystem}#{subsys_path.replace('/', '_')}#{ str(loop)}", + subsystem_data_abspath, test_dir, lcovrc_path + ) + + # remove some type which useless + cut_info(f"{subsystem}#{subsys_path.replace('/', '_')}#{str(loop)}", test_dir) + + loop += 1 + + +def generate_coverage_info(single_test_dir_list, lcovrc_path, subsystem_list): + cov_path = os.path.join(CODEPATH, COVERAGE_GCDA_RESULTS) + for index, cur_test_dir in enumerate(single_test_dir_list): + cur_test_abs_dir = os.path.join(cov_path, cur_test_dir) + gen_info(cur_test_abs_dir, cur_test_dir, subsystem_list, lcovrc_path) + + +def gen_all_test_info(subsystem_list): + cov_path = os.path.join(CODEPATH, COVERAGE_GCDA_RESULTS) + print(os.getpid(), os.getppid()) + single_test_dir_list = [] + for root, dirs, files in os.walk(cov_path): + single_test_dir_list = dirs + break + + return single_test_dir_list + + +def merge_subsystem_info_from_all_test(subsystem): + single_test_info_path = os.path.join( + CODEPATH, REPORT_PATH, "single_test" + ) + subsystem_info_list = [] + subsystem_info_name = f"{subsystem}_strip.info" + for root, dirs, files in os.walk(single_test_info_path): + for file in files: + if file.startswith(subsystem) and file.endswith("_strip.info"): + subsystem_info_path_tmp = os.path.join( + single_test_info_path, root, file + ) + print(f"##{subsystem_info_path_tmp}") + subsystem_info_list.append(subsystem_info_path_tmp) + + if len(subsystem_info_list) == 0: + return + + info_output_name = os.path.join( + CODEPATH, REPORT_PATH, subsystem_info_name + ) + cmd = "lcov -a {} -o {}".format( + " -a ".join(subsystem_info_list), info_output_name + ) + execute_command(cmd) + + +def merge_all_test_subsystem_info(subsystem_list): + single_test_info_path = os.path.join( + CODEPATH, REPORT_PATH, "single_test" + ) + if not os.path.exists(single_test_info_path): + print(f"Error: the single test info path " + f"{single_test_info_path} not exist") + return + + for subsystem in subsystem_list: + print(f"Merging all {subsystem} info from test data") + merge_subsystem_info_from_all_test(subsystem) + + +def merge_info(report_dir): + if not os.path.exists(report_dir): + print(f"Error: report dir {report_dir} not exists!") + return + + subsystem_name_list = get_files_from_dir(report_dir, "_strip.info") + if len(subsystem_name_list) == 0: + print("Error: get subsystem trace files in report directory failed.") + return + + trace_file_list = [] + for subsystem in subsystem_name_list: + trace_file_name = os.path.join(report_dir, subsystem) + trace_file_list.append(trace_file_name) + + cmd = "lcov -a {} -o {}".format( + " -a ".join(trace_file_list), os.path.join(report_dir, "ohos_codeCoverage.info") + ) + execute_command(cmd) + + +def merge_all_subsystem_info(): + print("Merging all the subsystem trace files") + merge_info(os.path.join(CODEPATH, REPORT_PATH)) + + +def gen_html(cov_path): + tracefile = os.path.join(CODEPATH, REPORT_PATH, "ohos_codeCoverage.info") + if not os.path.exists(tracefile): + print(f"Error: the trace file {tracefile} not exists!") + return + + cmd = "genhtml --branch-coverage --demangle-cpp -o {} -p {} --ignore-errors source {}".format( + os.path.join(CODEPATH, REPORT_PATH, "html"), CODEPATH, tracefile) + execute_command(cmd) + + +def gen_final_report(cov_path): + print("Generating the html report") + gen_html(cov_path) + + +if __name__ == '__main__': + current_path = os.path.abspath(os.path.dirname(__name__)) + CODEPATH = current_path.split("/test/testfwk/developer_test")[0] + # lcovrc配置文件集合 + LCOVRC_SET = f"{CODEPATH}/test/testfwk/developer_test/local_coverage/code_coverage/coverage_rc" + _init_sys_config() + from local_coverage.utils import get_product_name + # 编译生成的out路径 + OUTPUT = "out/{}".format(get_product_name(CODEPATH)) + + case_list = gen_all_test_info(subsystem_list=get_subsystem_name_list()) + multiprocessing.set_start_method("fork") # fork spawn forkserver + start = end = 0 + Tag = False + process_list = [] + for i in range(len(case_list)): + lcov_path = f"{LCOVRC_SET}/lcovrc_cov_{str(i)}" + print(lcov_path) + if os.path.exists(lcov_path): + print(f"{lcov_path}{'@' * 20}yes") + else: + raise Exception("mutilProcess have error -rc path not existed. " + "please fix add run") + + start = end + end += STEP_SIZE + if end >= len(case_list): + end = len(case_list) + Tag = True + + p = Process(target=generate_coverage_info, + args=(case_list[start:end], lcov_path, + get_subsystem_name_list())) + p.daemon = True + p.start() + process_list.append(p) + if Tag: + break + + for i in process_list: + i.join() + + merge_all_test_subsystem_info(subsystem_list=get_subsystem_name_list()) + merge_all_subsystem_info() + gen_final_report(os.path.join(CODEPATH, COVERAGE_GCDA_RESULTS)) diff --git a/localCoverage/coverage_tools.py b/local_coverage/coverage_tools.py similarity index 83% rename from localCoverage/coverage_tools.py rename to local_coverage/coverage_tools.py index f1c5ea9..177db12 100644 --- a/localCoverage/coverage_tools.py +++ b/local_coverage/coverage_tools.py @@ -1,203 +1,203 @@ -#!/usr/bin/env python3 -# coding=utf-8 - -# -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -import os -import sys -import json -import shutil -import subprocess -import stat -from shutil import copyfile - -from utils import get_product_name, coverage_command - -FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL -MODES = stat.S_IWUSR | stat.S_IRUSR - - -def get_subsystem_config(part_list, developer_path): - all_system_info_path = os.path.join( - developer_path, "localCoverage/all_subsystem_config.json" - ) - system_info_path = os.path.join( - developer_path, "localCoverage/codeCoverage/subsystem_config.json" - ) - if os.path.exists(all_system_info_path): - new_json_text = {} - for part in part_list: - with open(all_system_info_path, "r", encoding="utf-8") as system_text: - system_text_json = json.load(system_text) - if part in system_text_json: - new_json_text[part] = system_text_json[part] - else: - print("part not in all_subsystem_config.json") - - new_json = json.dumps(new_json_text, indent=4) - if os.path.exists(system_info_path): - os.remove(system_info_path) - with os.fdopen(os.open(system_info_path, FLAGS, MODES), 'w') as out_file: - out_file.write(new_json) - else: - print("%s not exists.", all_system_info_path) - - -def copy_coverage(developer_path): - print("*" * 40, "Start TO Get Code Coverage Report", "*" * 40) - coverage_path = os.path.join(developer_path, "reports/coverage") - code_path = os.path.join( - developer_path, "localCoverage/codeCoverage/results/coverage" - ) - if os.path.exists(code_path): - shutil.rmtree(code_path) - shutil.copytree(coverage_path, code_path) - - -def remove_thrd_gcda(developer_path): - print("remove thirdparty gcda") - gcda_dir_path = os.path.join(developer_path, "localCoverage/codeCoverage/results/coverage/data/cxx") - if os.path.exists(gcda_dir_path): - for i in os.listdir(gcda_dir_path): - remove_out = os.path.join(gcda_dir_path, i, "obj/out") - remove_thrd = os.path.join(gcda_dir_path, i, "obj/third_party") - if os.path.exists(remove_out): - print("remove {}".format(remove_out)) - shutil.rmtree(remove_out) - if os.path.exists(remove_thrd): - print("remove {}".format(remove_thrd)) - shutil.rmtree(remove_thrd) - - -def generate_coverage_rc(developer_path): - coverage_rc_path = os.path.join( - developer_path, "localCoverage/codeCoverage/coverage_rc" - ) - lcovrc_cov_template_path = os.path.join(coverage_rc_path, "lcovrc_cov_template") - for num in range(16): - tmp_cov_path = os.path.join(coverage_rc_path, f"tmp_cov_{num}") - lcovrc_cov_path = os.path.join(coverage_rc_path, f"lcovrc_cov_{num}") - if not os.path.exists(tmp_cov_path): - os.mkdir(tmp_cov_path) - if not os.path.exists(os.path.join(tmp_cov_path, "ex.txt")): - with open(os.path.join(tmp_cov_path, "ex.txt"), mode="w") as f: - f.write("") - - copyfile(lcovrc_cov_template_path, lcovrc_cov_path) - with open(lcovrc_cov_path, mode="a") as f: - f.write("\n\n") - f.write("# Location for temporary directories\n") - f.write(f"lcov_tmp_dir = {tmp_cov_path}") - - -def execute_code_cov_tools(developer_path): - llvm_gcov_path = os.path.join( - developer_path, "localCoverage/codeCoverage/llvm-gcov.sh" - ) - coverage_command("dos2unix %s" % llvm_gcov_path) - coverage_command("chmod 777 %s" % llvm_gcov_path) - tools_path = os.path.join( - developer_path, "localCoverage/codeCoverage/mutilProcess_CodeCoverage.py" - ) - coverage_command("python3 %s" % tools_path) - - -def get_subsystem_name(part_list, product_name): - if product_name: - testfwk_json_path = os.path.join( - root_path, "out", product_name, "build_configs/infos_for_testfwk.json" - ) - if os.path.exists(testfwk_json_path): - with open(testfwk_json_path, "r", encoding="utf-8") as json_text: - system_json = json.load(json_text) - subsystem_info = system_json.get("phone").get("subsystem_infos") - subsystem_list = [] - for part in part_list: - for key in subsystem_info.keys(): - if part in subsystem_info.get(key) and key not in subsystem_list: - subsystem_list.append(key) - subsystem_str = ','.join(list(map(str, subsystem_list))) - return subsystem_str - else: - print("%s not exists.", testfwk_json_path) - return "" - else: - print("product_name is not null") - return "" - - -def execute_interface_cov_tools(partname_str, developer_path): - print("*" * 40, "Start TO Get Interface Coverage Report", "*" * 40) - innerkits_json_path = os.path.join( - developer_path, - "localCoverage/interfaceCoverage/get_innerkits_json.py" - ) - coverage_command("python3 %s" % innerkits_json_path) - - interface_path = os.path.join( - developer_path, - "localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py" - ) - subprocess.run("python3 %s %s" % (interface_path, partname_str), shell=True) - - -if __name__ == '__main__': - testpart_args = sys.argv[1] - test_part_list = testpart_args.split("testpart=")[1].split(",") - - current_path = os.getcwd() - root_path = current_path.split("/test/testfwk/developer_test")[0] - developer_test_path = os.path.join(root_path, "test/testfwk/developer_test") - - # 获取产品形态 - product_names = get_product_name(root_path) - - # copy gcda数据到覆盖率工具指定位置 - copy_coverage(developer_test_path) - generate_coverage_rc(developer_test_path) - remove_thrd_gcda(developer_test_path) - - # 获取部件位置信息config - if len(test_part_list) > 0: - get_subsystem_config(test_part_list, developer_test_path) - - # 执行代码覆盖率 - execute_code_cov_tools(developer_test_path) - # 报备 - keyword_path = os.path.join( - developer_test_path, "localCoverage/keyword_registration/keyword_filter.py") - subprocess.run("python3 %s" % keyword_path, shell=True) - - # 执行接口覆盖率 - if len(test_part_list) > 0: - execute_interface_cov_tools(testpart_args, developer_test_path) - else: - print("subsystem or part without!") - - # 源代码还原 - after_lcov_branch_path = os.path.join( - developer_test_path, "localCoverage/restore_comment/after_lcov_branch.py") - if os.path.exists(after_lcov_branch_path): - subprocess.run("python3 %s " % after_lcov_branch_path, shell=True) - restore_source_code_path = os.path.join( - developer_test_path, "localCoverage/restore_comment/restore_source_code.py") - subprocess.run("python3 %s" % restore_source_code_path, shell=True) - - print(r"See the code coverage report in: " - r"/test/testfwk/developer_test/localCoverage/codeCoverage/results/coverage/reports/cxx/html") - print(r"See the interface coverage report in: " - r"/test/testfwk/developer_test/localCoverage/interfaceCoverage/results/coverage/interface_kits") +#!/usr/bin/env python3 +# coding=utf-8 + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +import os +import sys +import json +import shutil +import subprocess +import stat +from shutil import copyfile + +from utils import get_product_name, coverage_command + +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + + +def get_subsystem_config(part_list, developer_path): + all_system_info_path = os.path.join( + developer_path, "local_coverage/all_subsystem_config.json" + ) + system_info_path = os.path.join( + developer_path, "local_coverage/code_coverage/subsystem_config.json" + ) + if os.path.exists(all_system_info_path): + new_json_text = {} + for part in part_list: + with open(all_system_info_path, "r", encoding="utf-8") as system_text: + system_text_json = json.load(system_text) + if part in system_text_json: + new_json_text[part] = system_text_json[part] + else: + print("part not in all_subsystem_config.json") + + new_json = json.dumps(new_json_text, indent=4) + if os.path.exists(system_info_path): + os.remove(system_info_path) + with os.fdopen(os.open(system_info_path, FLAGS, MODES), 'w') as out_file: + out_file.write(new_json) + else: + print("%s not exists.", all_system_info_path) + + +def copy_coverage(developer_path): + print("*" * 40, "Start TO Get Code Coverage Report", "*" * 40) + coverage_path = os.path.join(developer_path, "reports/coverage") + code_path = os.path.join( + developer_path, "local_coverage/code_coverage/results/coverage" + ) + if os.path.exists(code_path): + shutil.rmtree(code_path) + shutil.copytree(coverage_path, code_path) + + +def remove_thrd_gcda(developer_path): + print("remove thirdparty gcda") + gcda_dir_path = os.path.join(developer_path, "local_coverage/code_coverage/results/coverage/data/cxx") + if os.path.exists(gcda_dir_path): + for i in os.listdir(gcda_dir_path): + remove_out = os.path.join(gcda_dir_path, i, "obj/out") + remove_thrd = os.path.join(gcda_dir_path, i, "obj/third_party") + if os.path.exists(remove_out): + print("remove {}".format(remove_out)) + shutil.rmtree(remove_out) + if os.path.exists(remove_thrd): + print("remove {}".format(remove_thrd)) + shutil.rmtree(remove_thrd) + + +def generate_coverage_rc(developer_path): + coverage_rc_path = os.path.join( + developer_path, "local_coverage/code_coverage/coverage_rc" + ) + lcovrc_cov_template_path = os.path.join(coverage_rc_path, "lcovrc_cov_template") + for num in range(16): + tmp_cov_path = os.path.join(coverage_rc_path, f"tmp_cov_{num}") + lcovrc_cov_path = os.path.join(coverage_rc_path, f"lcovrc_cov_{num}") + if not os.path.exists(tmp_cov_path): + os.mkdir(tmp_cov_path) + if not os.path.exists(os.path.join(tmp_cov_path, "ex.txt")): + with open(os.path.join(tmp_cov_path, "ex.txt"), mode="w") as f: + f.write("") + + copyfile(lcovrc_cov_template_path, lcovrc_cov_path) + with open(lcovrc_cov_path, mode="a") as f: + f.write("\n\n") + f.write("# Location for temporary directories\n") + f.write(f"lcov_tmp_dir = {tmp_cov_path}") + + +def execute_code_cov_tools(developer_path): + llvm_gcov_path = os.path.join( + developer_path, "local_coverage/code_coverage/llvm-gcov.sh" + ) + coverage_command("dos2unix %s" % llvm_gcov_path) + coverage_command("chmod 777 %s" % llvm_gcov_path) + tools_path = os.path.join( + developer_path, "local_coverage/code_coverage/multiprocess_code_coverage.py" + ) + coverage_command("python3 %s" % tools_path) + + +def get_subsystem_name(part_list, product_name): + if product_name: + testfwk_json_path = os.path.join( + root_path, "out", product_name, "build_configs/infos_for_testfwk.json" + ) + if os.path.exists(testfwk_json_path): + with open(testfwk_json_path, "r", encoding="utf-8") as json_text: + system_json = json.load(json_text) + subsystem_info = system_json.get("phone").get("subsystem_infos") + subsystem_list = [] + for part in part_list: + for key in subsystem_info.keys(): + if part in subsystem_info.get(key) and key not in subsystem_list: + subsystem_list.append(key) + subsystem_str = ','.join(list(map(str, subsystem_list))) + return subsystem_str + else: + print("%s not exists.", testfwk_json_path) + return "" + else: + print("product_name is not null") + return "" + + +def execute_interface_cov_tools(partname_str, developer_path): + print("*" * 40, "Start TO Get Interface Coverage Report", "*" * 40) + innerkits_json_path = os.path.join( + developer_path, + "local_coverage/interface_coverage/get_innerkits_json.py" + ) + coverage_command("python3 %s" % innerkits_json_path) + + interface_path = os.path.join( + developer_path, + "local_coverage/interface_coverage/interface_coverage_gcov_lcov.py" + ) + subprocess.run("python3 %s %s" % (interface_path, partname_str), shell=True) + + +if __name__ == '__main__': + testpart_args = sys.argv[1] + test_part_list = testpart_args.split("testpart=")[1].split(",") + + current_path = os.getcwd() + root_path = current_path.split("/test/testfwk/developer_test")[0] + developer_test_path = os.path.join(root_path, "test/testfwk/developer_test") + + # 获取产品形态 + product_names = get_product_name(root_path) + + # copy gcda数据到覆盖率工具指定位置 + copy_coverage(developer_test_path) + generate_coverage_rc(developer_test_path) + remove_thrd_gcda(developer_test_path) + + # 获取部件位置信息config + if len(test_part_list) > 0: + get_subsystem_config(test_part_list, developer_test_path) + + # 执行代码覆盖率 + execute_code_cov_tools(developer_test_path) + # 报备 + keyword_path = os.path.join( + developer_test_path, "local_coverage/keyword_registration/keyword_filter.py") + subprocess.run("python3 %s" % keyword_path, shell=True) + + # 执行接口覆盖率 + if len(test_part_list) > 0: + execute_interface_cov_tools(testpart_args, developer_test_path) + else: + print("subsystem or part without!") + + # 源代码还原 + after_lcov_branch_path = os.path.join( + developer_test_path, "local_coverage/restore_comment/after_lcov_branch.py") + if os.path.exists(after_lcov_branch_path): + subprocess.run("python3 %s " % after_lcov_branch_path, shell=True) + restore_source_code_path = os.path.join( + developer_test_path, "local_coverage/restore_comment/restore_source_code.py") + subprocess.run("python3 %s" % restore_source_code_path, shell=True) + + print(r"See the code coverage report in: " + r"/test/testfwk/developer_test/local_coverage/code_coverage/results/coverage/reports/cxx/html") + print(r"See the interface coverage report in: " + r"/test/testfwk/developer_test/local_coverage/interface_coverage/results/coverage/interface_kits") diff --git a/localCoverage/interfaceCoverage/__init__.py b/local_coverage/interface_coverage/__init__.py similarity index 100% rename from localCoverage/interfaceCoverage/__init__.py rename to local_coverage/interface_coverage/__init__.py diff --git a/localCoverage/interfaceCoverage/get_innerkits_json.py b/local_coverage/interface_coverage/get_innerkits_json.py similarity index 93% rename from localCoverage/interfaceCoverage/get_innerkits_json.py rename to local_coverage/interface_coverage/get_innerkits_json.py index e8484e3..9b0a565 100644 --- a/localCoverage/interfaceCoverage/get_innerkits_json.py +++ b/local_coverage/interface_coverage/get_innerkits_json.py @@ -1,80 +1,80 @@ -#!/usr/bin/env python3 -# coding=utf-8 - -# -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -import os -import json -import sys -import stat - -FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL -MODES = stat.S_IWUSR | stat.S_IRUSR - - -def _init_sys_config(): - sys.localcoverage_path = os.path.join(current_path, "..") - sys.path.insert(0, sys.localcoverage_path) - - -def gen_parts_info_json(folder_list, output_json_path, target_cpu): - """ - 根据部件信息,生成字典至json文件中 - """ - if len(folder_list) != 0: - data_dict = {} - for folder_str in folder_list: - data_dict[folder_str] = f"innerkits/ohos-{target_cpu}/{folder_str}" - output_json_path = os.path.join(output_json_path, "kits_modules_info.json") - json_str = json.dumps(data_dict, indent=2) - if os.path.exists(output_json_path): - os.remove(output_json_path) - with os.fdopen(os.open(output_json_path, FLAGS, MODES), 'w') as json_file: - json_file.write(json_str) - else: - print("part_name list information is null") - - -def get_parts_list(path): - """ - #获取out/ohos-arm-release/innerkits/ohos-arm内部接口文件夹名称列表 - """ - if os.path.exists(path): - folder_list = os.listdir(path) - else: - print("The folder: %s does not exist" % path) - folder_list = [] - return folder_list - - -if __name__ == "__main__": - current_path = os.getcwd() - _init_sys_config() - from localCoverage.utils import get_product_name, coverage_command, get_target_cpu - - root_path = current_path.split("/test/testfwk/developer_test")[0] - product_name = get_product_name(root_path) - cpu_type = get_target_cpu(root_path) - part_info_path = os.path.join( - root_path, "out", product_name, "innerkits/ohos-%s" % cpu_type - ) - json_path = os.path.join( - root_path, "out", product_name, "packages/phone/innerkits/ohos-%s" % cpu_type - ) - coverage_command("mkdir -p %s" % json_path) - part_list = get_parts_list(part_info_path) - gen_parts_info_json(part_list, json_path, cpu_type) +#!/usr/bin/env python3 +# coding=utf-8 + +# +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +import os +import json +import sys +import stat + +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + + +def _init_sys_config(): + sys.localcoverage_path = os.path.join(current_path, "..") + sys.path.insert(0, sys.localcoverage_path) + + +def gen_parts_info_json(folder_list, output_json_path, target_cpu): + """ + 根据部件信息,生成字典至json文件中 + """ + if len(folder_list) != 0: + data_dict = {} + for folder_str in folder_list: + data_dict[folder_str] = f"innerkits/ohos-{target_cpu}/{folder_str}" + output_json_path = os.path.join(output_json_path, "kits_modules_info.json") + json_str = json.dumps(data_dict, indent=2) + if os.path.exists(output_json_path): + os.remove(output_json_path) + with os.fdopen(os.open(output_json_path, FLAGS, MODES), 'w') as json_file: + json_file.write(json_str) + else: + print("part_name list information is null") + + +def get_parts_list(path): + """ + #获取out/ohos-arm-release/innerkits/ohos-arm内部接口文件夹名称列表 + """ + if os.path.exists(path): + folder_list = os.listdir(path) + else: + print("The folder: %s does not exist" % path) + folder_list = [] + return folder_list + + +if __name__ == "__main__": + current_path = os.getcwd() + _init_sys_config() + from local_coverage.utils import get_product_name, coverage_command, get_target_cpu + + root_path = current_path.split("/test/testfwk/developer_test")[0] + product_name = get_product_name(root_path) + cpu_type = get_target_cpu(root_path) + part_info_path = os.path.join( + root_path, "out", product_name, "innerkits/ohos-%s" % cpu_type + ) + json_path = os.path.join( + root_path, "out", product_name, "packages/phone/innerkits/ohos-%s" % cpu_type + ) + coverage_command("mkdir -p %s" % json_path) + part_list = get_parts_list(part_info_path) + gen_parts_info_json(part_list, json_path, cpu_type) diff --git a/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py b/local_coverage/interface_coverage/interface_coverage_gcov_lcov.py similarity index 98% rename from localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py rename to local_coverage/interface_coverage/interface_coverage_gcov_lcov.py index 47cc669..6974ebb 100644 --- a/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py +++ b/local_coverage/interface_coverage/interface_coverage_gcov_lcov.py @@ -443,12 +443,12 @@ if __name__ == "__main__": current_path = os.getcwd() CODEPATH = current_path.split("/test/testfwk/developer_test")[0] SUB_SYSTEM_INFO_PATH = os.path.join( - CODEPATH, "test/testfwk/developer_test/localCoverage/codeCoverage/results/coverage/reports/cxx") + CODEPATH, "test/testfwk/developer_test/local_coverage/code_coverage/results/coverage/reports/cxx") OUTPUT_REPORT_PATH = os.path.join( - CODEPATH, "test/testfwk/developer_test/localCoverage/interfaceCoverage/results/coverage/interface_kits" + CODEPATH, "test/testfwk/developer_test/local_coverage/interface_coverage/results/coverage/interface_kits" ) _init_sys_config() - from localCoverage.utils import get_product_name, get_target_cpu + from local_coverage.utils import get_product_name, get_target_cpu product_name = get_product_name(CODEPATH) cpu_type = get_target_cpu(CODEPATH) PATH_INFO_PATH = "out/{}/innerkits/ohos-{}".format(product_name, cpu_type) diff --git a/localCoverage/interfaceCoverage/make_report.py b/local_coverage/interface_coverage/make_report.py similarity index 100% rename from localCoverage/interfaceCoverage/make_report.py rename to local_coverage/interface_coverage/make_report.py diff --git a/localCoverage/interfaceCoverage/results/coverage/interface_kits/coverage_summary_file.xml b/local_coverage/interface_coverage/results/coverage/interface_kits/coverage_summary_file.xml similarity index 100% rename from localCoverage/interfaceCoverage/results/coverage/interface_kits/coverage_summary_file.xml rename to local_coverage/interface_coverage/results/coverage/interface_kits/coverage_summary_file.xml diff --git a/localCoverage/interfaceCoverage/results/coverage/interface_kits/ohos_interfaceCoverage.html b/local_coverage/interface_coverage/results/coverage/interface_kits/ohos_interfaceCoverage.html similarity index 100% rename from localCoverage/interfaceCoverage/results/coverage/interface_kits/ohos_interfaceCoverage.html rename to local_coverage/interface_coverage/results/coverage/interface_kits/ohos_interfaceCoverage.html diff --git a/localCoverage/keyword_registration/keyword.json b/local_coverage/keyword_registration/keyword.json similarity index 100% rename from localCoverage/keyword_registration/keyword.json rename to local_coverage/keyword_registration/keyword.json diff --git a/localCoverage/keyword_registration/keyword_filter.py b/local_coverage/keyword_registration/keyword_filter.py similarity index 99% rename from localCoverage/keyword_registration/keyword_filter.py rename to local_coverage/keyword_registration/keyword_filter.py index 778caba..b50a36c 100644 --- a/localCoverage/keyword_registration/keyword_filter.py +++ b/local_coverage/keyword_registration/keyword_filter.py @@ -219,6 +219,24 @@ class KeywordRegistration: return html_tag + @staticmethod + def modify_tag_style(tag, rate): + """ + 修改标签样式 + """ + if 75 <= rate < 90: + tag = tag.replace("headerCovTableEntryLo", "headerCovTableEntryMed") + tag = tag.replace("coverPerLo", "coverPerMed") + tag = tag.replace("coverNumLo", "coverNumMed") + elif rate >= 90: + tag = tag.replace("headerCovTableEntryLo", "headerCovTableEntryHi") + tag = tag.replace("headerCovTableEntryMed", "headerCovTableEntryHi") + tag = tag.replace("coverPerLo", "coverPerHi") + tag = tag.replace("coverNumLo", "coverNumHi") + tag = tag.replace("coverPerMed", "coverPerHi") + tag = tag.replace("coverNumMed", "coverNumHi") + return tag + @staticmethod def _branch_replace(branch): """ @@ -292,24 +310,6 @@ class KeywordRegistration: update_branch_tag += branch_tag return update_branch_tag - @staticmethod - def modify_tag_style(tag, rate): - """ - 修改标签样式 - """ - if 75 <= rate < 90: - tag = tag.replace("headerCovTableEntryLo", "headerCovTableEntryMed") - tag = tag.replace("coverPerLo", "coverPerMed") - tag = tag.replace("coverNumLo", "coverNumMed") - elif rate >= 90: - tag = tag.replace("headerCovTableEntryLo", "headerCovTableEntryHi") - tag = tag.replace("headerCovTableEntryMed", "headerCovTableEntryHi") - tag = tag.replace("coverPerLo", "coverPerHi") - tag = tag.replace("coverNumLo", "coverNumHi") - tag = tag.replace("coverPerMed", "coverPerHi") - tag = tag.replace("coverNumMed", "coverNumHi") - return tag - def get_coverage_lines_by_branch(self, file_path, content=None): """ 获取覆盖率报告中的所有的if分支行号 @@ -647,114 +647,6 @@ class KeywordRegistration: except (IndexError, TypeError, FileNotFoundError): print("修改分支统计数据出错") - def _check_if_branch_line(self, judge_key, sub_branch_line_list, - key_line, content, function_name): - """ - 确定if分支行号 - """ - if_branch_line = None - for branch_line in sub_branch_line_list: - if branch_line == key_line: - if_branch_line = key_line - break - # 获取分支行所在函数名 - branch_function_name = self.get_line_funcname( - branch_line, content) - # 关键字范围只在关键字所在函数之内 - branch_line_tag = self.get_tag(content, branch_line) - try: - if "{" not in branch_line_tag: - branch_line_tag = self.get_break_line_tag( - content, branch_line_tag, branch_line) - branch_line_source_code = self.get_source_code( - branch_line_tag) - if function_name == branch_function_name: - if judge_key in branch_line_source_code: - if_branch_line = branch_line - break - else: - break - except (ValueError, KeyError): - print("获取关键字if分支行报错", traceback.format_exc()) - - return if_branch_line - - def _multi_condition_modify_html(self, branch_html, branch_length, - condition_str_list, judge_index_list): - """ - 多条件修改代码块html - """ - line_item = ' ' - if branch_length % len(condition_str_list): - line_feed_index = branch_html.find(line_item) - update_branch_tag = branch_html[:line_feed_index] - update_branch_tag = update_branch_tag.replace("> - <", "> <") - branch_html = branch_html[line_feed_index:] - loop_count = 0 - while line_feed_index + 1: - loop_count += 1 - if loop_count > 200: - continue - line_feed_index = branch_html.count(line_item) - if line_feed_index > 1: - try: - line_feed_length = len(line_item) - branch_tag_before = branch_html[:line_feed_length] - branch_html = branch_html[line_feed_length:] - line_feed_index = branch_html.find(line_item) - branch_tag_after = branch_html[:line_feed_index] - branch_tag_after = branch_tag_after.replace("> - <", "> <") - branch_tag = branch_tag_before + branch_tag_after - except ValueError: - return "" - else: - branch_tag = branch_html - branch_tag = branch_tag.replace("> - <", "> <") - # 不再换行,索引为-1 - line_feed_index = -1 - - update_branch_tag += branch_tag - if line_feed_index == -1: - branch_html = "" - else: - branch_html = branch_html[line_feed_index:] - if branch_html != "": - branch_html = branch_html.replace("> - <", "> <") - update_branch_tag += branch_html - else: - branch_list = self.get_branch_data_by_tag(branch_html, True) - update_branch_tag = "" - end_count = -1 - try: - for index in judge_index_list: - branch_data = branch_list[:(index + 1) * 2] - # 要修改的分支数据列表长度 - branch_data_length = len(branch_data) - change_status = False - for count, branch in enumerate(branch_data, 1): - if count <= end_count: - continue - - end_count = count - branch = self._branch_replace(branch) - end_index = branch_html.find(branch) - branch_tag = branch_html[:end_index + 5] - if branch_data_length - count in [0, 1]: - if change_status: - continue - if branch == "> # <": - change_status = True - branch_tag = branch_tag.replace("> # <", "> * <") - elif branch == "> - <": - change_status = True - branch_tag = branch_tag.replace("> - <", "> * <") - update_branch_tag += branch_tag - branch_html = branch_html[end_index + 5:] - except (ValueError, TypeError): - return "" - update_branch_tag += branch_html - return update_branch_tag - def judge_branch_exists(self, file_path): """ 判断报告是否存在分支 @@ -909,6 +801,114 @@ class KeywordRegistration: pool.close() pool.join() + def _check_if_branch_line(self, judge_key, sub_branch_line_list, + key_line, content, function_name): + """ + 确定if分支行号 + """ + if_branch_line = None + for branch_line in sub_branch_line_list: + if branch_line == key_line: + if_branch_line = key_line + break + # 获取分支行所在函数名 + branch_function_name = self.get_line_funcname( + branch_line, content) + # 关键字范围只在关键字所在函数之内 + branch_line_tag = self.get_tag(content, branch_line) + try: + if "{" not in branch_line_tag: + branch_line_tag = self.get_break_line_tag( + content, branch_line_tag, branch_line) + branch_line_source_code = self.get_source_code( + branch_line_tag) + if function_name == branch_function_name: + if judge_key in branch_line_source_code: + if_branch_line = branch_line + break + else: + break + except (ValueError, KeyError): + print("获取关键字if分支行报错", traceback.format_exc()) + + return if_branch_line + + def _multi_condition_modify_html(self, branch_html, branch_length, + condition_str_list, judge_index_list): + """ + 多条件修改代码块html + """ + line_item = ' ' + if branch_length % len(condition_str_list): + line_feed_index = branch_html.find(line_item) + update_branch_tag = branch_html[:line_feed_index] + update_branch_tag = update_branch_tag.replace("> - <", "> <") + branch_html = branch_html[line_feed_index:] + loop_count = 0 + while line_feed_index + 1: + loop_count += 1 + if loop_count > 200: + continue + line_feed_index = branch_html.count(line_item) + if line_feed_index > 1: + try: + line_feed_length = len(line_item) + branch_tag_before = branch_html[:line_feed_length] + branch_html = branch_html[line_feed_length:] + line_feed_index = branch_html.find(line_item) + branch_tag_after = branch_html[:line_feed_index] + branch_tag_after = branch_tag_after.replace("> - <", "> <") + branch_tag = branch_tag_before + branch_tag_after + except ValueError: + return "" + else: + branch_tag = branch_html + branch_tag = branch_tag.replace("> - <", "> <") + # 不再换行,索引为-1 + line_feed_index = -1 + + update_branch_tag += branch_tag + if line_feed_index == -1: + branch_html = "" + else: + branch_html = branch_html[line_feed_index:] + if branch_html != "": + branch_html = branch_html.replace("> - <", "> <") + update_branch_tag += branch_html + else: + branch_list = self.get_branch_data_by_tag(branch_html, True) + update_branch_tag = "" + end_count = -1 + try: + for index in judge_index_list: + branch_data = branch_list[:(index + 1) * 2] + # 要修改的分支数据列表长度 + branch_data_length = len(branch_data) + change_status = False + for count, branch in enumerate(branch_data, 1): + if count <= end_count: + continue + + end_count = count + branch = self._branch_replace(branch) + end_index = branch_html.find(branch) + branch_tag = branch_html[:end_index + 5] + if branch_data_length - count in [0, 1]: + if change_status: + continue + if branch == "> # <": + change_status = True + branch_tag = branch_tag.replace("> # <", "> * <") + elif branch == "> - <": + change_status = True + branch_tag = branch_tag.replace("> - <", "> * <") + update_branch_tag += branch_tag + branch_html = branch_html[end_index + 5:] + except (ValueError, TypeError): + return "" + update_branch_tag += branch_html + return update_branch_tag + def main(report_path): print("*" * 50, "报备开始", "*" * 50) @@ -924,5 +924,5 @@ if __name__ == '__main__': current_path = os.getcwd() home_path = current_path.split("/test/testfwk/developer_test")[0] developer_path = os.path.join(home_path, "test/testfwk/developer_test") - html_path = os.path.join(developer_path, "localCoverage/codeCoverage/results/coverage/reports/cxx/html") + html_path = os.path.join(developer_path, "local_coverage/code_coverage/results/coverage/reports/cxx/html") main(html_path) diff --git a/localCoverage/push_coverage_so/__init__.py b/local_coverage/push_coverage_so/__init__.py similarity index 100% rename from localCoverage/push_coverage_so/__init__.py rename to local_coverage/push_coverage_so/__init__.py diff --git a/localCoverage/push_coverage_so/push_coverage.py b/local_coverage/push_coverage_so/push_coverage.py similarity index 97% rename from localCoverage/push_coverage_so/push_coverage.py rename to local_coverage/push_coverage_so/push_coverage.py index 0aa9663..5905d54 100644 --- a/localCoverage/push_coverage_so/push_coverage.py +++ b/local_coverage/push_coverage_so/push_coverage.py @@ -149,8 +149,8 @@ if __name__ == "__main__": current_path = os.path.abspath(os.path.dirname(__name__)) _init_sys_config() - from localCoverage.resident_service.public_method import get_config_ip, get_sn_list - from localCoverage.utils import get_product_name, hdc_command, tree_find_file_endswith,\ + from local_coverage.resident_service.public_method import get_config_ip, get_sn_list + from local_coverage.utils import get_product_name, hdc_command, tree_find_file_endswith,\ json_parse, logger, is_elffile root_path = current_path.split("/test/testfwk/developer_test")[0] diff --git a/localCoverage/resident_service/config/ams/ams.cfg b/local_coverage/resident_service/config/ams/ams.cfg similarity index 97% rename from localCoverage/resident_service/config/ams/ams.cfg rename to local_coverage/resident_service/config/ams/ams.cfg index 0859723..6a54d37 100644 --- a/localCoverage/resident_service/config/ams/ams.cfg +++ b/local_coverage/resident_service/config/ams/ams.cfg @@ -1,50 +1,50 @@ -{ - "jobs": [{ - "name": "services:ams", - "cmds": [ - "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", - "mkdir /data/storage/el1/bundle 0711 system system", - "mkdir /data/storage/el2/base 0711 system system", - "mkdir /data/storage/el2/database 0711 system system", - "mkdir /data/service/el1/public/notification 0711 foundation system", - "mkdir /data/service/el1/public/database 0711 ddms ddms", - "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", - "chown radio system /sys/power/wake_lock", - "chown radio system /sys/power/wake_unlock", - "chmod 0664 /sys/power/wakeup_count" - ] - },{ - "name": "services:restartfoundation", - "cmds": [ - "reset appspawn", - "reset accountmgr" - ] - } - ], - "services": [{ - "name": "ams", - "path": ["/system/bin/sa_main", "/system/profile/ams.xml"], - "critical": [1, 1, 60], - "importance": -20, - "uid": "foundation", - "permission": [ - "ohos.permission.INPUT_MONITORING", - "ohos.permission.PERMISSION_USED_STATS", - "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", - "ohos.permission.DISTRIBUTED_DATASYNC", - "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - "ohos.permission.INSTALL_BUNDLE", - "ohos.permission.MICROPHONE" - ], - "gid": ["system"], - "caps": ["SYS_PTRACE", "KILL"], - "jobs": { - "on-start": "services:ams", - "on-restart": "services:restartfoundation" - }, - "secon": "u:r:foundation:s0" - } - ] +{ + "jobs": [{ + "name": "services:ams", + "cmds": [ + "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", + "mkdir /data/storage/el1/bundle 0711 system system", + "mkdir /data/storage/el2/base 0711 system system", + "mkdir /data/storage/el2/database 0711 system system", + "mkdir /data/service/el1/public/notification 0711 foundation system", + "mkdir /data/service/el1/public/database 0711 ddms ddms", + "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", + "chown radio system /sys/power/wake_lock", + "chown radio system /sys/power/wake_unlock", + "chmod 0664 /sys/power/wakeup_count" + ] + },{ + "name": "services:restartfoundation", + "cmds": [ + "reset appspawn", + "reset accountmgr" + ] + } + ], + "services": [{ + "name": "ams", + "path": ["/system/bin/sa_main", "/system/profile/ams.xml"], + "critical": [1, 1, 60], + "importance": -20, + "uid": "foundation", + "permission": [ + "ohos.permission.INPUT_MONITORING", + "ohos.permission.PERMISSION_USED_STATS", + "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", + "ohos.permission.DISTRIBUTED_DATASYNC", + "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "ohos.permission.INSTALL_BUNDLE", + "ohos.permission.MICROPHONE" + ], + "gid": ["system"], + "caps": ["SYS_PTRACE", "KILL"], + "jobs": { + "on-start": "services:ams", + "on-restart": "services:restartfoundation" + }, + "secon": "u:r:foundation:s0" + } + ] } \ No newline at end of file diff --git a/localCoverage/resident_service/config/ams/ams.xml b/local_coverage/resident_service/config/ams/ams.xml similarity index 96% rename from localCoverage/resident_service/config/ams/ams.xml rename to local_coverage/resident_service/config/ams/ams.xml index 64894c7..e5a03b3 100644 --- a/localCoverage/resident_service/config/ams/ams.xml +++ b/local_coverage/resident_service/config/ams/ams.xml @@ -1,64 +1,64 @@ - - - - foundation - - - /system/lib64/libabilityms.z.so - /system/lib64/libdataobsms.z.so - /system/lib64/libupms.z.so - /system/lib64/libappms.z.so - - - - - 180 - /system/lib64/libabilityms.z.so - - - true - false - 1 - - - 182 - /system/lib64/libdataobsms.z.so - - - true - false - 1 - - - 183 - /system/lib64/libupms.z.so - - - true - false - 1 - - - 501 - /system/lib64/libappms.z.so - - - true - false - 1 - - + + + + foundation + + + /system/lib64/libabilityms.z.so + /system/lib64/libdataobsms.z.so + /system/lib64/libupms.z.so + /system/lib64/libappms.z.so + + + + + 180 + /system/lib64/libabilityms.z.so + + + true + false + 1 + + + 182 + /system/lib64/libdataobsms.z.so + + + true + false + 1 + + + 183 + /system/lib64/libupms.z.so + + + true + false + 1 + + + 501 + /system/lib64/libappms.z.so + + + true + false + 1 + + \ No newline at end of file diff --git a/localCoverage/resident_service/config/ams/foundation.xml b/local_coverage/resident_service/config/ams/foundation.xml similarity index 97% rename from localCoverage/resident_service/config/ams/foundation.xml rename to local_coverage/resident_service/config/ams/foundation.xml index 11d2a92..deda782 100644 --- a/localCoverage/resident_service/config/ams/foundation.xml +++ b/local_coverage/resident_service/config/ams/foundation.xml @@ -1,128 +1,128 @@ - - - - foundation - - /system/lib64/libcesfwk_services.z.so - libans.z.so - libbatteryservice.z.so - libdisplaymgrservice.z.so - libpowermgrservice.z.so - libtel_call_manager.z.so - libtel_state_registry.z.so - - - - - /system/lib64/libfms.z.so - /system/lib64/libbms.z.so - libwms.z.so - - - 401 - /system/lib64/libbms.z.so - 1301 - 60000 - true - false - 1 - CoreStartPhase - - - 4606 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 4607 - libwms.z.so - true - false - 1 - CoreStartPhase - - - 3299 - /system/lib64/libcesfwk_services.z.so - - - true - false - 1 - - - 3203 - libans.z.so - 1301 - 3299 - 5000 - true - false - 1 - - - 3302 - libbatteryservice.z.so - true - false - 1 - - - 3308 - libdisplaymgrservice.z.so - - - true - false - 1 - - - 3301 - libpowermgrservice.z.so - true - false - 1 - - - 4005 - libtel_call_manager.z.so - true - false - 1 - - - 4009 - libtel_state_registry.z.so - true - false - 1 - - - - 403 - /system/lib64/libfms.z.so - - - true - false - 1 - + + + + foundation + + /system/lib64/libcesfwk_services.z.so + libans.z.so + libbatteryservice.z.so + libdisplaymgrservice.z.so + libpowermgrservice.z.so + libtel_call_manager.z.so + libtel_state_registry.z.so + + + + + /system/lib64/libfms.z.so + /system/lib64/libbms.z.so + libwms.z.so + + + 401 + /system/lib64/libbms.z.so + 1301 + 60000 + true + false + 1 + CoreStartPhase + + + 4606 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 4607 + libwms.z.so + true + false + 1 + CoreStartPhase + + + 3299 + /system/lib64/libcesfwk_services.z.so + + + true + false + 1 + + + 3203 + libans.z.so + 1301 + 3299 + 5000 + true + false + 1 + + + 3302 + libbatteryservice.z.so + true + false + 1 + + + 3308 + libdisplaymgrservice.z.so + + + true + false + 1 + + + 3301 + libpowermgrservice.z.so + true + false + 1 + + + 4005 + libtel_call_manager.z.so + true + false + 1 + + + 4009 + libtel_state_registry.z.so + true + false + 1 + + + + 403 + /system/lib64/libfms.z.so + + + true + false + 1 + \ No newline at end of file diff --git a/localCoverage/resident_service/config/bms/bms.cfg b/local_coverage/resident_service/config/bms/bms.cfg similarity index 97% rename from localCoverage/resident_service/config/bms/bms.cfg rename to local_coverage/resident_service/config/bms/bms.cfg index f3da1bf..22830b0 100644 --- a/localCoverage/resident_service/config/bms/bms.cfg +++ b/local_coverage/resident_service/config/bms/bms.cfg @@ -1,50 +1,50 @@ -{ - "jobs": [{ - "name": "services:bms", - "cmds": [ - "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", - "mkdir /data/storage/el1/bundle 0711 system system", - "mkdir /data/storage/el2/base 0711 system system", - "mkdir /data/storage/el2/database 0711 system system", - "mkdir /data/service/el1/public/notification 0711 foundation system", - "mkdir /data/service/el1/public/database 0711 ddms ddms", - "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", - "chown radio system /sys/power/wake_lock", - "chown radio system /sys/power/wake_unlock", - "chmod 0664 /sys/power/wakeup_count" - ] - },{ - "name": "services:restartfoundation", - "cmds": [ - "reset appspawn", - "reset accountmgr" - ] - } - ], - "services": [{ - "name": "bms", - "path": ["/system/bin/sa_main", "/system/profile/bms.xml"], - "critical": [1, 1, 60], - "importance": -20, - "uid": "foundation", - "permission": [ - "ohos.permission.INPUT_MONITORING", - "ohos.permission.PERMISSION_USED_STATS", - "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", - "ohos.permission.DISTRIBUTED_DATASYNC", - "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - "ohos.permission.INSTALL_BUNDLE", - "ohos.permission.MICROPHONE" - ], - "gid": ["system"], - "caps": ["SYS_PTRACE", "KILL"], - "jobs": { - "on-start": "services:bms", - "on-restart": "services:restartfoundation" - }, - "secon": "u:r:foundation:s0" - } - ] +{ + "jobs": [{ + "name": "services:bms", + "cmds": [ + "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", + "mkdir /data/storage/el1/bundle 0711 system system", + "mkdir /data/storage/el2/base 0711 system system", + "mkdir /data/storage/el2/database 0711 system system", + "mkdir /data/service/el1/public/notification 0711 foundation system", + "mkdir /data/service/el1/public/database 0711 ddms ddms", + "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", + "chown radio system /sys/power/wake_lock", + "chown radio system /sys/power/wake_unlock", + "chmod 0664 /sys/power/wakeup_count" + ] + },{ + "name": "services:restartfoundation", + "cmds": [ + "reset appspawn", + "reset accountmgr" + ] + } + ], + "services": [{ + "name": "bms", + "path": ["/system/bin/sa_main", "/system/profile/bms.xml"], + "critical": [1, 1, 60], + "importance": -20, + "uid": "foundation", + "permission": [ + "ohos.permission.INPUT_MONITORING", + "ohos.permission.PERMISSION_USED_STATS", + "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", + "ohos.permission.DISTRIBUTED_DATASYNC", + "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "ohos.permission.INSTALL_BUNDLE", + "ohos.permission.MICROPHONE" + ], + "gid": ["system"], + "caps": ["SYS_PTRACE", "KILL"], + "jobs": { + "on-start": "services:bms", + "on-restart": "services:restartfoundation" + }, + "secon": "u:r:foundation:s0" + } + ] } \ No newline at end of file diff --git a/localCoverage/resident_service/config/bms/bms.xml b/local_coverage/resident_service/config/bms/bms.xml similarity index 97% rename from localCoverage/resident_service/config/bms/bms.xml rename to local_coverage/resident_service/config/bms/bms.xml index d74a33e..3b14f41 100644 --- a/localCoverage/resident_service/config/bms/bms.xml +++ b/local_coverage/resident_service/config/bms/bms.xml @@ -1,34 +1,34 @@ - - - - foundation - - - /system/lib64/libbms.z.so - - - - 401 - /system/lib64/libbms.z.so - 1301 - 60000 - true - false - 1 - CoreStartPhase - - + + + + foundation + + + /system/lib64/libbms.z.so + + + + 401 + /system/lib64/libbms.z.so + 1301 + 60000 + true + false + 1 + CoreStartPhase + + \ No newline at end of file diff --git a/localCoverage/resident_service/config/bms/foundation.xml b/local_coverage/resident_service/config/bms/foundation.xml similarity index 96% rename from localCoverage/resident_service/config/bms/foundation.xml rename to local_coverage/resident_service/config/bms/foundation.xml index c7be367..d9ebf1a 100644 --- a/localCoverage/resident_service/config/bms/foundation.xml +++ b/local_coverage/resident_service/config/bms/foundation.xml @@ -1,156 +1,156 @@ - - - - foundation - - /system/lib64/libcesfwk_services.z.so - libans.z.so - libbatteryservice.z.so - libdisplaymgrservice.z.so - libpowermgrservice.z.so - libtel_call_manager.z.so - libtel_state_registry.z.so - /system/lib64/libabilityms.z.so - /system/lib64/libdataobsms.z.so - /system/lib64/libupms.z.so - /system/lib64/libappms.z.so - /system/lib64/libfms.z.so - - libwms.z.so - - - - 4606 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 4607 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 3299 - /system/lib64/libcesfwk_services.z.so - - - true - false - 1 - - - 3203 - libans.z.so - 1301 - 3299 - 5000 - true - false - 1 - - - 3302 - libbatteryservice.z.so - true - false - 1 - - - 3308 - libdisplaymgrservice.z.so - - - true - false - 1 - - - 3301 - libpowermgrservice.z.so - true - false - 1 - - - 4005 - libtel_call_manager.z.so - true - false - 1 - - - 4009 - libtel_state_registry.z.so - true - false - 1 - - - 180 - /system/lib64/libabilityms.z.so - - - true - false - 1 - - - 182 - /system/lib64/libdataobsms.z.so - - - true - false - 1 - - - 183 - /system/lib64/libupms.z.so - - - true - false - 1 - - - 501 - /system/lib64/libappms.z.so - - - true - false - 1 - - - 403 - /system/lib64/libfms.z.so - - - true - false - 1 - + + + + foundation + + /system/lib64/libcesfwk_services.z.so + libans.z.so + libbatteryservice.z.so + libdisplaymgrservice.z.so + libpowermgrservice.z.so + libtel_call_manager.z.so + libtel_state_registry.z.so + /system/lib64/libabilityms.z.so + /system/lib64/libdataobsms.z.so + /system/lib64/libupms.z.so + /system/lib64/libappms.z.so + /system/lib64/libfms.z.so + + libwms.z.so + + + + 4606 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 4607 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 3299 + /system/lib64/libcesfwk_services.z.so + + + true + false + 1 + + + 3203 + libans.z.so + 1301 + 3299 + 5000 + true + false + 1 + + + 3302 + libbatteryservice.z.so + true + false + 1 + + + 3308 + libdisplaymgrservice.z.so + + + true + false + 1 + + + 3301 + libpowermgrservice.z.so + true + false + 1 + + + 4005 + libtel_call_manager.z.so + true + false + 1 + + + 4009 + libtel_state_registry.z.so + true + false + 1 + + + 180 + /system/lib64/libabilityms.z.so + + + true + false + 1 + + + 182 + /system/lib64/libdataobsms.z.so + + + true + false + 1 + + + 183 + /system/lib64/libupms.z.so + + + true + false + 1 + + + 501 + /system/lib64/libappms.z.so + + + true + false + 1 + + + 403 + /system/lib64/libfms.z.so + + + true + false + 1 + \ No newline at end of file diff --git a/localCoverage/resident_service/config/call/call.cfg b/local_coverage/resident_service/config/call/call.cfg similarity index 97% rename from localCoverage/resident_service/config/call/call.cfg rename to local_coverage/resident_service/config/call/call.cfg index 1d9a890..093320f 100644 --- a/localCoverage/resident_service/config/call/call.cfg +++ b/local_coverage/resident_service/config/call/call.cfg @@ -1,50 +1,50 @@ -{ - "jobs": [{ - "name": "services:call", - "cmds": [ - "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", - "mkdir /data/storage/el1/bundle 0711 system system", - "mkdir /data/storage/el2/base 0711 system system", - "mkdir /data/storage/el2/database 0711 system system", - "mkdir /data/service/el1/public/notification 0711 foundation system", - "mkdir /data/service/el1/public/database 0711 ddms ddms", - "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", - "chown radio system /sys/power/wake_lock", - "chown radio system /sys/power/wake_unlock", - "chmod 0664 /sys/power/wakeup_count" - ] - },{ - "name": "services:restartfoundation", - "cmds": [ - "reset appspawn", - "reset accountmgr" - ] - } - ], - "services": [{ - "name": "call", - "path": ["/system/bin/sa_main", "/system/profile/call.xml"], - "critical": [1, 1, 60], - "importance": -20, - "uid": "foundation", - "permission": [ - "ohos.permission.INPUT_MONITORING", - "ohos.permission.PERMISSION_USED_STATS", - "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", - "ohos.permission.DISTRIBUTED_DATASYNC", - "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - "ohos.permission.INSTALL_BUNDLE", - "ohos.permission.MICROPHONE" - ], - "gid": ["system"], - "caps": ["SYS_PTRACE", "KILL"], - "jobs": { - "on-start": "services:call", - "on-restart": "services:restartfoundation" - }, - "secon": "u:r:foundation:s0" - } - ] +{ + "jobs": [{ + "name": "services:call", + "cmds": [ + "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", + "mkdir /data/storage/el1/bundle 0711 system system", + "mkdir /data/storage/el2/base 0711 system system", + "mkdir /data/storage/el2/database 0711 system system", + "mkdir /data/service/el1/public/notification 0711 foundation system", + "mkdir /data/service/el1/public/database 0711 ddms ddms", + "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", + "chown radio system /sys/power/wake_lock", + "chown radio system /sys/power/wake_unlock", + "chmod 0664 /sys/power/wakeup_count" + ] + },{ + "name": "services:restartfoundation", + "cmds": [ + "reset appspawn", + "reset accountmgr" + ] + } + ], + "services": [{ + "name": "call", + "path": ["/system/bin/sa_main", "/system/profile/call.xml"], + "critical": [1, 1, 60], + "importance": -20, + "uid": "foundation", + "permission": [ + "ohos.permission.INPUT_MONITORING", + "ohos.permission.PERMISSION_USED_STATS", + "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", + "ohos.permission.DISTRIBUTED_DATASYNC", + "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "ohos.permission.INSTALL_BUNDLE", + "ohos.permission.MICROPHONE" + ], + "gid": ["system"], + "caps": ["SYS_PTRACE", "KILL"], + "jobs": { + "on-start": "services:call", + "on-restart": "services:restartfoundation" + }, + "secon": "u:r:foundation:s0" + } + ] } \ No newline at end of file diff --git a/localCoverage/resident_service/config/call/call.xml b/local_coverage/resident_service/config/call/call.xml similarity index 97% rename from localCoverage/resident_service/config/call/call.xml rename to local_coverage/resident_service/config/call/call.xml index e6f850f..8ac5436 100644 --- a/localCoverage/resident_service/config/call/call.xml +++ b/local_coverage/resident_service/config/call/call.xml @@ -1,32 +1,32 @@ - - - - foundation - - - libtel_call_manager.z.so - - - - - 4005 - libtel_call_manager.z.so - true - false - 1 - - + + + + foundation + + + libtel_call_manager.z.so + + + + + 4005 + libtel_call_manager.z.so + true + false + 1 + + \ No newline at end of file diff --git a/localCoverage/resident_service/config/call/foundation.xml b/local_coverage/resident_service/config/call/foundation.xml similarity index 97% rename from localCoverage/resident_service/config/call/foundation.xml rename to local_coverage/resident_service/config/call/foundation.xml index d25e2e2..77adc89 100644 --- a/localCoverage/resident_service/config/call/foundation.xml +++ b/local_coverage/resident_service/config/call/foundation.xml @@ -1,157 +1,157 @@ - - - - foundation - - /system/lib64/libcesfwk_services.z.so - libans.z.so - libbatteryservice.z.so - libdisplaymgrservice.z.so - libpowermgrservice.z.so - libtel_state_registry.z.so - /system/lib64/libabilityms.z.so - /system/lib64/libdataobsms.z.so - /system/lib64/libupms.z.so - /system/lib64/libappms.z.so - /system/lib64/libfms.z.so - /system/lib64/libbms.z.so - libwms.z.so - - - 401 - /system/lib64/libbms.z.so - 1301 - 60000 - true - false - 1 - CoreStartPhase - - - 4606 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 4607 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 3299 - /system/lib64/libcesfwk_services.z.so - - - true - false - 1 - - - 3203 - libans.z.so - 1301 - 3299 - 5000 - true - false - 1 - - - 3302 - libbatteryservice.z.so - true - false - 1 - - - 3308 - libdisplaymgrservice.z.so - - - true - false - 1 - - - 3301 - libpowermgrservice.z.so - true - false - 1 - - - 4009 - libtel_state_registry.z.so - true - false - 1 - - - 180 - /system/lib64/libabilityms.z.so - - - true - false - 1 - - - 182 - /system/lib64/libdataobsms.z.so - - - true - false - 1 - - - 183 - /system/lib64/libupms.z.so - - - true - false - 1 - - - 501 - /system/lib64/libappms.z.so - - - true - false - 1 - - - 403 - /system/lib64/libfms.z.so - - - true - false - 1 - + + + + foundation + + /system/lib64/libcesfwk_services.z.so + libans.z.so + libbatteryservice.z.so + libdisplaymgrservice.z.so + libpowermgrservice.z.so + libtel_state_registry.z.so + /system/lib64/libabilityms.z.so + /system/lib64/libdataobsms.z.so + /system/lib64/libupms.z.so + /system/lib64/libappms.z.so + /system/lib64/libfms.z.so + /system/lib64/libbms.z.so + libwms.z.so + + + 401 + /system/lib64/libbms.z.so + 1301 + 60000 + true + false + 1 + CoreStartPhase + + + 4606 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 4607 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 3299 + /system/lib64/libcesfwk_services.z.so + + + true + false + 1 + + + 3203 + libans.z.so + 1301 + 3299 + 5000 + true + false + 1 + + + 3302 + libbatteryservice.z.so + true + false + 1 + + + 3308 + libdisplaymgrservice.z.so + + + true + false + 1 + + + 3301 + libpowermgrservice.z.so + true + false + 1 + + + 4009 + libtel_state_registry.z.so + true + false + 1 + + + 180 + /system/lib64/libabilityms.z.so + + + true + false + 1 + + + 182 + /system/lib64/libdataobsms.z.so + + + true + false + 1 + + + 183 + /system/lib64/libupms.z.so + + + true + false + 1 + + + 501 + /system/lib64/libappms.z.so + + + true + false + 1 + + + 403 + /system/lib64/libfms.z.so + + + true + false + 1 + \ No newline at end of file diff --git a/localCoverage/resident_service/config/fms/fms.cfg b/local_coverage/resident_service/config/fms/fms.cfg similarity index 97% rename from localCoverage/resident_service/config/fms/fms.cfg rename to local_coverage/resident_service/config/fms/fms.cfg index fa67a1c..dbdea1d 100644 --- a/localCoverage/resident_service/config/fms/fms.cfg +++ b/local_coverage/resident_service/config/fms/fms.cfg @@ -1,50 +1,50 @@ -{ - "jobs": [{ - "name": "services:fms", - "cmds": [ - "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", - "mkdir /data/storage/el1/bundle 0711 system system", - "mkdir /data/storage/el2/base 0711 system system", - "mkdir /data/storage/el2/database 0711 system system", - "mkdir /data/service/el1/public/notification 0711 foundation system", - "mkdir /data/service/el1/public/database 0711 ddms ddms", - "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", - "chown radio system /sys/power/wake_lock", - "chown radio system /sys/power/wake_unlock", - "chmod 0664 /sys/power/wakeup_count" - ] - },{ - "name": "services:restartfoundation", - "cmds": [ - "reset appspawn", - "reset accountmgr" - ] - } - ], - "services": [{ - "name": "fms", - "path": ["/system/bin/sa_main", "/system/profile/fms.xml"], - "critical": [1, 1, 60], - "importance": -20, - "uid": "foundation", - "permission": [ - "ohos.permission.INPUT_MONITORING", - "ohos.permission.PERMISSION_USED_STATS", - "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", - "ohos.permission.DISTRIBUTED_DATASYNC", - "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - "ohos.permission.INSTALL_BUNDLE", - "ohos.permission.MICROPHONE" - ], - "gid": ["system"], - "caps": ["SYS_PTRACE", "KILL"], - "jobs": { - "on-start": "services:fms", - "on-restart": "services:restartfoundation" - }, - "secon": "u:r:foundation:s0" - } - ] +{ + "jobs": [{ + "name": "services:fms", + "cmds": [ + "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", + "mkdir /data/storage/el1/bundle 0711 system system", + "mkdir /data/storage/el2/base 0711 system system", + "mkdir /data/storage/el2/database 0711 system system", + "mkdir /data/service/el1/public/notification 0711 foundation system", + "mkdir /data/service/el1/public/database 0711 ddms ddms", + "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", + "chown radio system /sys/power/wake_lock", + "chown radio system /sys/power/wake_unlock", + "chmod 0664 /sys/power/wakeup_count" + ] + },{ + "name": "services:restartfoundation", + "cmds": [ + "reset appspawn", + "reset accountmgr" + ] + } + ], + "services": [{ + "name": "fms", + "path": ["/system/bin/sa_main", "/system/profile/fms.xml"], + "critical": [1, 1, 60], + "importance": -20, + "uid": "foundation", + "permission": [ + "ohos.permission.INPUT_MONITORING", + "ohos.permission.PERMISSION_USED_STATS", + "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", + "ohos.permission.DISTRIBUTED_DATASYNC", + "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "ohos.permission.INSTALL_BUNDLE", + "ohos.permission.MICROPHONE" + ], + "gid": ["system"], + "caps": ["SYS_PTRACE", "KILL"], + "jobs": { + "on-start": "services:fms", + "on-restart": "services:restartfoundation" + }, + "secon": "u:r:foundation:s0" + } + ] } \ No newline at end of file diff --git a/localCoverage/resident_service/config/fms/fms.xml b/local_coverage/resident_service/config/fms/fms.xml similarity index 97% rename from localCoverage/resident_service/config/fms/fms.xml rename to local_coverage/resident_service/config/fms/fms.xml index e5f5211..bd7a5cf 100644 --- a/localCoverage/resident_service/config/fms/fms.xml +++ b/local_coverage/resident_service/config/fms/fms.xml @@ -1,33 +1,33 @@ - - - - foundation - - - /system/lib64/libfms.z.so - - - - - 403 - /system/lib64/libfms.z.so - - true - false - 1 - - + + + + foundation + + + /system/lib64/libfms.z.so + + + + + 403 + /system/lib64/libfms.z.so + + true + false + 1 + + \ No newline at end of file diff --git a/localCoverage/resident_service/config/fms/foundation.xml b/local_coverage/resident_service/config/fms/foundation.xml similarity index 97% rename from localCoverage/resident_service/config/fms/foundation.xml rename to local_coverage/resident_service/config/fms/foundation.xml index b4514eb..a34b1ba 100644 --- a/localCoverage/resident_service/config/fms/foundation.xml +++ b/local_coverage/resident_service/config/fms/foundation.xml @@ -1,156 +1,156 @@ - - - - foundation - - /system/lib64/libcesfwk_services.z.so - libans.z.so - libbatteryservice.z.so - libdisplaymgrservice.z.so - libpowermgrservice.z.so - libtel_call_manager.z.so - libtel_state_registry.z.so - /system/lib64/libabilityms.z.so - /system/lib64/libdataobsms.z.so - /system/lib64/libupms.z.so - /system/lib64/libappms.z.so - /system/lib64/libbms.z.so - - libwms.z.so - - - 401 - /system/lib64/libbms.z.so - 1301 - 60000 - true - false - 1 - CoreStartPhase - - - 4606 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 4607 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 3299 - /system/lib64/libcesfwk_services.z.so - - - true - false - 1 - - - 3203 - libans.z.so - 1301 - 3299 - 5000 - true - false - 1 - - - 3302 - libbatteryservice.z.so - true - false - 1 - - - 3308 - libdisplaymgrservice.z.so - - - true - false - 1 - - - 3301 - libpowermgrservice.z.so - true - false - 1 - - - 4005 - libtel_call_manager.z.so - true - false - 1 - - - 4009 - libtel_state_registry.z.so - true - false - 1 - - - 180 - /system/lib64/libabilityms.z.so - - - true - false - 1 - - - 182 - /system/lib64/libdataobsms.z.so - - - true - false - 1 - - - 183 - /system/lib64/libupms.z.so - - - true - false - 1 - - - 501 - /system/lib64/libappms.z.so - - - true - false - 1 - + + + + foundation + + /system/lib64/libcesfwk_services.z.so + libans.z.so + libbatteryservice.z.so + libdisplaymgrservice.z.so + libpowermgrservice.z.so + libtel_call_manager.z.so + libtel_state_registry.z.so + /system/lib64/libabilityms.z.so + /system/lib64/libdataobsms.z.so + /system/lib64/libupms.z.so + /system/lib64/libappms.z.so + /system/lib64/libbms.z.so + + libwms.z.so + + + 401 + /system/lib64/libbms.z.so + 1301 + 60000 + true + false + 1 + CoreStartPhase + + + 4606 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 4607 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 3299 + /system/lib64/libcesfwk_services.z.so + + + true + false + 1 + + + 3203 + libans.z.so + 1301 + 3299 + 5000 + true + false + 1 + + + 3302 + libbatteryservice.z.so + true + false + 1 + + + 3308 + libdisplaymgrservice.z.so + + + true + false + 1 + + + 3301 + libpowermgrservice.z.so + true + false + 1 + + + 4005 + libtel_call_manager.z.so + true + false + 1 + + + 4009 + libtel_state_registry.z.so + true + false + 1 + + + 180 + /system/lib64/libabilityms.z.so + + + true + false + 1 + + + 182 + /system/lib64/libdataobsms.z.so + + + true + false + 1 + + + 183 + /system/lib64/libupms.z.so + + + true + false + 1 + + + 501 + /system/lib64/libappms.z.so + + + true + false + 1 + \ No newline at end of file diff --git a/localCoverage/resident_service/config/notification/foundation.xml b/local_coverage/resident_service/config/notification/foundation.xml similarity index 97% rename from localCoverage/resident_service/config/notification/foundation.xml rename to local_coverage/resident_service/config/notification/foundation.xml index 1951918..02406de 100644 --- a/localCoverage/resident_service/config/notification/foundation.xml +++ b/local_coverage/resident_service/config/notification/foundation.xml @@ -1,144 +1,144 @@ - - - - foundation - - libbatteryservice.z.so - libdisplaymgrservice.z.so - libpowermgrservice.z.so - libtel_call_manager.z.so - libtel_state_registry.z.so - /system/lib64/libabilityms.z.so - /system/lib64/libdataobsms.z.so - /system/lib64/libupms.z.so - /system/lib64/libappms.z.so - /system/lib64/libfms.z.so - /system/lib64/libbms.z.so - libwms.z.so - - - 401 - /system/lib64/libbms.z.so - 1301 - 60000 - true - false - 1 - CoreStartPhase - - - 4606 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 4607 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 3302 - libbatteryservice.z.so - true - false - 1 - - - 3308 - libdisplaymgrservice.z.so - - - true - false - 1 - - - 3301 - libpowermgrservice.z.so - true - false - 1 - - - 4005 - libtel_call_manager.z.so - true - false - 1 - - - 4009 - libtel_state_registry.z.so - true - false - 1 - - - 180 - /system/lib64/libabilityms.z.so - - - true - false - 1 - - - 182 - /system/lib64/libdataobsms.z.so - - - true - false - 1 - - - 183 - /system/lib64/libupms.z.so - - - true - false - 1 - - - 501 - /system/lib64/libappms.z.so - - - true - false - 1 - - - 403 - /system/lib64/libfms.z.so - - - true - false - 1 - + + + + foundation + + libbatteryservice.z.so + libdisplaymgrservice.z.so + libpowermgrservice.z.so + libtel_call_manager.z.so + libtel_state_registry.z.so + /system/lib64/libabilityms.z.so + /system/lib64/libdataobsms.z.so + /system/lib64/libupms.z.so + /system/lib64/libappms.z.so + /system/lib64/libfms.z.so + /system/lib64/libbms.z.so + libwms.z.so + + + 401 + /system/lib64/libbms.z.so + 1301 + 60000 + true + false + 1 + CoreStartPhase + + + 4606 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 4607 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 3302 + libbatteryservice.z.so + true + false + 1 + + + 3308 + libdisplaymgrservice.z.so + + + true + false + 1 + + + 3301 + libpowermgrservice.z.so + true + false + 1 + + + 4005 + libtel_call_manager.z.so + true + false + 1 + + + 4009 + libtel_state_registry.z.so + true + false + 1 + + + 180 + /system/lib64/libabilityms.z.so + + + true + false + 1 + + + 182 + /system/lib64/libdataobsms.z.so + + + true + false + 1 + + + 183 + /system/lib64/libupms.z.so + + + true + false + 1 + + + 501 + /system/lib64/libappms.z.so + + + true + false + 1 + + + 403 + /system/lib64/libfms.z.so + + + true + false + 1 + \ No newline at end of file diff --git a/localCoverage/resident_service/config/notification/notification.cfg b/local_coverage/resident_service/config/notification/notification.cfg similarity index 97% rename from localCoverage/resident_service/config/notification/notification.cfg rename to local_coverage/resident_service/config/notification/notification.cfg index 19528f2..1f63d81 100644 --- a/localCoverage/resident_service/config/notification/notification.cfg +++ b/local_coverage/resident_service/config/notification/notification.cfg @@ -1,50 +1,50 @@ -{ - "jobs": [{ - "name": "services:notification", - "cmds": [ - "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", - "mkdir /data/storage/el1/bundle 0711 system system", - "mkdir /data/storage/el2/base 0711 system system", - "mkdir /data/storage/el2/database 0711 system system", - "mkdir /data/service/el1/public/notification 0711 foundation system", - "mkdir /data/service/el1/public/database 0711 ddms ddms", - "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", - "chown radio system /sys/power/wake_lock", - "chown radio system /sys/power/wake_unlock", - "chmod 0664 /sys/power/wakeup_count" - ] - },{ - "name": "services:restartfoundation", - "cmds": [ - "reset appspawn", - "reset accountmgr" - ] - } - ], - "services": [{ - "name": "notification", - "path": ["/system/bin/sa_main", "/system/profile/notification.xml"], - "critical": [1, 1, 60], - "importance": -20, - "uid": "foundation", - "permission": [ - "ohos.permission.INPUT_MONITORING", - "ohos.permission.PERMISSION_USED_STATS", - "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", - "ohos.permission.DISTRIBUTED_DATASYNC", - "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - "ohos.permission.INSTALL_BUNDLE", - "ohos.permission.MICROPHONE" - ], - "gid": ["system"], - "caps": ["SYS_PTRACE", "KILL"], - "jobs": { - "on-start": "services:notification", - "on-restart": "services:restartfoundation" - }, - "secon": "u:r:foundation:s0" - } - ] +{ + "jobs": [{ + "name": "services:notification", + "cmds": [ + "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", + "mkdir /data/storage/el1/bundle 0711 system system", + "mkdir /data/storage/el2/base 0711 system system", + "mkdir /data/storage/el2/database 0711 system system", + "mkdir /data/service/el1/public/notification 0711 foundation system", + "mkdir /data/service/el1/public/database 0711 ddms ddms", + "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", + "chown radio system /sys/power/wake_lock", + "chown radio system /sys/power/wake_unlock", + "chmod 0664 /sys/power/wakeup_count" + ] + },{ + "name": "services:restartfoundation", + "cmds": [ + "reset appspawn", + "reset accountmgr" + ] + } + ], + "services": [{ + "name": "notification", + "path": ["/system/bin/sa_main", "/system/profile/notification.xml"], + "critical": [1, 1, 60], + "importance": -20, + "uid": "foundation", + "permission": [ + "ohos.permission.INPUT_MONITORING", + "ohos.permission.PERMISSION_USED_STATS", + "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", + "ohos.permission.DISTRIBUTED_DATASYNC", + "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "ohos.permission.INSTALL_BUNDLE", + "ohos.permission.MICROPHONE" + ], + "gid": ["system"], + "caps": ["SYS_PTRACE", "KILL"], + "jobs": { + "on-start": "services:notification", + "on-restart": "services:restartfoundation" + }, + "secon": "u:r:foundation:s0" + } + ] } \ No newline at end of file diff --git a/localCoverage/resident_service/config/notification/notification.xml b/local_coverage/resident_service/config/notification/notification.xml similarity index 97% rename from localCoverage/resident_service/config/notification/notification.xml rename to local_coverage/resident_service/config/notification/notification.xml index cc6ad89..72b7394 100644 --- a/localCoverage/resident_service/config/notification/notification.xml +++ b/local_coverage/resident_service/config/notification/notification.xml @@ -1,44 +1,44 @@ - - - - foundation - - - /system/lib64/libcesfwk_services.z.so - libans.z.so - - - - 3299 - /system/lib64/libcesfwk_services.z.so - - - true - false - 1 - - - 3203 - libans.z.so - 1301 - 3299 - 5000 - true - false - 1 - - + + + + foundation + + + /system/lib64/libcesfwk_services.z.so + libans.z.so + + + + 3299 + /system/lib64/libcesfwk_services.z.so + + + true + false + 1 + + + 3203 + libans.z.so + 1301 + 3299 + 5000 + true + false + 1 + + \ No newline at end of file diff --git a/localCoverage/resident_service/config/power/foundation.xml b/local_coverage/resident_service/config/power/foundation.xml similarity index 97% rename from localCoverage/resident_service/config/power/foundation.xml rename to local_coverage/resident_service/config/power/foundation.xml index 38a0e7f..b35a8c0 100644 --- a/localCoverage/resident_service/config/power/foundation.xml +++ b/local_coverage/resident_service/config/power/foundation.xml @@ -1,139 +1,139 @@ - - - - foundation - - /system/lib64/libcesfwk_services.z.so - libans.z.so - libtel_call_manager.z.so - libtel_state_registry.z.so - /system/lib64/libabilityms.z.so - /system/lib64/libdataobsms.z.so - /system/lib64/libupms.z.so - /system/lib64/libappms.z.so - /system/lib64/libfms.z.so - /system/lib64/libbms.z.so - libwms.z.so - - - 401 - /system/lib64/libbms.z.so - 1301 - 60000 - true - false - 1 - CoreStartPhase - - - 4606 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 4607 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 3299 - /system/lib64/libcesfwk_services.z.so - - - true - false - 1 - - - 3203 - libans.z.so - 1301 - 3299 - 5000 - true - false - 1 - - - 4005 - libtel_call_manager.z.so - true - false - 1 - - - 4009 - libtel_state_registry.z.so - true - false - 1 - - - 180 - /system/lib64/libabilityms.z.so - - - true - false - 1 - - - 182 - /system/lib64/libdataobsms.z.so - - - true - false - 1 - - - 183 - /system/lib64/libupms.z.so - - - true - false - 1 - - - 501 - /system/lib64/libappms.z.so - - - true - false - 1 - - - 403 - /system/lib64/libfms.z.so - - - true - false - 1 - + + + + foundation + + /system/lib64/libcesfwk_services.z.so + libans.z.so + libtel_call_manager.z.so + libtel_state_registry.z.so + /system/lib64/libabilityms.z.so + /system/lib64/libdataobsms.z.so + /system/lib64/libupms.z.so + /system/lib64/libappms.z.so + /system/lib64/libfms.z.so + /system/lib64/libbms.z.so + libwms.z.so + + + 401 + /system/lib64/libbms.z.so + 1301 + 60000 + true + false + 1 + CoreStartPhase + + + 4606 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 4607 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 3299 + /system/lib64/libcesfwk_services.z.so + + + true + false + 1 + + + 3203 + libans.z.so + 1301 + 3299 + 5000 + true + false + 1 + + + 4005 + libtel_call_manager.z.so + true + false + 1 + + + 4009 + libtel_state_registry.z.so + true + false + 1 + + + 180 + /system/lib64/libabilityms.z.so + + + true + false + 1 + + + 182 + /system/lib64/libdataobsms.z.so + + + true + false + 1 + + + 183 + /system/lib64/libupms.z.so + + + true + false + 1 + + + 501 + /system/lib64/libappms.z.so + + + true + false + 1 + + + 403 + /system/lib64/libfms.z.so + + + true + false + 1 + \ No newline at end of file diff --git a/localCoverage/resident_service/config/power/power.cfg b/local_coverage/resident_service/config/power/power.cfg similarity index 97% rename from localCoverage/resident_service/config/power/power.cfg rename to local_coverage/resident_service/config/power/power.cfg index 216fd27..d7c97e9 100644 --- a/localCoverage/resident_service/config/power/power.cfg +++ b/local_coverage/resident_service/config/power/power.cfg @@ -1,50 +1,50 @@ -{ - "jobs": [{ - "name": "services:power", - "cmds": [ - "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", - "mkdir /data/storage/el1/bundle 0711 system system", - "mkdir /data/storage/el2/base 0711 system system", - "mkdir /data/storage/el2/database 0711 system system", - "mkdir /data/service/el1/public/notification 0711 foundation system", - "mkdir /data/service/el1/public/database 0711 ddms ddms", - "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", - "chown radio system /sys/power/wake_lock", - "chown radio system /sys/power/wake_unlock", - "chmod 0664 /sys/power/wakeup_count" - ] - },{ - "name": "services:restartfoundation", - "cmds": [ - "reset appspawn", - "reset accountmgr" - ] - } - ], - "services": [{ - "name": "power", - "path": ["/system/bin/sa_main", "/system/profile/power.xml"], - "critical": [1, 1, 60], - "importance": -20, - "uid": "foundation", - "permission": [ - "ohos.permission.INPUT_MONITORING", - "ohos.permission.PERMISSION_USED_STATS", - "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", - "ohos.permission.DISTRIBUTED_DATASYNC", - "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - "ohos.permission.INSTALL_BUNDLE", - "ohos.permission.MICROPHONE" - ], - "gid": ["system"], - "caps": ["SYS_PTRACE", "KILL"], - "jobs": { - "on-start": "services:power", - "on-restart": "services:restartfoundation" - }, - "secon": "u:r:foundation:s0" - } - ] +{ + "jobs": [{ + "name": "services:power", + "cmds": [ + "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", + "mkdir /data/storage/el1/bundle 0711 system system", + "mkdir /data/storage/el2/base 0711 system system", + "mkdir /data/storage/el2/database 0711 system system", + "mkdir /data/service/el1/public/notification 0711 foundation system", + "mkdir /data/service/el1/public/database 0711 ddms ddms", + "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", + "chown radio system /sys/power/wake_lock", + "chown radio system /sys/power/wake_unlock", + "chmod 0664 /sys/power/wakeup_count" + ] + },{ + "name": "services:restartfoundation", + "cmds": [ + "reset appspawn", + "reset accountmgr" + ] + } + ], + "services": [{ + "name": "power", + "path": ["/system/bin/sa_main", "/system/profile/power.xml"], + "critical": [1, 1, 60], + "importance": -20, + "uid": "foundation", + "permission": [ + "ohos.permission.INPUT_MONITORING", + "ohos.permission.PERMISSION_USED_STATS", + "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", + "ohos.permission.DISTRIBUTED_DATASYNC", + "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "ohos.permission.INSTALL_BUNDLE", + "ohos.permission.MICROPHONE" + ], + "gid": ["system"], + "caps": ["SYS_PTRACE", "KILL"], + "jobs": { + "on-start": "services:power", + "on-restart": "services:restartfoundation" + }, + "secon": "u:r:foundation:s0" + } + ] } \ No newline at end of file diff --git a/localCoverage/resident_service/config/power/power.xml b/local_coverage/resident_service/config/power/power.xml similarity index 97% rename from localCoverage/resident_service/config/power/power.xml rename to local_coverage/resident_service/config/power/power.xml index 04e901a..20a473b 100644 --- a/localCoverage/resident_service/config/power/power.xml +++ b/local_coverage/resident_service/config/power/power.xml @@ -1,64 +1,64 @@ - - - - foundation - - - libbatteryservice.z.so - libdisplaymgrservice.z.so - libpowermgrservice.z.so - libthermalservice.z.so - libbatterystats_service.z.so - - - - - 3302 - libbatteryservice.z.so - true - false - 1 - - - 3308 - libdisplaymgrservice.z.so - true - false - 1 - - - 3301 - libpowermgrservice.z.so - true - false - 1 - - - 3303 - libthermalservice.z.so - true - false - 1 - - - 3304 - libbatterystats_service.z.so - true - false - 1 - - + + + + foundation + + + libbatteryservice.z.so + libdisplaymgrservice.z.so + libpowermgrservice.z.so + libthermalservice.z.so + libbatterystats_service.z.so + + + + + 3302 + libbatteryservice.z.so + true + false + 1 + + + 3308 + libdisplaymgrservice.z.so + true + false + 1 + + + 3301 + libpowermgrservice.z.so + true + false + 1 + + + 3303 + libthermalservice.z.so + true + false + 1 + + + 3304 + libbatterystats_service.z.so + true + false + 1 + + \ No newline at end of file diff --git a/localCoverage/resident_service/config/state/foundation.xml b/local_coverage/resident_service/config/state/foundation.xml similarity index 97% rename from localCoverage/resident_service/config/state/foundation.xml rename to local_coverage/resident_service/config/state/foundation.xml index 864ada0..e227109 100644 --- a/localCoverage/resident_service/config/state/foundation.xml +++ b/local_coverage/resident_service/config/state/foundation.xml @@ -1,157 +1,157 @@ - - - - foundation - - /system/lib64/libcesfwk_services.z.so - libans.z.so - libbatteryservice.z.so - libdisplaymgrservice.z.so - libpowermgrservice.z.so - libtel_call_manager.z.so - /system/lib64/libabilityms.z.so - /system/lib64/libdataobsms.z.so - /system/lib64/libupms.z.so - /system/lib64/libappms.z.so - /system/lib64/libfms.z.so - /system/lib64/libbms.z.so - libwms.z.so - - - 401 - /system/lib64/libbms.z.so - 1301 - 60000 - true - false - 1 - CoreStartPhase - - - 4606 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 4607 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 3299 - /system/lib64/libcesfwk_services.z.so - - - true - false - 1 - - - 3203 - libans.z.so - 1301 - 3299 - 5000 - true - false - 1 - - - 3302 - libbatteryservice.z.so - true - false - 1 - - - 3308 - libdisplaymgrservice.z.so - - - true - false - 1 - - - 3301 - libpowermgrservice.z.so - true - false - 1 - - - 4005 - libtel_call_manager.z.so - true - false - 1 - - - 180 - /system/lib64/libabilityms.z.so - - - true - false - 1 - - - 182 - /system/lib64/libdataobsms.z.so - - - true - false - 1 - - - 183 - /system/lib64/libupms.z.so - - - true - false - 1 - - - 501 - /system/lib64/libappms.z.so - - - true - false - 1 - - - 403 - /system/lib64/libfms.z.so - - - true - false - 1 - + + + + foundation + + /system/lib64/libcesfwk_services.z.so + libans.z.so + libbatteryservice.z.so + libdisplaymgrservice.z.so + libpowermgrservice.z.so + libtel_call_manager.z.so + /system/lib64/libabilityms.z.so + /system/lib64/libdataobsms.z.so + /system/lib64/libupms.z.so + /system/lib64/libappms.z.so + /system/lib64/libfms.z.so + /system/lib64/libbms.z.so + libwms.z.so + + + 401 + /system/lib64/libbms.z.so + 1301 + 60000 + true + false + 1 + CoreStartPhase + + + 4606 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 4607 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 3299 + /system/lib64/libcesfwk_services.z.so + + + true + false + 1 + + + 3203 + libans.z.so + 1301 + 3299 + 5000 + true + false + 1 + + + 3302 + libbatteryservice.z.so + true + false + 1 + + + 3308 + libdisplaymgrservice.z.so + + + true + false + 1 + + + 3301 + libpowermgrservice.z.so + true + false + 1 + + + 4005 + libtel_call_manager.z.so + true + false + 1 + + + 180 + /system/lib64/libabilityms.z.so + + + true + false + 1 + + + 182 + /system/lib64/libdataobsms.z.so + + + true + false + 1 + + + 183 + /system/lib64/libupms.z.so + + + true + false + 1 + + + 501 + /system/lib64/libappms.z.so + + + true + false + 1 + + + 403 + /system/lib64/libfms.z.so + + + true + false + 1 + \ No newline at end of file diff --git a/localCoverage/resident_service/config/state/state.cfg b/local_coverage/resident_service/config/state/state.cfg similarity index 97% rename from localCoverage/resident_service/config/state/state.cfg rename to local_coverage/resident_service/config/state/state.cfg index 95c3172..a3d88b2 100644 --- a/localCoverage/resident_service/config/state/state.cfg +++ b/local_coverage/resident_service/config/state/state.cfg @@ -1,50 +1,50 @@ -{ - "jobs": [{ - "name": "services:state", - "cmds": [ - "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", - "mkdir /data/storage/el1/bundle 0711 system system", - "mkdir /data/storage/el2/base 0711 system system", - "mkdir /data/storage/el2/database 0711 system system", - "mkdir /data/service/el1/public/notification 0711 foundation system", - "mkdir /data/service/el1/public/database 0711 ddms ddms", - "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", - "chown radio system /sys/power/wake_lock", - "chown radio system /sys/power/wake_unlock", - "chmod 0664 /sys/power/wakeup_count" - ] - },{ - "name": "services:restartfoundation", - "cmds": [ - "reset appspawn", - "reset accountmgr" - ] - } - ], - "services": [{ - "name": "state", - "path": ["/system/bin/sa_main", "/system/profile/state.xml"], - "critical": [1, 1, 60], - "importance": -20, - "uid": "foundation", - "permission": [ - "ohos.permission.INPUT_MONITORING", - "ohos.permission.PERMISSION_USED_STATS", - "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", - "ohos.permission.DISTRIBUTED_DATASYNC", - "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - "ohos.permission.INSTALL_BUNDLE", - "ohos.permission.MICROPHONE" - ], - "gid": ["system"], - "caps": ["SYS_PTRACE", "KILL"], - "jobs": { - "on-start": "services:state", - "on-restart": "services:restartfoundation" - }, - "secon": "u:r:foundation:s0" - } - ] +{ + "jobs": [{ + "name": "services:state", + "cmds": [ + "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", + "mkdir /data/storage/el1/bundle 0711 system system", + "mkdir /data/storage/el2/base 0711 system system", + "mkdir /data/storage/el2/database 0711 system system", + "mkdir /data/service/el1/public/notification 0711 foundation system", + "mkdir /data/service/el1/public/database 0711 ddms ddms", + "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", + "chown radio system /sys/power/wake_lock", + "chown radio system /sys/power/wake_unlock", + "chmod 0664 /sys/power/wakeup_count" + ] + },{ + "name": "services:restartfoundation", + "cmds": [ + "reset appspawn", + "reset accountmgr" + ] + } + ], + "services": [{ + "name": "state", + "path": ["/system/bin/sa_main", "/system/profile/state.xml"], + "critical": [1, 1, 60], + "importance": -20, + "uid": "foundation", + "permission": [ + "ohos.permission.INPUT_MONITORING", + "ohos.permission.PERMISSION_USED_STATS", + "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", + "ohos.permission.DISTRIBUTED_DATASYNC", + "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "ohos.permission.INSTALL_BUNDLE", + "ohos.permission.MICROPHONE" + ], + "gid": ["system"], + "caps": ["SYS_PTRACE", "KILL"], + "jobs": { + "on-start": "services:state", + "on-restart": "services:restartfoundation" + }, + "secon": "u:r:foundation:s0" + } + ] } \ No newline at end of file diff --git a/localCoverage/resident_service/config/state/state.xml b/local_coverage/resident_service/config/state/state.xml similarity index 97% rename from localCoverage/resident_service/config/state/state.xml rename to local_coverage/resident_service/config/state/state.xml index 0ddb3d9..0fa5973 100644 --- a/localCoverage/resident_service/config/state/state.xml +++ b/local_coverage/resident_service/config/state/state.xml @@ -1,32 +1,32 @@ - - - - foundation - - - libtel_state_registry.z.so - - - - - 4009 - libtel_state_registry.z.so - true - false - 1 - - + + + + foundation + + + libtel_state_registry.z.so + + + + + 4009 + libtel_state_registry.z.so + true + false + 1 + + \ No newline at end of file diff --git a/localCoverage/resident_service/config/wms/foundation.xml b/local_coverage/resident_service/config/wms/foundation.xml similarity index 97% rename from localCoverage/resident_service/config/wms/foundation.xml rename to local_coverage/resident_service/config/wms/foundation.xml index 9cc0818..2baf184 100644 --- a/localCoverage/resident_service/config/wms/foundation.xml +++ b/local_coverage/resident_service/config/wms/foundation.xml @@ -1,146 +1,146 @@ - - - - foundation - - /system/lib64/libcesfwk_services.z.so - libans.z.so - libbatteryservice.z.so - libdisplaymgrservice.z.so - libpowermgrservice.z.so - libtel_call_manager.z.so - libtel_state_registry.z.so - /system/lib64/libabilityms.z.so - /system/lib64/libdataobsms.z.so - /system/lib64/libupms.z.so - /system/lib64/libappms.z.so - /system/lib64/libfms.z.so - /system/lib64/libbms.z.so - - - - - 401 - /system/lib64/libbms.z.so - 1301 - 60000 - true - false - 1 - CoreStartPhase - - - 3299 - /system/lib64/libcesfwk_services.z.so - - - true - false - 1 - - - 3203 - libans.z.so - 1301 - 3299 - 5000 - true - false - 1 - - - 3302 - libbatteryservice.z.so - true - false - 1 - - - 3308 - libdisplaymgrservice.z.so - - - true - false - 1 - - - 3301 - libpowermgrservice.z.so - true - false - 1 - - - 4005 - libtel_call_manager.z.so - true - false - 1 - - - 4009 - libtel_state_registry.z.so - true - false - 1 - - - 180 - /system/lib64/libabilityms.z.so - - - true - false - 1 - - - 182 - /system/lib64/libdataobsms.z.so - - - true - false - 1 - - - 183 - /system/lib64/libupms.z.so - - - true - false - 1 - - - 501 - /system/lib64/libappms.z.so - - - true - false - 1 - - - 403 - /system/lib64/libfms.z.so - - - true - false - 1 - + + + + foundation + + /system/lib64/libcesfwk_services.z.so + libans.z.so + libbatteryservice.z.so + libdisplaymgrservice.z.so + libpowermgrservice.z.so + libtel_call_manager.z.so + libtel_state_registry.z.so + /system/lib64/libabilityms.z.so + /system/lib64/libdataobsms.z.so + /system/lib64/libupms.z.so + /system/lib64/libappms.z.so + /system/lib64/libfms.z.so + /system/lib64/libbms.z.so + + + + + 401 + /system/lib64/libbms.z.so + 1301 + 60000 + true + false + 1 + CoreStartPhase + + + 3299 + /system/lib64/libcesfwk_services.z.so + + + true + false + 1 + + + 3203 + libans.z.so + 1301 + 3299 + 5000 + true + false + 1 + + + 3302 + libbatteryservice.z.so + true + false + 1 + + + 3308 + libdisplaymgrservice.z.so + + + true + false + 1 + + + 3301 + libpowermgrservice.z.so + true + false + 1 + + + 4005 + libtel_call_manager.z.so + true + false + 1 + + + 4009 + libtel_state_registry.z.so + true + false + 1 + + + 180 + /system/lib64/libabilityms.z.so + + + true + false + 1 + + + 182 + /system/lib64/libdataobsms.z.so + + + true + false + 1 + + + 183 + /system/lib64/libupms.z.so + + + true + false + 1 + + + 501 + /system/lib64/libappms.z.so + + + true + false + 1 + + + 403 + /system/lib64/libfms.z.so + + + true + false + 1 + \ No newline at end of file diff --git a/localCoverage/resident_service/config/wms/wms.cfg b/local_coverage/resident_service/config/wms/wms.cfg similarity index 97% rename from localCoverage/resident_service/config/wms/wms.cfg rename to local_coverage/resident_service/config/wms/wms.cfg index 8c8ccfc..468cb03 100644 --- a/localCoverage/resident_service/config/wms/wms.cfg +++ b/local_coverage/resident_service/config/wms/wms.cfg @@ -1,50 +1,50 @@ -{ - "jobs": [{ - "name": "services:wms", - "cmds": [ - "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", - "mkdir /data/storage/el1/bundle 0711 system system", - "mkdir /data/storage/el2/base 0711 system system", - "mkdir /data/storage/el2/database 0711 system system", - "mkdir /data/service/el1/public/notification 0711 foundation system", - "mkdir /data/service/el1/public/database 0711 ddms ddms", - "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", - "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", - "chown radio system /sys/power/wake_lock", - "chown radio system /sys/power/wake_unlock", - "chmod 0664 /sys/power/wakeup_count" - ] - },{ - "name": "services:restartfoundation", - "cmds": [ - "reset appspawn", - "reset accountmgr" - ] - } - ], - "services": [{ - "name": "wms", - "path": ["/system/bin/sa_main", "/system/profile/wms.xml"], - "critical": [1, 1, 60], - "importance": -20, - "uid": "foundation", - "permission": [ - "ohos.permission.INPUT_MONITORING", - "ohos.permission.PERMISSION_USED_STATS", - "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", - "ohos.permission.DISTRIBUTED_DATASYNC", - "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - "ohos.permission.INSTALL_BUNDLE", - "ohos.permission.MICROPHONE" - ], - "gid": ["system"], - "caps": ["SYS_PTRACE", "KILL"], - "jobs": { - "on-start": "services:wms", - "on-restart": "services:restartfoundation" - }, - "secon": "u:r:foundation:s0" - } - ] +{ + "jobs": [{ + "name": "services:wms", + "cmds": [ + "mkdir /data/service/el1/public/AbilityManagerService 0711 foundation system", + "mkdir /data/storage/el1/bundle 0711 system system", + "mkdir /data/storage/el2/base 0711 system system", + "mkdir /data/storage/el2/database 0711 system system", + "mkdir /data/service/el1/public/notification 0711 foundation system", + "mkdir /data/service/el1/public/database 0711 ddms ddms", + "mkdir /data/service/el1/public/database/bundle_manager_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/notification_service 02770 foundation ddms", + "mkdir /data/service/el1/public/database/form_storage 02770 foundation ddms", + "chown radio system /sys/power/wake_lock", + "chown radio system /sys/power/wake_unlock", + "chmod 0664 /sys/power/wakeup_count" + ] + },{ + "name": "services:restartfoundation", + "cmds": [ + "reset appspawn", + "reset accountmgr" + ] + } + ], + "services": [{ + "name": "wms", + "path": ["/system/bin/sa_main", "/system/profile/wms.xml"], + "critical": [1, 1, 60], + "importance": -20, + "uid": "foundation", + "permission": [ + "ohos.permission.INPUT_MONITORING", + "ohos.permission.PERMISSION_USED_STATS", + "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", + "ohos.permission.DISTRIBUTED_DATASYNC", + "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "ohos.permission.INSTALL_BUNDLE", + "ohos.permission.MICROPHONE" + ], + "gid": ["system"], + "caps": ["SYS_PTRACE", "KILL"], + "jobs": { + "on-start": "services:wms", + "on-restart": "services:restartfoundation" + }, + "secon": "u:r:foundation:s0" + } + ] } \ No newline at end of file diff --git a/localCoverage/resident_service/config/wms/wms.xml b/local_coverage/resident_service/config/wms/wms.xml similarity index 96% rename from localCoverage/resident_service/config/wms/wms.xml rename to local_coverage/resident_service/config/wms/wms.xml index 826c37f..2160704 100644 --- a/localCoverage/resident_service/config/wms/wms.xml +++ b/local_coverage/resident_service/config/wms/wms.xml @@ -1,45 +1,45 @@ - - - - foundation - - - libwms.z.so - - - - - 4606 - libwms.z.so - - - true - false - 1 - CoreStartPhase - - - 4607 - libdms.z.so - - - true - false - 1 - CoreStartPhase - - + + + + foundation + + + libwms.z.so + + + + + 4606 + libwms.z.so + + + true + false + 1 + CoreStartPhase + + + 4607 + libdms.z.so + + + true + false + 1 + CoreStartPhase + + \ No newline at end of file diff --git a/localCoverage/resident_service/init_gcov.py b/local_coverage/resident_service/init_gcov.py similarity index 95% rename from localCoverage/resident_service/init_gcov.py rename to local_coverage/resident_service/init_gcov.py index a5848dc..3ef7f42 100644 --- a/localCoverage/resident_service/init_gcov.py +++ b/local_coverage/resident_service/init_gcov.py @@ -1,365 +1,365 @@ -#!/usr/bin/env python3 -# coding=utf-8 - -# -# Copyright (c) 2020-2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import os -import shutil -import subprocess -import json -import sys -import time -import stat -import xml.etree.ElementTree as ET -from public_method import get_server_dict, get_config_ip, get_sn_list - -FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL -MODES = stat.S_IWUSR | stat.S_IRUSR - - -def _init_sys_config(): - sys.localcoverage_path = os.path.join(current_path, "..") - sys.path.insert(0, sys.localcoverage_path) - - -def modify_init_file(developer_path, hdc_str): - """ - /etc/init.cfg文件添加cmds - """ - recv_path = os.path.join(developer_path, "localCoverage/resident_service/resources") - print("%s file recv /etc/init.cfg %s" % (hdc_str, recv_path)) - coverage_command("%s file recv /etc/init.cfg %s" % (hdc_str, recv_path)) - recv_restores_path = os.path.join(recv_path, "restores_environment") - if not os.path.exists(recv_restores_path): - os.mkdir(recv_restores_path) - recv_restores_name = os.path.join(recv_restores_path, "init.cfg") - if not os.path.exists(recv_restores_name): - coverage_command("%s file recv /etc/init.cfg %s" % (hdc_str, recv_restores_path)) - else: - print("INFO: file exit", recv_restores_name) - - cfg_file_path = os.path.join(recv_path, "init.cfg") - if os.path.exists(cfg_file_path): - with open(cfg_file_path, "r") as fp: - json_data = json.load(fp) - - for jobs_list in json_data["jobs"]: - if jobs_list["name"] == "init": - if jobs_list["cmds"][-1] != "export GCOV_FETCH_METHOD FM_SIGNA": - jobs_list["cmds"].append("mkdir /data/gcov 0777 system system") - jobs_list["cmds"].append("export GCOV_PREFIX /data/gcov") - jobs_list["cmds"].append("export GCOV_FETCH_METHOD FM_SIGNA") - else: - return - json_str = json.dumps(json_data, indent=2) - if os.path.exists(cfg_file_path): - os.remove(cfg_file_path) - with os.fdopen(os.open(cfg_file_path, FLAGS, MODES), 'w') as json_file: - json_file.write(json_str) - else: - print("init.cfg file not exists") - return - print("%s shell mount -o rw,remount / > /dev/null 2>&1" % hdc_str) - coverage_command("%s shell mount -o rw,remount / > /dev/null 2>&1" % hdc_str) - print("%s file send %s %s" % (hdc_str, cfg_file_path, "/etc/")) - coverage_command("%s file send %s %s" % (hdc_str, cfg_file_path, "/etc/")) - coverage_command("%s shell param set persist.appspawn.client.timeout 120 > /dev/null 2>&1" % hdc_str) - return - - -def modify_faultloggerd_file(developer_path, hdc_str): - _, enforce = subprocess.getstatusoutput("%s shell getenforce" % hdc_str) - coverage_command("%s shell mount -o rw,remount /" % hdc_str) - print("%s shell mount -o rw,remount /" % hdc_str) - if enforce != "Permissive": - coverage_command("%s shell sed -i 's/enforcing/permissive/g' /system/etc/selinux/config" % hdc_str) - - recv_path = os.path.join(developer_path, "localCoverage/resident_service/resources") - print("%s file recv /system/etc/init/faultloggerd.cfg %s" % (hdc_str, recv_path)) - coverage_command("%s file recv /system/etc/init/faultloggerd.cfg %s" % (hdc_str, recv_path)) - - cfg_file_path = os.path.join(recv_path, "faultloggerd.cfg") - if os.path.exists(cfg_file_path): - with open(cfg_file_path, "r") as fp: - json_data = json.load(fp) - if len(json_data["jobs"]) == 1 and json_data["jobs"][0]["name"] != "pre-init": - json_data["jobs"].insert(0, { - "name": "pre-init", - "cmds": [ - "export LD_PRELOAD libcoverage_signal_handler.z.so" - ] - }) - json_str = json.dumps(json_data, indent=4) - if os.path.exists(cfg_file_path): - os.remove(cfg_file_path) - with os.fdopen(os.open(cfg_file_path, FLAGS, MODES), 'w') as json_file: - json_file.write(json_str) - print("%s file send %s %s" % (hdc_str, cfg_file_path, "/system/etc/init/")) - coverage_command("%s file send %s %s" % (hdc_str, cfg_file_path, "/system/etc/init/")) - else: - print("faultloggerd.cfg file not exists.") - - return - - -def modify_foundation_xml(serv, config_path, origin_xml) -> str: - """ - 修改foundation.xml文件,删去拆分的进程相关 - :param serv: 拆分进程 - :param config_path: 配置文件路径 - :param origin_xml: 原foundation.xml - :return: 修改后foundation.xml路径 - """ - lib_list = FoundationServer.lib_dict.get(serv) - - tree = ET.parse(origin_xml) - root = tree.getroot() - loadlibs = root.find("loadlibs") - - for lib in lib_list: - for sa in root.findall('systemability'): - if lib in sa.find('libpath').text: - root.remove(sa) - for ll in loadlibs.findall('libpath'): - if lib in ll.text: - loadlibs.remove(ll) - - tree.write(os.path.join(config_path, 'foundation.xml'), encoding='utf-8', xml_declaration=True) - return os.path.join(config_path, 'foundation.xml') - - -def modify_foundation_json(serv, config_path, origin_json) -> str: - """ - 修改foundation.json文件,删去拆分的进程相关 - :param serv: 拆分进程 - :param config_path: 配置文件路径 - :param origin_json: 原foundation.json - :return: 修改后foundation.json路径 - """ - lib_list = FoundationServer.lib_dict.get(serv) - - with open(origin_json, "r", encoding="UTF-8") as f: - f_dict = json.load(f) - - tmp_list = list() - for i in range(len(f_dict["systemability"])): - if f_dict["systemability"][i]["libpath"] not in lib_list: - tmp_list.append(f_dict["systemability"][i]) - f_dict["systemability"] = tmp_list - - new_json = os.path.join(config_path, 'foundation.json') - if os.path.exists(new_json): - os.remove(new_json) - with os.fdopen(os.open(new_json, FLAGS, MODES), 'w') as f: - json.dump(f_dict, f, indent=4) - - return new_json - - -def create_service_json(serv, config_path, origin_json) -> str: - """ - 创建进程json - :param serv: 进程名 - :param config_path:配置文件所在目录 - :param origin_json: 原foundation.json - :return: json文件路径 - """ - lib_list = FoundationServer.lib_dict.get(serv) - with open(origin_json, "r", encoding="UTF-8") as f: - f_dict = json.load(f) - - tmp_list = list() - for lib in lib_list: - for i in range(len(f_dict["systemability"])): - if f_dict["systemability"][i]["libpath"] == lib: - tmp_list.append(f_dict["systemability"][i]) - f_dict["systemability"] = tmp_list - f_dict["process"] = "{}".format(serv) - - new_json = os.path.join(config_path, '{}.json'.format(serv)) - if os.path.exists(new_json): - os.remove(new_json) - with os.fdopen(os.open(new_json, FLAGS, MODES), 'w') as f: - json.dump(f_dict, f, indent=4) - - return new_json - - -def create_service_xml(serv, config_path, origin_xml) -> str: - """ - 创建进程xml - :param serv: 进程名 - :param config_path:配置文件所在目录 - :param origin_xml: 原foundation.xml - :return: xml文件路径 - """ - lib_list = FoundationServer.lib_dict.get(serv) - - tree = ET.parse(origin_xml) - root = tree.getroot() - loadlibs = root.find("loadlibs") - - for lib in lib_list: - for sa in root.findall('systemability'): - if lib not in sa.find('libpath').text: - root.remove(sa) - for lp in loadlibs.findall('libpath'): - if lib not in lp.text: - loadlibs.remove(lp) - - tree.write(os.path.join(config_path, '{}.xml'.format(serv)), encoding='utf-8', xml_declaration=True) - return os.path.join(config_path, '{}.xml'.format(serv)) - - -def create_service_cfg(serv, config_path, origin_cfg) -> str: - """ - 创建进程cfg文件 - :param serv: 进程名 - :param config_path:配置文件所在目录 - :param origin_cfg: 原foundation.cfg - :return: cfg文件路径 - """ - with open(origin_cfg, "r") as jf: - json_obj = json.load(jf) - json_obj["jobs"][0]["name"] = "services:{}".format(serv) - - json_obj["services"][0]["name"] = "{}".format(serv) - - path_list = json_obj["services"][0]["path"] - path_list.remove("/system/profile/foundation.json") - path_list.append("/system/profile/{}.json".format(serv)) - json_obj["services"][0]["path"] = path_list - - json_obj["services"][0]["jobs"]["on-start"] = "services:{}".format(serv) - - cfg_path = os.path.join(config_path, "{}.cfg".format(serv)) - if os.path.exists(cfg_path): - os.remove(cfg_path) - with os.fdopen(os.open(cfg_path, FLAGS, MODES), 'w') as r: - json.dump(json_obj, r, indent=4) - return cfg_path - - -def remove_configs(config_path): - """ - 清理配置文件目录下的xml和cfg文件 - :param config_path: 配置文件目录 - :return: - """ - logger("Clear config path...", "INFO") - shutil.rmtree(config_path) - os.mkdir(config_path) - - -def split_foundation_services(developer_path, system_info_dict, home_path, hdc_dict): - """ - foundation.xml、XXX.xml文件推送到 /system/profile - XXX.cfg文件推送到/etc/init/ - reboot设备,可以将服务从foundation中拆分出来,成为一个独立服务进程 - """ - config_path = os.path.join(developer_path, "localCoverage", "resident_service", "config") - remove_configs(config_path) - - device_ip = hdc_dict["device_ip"] - hdc_port = hdc_dict["device_port"] - device_sn = hdc_dict["device_sn_str"] - - hdc_command(device_ip, hdc_port, device_sn, "file recv /system/profile/foundation.json {}".format(config_path)) - hdc_command(device_ip, hdc_port, device_sn, "file recv /etc/init/foundation.cfg {}".format(config_path)) - - if os.path.exists(os.path.join(config_path, "foundation.json")): - origin_json = os.path.join(config_path, "foundation_origin.json") - os.rename(os.path.join(config_path, "foundation.json"), origin_json) - else: - logger("{} not exist, Cannot modify.".format(os.path.join(config_path, "foundation.json")), "ERROR") - return - - if os.path.exists(os.path.join(config_path, "foundation.cfg")): - origin_cfg = os.path.join(config_path, "foundation_origin.cfg") - os.rename(os.path.join(config_path, "foundation.cfg"), origin_cfg) - else: - logger("{} not exist, Cannot modify.".format(os.path.join(config_path, "foundation.cfg")), "ERROR") - return - - foundation_process_list = FoundationServer.lib_dict.keys() - - # 推送配置文件 - for _, value_list in system_info_dict.items(): - for process_str in value_list: - if process_str in foundation_process_list: - foundation_json = modify_foundation_json(process_str, config_path, origin_json) - service_json = create_service_json(process_str, config_path, origin_json) - service_cfg = create_service_cfg(process_str, config_path, origin_cfg) - - hdc_command(device_ip, hdc_port, device_sn, "shell rm -rf {}".format(home_path)) - hdc_command(device_ip, hdc_port, device_sn, "file send {} /system/profile/".format(foundation_json)) - hdc_command(device_ip, hdc_port, device_sn, "file send {} /system/profile/".format(service_json)) - hdc_command(device_ip, hdc_port, device_sn, "file send {} /etc/init/".format(service_cfg)) - - return - - -def modify_cfg_xml_file(developer_path, device_ip, device_sn_list, - system_info_dict, home_path, device_port): - if device_ip and len(device_sn_list) >= 1: - for device_sn_str in device_sn_list: - hdc_str = "hdc -s %s:%s -t %s" % (device_ip, device_port, device_sn_str) - hdc_dict = {"device_ip": device_ip, "device_port": device_port, "device_sn_str": device_sn_str} - modify_init_file(developer_path, hdc_str) - modify_faultloggerd_file( - developer_path, hdc_str) - # 推送服务对应的配置文件 - split_foundation_services(developer_path, system_info_dict, home_path, hdc_dict) - logger("{} shell reboot".format(hdc_str), "INFO") - coverage_command("%s shell reboot > /dev/null 2>&1" % hdc_str) - while True: - after_sn_list = get_sn_list("hdc -s %s:%s list targets" % (device_ip, device_port)) - time.sleep(10) - if device_sn_str in after_sn_list: - break - coverage_command("%s shell getenforce" % hdc_str) - else: - logger("user_config.xml device ip not config", "ERROR") - - -if __name__ == '__main__': - command_args = sys.argv[1] - command_str = command_args.split("command_str=")[1].replace(",", " ") - current_path = os.getcwd() - _init_sys_config() - from localCoverage.utils import coverage_command, \ - logger, hdc_command, FoundationServer - - root_path = current_path.split("/test/testfwk/developer_test")[0] - developer_test_path = os.path.join(root_path, "test/testfwk/developer_test") - home_paths = '/'.join(root_path.split("/")[:3]) - - # 获取user_config中的device ip - ip, port, sn = get_config_ip(os.path.join(developer_test_path, "config/user_config.xml")) - if not port: - port = "8710" - sn_list = [] - if sn: - sn_list.extend(sn.replace(" ", "").split(";")) - else: - sn_list = get_sn_list("hdc -s %s:%s list targets" % (ip, port)) - - # 获取子系统部件与服务的关系 - system_dict, _, _ = get_server_dict(command_str) - - # 修改设备init.cfg, faultloggerd.cfg等文件 - modify_cfg_xml_file(developer_test_path, ip, sn_list, - system_dict, home_paths, port) +#!/usr/bin/env python3 +# coding=utf-8 + +# +# Copyright (c) 2020-2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import shutil +import subprocess +import json +import sys +import time +import stat +import xml.etree.ElementTree as ET +from public_method import get_server_dict, get_config_ip, get_sn_list + +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + + +def _init_sys_config(): + sys.localcoverage_path = os.path.join(current_path, "..") + sys.path.insert(0, sys.localcoverage_path) + + +def modify_init_file(developer_path, hdc_str): + """ + /etc/init.cfg文件添加cmds + """ + recv_path = os.path.join(developer_path, "local_coverage/resident_service/resources") + print("%s file recv /etc/init.cfg %s" % (hdc_str, recv_path)) + coverage_command("%s file recv /etc/init.cfg %s" % (hdc_str, recv_path)) + recv_restores_path = os.path.join(recv_path, "restores_environment") + if not os.path.exists(recv_restores_path): + os.mkdir(recv_restores_path) + recv_restores_name = os.path.join(recv_restores_path, "init.cfg") + if not os.path.exists(recv_restores_name): + coverage_command("%s file recv /etc/init.cfg %s" % (hdc_str, recv_restores_path)) + else: + print("INFO: file exit", recv_restores_name) + + cfg_file_path = os.path.join(recv_path, "init.cfg") + if os.path.exists(cfg_file_path): + with open(cfg_file_path, "r") as fp: + json_data = json.load(fp) + + for jobs_list in json_data["jobs"]: + if jobs_list["name"] == "init": + if jobs_list["cmds"][-1] != "export GCOV_FETCH_METHOD FM_SIGNA": + jobs_list["cmds"].append("mkdir /data/gcov 0777 system system") + jobs_list["cmds"].append("export GCOV_PREFIX /data/gcov") + jobs_list["cmds"].append("export GCOV_FETCH_METHOD FM_SIGNA") + else: + return + json_str = json.dumps(json_data, indent=2) + if os.path.exists(cfg_file_path): + os.remove(cfg_file_path) + with os.fdopen(os.open(cfg_file_path, FLAGS, MODES), 'w') as json_file: + json_file.write(json_str) + else: + print("init.cfg file not exists") + return + print("%s shell mount -o rw,remount / > /dev/null 2>&1" % hdc_str) + coverage_command("%s shell mount -o rw,remount / > /dev/null 2>&1" % hdc_str) + print("%s file send %s %s" % (hdc_str, cfg_file_path, "/etc/")) + coverage_command("%s file send %s %s" % (hdc_str, cfg_file_path, "/etc/")) + coverage_command("%s shell param set persist.appspawn.client.timeout 120 > /dev/null 2>&1" % hdc_str) + return + + +def modify_faultloggerd_file(developer_path, hdc_str): + _, enforce = subprocess.getstatusoutput("%s shell getenforce" % hdc_str) + coverage_command("%s shell mount -o rw,remount /" % hdc_str) + print("%s shell mount -o rw,remount /" % hdc_str) + if enforce != "Permissive": + coverage_command("%s shell sed -i 's/enforcing/permissive/g' /system/etc/selinux/config" % hdc_str) + + recv_path = os.path.join(developer_path, "local_coverage/resident_service/resources") + print("%s file recv /system/etc/init/faultloggerd.cfg %s" % (hdc_str, recv_path)) + coverage_command("%s file recv /system/etc/init/faultloggerd.cfg %s" % (hdc_str, recv_path)) + + cfg_file_path = os.path.join(recv_path, "faultloggerd.cfg") + if os.path.exists(cfg_file_path): + with open(cfg_file_path, "r") as fp: + json_data = json.load(fp) + if len(json_data["jobs"]) == 1 and json_data["jobs"][0]["name"] != "pre-init": + json_data["jobs"].insert(0, { + "name": "pre-init", + "cmds": [ + "export LD_PRELOAD libcoverage_signal_handler.z.so" + ] + }) + json_str = json.dumps(json_data, indent=4) + if os.path.exists(cfg_file_path): + os.remove(cfg_file_path) + with os.fdopen(os.open(cfg_file_path, FLAGS, MODES), 'w') as json_file: + json_file.write(json_str) + print("%s file send %s %s" % (hdc_str, cfg_file_path, "/system/etc/init/")) + coverage_command("%s file send %s %s" % (hdc_str, cfg_file_path, "/system/etc/init/")) + else: + print("faultloggerd.cfg file not exists.") + + return + + +def modify_foundation_xml(serv, config_path, origin_xml) -> str: + """ + 修改foundation.xml文件,删去拆分的进程相关 + :param serv: 拆分进程 + :param config_path: 配置文件路径 + :param origin_xml: 原foundation.xml + :return: 修改后foundation.xml路径 + """ + lib_list = FoundationServer.lib_dict.get(serv) + + tree = ET.parse(origin_xml) + root = tree.getroot() + loadlibs = root.find("loadlibs") + + for lib in lib_list: + for sa in root.findall('systemability'): + if lib in sa.find('libpath').text: + root.remove(sa) + for ll in loadlibs.findall('libpath'): + if lib in ll.text: + loadlibs.remove(ll) + + tree.write(os.path.join(config_path, 'foundation.xml'), encoding='utf-8', xml_declaration=True) + return os.path.join(config_path, 'foundation.xml') + + +def modify_foundation_json(serv, config_path, origin_json) -> str: + """ + 修改foundation.json文件,删去拆分的进程相关 + :param serv: 拆分进程 + :param config_path: 配置文件路径 + :param origin_json: 原foundation.json + :return: 修改后foundation.json路径 + """ + lib_list = FoundationServer.lib_dict.get(serv) + + with open(origin_json, "r", encoding="UTF-8") as f: + f_dict = json.load(f) + + tmp_list = list() + for i in range(len(f_dict["systemability"])): + if f_dict["systemability"][i]["libpath"] not in lib_list: + tmp_list.append(f_dict["systemability"][i]) + f_dict["systemability"] = tmp_list + + new_json = os.path.join(config_path, 'foundation.json') + if os.path.exists(new_json): + os.remove(new_json) + with os.fdopen(os.open(new_json, FLAGS, MODES), 'w') as f: + json.dump(f_dict, f, indent=4) + + return new_json + + +def create_service_json(serv, config_path, origin_json) -> str: + """ + 创建进程json + :param serv: 进程名 + :param config_path:配置文件所在目录 + :param origin_json: 原foundation.json + :return: json文件路径 + """ + lib_list = FoundationServer.lib_dict.get(serv) + with open(origin_json, "r", encoding="UTF-8") as f: + f_dict = json.load(f) + + tmp_list = list() + for lib in lib_list: + for i in range(len(f_dict["systemability"])): + if f_dict["systemability"][i]["libpath"] == lib: + tmp_list.append(f_dict["systemability"][i]) + f_dict["systemability"] = tmp_list + f_dict["process"] = "{}".format(serv) + + new_json = os.path.join(config_path, '{}.json'.format(serv)) + if os.path.exists(new_json): + os.remove(new_json) + with os.fdopen(os.open(new_json, FLAGS, MODES), 'w') as f: + json.dump(f_dict, f, indent=4) + + return new_json + + +def create_service_xml(serv, config_path, origin_xml) -> str: + """ + 创建进程xml + :param serv: 进程名 + :param config_path:配置文件所在目录 + :param origin_xml: 原foundation.xml + :return: xml文件路径 + """ + lib_list = FoundationServer.lib_dict.get(serv) + + tree = ET.parse(origin_xml) + root = tree.getroot() + loadlibs = root.find("loadlibs") + + for lib in lib_list: + for sa in root.findall('systemability'): + if lib not in sa.find('libpath').text: + root.remove(sa) + for lp in loadlibs.findall('libpath'): + if lib not in lp.text: + loadlibs.remove(lp) + + tree.write(os.path.join(config_path, '{}.xml'.format(serv)), encoding='utf-8', xml_declaration=True) + return os.path.join(config_path, '{}.xml'.format(serv)) + + +def create_service_cfg(serv, config_path, origin_cfg) -> str: + """ + 创建进程cfg文件 + :param serv: 进程名 + :param config_path:配置文件所在目录 + :param origin_cfg: 原foundation.cfg + :return: cfg文件路径 + """ + with open(origin_cfg, "r") as jf: + json_obj = json.load(jf) + json_obj["jobs"][0]["name"] = "services:{}".format(serv) + + json_obj["services"][0]["name"] = "{}".format(serv) + + path_list = json_obj["services"][0]["path"] + path_list.remove("/system/profile/foundation.json") + path_list.append("/system/profile/{}.json".format(serv)) + json_obj["services"][0]["path"] = path_list + + json_obj["services"][0]["jobs"]["on-start"] = "services:{}".format(serv) + + cfg_path = os.path.join(config_path, "{}.cfg".format(serv)) + if os.path.exists(cfg_path): + os.remove(cfg_path) + with os.fdopen(os.open(cfg_path, FLAGS, MODES), 'w') as r: + json.dump(json_obj, r, indent=4) + return cfg_path + + +def remove_configs(config_path): + """ + 清理配置文件目录下的xml和cfg文件 + :param config_path: 配置文件目录 + :return: + """ + logger("Clear config path...", "INFO") + shutil.rmtree(config_path) + os.mkdir(config_path) + + +def split_foundation_services(developer_path, system_info_dict, home_path, hdc_dict): + """ + foundation.xml、XXX.xml文件推送到 /system/profile + XXX.cfg文件推送到/etc/init/ + reboot设备,可以将服务从foundation中拆分出来,成为一个独立服务进程 + """ + config_path = os.path.join(developer_path, "local_coverage", "resident_service", "config") + remove_configs(config_path) + + device_ip = hdc_dict["device_ip"] + hdc_port = hdc_dict["device_port"] + device_sn = hdc_dict["device_sn_str"] + + hdc_command(device_ip, hdc_port, device_sn, "file recv /system/profile/foundation.json {}".format(config_path)) + hdc_command(device_ip, hdc_port, device_sn, "file recv /etc/init/foundation.cfg {}".format(config_path)) + + if os.path.exists(os.path.join(config_path, "foundation.json")): + origin_json = os.path.join(config_path, "foundation_origin.json") + os.rename(os.path.join(config_path, "foundation.json"), origin_json) + else: + logger("{} not exist, Cannot modify.".format(os.path.join(config_path, "foundation.json")), "ERROR") + return + + if os.path.exists(os.path.join(config_path, "foundation.cfg")): + origin_cfg = os.path.join(config_path, "foundation_origin.cfg") + os.rename(os.path.join(config_path, "foundation.cfg"), origin_cfg) + else: + logger("{} not exist, Cannot modify.".format(os.path.join(config_path, "foundation.cfg")), "ERROR") + return + + foundation_process_list = FoundationServer.lib_dict.keys() + + # 推送配置文件 + for _, value_list in system_info_dict.items(): + for process_str in value_list: + if process_str in foundation_process_list: + foundation_json = modify_foundation_json(process_str, config_path, origin_json) + service_json = create_service_json(process_str, config_path, origin_json) + service_cfg = create_service_cfg(process_str, config_path, origin_cfg) + + hdc_command(device_ip, hdc_port, device_sn, "shell rm -rf {}".format(home_path)) + hdc_command(device_ip, hdc_port, device_sn, "file send {} /system/profile/".format(foundation_json)) + hdc_command(device_ip, hdc_port, device_sn, "file send {} /system/profile/".format(service_json)) + hdc_command(device_ip, hdc_port, device_sn, "file send {} /etc/init/".format(service_cfg)) + + return + + +def modify_cfg_xml_file(developer_path, device_ip, device_sn_list, + system_info_dict, home_path, device_port): + if device_ip and len(device_sn_list) >= 1: + for device_sn_str in device_sn_list: + hdc_str = "hdc -s %s:%s -t %s" % (device_ip, device_port, device_sn_str) + hdc_dict = {"device_ip": device_ip, "device_port": device_port, "device_sn_str": device_sn_str} + modify_init_file(developer_path, hdc_str) + modify_faultloggerd_file( + developer_path, hdc_str) + # 推送服务对应的配置文件 + split_foundation_services(developer_path, system_info_dict, home_path, hdc_dict) + logger("{} shell reboot".format(hdc_str), "INFO") + coverage_command("%s shell reboot > /dev/null 2>&1" % hdc_str) + while True: + after_sn_list = get_sn_list("hdc -s %s:%s list targets" % (device_ip, device_port)) + time.sleep(10) + if device_sn_str in after_sn_list: + break + coverage_command("%s shell getenforce" % hdc_str) + else: + logger("user_config.xml device ip not config", "ERROR") + + +if __name__ == '__main__': + command_args = sys.argv[1] + command_str = command_args.split("command_str=")[1].replace(",", " ") + current_path = os.getcwd() + _init_sys_config() + from local_coverage.utils import coverage_command, \ + logger, hdc_command, FoundationServer + + root_path = current_path.split("/test/testfwk/developer_test")[0] + developer_test_path = os.path.join(root_path, "test/testfwk/developer_test") + home_paths = '/'.join(root_path.split("/")[:3]) + + # 获取user_config中的device ip + ip, port, sn = get_config_ip(os.path.join(developer_test_path, "config/user_config.xml")) + if not port: + port = "8710" + sn_list = [] + if sn: + sn_list.extend(sn.replace(" ", "").split(";")) + else: + sn_list = get_sn_list("hdc -s %s:%s list targets" % (ip, port)) + + # 获取子系统部件与服务的关系 + system_dict, _, _ = get_server_dict(command_str) + + # 修改设备init.cfg, faultloggerd.cfg等文件 + modify_cfg_xml_file(developer_test_path, ip, sn_list, + system_dict, home_paths, port) diff --git a/localCoverage/resident_service/public_method.py b/local_coverage/resident_service/public_method.py similarity index 96% rename from localCoverage/resident_service/public_method.py rename to local_coverage/resident_service/public_method.py index 7714459..1cca156 100644 --- a/localCoverage/resident_service/public_method.py +++ b/local_coverage/resident_service/public_method.py @@ -1,143 +1,143 @@ -#!/usr/bin/env python3 -# coding=utf-8 - -# -# Copyright (c) 2020-2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import os -import subprocess -import json -import xml.etree.ElementTree as ET - - -def get_config_ip(filepath): - ip_config = "" - sn = "" - port = "" - try: - data_dic = {} - if os.path.exists(filepath): - tree = ET.parse(filepath) - root = tree.getroot() - for node in root.findall("environment/device"): - if node.attrib["type"] != "usb-hdc": - continue - for sub in node: - data_dic[sub.tag] = sub.text if sub.text else "" - ip_config = data_dic.get("ip", "") - sn = data_dic.get("sn", "") - port = data_dic.get("port", "") - except ET.ParseError as xml_exception: - print("occurs exception:{}".format(xml_exception.args)) - - return ip_config, port, sn - - -def get_sn_list(command): - device_sn_list = [] - # 执行查询设备sn号命令并获取执行结果 - proc = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - strout = proc.stdout.read() - if isinstance(strout, bytes): - strout = strout.decode("utf-8", "ignore") - for line in strout.split("\n"): - line = line.strip().replace('\t', ' ') - if line != "": - device_sn_list.append(line) - - return device_sn_list - - -def get_all_part_service(): - current_path = os.getcwd() - root_path = current_path.split("/test/testfwk/developer_test")[0] - developer_path = os.path.join(root_path, "test/testfwk/developer_test") - system_part_service_path = os.path.join( - developer_path, "localCoverage/resident_service/system_part_service.json") - if os.path.exists(system_part_service_path): - with open(system_part_service_path, "r") as system_text: - system_text_json = json.load(system_text) - system_info_dict = system_text_json["system_info_dict"] - services_component_dict = system_text_json["services_component_dict"] - component_gcda_dict = system_text_json["component_gcda_dict"] - return system_info_dict, services_component_dict, component_gcda_dict - print("%s not exists.", system_part_service_path) - return {}, {}, {} - - -def get_system_dict_to_server_name(server_name: str, system_info_dict): - for system, server_list in system_info_dict.items(): - if server_name in server_list: - system_info_dict_after = { - system: [server_name] - } - return system_info_dict_after - return {} - - -def get_server_dict(command): - system_info_dict, services_component_dict, component_gcda_dict = get_all_part_service() - system_info_dict_after = {} - services_component_dict_after = {} - component_gcda_dict_after = {} - server_name = None - if " -ts " in command: - _, testsuite = command.split(" -ts ") - if testsuite in services_component_dict.get("dinput"): - services_component_dict_after = { - "dinput": [testsuite] - } - server_name = "dinput" - elif testsuite in services_component_dict.get("softbus_server"): - services_component_dict_after = { - "softbus_server": [testsuite] - } - server_name = "softbus_server" - if server_name: - system_info_dict_after = get_system_dict_to_server_name(server_name, system_info_dict) - component_gcda_dict_after = { - server_name: component_gcda_dict.get(server_name) - } - elif " -tp " in command: - component_name = command.split(" -tp ")[-1].split(" ")[0] - for server, component_list in services_component_dict.items(): - if component_name in component_list: - if server in ["dinput", "softbus_server"]: - break - services_component_dict_after = { - server: [component_name] - } - server_name = server - break - if server_name: - system_info_dict_after = get_system_dict_to_server_name(server_name, system_info_dict) - component_gcda_dict_after = { - server_name: component_gcda_dict.get(server_name) - } - elif " -ss " in command: - system_name = command.split(" -ss ")[-1].split(" ")[0] - server_list = system_info_dict.get(system_name) if system_info_dict.get(system_name) else [] - system_info_dict_after = { - system_name: server_list - } - for server_name in server_list: - services_component_dict_after.update({ - server_name: services_component_dict.get(server_name) - }) - component_gcda_dict_after.update({ - server_name: component_gcda_dict.get(server_name) - }) - return system_info_dict_after, services_component_dict_after, component_gcda_dict_after +#!/usr/bin/env python3 +# coding=utf-8 + +# +# Copyright (c) 2020-2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import subprocess +import json +import xml.etree.ElementTree as ET + + +def get_config_ip(filepath): + ip_config = "" + sn = "" + port = "" + try: + data_dic = {} + if os.path.exists(filepath): + tree = ET.parse(filepath) + root = tree.getroot() + for node in root.findall("environment/device"): + if node.attrib["type"] != "usb-hdc": + continue + for sub in node: + data_dic[sub.tag] = sub.text if sub.text else "" + ip_config = data_dic.get("ip", "") + sn = data_dic.get("sn", "") + port = data_dic.get("port", "") + except ET.ParseError as xml_exception: + print("occurs exception:{}".format(xml_exception.args)) + + return ip_config, port, sn + + +def get_sn_list(command): + device_sn_list = [] + # 执行查询设备sn号命令并获取执行结果 + proc = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + strout = proc.stdout.read() + if isinstance(strout, bytes): + strout = strout.decode("utf-8", "ignore") + for line in strout.split("\n"): + line = line.strip().replace('\t', ' ') + if line != "": + device_sn_list.append(line) + + return device_sn_list + + +def get_all_part_service(): + current_path = os.getcwd() + root_path = current_path.split("/test/testfwk/developer_test")[0] + developer_path = os.path.join(root_path, "test/testfwk/developer_test") + system_part_service_path = os.path.join( + developer_path, "local_coverage/resident_service/system_part_service.json") + if os.path.exists(system_part_service_path): + with open(system_part_service_path, "r") as system_text: + system_text_json = json.load(system_text) + system_info_dict = system_text_json["system_info_dict"] + services_component_dict = system_text_json["services_component_dict"] + component_gcda_dict = system_text_json["component_gcda_dict"] + return system_info_dict, services_component_dict, component_gcda_dict + print("%s not exists.", system_part_service_path) + return {}, {}, {} + + +def get_system_dict_to_server_name(server_name: str, system_info_dict): + for system, server_list in system_info_dict.items(): + if server_name in server_list: + system_info_dict_after = { + system: [server_name] + } + return system_info_dict_after + return {} + + +def get_server_dict(command): + system_info_dict, services_component_dict, component_gcda_dict = get_all_part_service() + system_info_dict_after = {} + services_component_dict_after = {} + component_gcda_dict_after = {} + server_name = None + if " -ts " in command: + _, testsuite = command.split(" -ts ") + if testsuite in services_component_dict.get("dinput"): + services_component_dict_after = { + "dinput": [testsuite] + } + server_name = "dinput" + elif testsuite in services_component_dict.get("softbus_server"): + services_component_dict_after = { + "softbus_server": [testsuite] + } + server_name = "softbus_server" + if server_name: + system_info_dict_after = get_system_dict_to_server_name(server_name, system_info_dict) + component_gcda_dict_after = { + server_name: component_gcda_dict.get(server_name) + } + elif " -tp " in command: + component_name = command.split(" -tp ")[-1].split(" ")[0] + for server, component_list in services_component_dict.items(): + if component_name in component_list: + if server in ["dinput", "softbus_server"]: + break + services_component_dict_after = { + server: [component_name] + } + server_name = server + break + if server_name: + system_info_dict_after = get_system_dict_to_server_name(server_name, system_info_dict) + component_gcda_dict_after = { + server_name: component_gcda_dict.get(server_name) + } + elif " -ss " in command: + system_name = command.split(" -ss ")[-1].split(" ")[0] + server_list = system_info_dict.get(system_name) if system_info_dict.get(system_name) else [] + system_info_dict_after = { + system_name: server_list + } + for server_name in server_list: + services_component_dict_after.update({ + server_name: services_component_dict.get(server_name) + }) + component_gcda_dict_after.update({ + server_name: component_gcda_dict.get(server_name) + }) + return system_info_dict_after, services_component_dict_after, component_gcda_dict_after diff --git a/localCoverage/resident_service/pull_service_gcda.py b/local_coverage/resident_service/pull_service_gcda.py similarity index 95% rename from localCoverage/resident_service/pull_service_gcda.py rename to local_coverage/resident_service/pull_service_gcda.py index e8b2ac7..8f5af65 100644 --- a/localCoverage/resident_service/pull_service_gcda.py +++ b/local_coverage/resident_service/pull_service_gcda.py @@ -1,161 +1,161 @@ -#!/usr/bin/env python3 -# coding=utf-8 - -# -# Copyright (c) 2020-2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import os -import sys - -from public_method import get_server_dict, get_config_ip, get_sn_list - - -def _init_sys_config(): - sys.localcoverage_path = os.path.join(current_path, "..") - sys.path.insert(0, sys.localcoverage_path) - - -def restore_config(device_ip, device_port, device_sn, cfg_path): - """ - 恢复设备内配置文件 - :param device_ip: - :param device_sn: - :param cfg_path: - :param device_port: - :return: - """ - remount_cmd = "shell mount -o rw,remount /" - hdc_command(device_ip, device_port, device_sn, remount_cmd) - origin_foundation = os.path.join(cfg_path, "foundation_origin.json") - restore_foundation_cmd = "file send {} /system/profile/foundation.json".format(origin_foundation) - hdc_command(device_ip, device_port, device_sn, restore_foundation_cmd) - serv_list = FoundationServer.lib_dict - for serv in serv_list: - rm_xml_cmd = "shell rm /system/profile/{}.json".format(serv) - hdc_command(device_ip, device_port, device_sn, rm_xml_cmd) - rm_cfg_cmd = "shell rm /etc/init/{}.cfg".format(serv) - hdc_command(device_ip, device_port, device_sn, rm_cfg_cmd) - - -def attach_pid(device_ip, device_sn, process_str, component_gcda_dict, developer_path, - resident_service_path, services_str, root, device_port): - """ - 1. 在设备里ps -ef | grep SERVICE 获取进程号 - 2. kill - '信号' pid - """ - hdc_str = "hdc -s %s:%s -t %s" % (device_ip, device_port, device_sn) - print("%s shell chmod 777 /data/gcov -R" % hdc_str) - coverage_command("%s shell chmod 777 /data/gcov -R" % hdc_str) - coverage_command("%s shell mount -o rw,remount /" % hdc_str) - local_sh_path = os.path.join(resident_service_path, "resources", "gcov_flush.sh") - coverage_command("dos2unix %s" % local_sh_path) - print("%s file send %s %s" % (hdc_str, local_sh_path, "/data/")) - coverage_command("%s file send %s %s" % (hdc_str, local_sh_path, "/data/")) - coverage_command("%s shell chmod 777 /data/gcov_flush.sh" % hdc_str) - print("%s shell sh /data/gcov_flush.sh %s" % (hdc_str, services_str)) - coverage_command("%s shell sh /data/gcov_flush.sh %s" % (hdc_str, services_str)) - - # 拉取gcda文件 - get_gcda_file(device_ip, device_sn, process_str, component_gcda_dict, - developer_path, services_str, root, device_port) - - -def get_gcda_file(device_ip, device_sn, process_str, component_gcda_dict, - developertest_path, services_str, roots_path, device_port): - hdc_str = "hdc -s %s:%s -t %s" % (device_ip, device_port, device_sn) - home_path = '/'.join(roots_path.split("/")[:3]) - gcda_path = f"/data/gcov{roots_path}" - - component_gcda_paths = component_gcda_dict.get(process_str) if component_gcda_dict.get(process_str) else [] - for component_gcda_path in component_gcda_paths: - gcov_root = os.path.join(gcda_path, 'out', product_name, component_gcda_path) - gcda_file_name = os.path.basename(gcov_root) - gcda_file_path = os.path.dirname(gcov_root) - print("%s shell 'cd %s; tar -czf %s.tar.gz %s'" % ( - hdc_str, gcda_file_path, gcda_file_name, gcda_file_name)) - coverage_command("%s shell 'cd %s; tar -czf %s.tar.gz %s'" % ( - hdc_str, gcda_file_path, gcda_file_name, gcda_file_name - )) - - local_gcda_path = os.path.dirname( - os.path.join(developertest_path, "reports/coverage/data/cxx", - f"{services_str}_service", component_gcda_path)) - - if not os.path.exists(local_gcda_path): - os.makedirs(local_gcda_path) - tar_path = os.path.join(gcda_file_path, "%s.tar.gz" % gcda_file_name) - print("%s file recv %s %s" % (hdc_str, tar_path, local_gcda_path)) - coverage_command("%s file recv %s %s" % ( - hdc_str, tar_path, local_gcda_path)) - - local_tar = os.path.join(local_gcda_path, "%s.tar.gz" % gcda_file_name) - print("tar -zxf %s -C %s > /dev/null 2>&1" % (local_tar, local_gcda_path)) - coverage_command("tar -zxf %s -C %s > /dev/null 2>&1" % ( - local_tar, local_gcda_path)) - coverage_command("rm -rf %s" % local_tar) - print("%s shell rm -fr %s" % (hdc_str, f"/data/gcov{home_path}")) - coverage_command("%s shell rm -fr %s" % (hdc_str, f"/data/gcov{home_path}")) - - -def get_service_list(device_ip, device_sn, system_info_dict, services_component_dict, - component_gcda_dict, developer_path, resident_service_path, root, port_nu): - - service_list = [] - for key, value_list in system_info_dict.items(): - for process_str in value_list: - if process_str in services_component_dict.keys(): - service_list.append(process_str) - else: - return - if len(service_list) > 0: - for process_str in service_list: - services_list = process_str.split("|") - for services_str in services_list: - attach_pid(device_ip, device_sn, process_str, component_gcda_dict, - developer_path, resident_service_path, services_str, root, port_nu) - return - - -if __name__ == '__main__': - command_args = sys.argv[1] - command_str = command_args.split("command_str=")[1].replace(",", " ") - current_path = os.getcwd() - _init_sys_config() - from localCoverage.utils import get_product_name, coverage_command, hdc_command, FoundationServer - - root_path = current_path.split("/test/testfwk/developer_test")[0] - developer_test_path = os.path.join(root_path, "test/testfwk/developer_test") - service_path = os.path.join( - developer_test_path, "localCoverage/resident_service") - config_path = os.path.join(service_path, "config") - product_name = get_product_name(root_path) - - # 获取子系统部件与服务的关系 - system_dict, services_dict, component_dict = get_server_dict(command_str) - - ip, port, sn = get_config_ip(os.path.join(developer_test_path, "config/user_config.xml")) - if not port: - port = "8710" - device_sn_list = [] - if sn: - device_sn_list.extend(sn.replace(" ", "").split(";")) - else: - device_sn_list = get_sn_list("hdc -s %s:%s list targets" % (ip, port)) - - if ip and len(device_sn_list) >= 1 and len(system_dict.keys()) >= 1: - for sn_str in device_sn_list: - get_service_list(ip, sn_str, system_dict, services_dict, component_dict, - developer_test_path, service_path, root_path, port) - restore_config(ip, port, sn_str, config_path) +#!/usr/bin/env python3 +# coding=utf-8 + +# +# Copyright (c) 2020-2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import sys + +from public_method import get_server_dict, get_config_ip, get_sn_list + + +def _init_sys_config(): + sys.localcoverage_path = os.path.join(current_path, "..") + sys.path.insert(0, sys.localcoverage_path) + + +def restore_config(device_ip, device_port, device_sn, cfg_path): + """ + 恢复设备内配置文件 + :param device_ip: + :param device_sn: + :param cfg_path: + :param device_port: + :return: + """ + remount_cmd = "shell mount -o rw,remount /" + hdc_command(device_ip, device_port, device_sn, remount_cmd) + origin_foundation = os.path.join(cfg_path, "foundation_origin.json") + restore_foundation_cmd = "file send {} /system/profile/foundation.json".format(origin_foundation) + hdc_command(device_ip, device_port, device_sn, restore_foundation_cmd) + serv_list = FoundationServer.lib_dict + for serv in serv_list: + rm_xml_cmd = "shell rm /system/profile/{}.json".format(serv) + hdc_command(device_ip, device_port, device_sn, rm_xml_cmd) + rm_cfg_cmd = "shell rm /etc/init/{}.cfg".format(serv) + hdc_command(device_ip, device_port, device_sn, rm_cfg_cmd) + + +def attach_pid(device_ip, device_sn, process_str, component_gcda_dict, developer_path, + resident_service_path, services_str, root, device_port): + """ + 1. 在设备里ps -ef | grep SERVICE 获取进程号 + 2. kill - '信号' pid + """ + hdc_str = "hdc -s %s:%s -t %s" % (device_ip, device_port, device_sn) + print("%s shell chmod 777 /data/gcov -R" % hdc_str) + coverage_command("%s shell chmod 777 /data/gcov -R" % hdc_str) + coverage_command("%s shell mount -o rw,remount /" % hdc_str) + local_sh_path = os.path.join(resident_service_path, "resources", "gcov_flush.sh") + coverage_command("dos2unix %s" % local_sh_path) + print("%s file send %s %s" % (hdc_str, local_sh_path, "/data/")) + coverage_command("%s file send %s %s" % (hdc_str, local_sh_path, "/data/")) + coverage_command("%s shell chmod 777 /data/gcov_flush.sh" % hdc_str) + print("%s shell sh /data/gcov_flush.sh %s" % (hdc_str, services_str)) + coverage_command("%s shell sh /data/gcov_flush.sh %s" % (hdc_str, services_str)) + + # 拉取gcda文件 + get_gcda_file(device_ip, device_sn, process_str, component_gcda_dict, + developer_path, services_str, root, device_port) + + +def get_gcda_file(device_ip, device_sn, process_str, component_gcda_dict, + developertest_path, services_str, roots_path, device_port): + hdc_str = "hdc -s %s:%s -t %s" % (device_ip, device_port, device_sn) + home_path = '/'.join(roots_path.split("/")[:3]) + gcda_path = f"/data/gcov{roots_path}" + + component_gcda_paths = component_gcda_dict.get(process_str) if component_gcda_dict.get(process_str) else [] + for component_gcda_path in component_gcda_paths: + gcov_root = os.path.join(gcda_path, 'out', product_name, component_gcda_path) + gcda_file_name = os.path.basename(gcov_root) + gcda_file_path = os.path.dirname(gcov_root) + print("%s shell 'cd %s; tar -czf %s.tar.gz %s'" % ( + hdc_str, gcda_file_path, gcda_file_name, gcda_file_name)) + coverage_command("%s shell 'cd %s; tar -czf %s.tar.gz %s'" % ( + hdc_str, gcda_file_path, gcda_file_name, gcda_file_name + )) + + local_gcda_path = os.path.dirname( + os.path.join(developertest_path, "reports/coverage/data/cxx", + f"{services_str}_service", component_gcda_path)) + + if not os.path.exists(local_gcda_path): + os.makedirs(local_gcda_path) + tar_path = os.path.join(gcda_file_path, "%s.tar.gz" % gcda_file_name) + print("%s file recv %s %s" % (hdc_str, tar_path, local_gcda_path)) + coverage_command("%s file recv %s %s" % ( + hdc_str, tar_path, local_gcda_path)) + + local_tar = os.path.join(local_gcda_path, "%s.tar.gz" % gcda_file_name) + print("tar -zxf %s -C %s > /dev/null 2>&1" % (local_tar, local_gcda_path)) + coverage_command("tar -zxf %s -C %s > /dev/null 2>&1" % ( + local_tar, local_gcda_path)) + coverage_command("rm -rf %s" % local_tar) + print("%s shell rm -fr %s" % (hdc_str, f"/data/gcov{home_path}")) + coverage_command("%s shell rm -fr %s" % (hdc_str, f"/data/gcov{home_path}")) + + +def get_service_list(device_ip, device_sn, system_info_dict, services_component_dict, + component_gcda_dict, developer_path, resident_service_path, root, port_nu): + + service_list = [] + for key, value_list in system_info_dict.items(): + for process_str in value_list: + if process_str in services_component_dict.keys(): + service_list.append(process_str) + else: + return + if len(service_list) > 0: + for process_str in service_list: + services_list = process_str.split("|") + for services_str in services_list: + attach_pid(device_ip, device_sn, process_str, component_gcda_dict, + developer_path, resident_service_path, services_str, root, port_nu) + return + + +if __name__ == '__main__': + command_args = sys.argv[1] + command_str = command_args.split("command_str=")[1].replace(",", " ") + current_path = os.getcwd() + _init_sys_config() + from local_coverage.utils import get_product_name, coverage_command, hdc_command, FoundationServer + + root_path = current_path.split("/test/testfwk/developer_test")[0] + developer_test_path = os.path.join(root_path, "test/testfwk/developer_test") + service_path = os.path.join( + developer_test_path, "local_coverage/resident_service") + config_path = os.path.join(service_path, "config") + product_name = get_product_name(root_path) + + # 获取子系统部件与服务的关系 + system_dict, services_dict, component_dict = get_server_dict(command_str) + + ip, port, sn = get_config_ip(os.path.join(developer_test_path, "config/user_config.xml")) + if not port: + port = "8710" + device_sn_list = [] + if sn: + device_sn_list.extend(sn.replace(" ", "").split(";")) + else: + device_sn_list = get_sn_list("hdc -s %s:%s list targets" % (ip, port)) + + if ip and len(device_sn_list) >= 1 and len(system_dict.keys()) >= 1: + for sn_str in device_sn_list: + get_service_list(ip, sn_str, system_dict, services_dict, component_dict, + developer_test_path, service_path, root_path, port) + restore_config(ip, port, sn_str, config_path) diff --git a/localCoverage/resident_service/resources/gcov_flush.sh b/local_coverage/resident_service/resources/gcov_flush.sh similarity index 100% rename from localCoverage/resident_service/resources/gcov_flush.sh rename to local_coverage/resident_service/resources/gcov_flush.sh diff --git a/localCoverage/resident_service/system_part_service.json b/local_coverage/resident_service/system_part_service.json similarity index 98% rename from localCoverage/resident_service/system_part_service.json rename to local_coverage/resident_service/system_part_service.json index b1dba00..fe539c1 100644 --- a/localCoverage/resident_service/system_part_service.json +++ b/local_coverage/resident_service/system_part_service.json @@ -1,115 +1,115 @@ -{ - "system_info_dict": { - "window": ["wms"], - "security": ["huks_service", "dlp_permission", "accesstoken_ser|privacy_service|token_sync_ser", "dlp_credential_"], - "multimedia": ["media_service", "av_session"], - "resourceschedule": ["device_usage_st", "resource_schedu", "bgtaskmgr_servi"], - "account": ["accountmgr"], - "telephony": ["telephony|riladapter_host"], - "communication": ["netmanager", "samgr"], - "deviceprofile": ["distributedsche"], - "bundlemanager": ["bms"], - "distributeddatamgr": ["pasteboard_serv"], - "filemanagement": ["com.ohos.medialibrary.medialibrarydata.entry:FileExtensionAbility", "com.ohos.UserFile.ExternalFileManager.entry:FileExtensionAbility"], - "miscservices": ["inputmethod_ser"], - "hdf": [ - "hdf_devmgr|input_host|audio_host|sample_host|fingerprint_auth_host|user_auth_host|pin_auth_host|face_auth_host|nfc_host|codec_host|wifi_host|motion_host|sensor_host|riladapter_host|hwc_host|gralloc_host|camera_host|usb_host|blue_host|audio_hdi_server_host|power_host|a2dp_host|location_host|dcamera_host|daudio_host" - ], - "notification": ["ans"], - "graphic": ["render_service"], - "location": ["locationhub"], - "time_service": ["time_service"], - "sensors": ["sensors"], - "msdp": ["msdp"], - "screenlock_serv": ["screenlock_serv"], - "dlp_credential_service_sa": ["dlp_credential_service_sa"], - "wallpaper_servi": ["wallpaper_servi"], - "hilogd": ["hilogd|hidumper_service"], - "power_mgr": ["power"], - "data_share": ["com.ohos.medialibrary.medialibrarydata"], - "dinput": ["dinput"], - "dsoftbus": ["softbus_server"] - }, - "services_component_dict": { - "wms": ["window_manager"], - "bms": ["bundle_framework"], - "power": ["battery_manager", "battery_statistics", "display_manager", "power_manager", "thermal_manager"], - "huks_service": ["huks"], - "dlp_permission": ["dlp_permission_service"], - "media_service": ["player_framework"], - "device_usage_st": ["device_usage_statistics"], - "accountmgr": ["os_account"], - "av_session": ["multimedia_av_session"], - "accesstoken_ser|privacy_service|token_sync_ser": ["access_token"], - "telephony|riladapter_host": [ - "call_manager", "cellular_call", "cellular_data", "core_service","data_storage", - "ril_adapter", "state_registry", "ims", "sms_mms" - ], - "netmanager": ["netmanager_base", "netmanager_ext", "netstack"], - "samgr": ["samgr"], - "distributedsche": ["dmsfwk", "device_info_manager"], - "resource_schedu": ["efficiency_manager"], - "bgtaskmgr_servi": ["background_task_mgr"], - "pasteboard_serv": ["pasteboard"], - "com.ohos.medialibrary.medialibrarydata.entry:FileExtensionAbility|com.ohos.UserFile.ExternalFileManager.entry:FileExtensionAbility": ["filemanagement"], - "com.ohos.medialibrary.medialibrarydata": ["data_share"], - "inputmethod_ser": ["imf"], - "hdf_devmgr|input_host|audio_host|sample_host|fingerprint_auth_host|user_auth_host|pin_auth_host|face_auth_host|nfc_host|codec_host|wifi_host|motion_host|sensor_host|riladapter_host|hwc_host|gralloc_host|camera_host|usb_host|blue_host|audio_hdi_server_host|power_host|a2dp_host|location_host|dcamera_host|daudio_host": [ - "drivers_peripheral_battery", "drivers_peripheral_motion", "drivers_peripheral_sensor", - "drivers_peripheral_thermal", "hdf", "hdf_core", "hidl_adapter","drivers_peripheral_input", - "drivers_peripheral_power" - ], - "ans": ["distributed_notification_service"], - "render_service": ["graphic", "graphic_2d"], - "dlp_credential_|dlp_credential_service_sa": ["dlp_credential_service"], - "locationhub": ["location"], - "time_service": ["time_service"], - "sensors": ["sensor"], - "msdp": ["algorithm", "geofence", "movement", "timeline", "spatialawareness_manager_native", "msdp"], - "screenlock_serv": ["screenlock"], - "wallpaper_servi": ["theme", "wallpaper_mgr"], - "hilogd|hidumper_service": ["hiviewdfx"], - "dinput": ["distributed_input_sourcemanager_test", "distributed_input_sourcetrans_test"], - "softbus_server": [ - "BusCenterHeartbeatSdkTest", "BusCenterMetaNodeSdkTest", "BusCenterSdkTest", - "BusCenterServerTest", "ClientBusCenterMgrTest", "ClientBusMangerTest", "SetDataChangeTest" - ] - }, - "component_gcda_dict": { - "wms": ["obj/foundation/window/window_manager"], - "huks_service": ["obj/base/security/huks"], - "dlp_permission": ["obj/base/security/dlp_permission_service"], - "media_service": ["obj/foundation/multimedia/player_framework"], - "device_usage_st": ["obj/foundation/resourceschedule"], - "accountmgr": ["obj/base/account/os_account"], - "av_session": ["obj/foundation/multimedia/av_session"], - "accesstoken_ser|privacy_service|token_sync_ser": ["obj/base/security/access_token"], - "telephony|riladapter_host": ["obj/base/telephony"], - "netmanager": ["obj/foundation/communication"], - "samgr": ["obj/foundation/systemabilitymgr"], - "distributedsche": ["obj/foundation/ability/dmsfwk", "obj/foundation/deviceprofile"], - "resource_schedu": ["obj/foundation/resourceschedule/efficiency_manager"], - "bgtaskmgr_servi": ["obj/foundation/resourceschedule/background_task_mgr"], - "bms": ["obj/foundation/bundlemanager/bundle_framework"], - "pasteboard_serv": ["obj/foundation/distributeddatamgr"], - "com.ohos.medialibrary.medialibrarydata.entry:FileExtensionAbility|com.ohos.UserFile.ExternalFileManager.entry:FileExtensionAbility": ["obj/foundation/multimedia", "obj/foundation/filemanagement"], - "inputmethod_ser": ["obj/base/inputmethod/imf"], - "hdf_devmgr|input_host|audio_host|sample_host|fingerprint_auth_host|user_auth_host|pin_auth_host|face_auth_host|nfc_host|codec_host|wifi_host|motion_host|sensor_host|riladapter_host|hwc_host|gralloc_host|camera_host|usb_host|blue_host|audio_hdi_server_host|power_host|a2dp_host|location_host|dcamera_host|daudio_host": [ - "obj/drivers" - ], - "ans": ["obj/base/notification/distributed_notification_service"], - "render_service": ["obj/foundation/graphic/graphic_2d"], - "dlp_credential_|dlp_credential_service_sa": ["obj/base/security/dlp_credential_service"], - "locationhub": ["obj/base/location/services"], - "time_service": ["obj/base/time/time_service"], - "sensors": ["obj/base/sensors"], - "msdp": ["obj/base/msdp"], - "screenlock_serv": ["obj/base/theme/screenlock_mgr/services"], - "wallpaper_servi": ["obj/base/theme/wallpaper_mgr"], - "hilogd|hidumper_service": ["obj/base/hiviewdfx"], - "power": ["obj/base/powermgr"], - "com.ohos.medialibrary.medialibrarydata": ["obj/foundation/distributeddatamgr/data_share"], - "dinput": ["obj/foundation/distributedhardware/distributed_input"], - "softbus_server": ["obj/foundation/communication/dsoftbus"] - } +{ + "system_info_dict": { + "window": ["wms"], + "security": ["huks_service", "dlp_permission", "accesstoken_ser|privacy_service|token_sync_ser", "dlp_credential_"], + "multimedia": ["media_service", "av_session"], + "resourceschedule": ["device_usage_st", "resource_schedu", "bgtaskmgr_servi"], + "account": ["accountmgr"], + "telephony": ["telephony|riladapter_host"], + "communication": ["netmanager", "samgr"], + "deviceprofile": ["distributedsche"], + "bundlemanager": ["bms"], + "distributeddatamgr": ["pasteboard_serv"], + "filemanagement": ["com.ohos.medialibrary.medialibrarydata.entry:FileExtensionAbility", "com.ohos.UserFile.ExternalFileManager.entry:FileExtensionAbility"], + "miscservices": ["inputmethod_ser"], + "hdf": [ + "hdf_devmgr|input_host|audio_host|sample_host|fingerprint_auth_host|user_auth_host|pin_auth_host|face_auth_host|nfc_host|codec_host|wifi_host|motion_host|sensor_host|riladapter_host|hwc_host|gralloc_host|camera_host|usb_host|blue_host|audio_hdi_server_host|power_host|a2dp_host|location_host|dcamera_host|daudio_host" + ], + "notification": ["ans"], + "graphic": ["render_service"], + "location": ["locationhub"], + "time_service": ["time_service"], + "sensors": ["sensors"], + "msdp": ["msdp"], + "screenlock_serv": ["screenlock_serv"], + "dlp_credential_service_sa": ["dlp_credential_service_sa"], + "wallpaper_servi": ["wallpaper_servi"], + "hilogd": ["hilogd|hidumper_service"], + "power_mgr": ["power"], + "data_share": ["com.ohos.medialibrary.medialibrarydata"], + "dinput": ["dinput"], + "dsoftbus": ["softbus_server"] + }, + "services_component_dict": { + "wms": ["window_manager"], + "bms": ["bundle_framework"], + "power": ["battery_manager", "battery_statistics", "display_manager", "power_manager", "thermal_manager"], + "huks_service": ["huks"], + "dlp_permission": ["dlp_permission_service"], + "media_service": ["player_framework"], + "device_usage_st": ["device_usage_statistics"], + "accountmgr": ["os_account"], + "av_session": ["multimedia_av_session"], + "accesstoken_ser|privacy_service|token_sync_ser": ["access_token"], + "telephony|riladapter_host": [ + "call_manager", "cellular_call", "cellular_data", "core_service","data_storage", + "ril_adapter", "state_registry", "ims", "sms_mms" + ], + "netmanager": ["netmanager_base", "netmanager_ext", "netstack"], + "samgr": ["samgr"], + "distributedsche": ["dmsfwk", "device_info_manager"], + "resource_schedu": ["efficiency_manager"], + "bgtaskmgr_servi": ["background_task_mgr"], + "pasteboard_serv": ["pasteboard"], + "com.ohos.medialibrary.medialibrarydata.entry:FileExtensionAbility|com.ohos.UserFile.ExternalFileManager.entry:FileExtensionAbility": ["filemanagement"], + "com.ohos.medialibrary.medialibrarydata": ["data_share"], + "inputmethod_ser": ["imf"], + "hdf_devmgr|input_host|audio_host|sample_host|fingerprint_auth_host|user_auth_host|pin_auth_host|face_auth_host|nfc_host|codec_host|wifi_host|motion_host|sensor_host|riladapter_host|hwc_host|gralloc_host|camera_host|usb_host|blue_host|audio_hdi_server_host|power_host|a2dp_host|location_host|dcamera_host|daudio_host": [ + "drivers_peripheral_battery", "drivers_peripheral_motion", "drivers_peripheral_sensor", + "drivers_peripheral_thermal", "hdf", "hdf_core", "hidl_adapter","drivers_peripheral_input", + "drivers_peripheral_power" + ], + "ans": ["distributed_notification_service"], + "render_service": ["graphic", "graphic_2d"], + "dlp_credential_|dlp_credential_service_sa": ["dlp_credential_service"], + "locationhub": ["location"], + "time_service": ["time_service"], + "sensors": ["sensor"], + "msdp": ["algorithm", "geofence", "movement", "timeline", "spatialawareness_manager_native", "msdp"], + "screenlock_serv": ["screenlock"], + "wallpaper_servi": ["theme", "wallpaper_mgr"], + "hilogd|hidumper_service": ["hiviewdfx"], + "dinput": ["distributed_input_sourcemanager_test", "distributed_input_sourcetrans_test"], + "softbus_server": [ + "BusCenterHeartbeatSdkTest", "BusCenterMetaNodeSdkTest", "BusCenterSdkTest", + "BusCenterServerTest", "ClientBusCenterMgrTest", "ClientBusMangerTest", "SetDataChangeTest" + ] + }, + "component_gcda_dict": { + "wms": ["obj/foundation/window/window_manager"], + "huks_service": ["obj/base/security/huks"], + "dlp_permission": ["obj/base/security/dlp_permission_service"], + "media_service": ["obj/foundation/multimedia/player_framework"], + "device_usage_st": ["obj/foundation/resourceschedule"], + "accountmgr": ["obj/base/account/os_account"], + "av_session": ["obj/foundation/multimedia/av_session"], + "accesstoken_ser|privacy_service|token_sync_ser": ["obj/base/security/access_token"], + "telephony|riladapter_host": ["obj/base/telephony"], + "netmanager": ["obj/foundation/communication"], + "samgr": ["obj/foundation/systemabilitymgr"], + "distributedsche": ["obj/foundation/ability/dmsfwk", "obj/foundation/deviceprofile"], + "resource_schedu": ["obj/foundation/resourceschedule/efficiency_manager"], + "bgtaskmgr_servi": ["obj/foundation/resourceschedule/background_task_mgr"], + "bms": ["obj/foundation/bundlemanager/bundle_framework"], + "pasteboard_serv": ["obj/foundation/distributeddatamgr"], + "com.ohos.medialibrary.medialibrarydata.entry:FileExtensionAbility|com.ohos.UserFile.ExternalFileManager.entry:FileExtensionAbility": ["obj/foundation/multimedia", "obj/foundation/filemanagement"], + "inputmethod_ser": ["obj/base/inputmethod/imf"], + "hdf_devmgr|input_host|audio_host|sample_host|fingerprint_auth_host|user_auth_host|pin_auth_host|face_auth_host|nfc_host|codec_host|wifi_host|motion_host|sensor_host|riladapter_host|hwc_host|gralloc_host|camera_host|usb_host|blue_host|audio_hdi_server_host|power_host|a2dp_host|location_host|dcamera_host|daudio_host": [ + "obj/drivers" + ], + "ans": ["obj/base/notification/distributed_notification_service"], + "render_service": ["obj/foundation/graphic/graphic_2d"], + "dlp_credential_|dlp_credential_service_sa": ["obj/base/security/dlp_credential_service"], + "locationhub": ["obj/base/location/services"], + "time_service": ["obj/base/time/time_service"], + "sensors": ["obj/base/sensors"], + "msdp": ["obj/base/msdp"], + "screenlock_serv": ["obj/base/theme/screenlock_mgr/services"], + "wallpaper_servi": ["obj/base/theme/wallpaper_mgr"], + "hilogd|hidumper_service": ["obj/base/hiviewdfx"], + "power": ["obj/base/powermgr"], + "com.ohos.medialibrary.medialibrarydata": ["obj/foundation/distributeddatamgr/data_share"], + "dinput": ["obj/foundation/distributedhardware/distributed_input"], + "softbus_server": ["obj/foundation/communication/dsoftbus"] + } } \ No newline at end of file diff --git a/localCoverage/restore_comment/__init__.py b/local_coverage/restore_comment/__init__.py similarity index 100% rename from localCoverage/restore_comment/__init__.py rename to local_coverage/restore_comment/__init__.py diff --git a/localCoverage/restore_comment/after_lcov_branch.py b/local_coverage/restore_comment/after_lcov_branch.py similarity index 94% rename from localCoverage/restore_comment/after_lcov_branch.py rename to local_coverage/restore_comment/after_lcov_branch.py index 609a43c..6a5fe8a 100644 --- a/localCoverage/restore_comment/after_lcov_branch.py +++ b/local_coverage/restore_comment/after_lcov_branch.py @@ -1,85 +1,85 @@ -#!/usr/bin/env python3 -# coding=utf-8 - -# -# Copyright (c) 2020-2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import os -import subprocess -import stat - -FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL -MODES = stat.S_IWUSR | stat.S_IRUSR - - -def get_file_list(find_path, postfix=""): - file_names = os.listdir(find_path) - file_list = [] - if len(file_names) > 0: - for fn in file_names: - if postfix != "": - if fn.find(postfix) != -1 and fn[-len(postfix):] == postfix: - file_list.append(fn) - else: - file_list.append(fn) - return file_list - - -def get_file_list_by_postfix(path, postfix=""): - file_list = [] - for dirs in os.walk(path): - files = get_file_list(find_path=dirs[0], postfix=postfix) - for file_name in files: - if "" != file_name and -1 == file_name.find(__file__): - file_name = os.path.join(dirs[0], file_name) - if os.path.isfile(file_name): - file_list.append(file_name) - return file_list - - -def recover_source_file(cpp_list, keys): - if not cpp_list: - print("no any .cpp file here") - return - - for path in cpp_list: - if not os.path.exists(path): - return - for key in keys: - with open(path, "r") as read_fp: - code_lines = read_fp.readlines() - if os.path.exists(f"{path.split('.')[0]}_bk.html"): - os.remove(f"{path.split('.')[0]}_bk.html") - with os.fdopen(os.open(f"{path.split('.')[0]}_bk.html", FLAGS, MODES), 'w') as write_fp: - for line in code_lines: - if key in line: - write_fp.write(line.strip("\n").strip("\n\r").replace(" //LCOV_EXCL_BR_LINE", "")) - write_fp.write("\n") - else: - write_fp.write(line) - - os.remove(path) - subprocess.Popen("mv %s %s" % (f"{path.split('.')[0]}_bk.html", path), - shell=True).communicate() - - -if __name__ == '__main__': - current_path = os.getcwd() - root_path = current_path.split("/test/testfwk/developer_test")[0] - html_path = os.path.join( - root_path, - "test/testfwk/developer_test/localCoverage/codeCoverage/results/coverage/reports/cxx/html") - cpp_arr_list = get_file_list_by_postfix(html_path, ".html") - recover_source_file(cpp_arr_list, keys=[" //LCOV_EXCL_BR_LINE"]) +#!/usr/bin/env python3 +# coding=utf-8 + +# +# Copyright (c) 2020-2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import subprocess +import stat + +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + + +def get_file_list(find_path, postfix=""): + file_names = os.listdir(find_path) + file_list = [] + if len(file_names) > 0: + for fn in file_names: + if postfix != "": + if fn.find(postfix) != -1 and fn[-len(postfix):] == postfix: + file_list.append(fn) + else: + file_list.append(fn) + return file_list + + +def get_file_list_by_postfix(path, postfix=""): + file_list = [] + for dirs in os.walk(path): + files = get_file_list(find_path=dirs[0], postfix=postfix) + for file_name in files: + if "" != file_name and -1 == file_name.find(__file__): + file_name = os.path.join(dirs[0], file_name) + if os.path.isfile(file_name): + file_list.append(file_name) + return file_list + + +def recover_source_file(cpp_list, keys): + if not cpp_list: + print("no any .cpp file here") + return + + for path in cpp_list: + if not os.path.exists(path): + return + for key in keys: + with open(path, "r") as read_fp: + code_lines = read_fp.readlines() + if os.path.exists(f"{path.split('.')[0]}_bk.html"): + os.remove(f"{path.split('.')[0]}_bk.html") + with os.fdopen(os.open(f"{path.split('.')[0]}_bk.html", FLAGS, MODES), 'w') as write_fp: + for line in code_lines: + if key in line: + write_fp.write(line.strip("\n").strip("\n\r").replace(" //LCOV_EXCL_BR_LINE", "")) + write_fp.write("\n") + else: + write_fp.write(line) + + os.remove(path) + subprocess.Popen("mv %s %s" % (f"{path.split('.')[0]}_bk.html", path), + shell=True).communicate() + + +if __name__ == '__main__': + current_path = os.getcwd() + root_path = current_path.split("/test/testfwk/developer_test")[0] + html_path = os.path.join( + root_path, + "test/testfwk/developer_test/local_coverage/code_coverage/results/coverage/reports/cxx/html") + cpp_arr_list = get_file_list_by_postfix(html_path, ".html") + recover_source_file(cpp_arr_list, keys=[" //LCOV_EXCL_BR_LINE"]) diff --git a/localCoverage/restore_comment/build_before_generate.py b/local_coverage/restore_comment/build_before_generate.py similarity index 97% rename from localCoverage/restore_comment/build_before_generate.py rename to local_coverage/restore_comment/build_before_generate.py index 9d5e00e..6c7deb9 100644 --- a/localCoverage/restore_comment/build_before_generate.py +++ b/local_coverage/restore_comment/build_before_generate.py @@ -136,10 +136,10 @@ if __name__ == '__main__': root_path = current_path.split("/test/testfwk/developer_test")[0] all_system_info_path = os.path.join( root_path, - "test/testfwk/developer_test/localCoverage/all_subsystem_config.json") + "test/testfwk/developer_test/local_coverage/all_subsystem_config.json") part_info_path = os.path.join( root_path, - "test/testfwk/developer_test/localCoverage/restore_comment/part_config.json") + "test/testfwk/developer_test/local_coverage/restore_comment/part_config.json") # 获取要修改的源代码的部件信息 get_part_config_json(part_name_list, all_system_info_path, part_info_path) diff --git a/localCoverage/restore_comment/restore_source_code.py b/local_coverage/restore_comment/restore_source_code.py similarity index 92% rename from localCoverage/restore_comment/restore_source_code.py rename to local_coverage/restore_comment/restore_source_code.py index d6b543c..00ffa4f 100644 --- a/localCoverage/restore_comment/restore_source_code.py +++ b/local_coverage/restore_comment/restore_source_code.py @@ -1,46 +1,46 @@ -#!/usr/bin/env python3 -# coding=utf-8 - -# -# Copyright (c) 2020-2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import os -import subprocess -import traceback -import json - - -if __name__ == '__main__': - try: - current_path = os.getcwd() - root_path = current_path.split("/test/testfwk/developer_test")[0] - subsystem_config_path = os.path.join( - root_path, "test/testfwk/developer_test/localCoverage/restore_comment/part_config.json") - if os.path.exists(subsystem_config_path): - with open(subsystem_config_path, "r", encoding="utf-8", errors="ignore") as fp: - data_dict = json.load(fp) - for key, value in data_dict.items(): - if "path" in value.keys(): - for path_str in value["path"]: - file_path = os.path.join(root_path, path_str) - if os.path.exists(file_path): - if os.path.exists(f"{file_path}_primal"): - subprocess.Popen("rm -rf %s" % file_path, shell=True).communicate() - subprocess.Popen("mv %s %s" % ( - f"{file_path}_primal", file_path), shell=True).communicate() - else: - print("The directory does not exist.", file_path) - except(FileNotFoundError, AttributeError, ValueError, KeyError): - print("restore source code Error") +#!/usr/bin/env python3 +# coding=utf-8 + +# +# Copyright (c) 2020-2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import subprocess +import traceback +import json + + +if __name__ == '__main__': + try: + current_path = os.getcwd() + root_path = current_path.split("/test/testfwk/developer_test")[0] + subsystem_config_path = os.path.join( + root_path, "test/testfwk/developer_test/local_coverage/restore_comment/part_config.json") + if os.path.exists(subsystem_config_path): + with open(subsystem_config_path, "r", encoding="utf-8", errors="ignore") as fp: + data_dict = json.load(fp) + for key, value in data_dict.items(): + if "path" in value.keys(): + for path_str in value["path"]: + file_path = os.path.join(root_path, path_str) + if os.path.exists(file_path): + if os.path.exists(f"{file_path}_primal"): + subprocess.Popen("rm -rf %s" % file_path, shell=True).communicate() + subprocess.Popen("mv %s %s" % ( + f"{file_path}_primal", file_path), shell=True).communicate() + else: + print("The directory does not exist.", file_path) + except(FileNotFoundError, AttributeError, ValueError, KeyError): + print("restore source code Error") diff --git a/localCoverage/utils.py b/local_coverage/utils.py similarity index 100% rename from localCoverage/utils.py rename to local_coverage/utils.py diff --git a/src/core/command/run.py b/src/core/command/run.py index 887b507..b600a30 100644 --- a/src/core/command/run.py +++ b/src/core/command/run.py @@ -53,7 +53,7 @@ class Run(object): current_raw_cmd = ",".join(list(map(str, options.current_raw_cmd.split(" ")))) if options.coverage and platform.system() != "Windows": if not options.pullgcda: - push_cov_path = os.path.join(sys.framework_root_dir, "localCoverage/push_coverage_so/push_coverage.py") + push_cov_path = os.path.join(sys.framework_root_dir, "local_coverage/push_coverage_so/push_coverage.py") if os.path.exists(push_cov_path): if str(options.testpart) == "[]" and str(options.subsystem) == "[]": LOG.info("No subsystem or part input. Not push coverage so.") @@ -71,7 +71,7 @@ class Run(object): else: print(f"{push_cov_path} not exists.") - init_gcov_path = os.path.join(sys.framework_root_dir, "localCoverage/resident_service/init_gcov.py") + init_gcov_path = os.path.join(sys.framework_root_dir, "local_coverage/resident_service/init_gcov.py") if os.path.exists(init_gcov_path): subprocess.run("python3 %s command_str=%s" % ( init_gcov_path, current_raw_cmd), shell=True) @@ -295,14 +295,14 @@ class Run(object): if options.coverage and platform.system() != "Windows": pull_service_gcov_path = os.path.join( - sys.framework_root_dir, "localCoverage/resident_service/pull_service_gcda.py") + sys.framework_root_dir, "local_coverage/resident_service/pull_service_gcda.py") if os.path.exists(pull_service_gcov_path): subprocess.run("python3 %s command_str=%s" % (pull_service_gcov_path, current_raw_cmd), shell=True) else: print(f"{pull_service_gcov_path} not exists.") if not options.pullgcda: - cov_main_file_path = os.path.join(sys.framework_root_dir, "localCoverage/coverage_tools.py") + cov_main_file_path = os.path.join(sys.framework_root_dir, "local_coverage/coverage_tools.py") testpart = ",".join(list(map(str, options.partname_list))) if os.path.exists(cov_main_file_path): subprocess.run("python3 %s testpart=%s" % ( -- Gitee From 46165afbe86640eac7c0a24eeac83466476ef4d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=9B=BD=E8=BE=89?= Date: Tue, 30 Jul 2024 07:31:13 +0000 Subject: [PATCH 3/3] =?UTF-8?q?Signed-off-by:=20=E9=BB=84=E5=9B=BD?= =?UTF-8?q?=E8=BE=89=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 黄国辉 --- .../code_coverage/code_coverage_gcov_lcov.py | 2 +- .../multiprocess_code_coverage.py | 2 +- .../interface_coverage_gcov_lcov.py | 91 ++++++++++--------- .../interface_coverage/make_report.py | 16 ++-- 4 files changed, 59 insertions(+), 52 deletions(-) diff --git a/local_coverage/code_coverage/code_coverage_gcov_lcov.py b/local_coverage/code_coverage/code_coverage_gcov_lcov.py index 4ec40f9..8967aa3 100644 --- a/local_coverage/code_coverage/code_coverage_gcov_lcov.py +++ b/local_coverage/code_coverage/code_coverage_gcov_lcov.py @@ -75,7 +75,7 @@ def get_subsystem_config_info(): with open(subsystem_config_filepath, 'r') as f: data = json.load(f) if not data: - print("subsystem config file error.") + print("subsystem config file error.") for value in data.values(): subsystem_name = value.get('name') subsystem_dir = value.get('dir') diff --git a/local_coverage/code_coverage/multiprocess_code_coverage.py b/local_coverage/code_coverage/multiprocess_code_coverage.py index fc3efcd..ecf0a25 100644 --- a/local_coverage/code_coverage/multiprocess_code_coverage.py +++ b/local_coverage/code_coverage/multiprocess_code_coverage.py @@ -202,7 +202,7 @@ def gen_subsystem_trace_info(subsystem, data_dir, test_dir, lcovrc_path): def cut_info(subsystem, test_dir): trace_file = os.path.join( CODEPATH, REPORT_PATH, "single_test", - test_dir, f"{subsystem}_output.info" + test_dir, f"{subsystem}_output.info" ) output_name = os.path.join( CODEPATH, REPORT_PATH, "single_test", diff --git a/local_coverage/interface_coverage/interface_coverage_gcov_lcov.py b/local_coverage/interface_coverage/interface_coverage_gcov_lcov.py index 6974ebb..bad375d 100644 --- a/local_coverage/interface_coverage/interface_coverage_gcov_lcov.py +++ b/local_coverage/interface_coverage/interface_coverage_gcov_lcov.py @@ -99,14 +99,16 @@ def get_file_list_by_postfix(path, postfix, filter_jar=""): for dirs in os.walk(path): files = get_file_list(find_path=dirs[0], postfix=postfix) for file_path in files: - if "" != file_path and -1 == file_path.find(__file__): - pos = file_path.rfind(os.sep) - file_name = file_path[pos + 1:] - file_path = os.path.join(dirs[0], file_path) - if filter_jar != "" and file_name == filter_jar: - print("Skipped %s" % file_path) - continue - file_list.append(file_path) + if "" == file_path or -1 != file_path.find(__file__): + continue + + pos = file_path.rfind(os.sep) + file_name = file_path[pos + 1:] + file_path = os.path.join(dirs[0], file_path) + if filter_jar != "" and file_name == filter_jar: + print("Skipped %s" % file_path) + continue + file_list.append(file_path) return file_list @@ -191,16 +193,17 @@ def get_sdk_interface_func_list(part_name): return interface_func_list sdk_path = os.path.join(CODEPATH, "out", product_name, sub_path) - if os.path.exists(sdk_path): - file_list = get_file_list_by_postfix(sdk_path, ".h") - for file in file_list: - try: - if is_need_to_be_parsed(file): - interface_func_list += get_pubilc_func_list_from_headfile(file) - except Exception: - print("get interface error ", sdk_path) - else: + if not os.path.exists(sdk_path): print("Error: %s is not exist." % sdk_path) + return interface_func_list + + file_list = get_file_list_by_postfix(sdk_path, ".h") + for file in file_list: + try: + if is_need_to_be_parsed(file): + interface_func_list += get_pubilc_func_list_from_headfile(file) + except Exception: + print("get interface error ", sdk_path) return interface_func_list @@ -219,23 +222,28 @@ def get_covered_function_list(part_name): covered_function_list = [] file_name = f"{part_name}_strip.info" file_path = os.path.join(SUB_SYSTEM_INFO_PATH, file_name) - if os.path.exists(file_path): - with open(file_path, "r") as fd: - for line in fd: - if line.startswith("FNDA:"): - sub_line_string = line[len("FNDA:"):].replace("\n", "").strip() - temp_list = sub_line_string.split(",") - if len(temp_list) == 2 and int(temp_list[0]) != 0: - func_info = get_function_info_string(temp_list[1]) - after_func_info = func_info.decode("utf-8") - if "" == after_func_info: - continue - after_func_info = after_func_info.replace("\n", "") - if after_func_info == temp_list[1] and after_func_info.startswith("_"): - continue - covered_function_list.append(after_func_info) - else: - pass + if not os.path.exists(file_path): + return covered_function_list + + with open(file_path, "r") as fd: + for line in fd: + if not line.startswith("FNDA:"): + continue + + sub_line_string = line[len("FNDA:"):].replace("\n", "").strip() + temp_list = sub_line_string.split(",") + if len(temp_list) != 2 or int(temp_list[0]) == 0: + continue + + func_info = get_function_info_string(temp_list[1]) + after_func_info = func_info.decode("utf-8") + if "" == after_func_info: + continue + + after_func_info = after_func_info.replace("\n", "") + if after_func_info == temp_list[1] and after_func_info.startswith("_"): + continue + covered_function_list.append(after_func_info) return covered_function_list @@ -245,8 +253,7 @@ def get_para_sub_string(content): parentheses_list_left = [] parentheses_list_right = [] - for index in range(len(content)): - char = content[index] + for index, char in enumerate(content): if "<" == char: if 0 == len(parentheses_list_left): start_index = index @@ -303,13 +310,13 @@ def get_covered_result_data(public_interface_func_list, covered_func_list): para_list = data_list[3] return_val = data_list[4] para_string = "" - for index in range(len(para_list)): - if para_list[index].strip() == "": + new_list = [] + for curr_para in para_list: + if curr_para.strip() == "": continue - curr_para = para_list[index] - para_string += curr_para - if index < len(para_list) - 1: - para_string += ", " + + new_list.append(curr_para) + para_string = ",".join(new_list) fun_string = f"{return_val}' '{func_name}({para_string.strip().strip(',')})" fun_string = fun_string.strip() fun_string = filter_para_sub_string(fun_string) diff --git a/local_coverage/interface_coverage/make_report.py b/local_coverage/interface_coverage/make_report.py index 1a06513..38fcd5c 100644 --- a/local_coverage/interface_coverage/make_report.py +++ b/local_coverage/interface_coverage/make_report.py @@ -28,7 +28,7 @@ FLAGS_WRITE = os.O_WRONLY | os.O_CREAT | os.O_EXCL FLAGS_ADD = os.O_WRONLY | os.O_APPEND | os.O_CREAT MODES = stat.S_IWUSR | stat.S_IRUSR -html_head = """ +HTML_HEAD = """ @@ -74,12 +74,12 @@ html_head = """ """ -html_body_start = """ +HTML_BODY_START = """ """ -html_body_ended = """ +HTML_BODY_ENDED = """ """ -html_ended = """ +HTML_ENDED = """ """ @@ -96,8 +96,8 @@ def create_html_start(reportpath): if os.path.exists(reportpath): os.remove(reportpath) with os.fdopen(os.open(reportpath, FLAGS_WRITE, MODES), 'w') as report: - report.write(html_head) - report.write(html_body_start) + report.write(HTML_HEAD) + report.write(HTML_BODY_START) except(IOError, ValueError): print("Error for create html start ",) @@ -242,7 +242,7 @@ def create_table_test(reportpath, subsystem_name, datalist, total_count, covered def create_html_ended(reportpath): try: with os.fdopen(os.open(reportpath, FLAGS_ADD, MODES), 'a') as report: - report.write(html_body_ended) - report.write(html_ended) + report.write(HTML_BODY_ENDED) + report.write(HTML_ENDED) except(IOError, ValueError): print("Error for create html end") -- Gitee