From 5cadbd73102901bec9f68e3d6bf4d4b1022ce27a Mon Sep 17 00:00:00 2001 From: Teacher_Dong Date: Mon, 26 Feb 2024 17:19:04 +0800 Subject: [PATCH 1/3] Signed-off-by:Teacher_Dong --- aw/cxx/distributed/distributed.h | 2 +- aw/cxx/distributed/distributed_major.cpp | 2 +- aw/python/distributed/common/common.py | 5 +- aw/python/distributed/common/devices.py | 8 +-- aw/python/distributed/common/drivers.py | 11 +++- .../distributed/distribute/distribute.py | 13 ++++- examples/sleep/src/sleep_ex.cpp | 8 +-- .../performance/common/spent_time_test.cpp | 2 +- libs/benchmark/report/generate_report.py | 31 ++++++----- libs/fuzzlib/fuzzer_helper.py | 35 ++++++++++--- libs/fuzzlib/tools/colored.py | 6 ++- libs/fuzzlib/tools/run_result.py | 9 +++- .../codeCoverage/codeCoverage_gcov_lcov.py | 6 ++- .../codeCoverage/mutilProcess_CodeCoverage.py | 7 ++- localCoverage/coverage_tools.py | 8 ++- .../interfaceCoverage/get_innerkits_json.py | 8 ++- .../interfaceCoverage_gcov_lcov.py | 8 ++- .../interfaceCoverage/make_report.py | 17 ++++-- .../keyword_registration/keyword_filter.py | 52 ++++++++++++------- localCoverage/resident_service/init_gcov.py | 24 +++++++-- .../resident_service/public_method.py | 2 + .../resident_service/pull_service_gcda.py | 8 +-- .../restore_comment/after_lcov_branch.py | 8 ++- .../restore_comment/build_before_generate.py | 37 ++++--------- src/core/build/build_manager.py | 9 +++- src/core/build/build_testcases.py | 4 +- src/core/build/pretreat_targets.py | 19 ++++--- src/core/command/console.py | 3 +- src/core/command/display.py | 2 +- src/core/command/distribute_utils.py | 9 +++- src/core/command/gen.py | 8 ++- src/core/command/run.py | 6 +-- src/core/common.py | 4 +- src/core/config/config_manager.py | 4 +- src/core/driver/drivers.py | 45 ++++++++++------ src/core/testcase/testcase_manager.py | 19 +++++-- src/core/testkit/kit_lite.py | 4 +- src/core/utils.py | 5 +- src/main/_init_global_config.py | 4 +- 39 files changed, 312 insertions(+), 150 deletions(-) diff --git a/aw/cxx/distributed/distributed.h b/aw/cxx/distributed/distributed.h index 44c712f..a9fb144 100644 --- a/aw/cxx/distributed/distributed.h +++ b/aw/cxx/distributed/distributed.h @@ -39,7 +39,7 @@ struct DistributedCmd { }; using DistributedMsg = DistributedCmd; -#define DST_COMMAND_HEAD_LEN (sizeof(DistributedCmd)- sizeof(int)) +#define DST_COMMAND_HEAD_LEN (sizeof(DistributedCmd) - sizeof(int)) struct DistDevInfo { int devNo; diff --git a/aw/cxx/distributed/distributed_major.cpp b/aw/cxx/distributed/distributed_major.cpp index afc79f4..54690b3 100644 --- a/aw/cxx/distributed/distributed_major.cpp +++ b/aw/cxx/distributed/distributed_major.cpp @@ -255,7 +255,7 @@ bool DistributeTestEnvironment::RunTestCmd(size_t devNo, const std::string &strC return breturn; } // add 2 '\0' - size_t rlen = cmdLen + expectValueLen + DST_COMMAND_HEAD_LEN + sizeof(int)*HALF_BUF_LEN + HALF_BUF_LEN; + size_t rlen = cmdLen + expectValueLen + DST_COMMAND_HEAD_LEN + sizeof(int) * HALF_BUF_LEN + HALF_BUF_LEN; if (rlen <= MAX_BUFF_LEN) { auto pCmdTest = reinterpret_cast(szbuf); pCmdTest->cmdTestType = DST_COMMAND_CALL; diff --git a/aw/python/distributed/common/common.py b/aw/python/distributed/common/common.py index e0c087b..8581ae8 100755 --- a/aw/python/distributed/common/common.py +++ b/aw/python/distributed/common/common.py @@ -18,7 +18,10 @@ import os import time +import stat +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR ############################################################################## ############################################################################## @@ -81,7 +84,7 @@ def create_empty_result_file(savepath, filename, message=""): if filename.endswith(".hap"): filename = filename.split(".")[0] if not os.path.exists(savepath): - with open(savepath, "w", encoding='utf-8') as file_desc: + with os.fdopen(os.open(savepath, FLAGS, MODES), 'w') as file_desc: time_stamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) file_desc.write('\n') diff --git a/aw/python/distributed/common/devices.py b/aw/python/distributed/common/devices.py index 057d9c9..913de00 100755 --- a/aw/python/distributed/common/devices.py +++ b/aw/python/distributed/common/devices.py @@ -54,7 +54,7 @@ def get_package_name(hap_filepath): try: zf_desc.extractall(path=hap_bak_path) except RuntimeError as error: - print(error) + print("Unzip error", hap_bak_path) zf_desc.close() # verify config.json file @@ -215,15 +215,15 @@ class DeviceShell: stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) - + result = "" try: data, _ = proc.communicate() if isinstance(data, bytes): - data = data.decode('utf-8', 'ignore') + result = data.decode("utf-8", "ignore") finally: proc.stdout.close() proc.stderr.close() - return data + return data if result else data @classmethod def check_path_legal(cls, path): diff --git a/aw/python/distributed/common/drivers.py b/aw/python/distributed/common/drivers.py index c09ae37..2585ac7 100755 --- a/aw/python/distributed/common/drivers.py +++ b/aw/python/distributed/common/drivers.py @@ -20,6 +20,7 @@ import os import platform import subprocess import tempfile +import stat from abc import ABCMeta from abc import abstractmethod @@ -29,6 +30,9 @@ from core.config.resource_manager import ResourceManager ############################################################################## ############################################################################## +FLAGS = os.O_WRONLY | os.O_APPEND | os.O_CREAT +MODES = stat.S_IWUSR | stat.S_IRUSR + DEVICE_TEST_PATH = "/%s/%s/" % ("data", "test") @@ -48,10 +52,10 @@ def make_long_command_file(command, longcommand_path, filename): sh_file_name = '%s.sh' % filename file_path = os.path.join(longcommand_path, sh_file_name) try: - with open(file_path, "a") as file_desc: + with os.fdopen(os.open(file_path, FLAGS, MODES), 'a') as file_desc: file_desc.write(command) except(IOError, ValueError) as err_msg: - print("Error for make long command file: ", err_msg) + print(f"Error for make long command file: {err_msg}") return sh_file_name, file_path @@ -162,6 +166,9 @@ class CppTestDriver(ITestDriver): if options.coverage: receive_coverage_data(self.device, result_path, suite_file, file_name) + if os.path.exists(long_command_path): + os.remove(long_command_path) + ############################################################################## ############################################################################## diff --git a/aw/python/distributed/distribute/distribute.py b/aw/python/distributed/distribute/distribute.py index a4083f0..ad3e24c 100755 --- a/aw/python/distributed/distribute/distribute.py +++ b/aw/python/distributed/distribute/distribute.py @@ -21,6 +21,10 @@ import sys import re import time import platform +import stat + +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR # insert src path for loading xdevice modules @@ -284,6 +288,8 @@ class Distribute: dev_nodeid_info = re.findall(r"Uuid = (.*?\r\n)", device_info) if dev_nodeid_info: return str(dev_nodeid_info[0]) + else: + return "" @staticmethod def _query_device_agent_uuid(device): @@ -296,6 +302,8 @@ class Distribute: dev_nodeid_info = re.findall(r"Uuid = (.*?\r\n)", device_info) if dev_nodeid_info: return str(dev_nodeid_info[0]) + else: + return "" @staticmethod def _write_device_config(device_info, file_path): @@ -303,11 +311,12 @@ class Distribute: final_file = os.path.join(file_dir, file_name.split('.')[0] + ".desc") if os.path.exists(final_file): os.remove(final_file) - with open(file_path, 'w') as file_desc: + if os.path.exists(file_path): + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS, MODES), 'w') as file_desc: file_desc.write(device_info) os.rename(file_path, final_file) - ############################################################################## ############################################################################## diff --git a/examples/sleep/src/sleep_ex.cpp b/examples/sleep/src/sleep_ex.cpp index 46444f1..5d57d29 100644 --- a/examples/sleep/src/sleep_ex.cpp +++ b/examples/sleep/src/sleep_ex.cpp @@ -32,10 +32,10 @@ static double TimeDiff(struct timeval *x , struct timeval *y) return 0; } - double xUs = reinterpret_cast(x->tv_sec * SleepTest::ID_MS_TO_NS_LEVEL) - + reinterpret_cast(x->tv_usec); - double yUs = reinterpret_cast(y->tv_sec * SleepTest::ID_MS_TO_NS_LEVEL) - + reinterpret_cast(y->tv_usec); + double xUs = reinterpret_cast(x->tv_sec * SleepTest::ID_MS_TO_NS_LEVEL) + + reinterpret_cast(x->tv_usec); + double yUs = reinterpret_cast(y->tv_sec * SleepTest::ID_MS_TO_NS_LEVEL) + + reinterpret_cast(y->tv_usec); return (yUs - xUs); } diff --git a/examples/sleep/test/performance/common/spent_time_test.cpp b/examples/sleep/test/performance/common/spent_time_test.cpp index 421ffde..fe3c568 100644 --- a/examples/sleep/test/performance/common/spent_time_test.cpp +++ b/examples/sleep/test/performance/common/spent_time_test.cpp @@ -36,7 +36,7 @@ static void LoopMsleep(void* pMsec) return; } - int msec = *reinterpret_cast (pMsec); + int msec = *reinterpret_cast(pMsec); for (int index = 0; index < msec; index++) { Msleep(1); } diff --git a/libs/benchmark/report/generate_report.py b/libs/benchmark/report/generate_report.py index 9cb5c23..45ae6bd 100644 --- a/libs/benchmark/report/generate_report.py +++ b/libs/benchmark/report/generate_report.py @@ -20,6 +20,10 @@ import json import os import shutil import sys +import stat + +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR SETTING_RED_STYLE = """\033[33;31m%s\033[0m""" @@ -33,8 +37,7 @@ def load_json_data(json_file_path): print("Loading file \"%s\" error" % json_file_path) return {} except(IOError, ValueError) as err_msg: - print("Error for load_json_data: \"%s\"" % - json_file_path, err_msg) + print("Error for load_json_data: ", json_file_path) else: print("Info: \"%s\" not exist." % json_file_path) return json_data @@ -265,16 +268,16 @@ class BenchmarkReport(object): len(content_new)] try: - with open(os.path.abspath(out_report_file_path), "w") \ - as output_fd: + if os.path.exists(os.path.abspath(out_report_file_path)): + os.remove(os.path.abspath(out_report_file_path)) + with os.fdopen(os.open(os.path.abspath(out_report_file_path), + FLAGS, MODES), 'w') as output_fd: content_new = str(content_new) output_fd.write(content_new) except IOError as err_msg: - print("Error5 for open %s failed, with msg %s" % - (out_report_file_path, err_msg)) + print("Error5 for open %s failed:" % out_report_file_path) except IOError as err_msg: - print("Error6 for open %s failed, with msg %s" % - (tmpl_file_path, err_msg)) + print("Error6 for open %s failed:" % tmpl_file_path) def _generate_all_benchmark_detail(self, dest_dir_parh): for benchmark_info in self.benchmark_list: @@ -327,15 +330,15 @@ class BenchmarkReport(object): self._update_report_summary(content_new, detail_info) try: - with open(os.path.abspath(out_report_file_path), "w") \ - as output_fd: + if os.path.exists(os.path.abspath(out_report_file_path)): + os.remove(os.path.abspath(out_report_file_path)) + with os.fdopen(os.open(os.path.abspath(out_report_file_path), + FLAGS, MODES), 'w') as output_fd: output_fd.write(content_new) except IOError as err_msg: - print("Error5 for open %s failed, with msg %s" % - (out_report_file_path, err_msg)) + print("Error5 for open %s failed:" % out_report_file_path) except IOError as err_msg: - print("Error6 for open %s failed, with msg %s" % - (report_tmpl_file_path, err_msg)) + print("Error6 for open %s failed" % report_tmpl_file_path) def _get_detail_info(self, benchmark_info): detail_info = [] diff --git a/libs/fuzzlib/fuzzer_helper.py b/libs/fuzzlib/fuzzer_helper.py index df633f0..e451ee3 100644 --- a/libs/fuzzlib/fuzzer_helper.py +++ b/libs/fuzzlib/fuzzer_helper.py @@ -29,6 +29,7 @@ import time import copy import shutil from pprint import pprint +import stat from tools.colored import Colored from tools.templates import GN_ENTRY_TEMPLATE @@ -38,6 +39,9 @@ from tools.templates import PROJECT_HEADER_TEMPLATE from tools.templates import PROJECT_XML_TEMPLATE from tools.run_result import RunResult +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) SOURCE_ROOT_DIR = os.path.dirname( os.path.dirname( @@ -93,7 +97,7 @@ def _get_fuzzer_yaml_config(fuzzer_name): fuzzer_name, "project.yaml") if not os.path.exists(project_yaml_path): - return + return {} #log run stdout to fuzzlog dir with open(project_yaml_path) as filehandle: yaml_config = yaml.safe_load(filehandle) @@ -129,25 +133,36 @@ def generate(args): color_logger.green('Writing new files to %s' % project_dir_path) file_path = os.path.join(project_dir_path, 'project.xml') - with open(file_path, 'w') as filehandle: + if os.path.exists(file_path): + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS, MODES), 'w') as filehandle: filehandle.write(PROJECT_XML_TEMPLATE % template_args) file_path = os.path.join(project_dir_path, "%s.cpp" % args.project_name) - with open(file_path, 'w') as filehandle: + if os.path.exists(file_path): + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS, MODES), 'w') as filehandle: filehandle.write(PROJECT_DEMO_TEMPLATE % template_args) file_path = os.path.join(project_dir_path, "%s.h" % args.project_name) - with open(file_path, 'w') as filehandle: + if os.path.exists(file_path): + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS, MODES), 'w') as filehandle: filehandle.write(PROJECT_HEADER_TEMPLATE % template_args) file_path = os.path.join(project_dir_path, "BUILD.gn") - with open(file_path, 'w') as filehandle: + if os.path.exists(file_path): + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS, MODES), 'w') as filehandle: filehandle.write(PROJECT_GN_TEMPLATE % template_args) corpus_dir = os.path.join(project_dir_path, 'corpus') if not os.path.exists(corpus_dir): os.mkdir(corpus_dir) - with open(os.path.join(corpus_dir, 'init'), 'w') as filehandle: + if os.path.exists(os.path.join(corpus_dir, 'init')): + os.remove(os.path.join(corpus_dir, 'init')) + with os.fdopen(os.open(os.path.join(corpus_dir, 'init'), FLAGS, MODES), 'w') as filehandle: filehandle.write("FUZZ") + return 0 #complie fuzzer project @@ -187,7 +202,9 @@ def make(args, stdout=None): ) if not os.path.exists(os.path.dirname(subsystem_src_flag_file_path)): os.makedirs(os.path.dirname(subsystem_src_flag_file_path)) - with open(subsystem_src_flag_file_path, "wb") as file_handle: + if os.path.exists(subsystem_src_flag_file_path): + os.remove(subsystem_src_flag_file_path) + with os.fdopen(os.open(subsystem_src_flag_file_path, FLAGS, MODES), 'wb') as file_handle: file_handle.write(args.project_name.encode()) try: @@ -260,6 +277,10 @@ def main(): elif args.command == 'report': report(args) + return 1 + else: + return 0 + if __name__ == "__main__": main() diff --git a/libs/fuzzlib/tools/colored.py b/libs/fuzzlib/tools/colored.py index 63a4887..865c1f3 100644 --- a/libs/fuzzlib/tools/colored.py +++ b/libs/fuzzlib/tools/colored.py @@ -17,6 +17,10 @@ import sys import os import time +import stat + +FLAGS = os.O_WRONLY | os.O_APPEND | os.O_CREAT +MODES = stat.S_IWUSR | stat.S_IRUSR class Colored(object): @@ -82,7 +86,7 @@ class Colored(object): self.get_fuzz_current_project_log_dir(), "run.log" ) - with open(run_log, 'ab') as f: + with os.fdopen(os.open(run_log, FLAGS, MODES), 'ab') as f: f.write(msg + "\n") diff --git a/libs/fuzzlib/tools/run_result.py b/libs/fuzzlib/tools/run_result.py index 5fb2b6e..8c2490b 100644 --- a/libs/fuzzlib/tools/run_result.py +++ b/libs/fuzzlib/tools/run_result.py @@ -16,6 +16,11 @@ # import re +import os +import stat + +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR class RunResult(): @@ -75,7 +80,9 @@ class RunResult(): pass def write_analysis_result(self, analysis_ressult_path, html_format=True): - with open(analysis_ressult_path, "wb") as f: + if os.path.exists(analysis_ressult_path): + os.remove(analysis_ressult_path) + with os.fdopen(os.open(analysis_ressult_path, FLAGS, MODES), 'wb') as f: if html_format: f.write(RunResult.filter_log(render_detail(self.crash_info))) else: diff --git a/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py b/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py index 4edf5d4..ae82dbb 100644 --- a/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py +++ b/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py @@ -23,6 +23,10 @@ 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" @@ -57,7 +61,7 @@ def execute_command(command, printflag=False): cmd_list = shlex.split(command) coverage_log_path = os.path.join( CODEPATH, "test/testfwk/developer_test/localCoverage", "coverage.log") - with open(coverage_log_path, 'a') as fd: + 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") diff --git a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py index 1acba90..753b43b 100644 --- a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py +++ b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py @@ -23,8 +23,13 @@ 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 @@ -61,7 +66,7 @@ def execute_command(command, printflag=False): cmd_list = shlex.split(command) coverage_log_path = os.path.join( CODEPATH, "test/testfwk/developer_test/localCoverage", "coverage.log") - with open(coverage_log_path, 'a') as fd: + 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") diff --git a/localCoverage/coverage_tools.py b/localCoverage/coverage_tools.py index 1aee796..f1c5ea9 100644 --- a/localCoverage/coverage_tools.py +++ b/localCoverage/coverage_tools.py @@ -22,10 +22,14 @@ 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( @@ -45,7 +49,9 @@ def get_subsystem_config(part_list, developer_path): print("part not in all_subsystem_config.json") new_json = json.dumps(new_json_text, indent=4) - with open(system_info_path, "w") as out_file: + 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) diff --git a/localCoverage/interfaceCoverage/get_innerkits_json.py b/localCoverage/interfaceCoverage/get_innerkits_json.py index 27a3621..e8484e3 100644 --- a/localCoverage/interfaceCoverage/get_innerkits_json.py +++ b/localCoverage/interfaceCoverage/get_innerkits_json.py @@ -20,6 +20,10 @@ 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(): @@ -37,7 +41,9 @@ def gen_parts_info_json(folder_list, output_json_path, target_cpu): 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) - with open(output_json_path, "w") as json_file: + 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") diff --git a/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py b/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py index b88b01b..47cc669 100644 --- a/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py +++ b/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py @@ -22,10 +22,14 @@ import sys import json import shutil import subprocess +import stat import CppHeaderParser import get_innerkits_json import make_report +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + filter_file_name_list = [ "appexecfwk/libjnikit/include/jni.h", ] @@ -389,7 +393,9 @@ def get_summary_data(interface_data_list): def make_summary_file(summary_list, output_path): report_path = os.path.join(output_path, "coverage_summary_file.xml") try: - with open(report_path, "w") as fd: + if os.path.exists(report_path): + os.remove(report_path) + with os.fdopen(os.open(report_path, FLAGS, MODES), 'w') as fd: fd.write('\n') fd.write('\n') for item in summary_list: diff --git a/localCoverage/interfaceCoverage/make_report.py b/localCoverage/interfaceCoverage/make_report.py index c9a6d5e..1a06513 100644 --- a/localCoverage/interfaceCoverage/make_report.py +++ b/localCoverage/interfaceCoverage/make_report.py @@ -19,9 +19,14 @@ import sys import datetime +import os +import stat from importlib import reload reload(sys) +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 = """ @@ -88,7 +93,9 @@ def sort_by_field_element_data(elem): def create_html_start(reportpath): try: - with open(reportpath, "w") as report: + 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) except(IOError, ValueError): @@ -123,7 +130,7 @@ def create_title(reportpath, title_name, summary_list): nocoverd = item[1] - item[2] report_title = report_title % (item[1], item[2], nocoverd) try: - with open(reportpath, "a") as report: + with os.fdopen(os.open(reportpath, FLAGS_ADD, MODES), 'a') as report: report.write(report_title) except(IOError, ValueError): print("Error for create html title") @@ -158,7 +165,7 @@ def create_summary(reportpath, summary_list): try: if len(summary_list) == 0: return - with open(reportpath, "a") as report: + with os.fdopen(os.open(reportpath, FLAGS_ADD, MODES), 'a') as report: report.write(table_title) report.write(table_start) report.write(table_head) @@ -198,7 +205,7 @@ def create_table_test(reportpath, subsystem_name, datalist, total_count, covered table_ended = """ """ try: - with open(reportpath, "a") as report: + with os.fdopen(os.open(reportpath, FLAGS_ADD, MODES), 'a') as report: print("part_name==" + subsystem_name) tabletitle = table_title % (subsystem_name) print("tabletitle==" + tabletitle) @@ -234,7 +241,7 @@ def create_table_test(reportpath, subsystem_name, datalist, total_count, covered def create_html_ended(reportpath): try: - with open(reportpath, "a") as report: + with os.fdopen(os.open(reportpath, FLAGS_ADD, MODES), 'a') as report: report.write(html_body_ended) report.write(html_ended) except(IOError, ValueError): diff --git a/localCoverage/keyword_registration/keyword_filter.py b/localCoverage/keyword_registration/keyword_filter.py index 0c1e886..ddb627e 100644 --- a/localCoverage/keyword_registration/keyword_filter.py +++ b/localCoverage/keyword_registration/keyword_filter.py @@ -20,6 +20,7 @@ import os import re import time import json +import stat import fcntl import platform import linecache @@ -28,6 +29,10 @@ from multiprocessing import Pool from lxml import html from selectolax.parser import HTMLParser +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 + class CoverageReportPath: def __init__(self, report_path): @@ -61,8 +66,9 @@ span.branchnocovupdate { background-color:#BBBBBB; }""" - with open(css_file_path, "a+", encoding="utf-8") as file: - file.write(text) + if os.path.exists(css_file_path): + with os.fdopen(os.open(css_file_path, FLAGS_ADD, MODES), 'a+') as file: + file.write(text) def get_statistic_path(self, gcov_file_path: str): """ @@ -106,7 +112,7 @@ class KeywordRegistration: 获取覆盖率文件内容 """ if not os.path.exists(file_path): - return + return "" with open(file_path, "r", encoding="utf-8") as file: content = file.read() return content @@ -153,7 +159,7 @@ class KeywordRegistration: if not content: content = self.get_coverage_content(file_path) if not content: - return + return [] _, file_name = os.path.split(file_path) branch_line_list = re.findall( r''' 200: - return + return "" previous_line -= 1 tag = get_tag(content, previous_line) tag_text = HTMLParser(tag).text() @@ -271,7 +279,7 @@ class KeywordRegistration: while previous_line: child_count += 1 if child_count > 200: - return + return "" previous_line -= 1 html_text = get_tag(content, previous_line) source_code = HTMLParser(html_text).text()[39:].strip() @@ -285,16 +293,18 @@ class KeywordRegistration: if class_name_list: function_name_str = class_name_list[0] if not function_name_str: - return + return "" + function_name = function_name_str.split()[-1] return function_name function_name_list = re.findall(r' (.*?)\(', source_code) if function_name_list: function_name_str = function_name_list[0] if not function_name_str: - return + return "" function_name = function_name_str.split()[-1] return function_name + return "" except (OSError, IndexError, TypeError) as error: print(f"覆盖率报告{branch_line}行获取函数名报错, error:{error}", traceback.format_exc()) @@ -325,7 +335,7 @@ class KeywordRegistration: keyword_index = keyword_source_code.find(keyword) if keyword_index == -1: - return + return "" try: keyword_code = keyword_source_code[:keyword_index + len(keyword)] @@ -338,6 +348,7 @@ class KeywordRegistration: return judge_key except (IndexError, ValueError): print("获取关键字替代字符失败") + return "" @staticmethod def get_branch_data_by_tag(tag_html: str, symbol_status=None): @@ -460,7 +471,8 @@ class KeywordRegistration: if replace_tag in content: content = content.replace(replace_tag, update_tag) - with open(file_path, "w", encoding="utf-8") as file: + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS_WRITE, MODES), 'w') as file: file.write(content) # 修改数据统计页面 @@ -565,7 +577,8 @@ class KeywordRegistration: content = content.replace(replace_tag, update_tag) if file_tag in content: content = content.replace(file_tag, update_branch_tag) - with open(index_path, "w", encoding="utf-8") as file: + os.remove(index_path) + with os.fdopen(os.open(index_path, FLAGS_WRITE, MODES), 'w') as file: file.write(content) fcntl.flock(file.fileno(), fcntl.LOCK_UN) time.sleep(1) @@ -641,7 +654,7 @@ class KeywordRegistration: update_branch_tag = update_branch_tag.replace("> # <", "> <") update_branch_tag = branch_tag + update_branch_tag except ValueError: - return + return "" else: line_feed_index = branch_html.find(line_item) update_branch_tag = branch_html[:line_feed_index + len(line_item) + 1] @@ -670,7 +683,7 @@ class KeywordRegistration: branch_tag = branch_tag[line_feed_index + len(line_item) + 1:] line_feed_index = branch_tag.find(line_item) except ValueError: - return + return "" branch_tag = branch_tag.replace("> - <", "> <") update_branch_tag = update_branch_tag.replace("> # <", "> <") @@ -704,7 +717,7 @@ class KeywordRegistration: branch_tag_after = branch_tag_after.replace("> - <", "> <") branch_tag = branch_tag_before + branch_tag_after except ValueError: - return + return "" else: branch_tag = branch_html branch_tag = branch_tag.replace("> - <", "> <") @@ -749,7 +762,7 @@ class KeywordRegistration: update_branch_tag += branch_tag branch_html = branch_html[end_index + 5:] except (ValueError, TypeError): - return + return "" update_branch_tag += branch_html return update_branch_tag @@ -856,12 +869,15 @@ class KeywordRegistration: update_source_code_tag_list) content = content.replace( source_code_tag_html, update_source_code_tag_html) - with open(file_path, "w", encoding="utf-8") as new_html: + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS_WRITE, MODES), 'w') as new_html: new_html.write(content) content = self.get_coverage_content(file_path) content = content.replace('> * ', '> ') - with open(file_path, "w", encoding="utf-8") as new_html: + os.remove(file_path) + + with os.fdopen(os.open(file_path, FLAGS_WRITE, MODES), 'w') as new_html: new_html.write(content) def keyword_registration(self, file_path, keyword_list): diff --git a/localCoverage/resident_service/init_gcov.py b/localCoverage/resident_service/init_gcov.py index b42d11c..a5848dc 100644 --- a/localCoverage/resident_service/init_gcov.py +++ b/localCoverage/resident_service/init_gcov.py @@ -22,9 +22,13 @@ 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, "..") @@ -61,7 +65,9 @@ def modify_init_file(developer_path, hdc_str): else: return json_str = json.dumps(json_data, indent=2) - with open(cfg_file_path, "w") as json_file: + 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") @@ -97,7 +103,9 @@ def modify_faultloggerd_file(developer_path, hdc_str): ] }) json_str = json.dumps(json_data, indent=4) - with open(cfg_file_path, "w") as json_file: + 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/")) @@ -153,7 +161,9 @@ def modify_foundation_json(serv, config_path, origin_json) -> str: f_dict["systemability"] = tmp_list new_json = os.path.join(config_path, 'foundation.json') - with open(new_json, "w", encoding="utf-8") as f: + 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 @@ -180,7 +190,9 @@ def create_service_json(serv, config_path, origin_json) -> str: f_dict["process"] = "{}".format(serv) new_json = os.path.join(config_path, '{}.json'.format(serv)) - with open(new_json, "w", encoding="utf-8") as f: + 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 @@ -234,7 +246,9 @@ def create_service_cfg(serv, config_path, origin_cfg) -> str: json_obj["services"][0]["jobs"]["on-start"] = "services:{}".format(serv) cfg_path = os.path.join(config_path, "{}.cfg".format(serv)) - with open(cfg_path, 'w') as r: + 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 diff --git a/localCoverage/resident_service/public_method.py b/localCoverage/resident_service/public_method.py index f203c2c..7714459 100644 --- a/localCoverage/resident_service/public_method.py +++ b/localCoverage/resident_service/public_method.py @@ -75,6 +75,7 @@ def get_all_part_service(): 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): @@ -84,6 +85,7 @@ def get_system_dict_to_server_name(server_name: str, system_info_dict): system: [server_name] } return system_info_dict_after + return {} def get_server_dict(command): diff --git a/localCoverage/resident_service/pull_service_gcda.py b/localCoverage/resident_service/pull_service_gcda.py index 1ea9227..e8b2ac7 100644 --- a/localCoverage/resident_service/pull_service_gcda.py +++ b/localCoverage/resident_service/pull_service_gcda.py @@ -50,7 +50,7 @@ def restore_config(device_ip, device_port, device_sn, cfg_path): def attach_pid(device_ip, device_sn, process_str, component_gcda_dict, developer_path, - resident_service_path, services_str, root_path, device_port): + resident_service_path, services_str, root, device_port): """ 1. 在设备里ps -ef | grep SERVICE 获取进程号 2. kill - '信号' pid @@ -69,7 +69,7 @@ def attach_pid(device_ip, device_sn, process_str, component_gcda_dict, developer # 拉取gcda文件 get_gcda_file(device_ip, device_sn, process_str, component_gcda_dict, - developer_path, services_str, root_path, device_port) + developer_path, services_str, root, device_port) def get_gcda_file(device_ip, device_sn, process_str, component_gcda_dict, @@ -110,7 +110,7 @@ def get_gcda_file(device_ip, device_sn, process_str, component_gcda_dict, def get_service_list(device_ip, device_sn, system_info_dict, services_component_dict, - component_gcda_dict, developer_path, resident_service_path, root_path, port): + component_gcda_dict, developer_path, resident_service_path, root, port_nu): service_list = [] for key, value_list in system_info_dict.items(): @@ -124,7 +124,7 @@ def get_service_list(device_ip, device_sn, system_info_dict, services_component_ 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_path, port) + developer_path, resident_service_path, services_str, root, port_nu) return diff --git a/localCoverage/restore_comment/after_lcov_branch.py b/localCoverage/restore_comment/after_lcov_branch.py index 7c8198c..609a43c 100644 --- a/localCoverage/restore_comment/after_lcov_branch.py +++ b/localCoverage/restore_comment/after_lcov_branch.py @@ -18,6 +18,10 @@ 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=""): @@ -56,7 +60,9 @@ def recover_source_file(cpp_list, keys): for key in keys: with open(path, "r") as read_fp: code_lines = read_fp.readlines() - with open(f"{path.split('.')[0]}_bk.html", "w") as write_fp: + 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", "")) diff --git a/localCoverage/restore_comment/build_before_generate.py b/localCoverage/restore_comment/build_before_generate.py index 4f79506..9d5e00e 100644 --- a/localCoverage/restore_comment/build_before_generate.py +++ b/localCoverage/restore_comment/build_before_generate.py @@ -19,31 +19,10 @@ import os import subprocess import json +import stat - -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 - - -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 +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR def get_source_file_list(path): @@ -77,9 +56,9 @@ def rewrite_source_file(source_path_list: list): with open(path, "r", encoding="utf-8", errors="ignore") as read_fp: code_lines = read_fp.readlines() source_dir, suffix_name = os.path.splitext(path) - with open(f"{source_dir}_bk.{suffix_name}", "w", - encoding="utf-8", errors="ignore") as write_fp: - + if os.path.exists(f"{source_dir}_bk.{suffix_name}"): + os.remove(f"{source_dir}_bk.{suffix_name}") + with os.fdopen(os.open(f"{source_dir}_bk.{suffix_name}", FLAGS, MODES), 'w') as write_fp: for line in code_lines: for key in keys: if key in line and line.strip().startswith(key): @@ -129,7 +108,9 @@ def get_part_config_json(part_list, system_info_path, part_path): else: print("part not in all_subsystem_config.json") new_json = json.dumps(new_json_text, indent=4) - with open(part_path, "w") as out_file: + if os.path.exists(part_path): + os.remove(part_path) + with os.fdopen(os.open(part_path, FLAGS, MODES), 'w') as out_file: out_file.write(new_json) else: print("%s not exists.", system_info_path) diff --git a/src/core/build/build_manager.py b/src/core/build/build_manager.py index b7ca0e2..3c8ad7a 100644 --- a/src/core/build/build_manager.py +++ b/src/core/build/build_manager.py @@ -17,6 +17,8 @@ # import os +import stat + from xdevice import platform_logger from core.utils import scan_support_product from core.config.config_manager import UserConfigManager, FrameworkConfigManager @@ -26,6 +28,9 @@ from core.build.build_testcases import BuildTestcases from core.command.gen import Gen from core.command.run import Run +FLAGS = os.O_WRONLY | os.O_APPEND | os.O_CREAT +MODES = stat.S_IWUSR | stat.S_IRUSR + LOG = platform_logger("BuildManager") @@ -37,7 +42,9 @@ class BuildManager(object): @classmethod def _make_gn_file(cls, filepath, target_list): LOG.info("The gn file path: %s" % filepath) - with open(filepath, "w") as gn_file: + if os.path.exists(filepath): + os.remove(filepath) + with os.fdopen(os.open(filepath, FLAGS, MODES), 'w') as gn_file: gn_file.write("group(\"make_temp_test\") {\n") gn_file.write(" testonly = true\n") gn_file.write(" deps = []\n") diff --git a/src/core/build/build_testcases.py b/src/core/build/build_testcases.py index 4973aec..24f9ff3 100644 --- a/src/core/build/build_testcases.py +++ b/src/core/build/build_testcases.py @@ -346,7 +346,7 @@ class BuildTestcases(object): self._delete_xts_testcase_dir(para) xts_build_command = [] if para.productform == "rk3568": - pass + False else: xts_build_test_command = ["--abi-type", "generic_generic_arm_64only", "--device-type", get_output_path().split("/")[-1], "--build-variant", "root", "--gn-args", @@ -357,7 +357,7 @@ class BuildTestcases(object): xts_build_test_command.append(input_subsystem) if para.testsuit != "" and len(para.subsystem) == 0: LOG.error("Please specify subsystem.") - return + 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) diff --git a/src/core/build/pretreat_targets.py b/src/core/build/pretreat_targets.py index 7d30c9e..a5113df 100644 --- a/src/core/build/pretreat_targets.py +++ b/src/core/build/pretreat_targets.py @@ -19,11 +19,16 @@ import os import sys import json +import stat import shutil from core.constants import JsTestConst from xdevice import platform_logger +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 + LOG = platform_logger("PretreatTargets") @@ -84,14 +89,15 @@ class PretreatTargets(object): output_path = self._parse_output_path_in_gn(gn_path) if output_path == "": LOG.error(" BUILD.gn needs 'module_output_path'") - return + return False os.rename(gn_path, gn_bak_path) template_args = {'output_path': output_path, 'suite_name': name} - with open(gn_path, 'w') as filehandle: + os.remove(gn_path) + with os.fdopen(os.open(gn_path, FLAGS_WRITE, MODES), 'w') as filehandle: filehandle.write(JsTestConst.BUILD_GN_FILE_TEMPLATE % template_args) - #copy js hap template to target path + # copy js hap template to target path shutil.copytree(template_path, os.path.join(target_path, "src")) shutil.copy(config_path, os.path.join(target_path, "src", "main")) file_name = os.listdir(target_path) @@ -99,8 +105,8 @@ class PretreatTargets(object): if file.endswith(".js"): LOG.info("file: %s" % file) shutil.copy(os.path.join(target_path, file), test_path) - with open(os.path.join(test_path, "List.test.js"), 'a') \ - as list_data: + with os.fdopen(os.open(os.path.join(test_path, "List.test.js"), + FLAGS_ADD, MODES), 'a') as list_data: list_data.write("require('./%s')\n" % file) #modify i18n json file @@ -113,7 +119,8 @@ class PretreatTargets(object): if "TargetName" in line: line = line.replace("TargetName", name) json_data += line - with open(i18n_path, 'w') as i18n_file: + os.remove(i18n_path) + with os.fdopen(os.open(i18n_path, FLAGS_WRITE, MODES), 'w') as i18n_file: i18n_file.write(json_data) return True diff --git a/src/core/command/console.py b/src/core/command/console.py index 249defa..84624f7 100755 --- a/src/core/command/console.py +++ b/src/core/command/console.py @@ -363,8 +363,7 @@ class Console(object): else: print("The %s command is not supported." % command) except (AttributeError, IOError, IndexError, ImportError, NameError, - RuntimeError, SystemError, TypeError, ValueError, - UnicodeError) as exception: + RuntimeError, SystemError, TypeError, ValueError) as exception: LOG.exception(exception, exc_info=False) @classmethod diff --git a/src/core/command/display.py b/src/core/command/display.py index c0ce5db..a762f47 100644 --- a/src/core/command/display.py +++ b/src/core/command/display.py @@ -198,7 +198,7 @@ def select_user_input(data_list): exit the frame.") quit() sys.exit(0) - return select_item_value, select_item_index + return select_item_value, select_item_index # 选择productform diff --git a/src/core/command/distribute_utils.py b/src/core/command/distribute_utils.py index ffd1679..9073a5f 100755 --- a/src/core/command/distribute_utils.py +++ b/src/core/command/distribute_utils.py @@ -20,11 +20,16 @@ import os import subprocess import sys import re +import stat + from xdevice import platform_logger from xdevice import EnvironmentManager from xdevice import ResultReporter from xdevice import ExecInfo +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + LOG = platform_logger("distribute_utils") @@ -32,7 +37,9 @@ def make_device_info_file(tmp_path): env_manager = EnvironmentManager() device_info_file_path = os.path.join(tmp_path, "device_info_file.txt") - with open(device_info_file_path, "w") as file_handle: + if os.path.exists(device_info_file_path): + os.remove(device_info_file_path) + with os.fdopen(os.open(device_info_file_path, FLAGS, MODES), 'w') as file_handle: if not env_manager.managers: return if list(env_manager.managers.values())[0].devices_list: diff --git a/src/core/command/gen.py b/src/core/command/gen.py index 4bc0fee..332ed40 100644 --- a/src/core/command/gen.py +++ b/src/core/command/gen.py @@ -19,9 +19,13 @@ import os import sys import subprocess +import stat from xdevice import platform_logger +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + LOG = platform_logger("Gen") class Gen(object): @@ -40,7 +44,9 @@ class Gen(object): filepath = os.path.join(sys.source_code_root_path, "test", "developertest", "libs", "fuzzlib", "fuzzer_list.txt") LOG.info("The fuzzer list file path: %s" % filepath) - with open(filepath, "w") as gn_file: + if os.path.exists(filepath): + os.remove(filepath) + with os.fdopen(os.open(filepath, FLAGS, MODES), 'w') as gn_file: gn_file.truncate(0) if fuzzer_list: for target in fuzzer_list: diff --git a/src/core/command/run.py b/src/core/command/run.py index 20bb93f..1e33641 100644 --- a/src/core/command/run.py +++ b/src/core/command/run.py @@ -297,7 +297,7 @@ class Run(object): if len(self.history_cmd_list) >= 10: del self.history_cmd_list[0] self.history_cmd_list.append(cmd_record) - print("-------------run end: ", self.history_cmd_list) + 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") @@ -422,7 +422,7 @@ class Run(object): xts_test_case_path = self.get_xts_tests_out_path(options.productform, options.testtype) if not os.path.exists(xts_test_case_path): LOG.error("%s is not exist." % xts_test_case_path) - return + return {} xts_test_dict = TestCaseManager().get_xts_test_files(xts_test_case_path, options) return xts_test_dict @@ -431,7 +431,7 @@ class Run(object): test_case_path = self.get_tests_out_path(options.productform) if not os.path.exists(test_case_path): LOG.error("%s is not exist." % test_case_path) - return + return {} test_dict = TestCaseManager().get_test_files(test_case_path, options) return test_dict diff --git a/src/core/common.py b/src/core/common.py index e46dbc9..878aa10 100755 --- a/src/core/common.py +++ b/src/core/common.py @@ -49,6 +49,4 @@ def get_source_code_root_path(path): def is_open_source_product(product_name): open_source_products = ["Hi3516DV300"] return True - if product_name in open_source_products: - return True - return False + diff --git a/src/core/config/config_manager.py b/src/core/config/config_manager.py index 7f05543..b9d12fa 100755 --- a/src/core/config/config_manager.py +++ b/src/core/config/config_manager.py @@ -239,12 +239,12 @@ class UserConfigManager(object): node = root.find(target_name) if not node: - return + return data_dic if sub_target != "": node = node.find(sub_target) if not node: - return + return data_dic for sub in node: if sub.text is None: diff --git a/src/core/driver/drivers.py b/src/core/driver/drivers.py index f77f8b8..d203c33 100644 --- a/src/core/driver/drivers.py +++ b/src/core/driver/drivers.py @@ -61,6 +61,9 @@ TIME_OUT = 900 * 1000 JS_TIMEOUT = 10 CYCLE_TIMES = 30 +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + ############################################################################## ############################################################################## @@ -184,7 +187,7 @@ def _create_empty_result_file(filepath, filename, error_message): if filename.endswith(".hap"): filename = filename.split(".")[0] if not os.path.exists(filepath): - with open(filepath, "w", encoding='utf-8') as file_desc: + with os.fdopen(os.open(filepath, FLAGS, MODES), 'w') as file_desc: time_stamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) file_desc.write('\n') @@ -231,7 +234,7 @@ def _sleep_according_to_result(result): def _create_fuzz_crash_file(filepath, filename): if not os.path.exists(filepath): - with open(filepath, "w", encoding='utf-8') as file_desc: + with os.fdopen(os.open(filepath, FLAGS, MODES), 'w') as file_desc: time_stamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) file_desc.write('\n') @@ -257,7 +260,7 @@ def _create_fuzz_crash_file(filepath, filename): def _create_fuzz_pass_file(filepath, filename): if not os.path.exists(filepath): - with open(filepath, "w", encoding='utf-8') as file_desc: + with os.fdopen(os.open(filepath, FLAGS, MODES), 'w') as file_desc: time_stamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) file_desc.write('\n') @@ -685,16 +688,29 @@ class CppTestDriver(IDriver): @staticmethod def _alter_init(name): - lines = list() - with open(name, "r") as f: - for line in f: - line_strip = line.strip() - if not line_strip: - continue - if line_strip[0] != "#" and line_strip[0] != "/" and line_strip[0] != "*": - lines.append(line_strip) - with open(name, "w") as f: - f.writelines(lines) + 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") + with open(name, "wb") as f: + 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" @@ -1091,7 +1107,7 @@ class JSUnitTestDriver(IDriver): try: zf_desc.extractall(path=hap_bak_path) except RuntimeError as error: - print(error) + print("Unzip error:", hap_bak_path) zf_desc.close() # verify config.json file @@ -1132,7 +1148,6 @@ class JSUnitTestDriver(IDriver): return package_name, ability_name - @Plugin(type=Plugin.DRIVER, id=DeviceTestType.oh_rust_test) class OHRustTestDriver(IDriver): def __init__(self): diff --git a/src/core/testcase/testcase_manager.py b/src/core/testcase/testcase_manager.py index 428b541..41cb2e1 100644 --- a/src/core/testcase/testcase_manager.py +++ b/src/core/testcase/testcase_manager.py @@ -296,7 +296,7 @@ class TestCaseManager(object): def get_hap_test_driver(cls, hap_file_path): data_dic = cls.get_hap_json(hap_file_path) if not data_dic: - return False + return "" else: if "driver" in data_dic.keys(): driver_dict = data_dic.get("driver") @@ -305,6 +305,9 @@ class TestCaseManager(object): 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): @@ -314,6 +317,10 @@ class TestCaseManager(object): 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): @@ -323,13 +330,19 @@ class TestCaseManager(object): 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 False + return "" else: if "part" in data_dic.keys(): part_name = data_dic["part"] - return part_name \ No newline at end of file + return part_name + else: + return "" diff --git a/src/core/testkit/kit_lite.py b/src/core/testkit/kit_lite.py index bb062d1..35fafde 100755 --- a/src/core/testkit/kit_lite.py +++ b/src/core/testkit/kit_lite.py @@ -142,4 +142,6 @@ class DeployKit(ITestKit): 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) \ No newline at end of file + return shutil.copyfile(original_file, new_temp_tool_path) + else: + return "" diff --git a/src/core/utils.py b/src/core/utils.py index 7be7853..fdab9db 100755 --- a/src/core/utils.py +++ b/src/core/utils.py @@ -139,13 +139,14 @@ def parse_device_name(product_form): device_json_file = os.path.join(sys.source_code_root_path, "productdefine", "common", "products", "{}.json".format(product_form)) + device_name = "" if not os.path.exists(device_json_file): - return + return device_name with open(device_json_file, 'r') as json_file: json_info = json.load(json_file) if not json_info: - return + return device_name device_name = json_info.get('product_device') if not device_name: device_name = get_output_path() diff --git a/src/main/_init_global_config.py b/src/main/_init_global_config.py index 7dddbf5..e79ee0e 100755 --- a/src/main/_init_global_config.py +++ b/src/main/_init_global_config.py @@ -122,13 +122,13 @@ def _load_internal_plugins(): import benchmark.report.benchmark_reporter _iter_module_plugins([core.driver, benchmark.report.benchmark_reporter]) - except (ModuleNotFoundError, ImportError): + except ImportError: pass try: import script.report _iter_module_plugins([script.report]) - except (ModuleNotFoundError, ImportError): + except ImportError: pass -- Gitee From 99ec6752085c79bfd0639c7a22ea8b14e08e34b7 Mon Sep 17 00:00:00 2001 From: Teacher_Dong Date: Tue, 27 Feb 2024 15:58:05 +0800 Subject: [PATCH 2/3] Signed-off-by:Teacher_Dong --- .../entry/src/main/ets/Application/AbilityStage.ts | 13 +++++++++++++ .../entry/src/main/ets/FormAbility/FormAbility.ts | 13 +++++++++++++ .../entry/src/main/ets/MainAbility/MainAbility.ts | 13 +++++++++++++ .../src/main/ets/ServiceAbility/FormAbility.ts | 13 +++++++++++++ .../entry/src/main/ets/TestAbility/TestAbility.ts | 13 +++++++++++++ .../main/ets/TestRunner/OpenHarmonyTestRunner.ts | 13 +++++++++++++ .../interface_kits/coverage_summary_file.xml | 14 ++++++++++++++ .../keyword_registration/keyword_filter.py | 2 ++ localCoverage/resident_service/config/ams/ams.xml | 14 ++++++++++++++ .../resident_service/config/ams/foundation.xml | 14 ++++++++++++++ localCoverage/resident_service/config/bms/bms.xml | 14 ++++++++++++++ .../resident_service/config/bms/foundation.xml | 14 ++++++++++++++ .../resident_service/config/call/call.xml | 14 ++++++++++++++ .../resident_service/config/call/foundation.xml | 14 ++++++++++++++ localCoverage/resident_service/config/fms/fms.xml | 14 ++++++++++++++ .../resident_service/config/fms/foundation.xml | 14 ++++++++++++++ .../config/notification/foundation.xml | 14 ++++++++++++++ .../config/notification/notification.xml | 14 ++++++++++++++ .../resident_service/config/power/foundation.xml | 14 ++++++++++++++ .../resident_service/config/power/power.xml | 14 ++++++++++++++ .../resident_service/config/state/foundation.xml | 14 ++++++++++++++ .../resident_service/config/state/state.xml | 14 ++++++++++++++ .../resident_service/config/wms/foundation.xml | 14 ++++++++++++++ localCoverage/resident_service/config/wms/wms.xml | 14 ++++++++++++++ src/core/driver/drivers.py | 7 ++----- 25 files changed, 320 insertions(+), 5 deletions(-) diff --git a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/Application/AbilityStage.ts b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/Application/AbilityStage.ts index 379bc0b..e0732e9 100644 --- a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/Application/AbilityStage.ts +++ b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/Application/AbilityStage.ts @@ -1,3 +1,16 @@ +// 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 AbilityStage from "@ohos.app.ability.AbilityStage" export default class MyAbilityStage extends AbilityStage { diff --git a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/FormAbility/FormAbility.ts b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/FormAbility/FormAbility.ts index d443631..0c95f0e 100644 --- a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/FormAbility/FormAbility.ts +++ b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/FormAbility/FormAbility.ts @@ -1,3 +1,16 @@ +// 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 FormExtension from '@ohos.app.form.FormExtensionAbility'; import formBindingData from '@ohos.application.formBindingData'; import formInfo from '@ohos.application.formInfo'; diff --git a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/MainAbility/MainAbility.ts b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/MainAbility/MainAbility.ts index 6ee21a3..3141c2e 100644 --- a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,3 +1,16 @@ +// 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 Ability from '@ohos.app.ability.UIAbility' export default class MainAbility extends Ability { diff --git a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/ServiceAbility/FormAbility.ts b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/ServiceAbility/FormAbility.ts index d443631..0c95f0e 100644 --- a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/ServiceAbility/FormAbility.ts +++ b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/ServiceAbility/FormAbility.ts @@ -1,3 +1,16 @@ +// 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 FormExtension from '@ohos.app.form.FormExtensionAbility'; import formBindingData from '@ohos.application.formBindingData'; import formInfo from '@ohos.application.formInfo'; diff --git a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestAbility/TestAbility.ts b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestAbility/TestAbility.ts index 8f18d88..730e694 100644 --- a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestAbility/TestAbility.ts +++ b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestAbility/TestAbility.ts @@ -1,3 +1,16 @@ +// 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 Ability from '@ohos.app.ability.UIAbility' export default class TestAbility extends Ability { diff --git a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts index 42f9867..f314906 100644 --- a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts +++ b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -1,3 +1,16 @@ +// 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 TestRunner from '@ohos.application.testRunner' import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' diff --git a/localCoverage/interfaceCoverage/results/coverage/interface_kits/coverage_summary_file.xml b/localCoverage/interfaceCoverage/results/coverage/interface_kits/coverage_summary_file.xml index fb67817..fc3d4ae 100644 --- a/localCoverage/interfaceCoverage/results/coverage/interface_kits/coverage_summary_file.xml +++ b/localCoverage/interfaceCoverage/results/coverage/interface_kits/coverage_summary_file.xml @@ -1,4 +1,18 @@ + diff --git a/localCoverage/keyword_registration/keyword_filter.py b/localCoverage/keyword_registration/keyword_filter.py index ddb627e..35b3646 100644 --- a/localCoverage/keyword_registration/keyword_filter.py +++ b/localCoverage/keyword_registration/keyword_filter.py @@ -105,6 +105,7 @@ class KeywordRegistration: return keyword_list except (FileNotFoundError, AttributeError, FileExistsError): print(f"获取报备过滤关键字报错") + return [] @staticmethod def get_coverage_content(file_path): @@ -308,6 +309,7 @@ class KeywordRegistration: except (OSError, IndexError, TypeError) as error: print(f"覆盖率报告{branch_line}行获取函数名报错, error:{error}", traceback.format_exc()) + return "" @staticmethod def get_branch_line_list(keyword_line: int, branch_line_list: list): diff --git a/localCoverage/resident_service/config/ams/ams.xml b/localCoverage/resident_service/config/ams/ams.xml index 9fbe4b6..64894c7 100644 --- a/localCoverage/resident_service/config/ams/ams.xml +++ b/localCoverage/resident_service/config/ams/ams.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/ams/foundation.xml b/localCoverage/resident_service/config/ams/foundation.xml index 6b8da40..11d2a92 100644 --- a/localCoverage/resident_service/config/ams/foundation.xml +++ b/localCoverage/resident_service/config/ams/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/bms/bms.xml b/localCoverage/resident_service/config/bms/bms.xml index 6086c22..d74a33e 100644 --- a/localCoverage/resident_service/config/bms/bms.xml +++ b/localCoverage/resident_service/config/bms/bms.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/bms/foundation.xml b/localCoverage/resident_service/config/bms/foundation.xml index 845b3c3..c7be367 100644 --- a/localCoverage/resident_service/config/bms/foundation.xml +++ b/localCoverage/resident_service/config/bms/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/call/call.xml b/localCoverage/resident_service/config/call/call.xml index e8d279d..e6f850f 100644 --- a/localCoverage/resident_service/config/call/call.xml +++ b/localCoverage/resident_service/config/call/call.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/call/foundation.xml b/localCoverage/resident_service/config/call/foundation.xml index a8e632c..d25e2e2 100644 --- a/localCoverage/resident_service/config/call/foundation.xml +++ b/localCoverage/resident_service/config/call/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/fms/fms.xml b/localCoverage/resident_service/config/fms/fms.xml index abecd76..e5f5211 100644 --- a/localCoverage/resident_service/config/fms/fms.xml +++ b/localCoverage/resident_service/config/fms/fms.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/fms/foundation.xml b/localCoverage/resident_service/config/fms/foundation.xml index aae2385..b4514eb 100644 --- a/localCoverage/resident_service/config/fms/foundation.xml +++ b/localCoverage/resident_service/config/fms/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/notification/foundation.xml b/localCoverage/resident_service/config/notification/foundation.xml index ffcb838..1951918 100644 --- a/localCoverage/resident_service/config/notification/foundation.xml +++ b/localCoverage/resident_service/config/notification/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/notification/notification.xml b/localCoverage/resident_service/config/notification/notification.xml index 259bc9e..cc6ad89 100644 --- a/localCoverage/resident_service/config/notification/notification.xml +++ b/localCoverage/resident_service/config/notification/notification.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/power/foundation.xml b/localCoverage/resident_service/config/power/foundation.xml index 8df55e1..38a0e7f 100644 --- a/localCoverage/resident_service/config/power/foundation.xml +++ b/localCoverage/resident_service/config/power/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/power/power.xml b/localCoverage/resident_service/config/power/power.xml index a9f99c8..04e901a 100644 --- a/localCoverage/resident_service/config/power/power.xml +++ b/localCoverage/resident_service/config/power/power.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/state/foundation.xml b/localCoverage/resident_service/config/state/foundation.xml index d72b395..864ada0 100644 --- a/localCoverage/resident_service/config/state/foundation.xml +++ b/localCoverage/resident_service/config/state/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/state/state.xml b/localCoverage/resident_service/config/state/state.xml index 4fb86e2..0ddb3d9 100644 --- a/localCoverage/resident_service/config/state/state.xml +++ b/localCoverage/resident_service/config/state/state.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/wms/foundation.xml b/localCoverage/resident_service/config/wms/foundation.xml index f653b6f..9cc0818 100644 --- a/localCoverage/resident_service/config/wms/foundation.xml +++ b/localCoverage/resident_service/config/wms/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/wms/wms.xml b/localCoverage/resident_service/config/wms/wms.xml index e74b72e..826c37f 100644 --- a/localCoverage/resident_service/config/wms/wms.xml +++ b/localCoverage/resident_service/config/wms/wms.xml @@ -1,4 +1,18 @@ + foundation diff --git a/src/core/driver/drivers.py b/src/core/driver/drivers.py index d203c33..57e6bfa 100644 --- a/src/core/driver/drivers.py +++ b/src/core/driver/drivers.py @@ -706,9 +706,8 @@ class CppTestDriver(IDriver): striped_content = str_content striped_bt = striped_content.encode("utf-8") - with open(name, "wb") as f: - if os.path.exists(name): - os.remove(name) + if os.path.exists(name): + os.remove(name) with os.fdopen(os.open(name, FLAGS, MODES), 'wb') as f: f.write(striped_bt) @@ -1084,8 +1083,6 @@ class JSUnitTestDriver(IDriver): driver_dict = data_dic.get("driver") if driver_dict and "test-timeout" in driver_dict.keys(): test_timeout = int(driver_dict["shell-timeout"]) / 1000 - else: - return return test_timeout except JSONDecodeError: return test_timeout -- Gitee From 3b817b185e472c9387c16615be392592f207d96e Mon Sep 17 00:00:00 2001 From: Teacher_Dong Date: Wed, 28 Feb 2024 17:45:57 +0800 Subject: [PATCH 3/3] Signed-off-by:Teacher_Dong --- .../interface_kits/ohos_interfaceCoverage.html | 1 - .../results/coverage/interface_kits/test.png | Bin 8752 -> 0 bytes 2 files changed, 1 deletion(-) delete mode 100644 localCoverage/interfaceCoverage/results/coverage/interface_kits/test.png diff --git a/localCoverage/interfaceCoverage/results/coverage/interface_kits/ohos_interfaceCoverage.html b/localCoverage/interfaceCoverage/results/coverage/interface_kits/ohos_interfaceCoverage.html index e506f9b..0de8cbb 100644 --- a/localCoverage/interfaceCoverage/results/coverage/interface_kits/ohos_interfaceCoverage.html +++ b/localCoverage/interfaceCoverage/results/coverage/interface_kits/ohos_interfaceCoverage.html @@ -49,7 +49,6 @@
-

Summary Report

接口总数147,已覆盖0,未覆盖147

diff --git a/localCoverage/interfaceCoverage/results/coverage/interface_kits/test.png b/localCoverage/interfaceCoverage/results/coverage/interface_kits/test.png deleted file mode 100644 index 9926563cf3090c93597c170f83e1951d9fabb462..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8752 zcmch7bySp5*DpvZl7iCGARtJ0NQ2TPNJ}G7^MR+3Bz z9MD~)6ty0L4ffDH1YAFIRM2xlLBTiu_eU+1D6j!Hg&?xJ5KRY5$Y)b$3zSc$5Jx)) zh@H&`8m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