From af241a47f0fcbbeed6f3a7b07f23e73248302baa Mon Sep 17 00:00:00 2001 From: Teacher_Dong Date: Sat, 6 Jan 2024 09:33:55 +0000 Subject: [PATCH 1/6] Signed-off-by: Teacher_Dong Signed-off-by: Teacher_Dong --- aw/cxx/distributed/distributed.h | 2 +- aw/cxx/distributed/distributed_major.cpp | 2 +- aw/python/distributed/common/common.py | 7 ++- aw/python/distributed/common/devices.py | 7 ++- 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 | 33 +++++----- libs/fuzzlib/fuzzer_helper.py | 25 ++++++-- libs/fuzzlib/tools/colored.py | 7 ++- libs/fuzzlib/tools/run_result.py | 10 +++- .../codeCoverage/codeCoverage_gcov_lcov.py | 7 ++- .../codeCoverage/mutilProcess_CodeCoverage.py | 10 +++- localCoverage/coverage_tools.py | 9 ++- .../interfaceCoverage/get_innerkits_json.py | 7 ++- .../interfaceCoverage_gcov_lcov.py | 8 ++- .../interfaceCoverage/make_report.py | 21 +++++-- .../keyword_registration/keyword_filter.py | 60 ++++++++++++++----- localCoverage/resident_service/init_gcov.py | 30 ++++++++-- .../resident_service/public_method.py | 2 + .../resident_service/pull_service_gcda.py | 8 +-- .../restore_comment/after_lcov_branch.py | 9 ++- .../restore_comment/build_before_generate.py | 17 ++++-- src/core/build/build_manager.py | 10 +++- src/core/build/build_testcases.py | 5 +- src/core/build/pretreat_targets.py | 20 +++++-- src/core/command/console.py | 3 +- src/core/command/display.py | 3 +- src/core/command/distribute_utils.py | 10 +++- src/core/command/gen.py | 9 ++- src/core/command/run.py | 4 +- src/core/common.py | 6 +- src/core/config/config_manager.py | 4 +- src/core/driver/drivers.py | 19 +++--- 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, 329 insertions(+), 111 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..5cd096c 100755 --- a/aw/python/distributed/common/common.py +++ b/aw/python/distributed/common/common.py @@ -18,6 +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 +85,8 @@ 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 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..e0443f3 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 @@ -216,14 +216,15 @@ class DeviceShell: 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 result 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..c564a7f 100755 --- a/aw/python/distributed/common/drivers.py +++ b/aw/python/distributed/common/drivers.py @@ -22,6 +22,7 @@ import subprocess import tempfile from abc import ABCMeta from abc import abstractmethod +import stat from core.config.resource_manager import ResourceManager @@ -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,11 @@ 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 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: {file_path}") return sh_file_name, file_path @@ -161,6 +166,8 @@ class CppTestDriver(ITestDriver): if options.coverage: receive_coverage_data(self.device, result_path, suite_file, file_name) + + del long_command_path ############################################################################## diff --git a/aw/python/distributed/distribute/distribute.py b/aw/python/distributed/distribute/distribute.py index a4083f0..e8009b3 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,7 +311,10 @@ 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: + # 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..e791f96 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..a358233 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,17 @@ class BenchmarkReport(object): len(content_new)] try: - with open(os.path.abspath(out_report_file_path), "w") \ - as output_fd: + # with open(os.path.abspath(out_report_file_path), "w") \ + is 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 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 failed", tmpl_file_path)) def _generate_all_benchmark_detail(self, dest_dir_parh): for benchmark_info in self.benchmark_list: @@ -327,15 +331,16 @@ 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: + # with open(os.path.abspath(out_report_file_path), "w") \ + is 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 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 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..60a6175 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,18 +133,22 @@ 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: + # with open(file_path, 'w') as filehandle: + 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: + # with open(file_path, 'w') as filehandle: + 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: + # with open(file_path, 'w') as filehandle: + 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: + # with open(file_path, 'w') as filehandle: + 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') @@ -148,6 +156,7 @@ def generate(args): os.mkdir(corpus_dir) with open(os.path.join(corpus_dir, 'init'), 'w') as filehandle: filehandle.write("FUZZ") + return 0 #complie fuzzer project @@ -187,7 +196,8 @@ 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: + # with open(subsystem_src_flag_file_path, "wb") as file_handle: + with os.fdopen(os.open(subsystem_src_flag_file_path, FLAGS, MODES), 'wb') as filehandle: file_handle.write(args.project_name.encode()) try: @@ -260,6 +270,9 @@ 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..083d8cd 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,8 @@ class Colored(object): self.get_fuzz_current_project_log_dir(), "run.log" ) - with open(run_log, 'ab') as f: + # with open(run_log, 'ab') as f: + with os.fdopen(os.open(run_log, FLAGS, MODES), 'ab') as fout: f.write(msg + "\n") diff --git a/libs/fuzzlib/tools/run_result.py b/libs/fuzzlib/tools/run_result.py index 5fb2b6e..ee3c05e 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,10 @@ class RunResult(): pass def write_analysis_result(self, analysis_ressult_path, html_format=True): - with open(analysis_ressult_path, "wb") as f: + # with open(analysis_ressult_path, "wb") as f: + is 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..257d119 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,8 @@ 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 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..4085cda 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,10 @@ 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 open(coverage_log_path, 'a') as fd: + if os.path.exists(coverage_log_path): + os.remove(coverage_log_path) + with os.fdopen(os.open(coverage_log_path, FLAGS, MODES), 'a') as fout: 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 7f235c5..e663bc3 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,10 @@ def get_subsystem_config(part_list, developer_path): print("Error: 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: + # 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..e0f2433 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,8 @@ 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: + # with open(output_json_path, "w") as json_file: + 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..3d59388 100644 --- a/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py +++ b/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py @@ -22,10 +22,15 @@ 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 +394,8 @@ 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: + # with open(report_path, "w") as fd: + 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..f6e1a21 100644 --- a/localCoverage/interfaceCoverage/make_report.py +++ b/localCoverage/interfaceCoverage/make_report.py @@ -21,6 +21,12 @@ import sys import datetime from importlib import reload reload(sys) +import os +import stat + +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 +94,8 @@ def sort_by_field_element_data(elem): def create_html_start(reportpath): try: - with open(reportpath, "w") as report: + # with open(reportpath, "w") as report: + with os.fdopen(os.open(reportpath, FLAGS_WRITE, MODES), 'w') as fout: report.write(html_head) report.write(html_body_start) except(IOError, ValueError): @@ -123,7 +130,8 @@ 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 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 +166,8 @@ def create_summary(reportpath, summary_list): try: if len(summary_list) == 0: return - with open(reportpath, "a") as report: + # 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 +207,8 @@ def create_table_test(reportpath, subsystem_name, datalist, total_count, covered table_ended = """ """ try: - with open(reportpath, "a") as report: + # 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 +244,8 @@ def create_table_test(reportpath, subsystem_name, datalist, total_count, covered def create_html_ended(reportpath): try: - with open(reportpath, "a") as report: + # 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..1ed1fdb 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,7 +66,8 @@ span.branchnocovupdate { background-color:#BBBBBB; }""" - with open(css_file_path, "a+", encoding="utf-8") as file: + # with open(css_file_path, "a+", encoding="utf-8") as file: + with os.fdopen(os.open(css_file_path, FLAGS_WRITE, MODES), 'a+') as file: file.write(text) def get_statistic_path(self, gcov_file_path: str): @@ -99,6 +105,7 @@ class KeywordRegistration: return keyword_list except (FileNotFoundError, AttributeError, FileExistsError): print(f"获取报备过滤关键字报错") + return [] @staticmethod def get_coverage_content(file_path): @@ -106,7 +113,8 @@ 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 +161,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 +284,8 @@ 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,19 +299,24 @@ 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()) + return "" @staticmethod def get_branch_line_list(keyword_line: int, branch_line_list: list): @@ -325,7 +344,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 +357,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 +480,9 @@ class KeywordRegistration: if replace_tag in content: content = content.replace(replace_tag, update_tag) - with open(file_path, "w", encoding="utf-8") as file: + # 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 +587,9 @@ 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: + # 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 +665,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 +694,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 +728,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 +773,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 +880,16 @@ 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: + # 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 open(file_path, "w", encoding="utf-8") as new_html: + 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..de44f06 100644 --- a/localCoverage/resident_service/init_gcov.py +++ b/localCoverage/resident_service/init_gcov.py @@ -24,6 +24,11 @@ import sys import time import xml.etree.ElementTree as ET from public_method import get_server_dict, get_config_ip, get_sn_list +import stat + +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 def _init_sys_config(): @@ -61,7 +66,10 @@ 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: + # 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_WRITE, MODES), 'w') as json_file: json_file.write(json_str) else: print("init.cfg file not exists") @@ -97,7 +105,10 @@ 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: + # 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_WRITE, 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 +164,10 @@ 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: + # 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_WRITE, MODES), 'w') as f: json.dump(f_dict, f, indent=4) return new_json @@ -180,7 +194,10 @@ 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: + # 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_WRITE, MODES), 'w') as f: json.dump(f_dict, f, indent=4) return new_json @@ -234,7 +251,10 @@ 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: + # 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_WRITE, MODES), 'w') as f: 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..89f38a7 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,10 @@ 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: + # with open(f"{path.split('.')[0]}_bk.html", "w") as write_fp: + is 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 b13f32e..66d0e50 100644 --- a/localCoverage/restore_comment/build_before_generate.py +++ b/localCoverage/restore_comment/build_before_generate.py @@ -19,6 +19,10 @@ import os import subprocess import json +import stat + +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR def get_source_file_list(path): @@ -52,9 +56,11 @@ 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: - + # 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 read_fp: for line in code_lines: sign_number = 0 for key in keys: @@ -109,7 +115,10 @@ def get_part_config_json(part_list, system_info_path, part_path): else: print("Error: part not in all_subsystem_config.json") new_json = json.dumps(new_json_text, indent=4) - with open(part_path, "w") as out_file: + # 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..b7ac0a5 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,10 @@ 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: + # 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..f67db64 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", @@ -355,9 +355,10 @@ class BuildTestcases(object): input_subsystem = ",".join(para.subsystem) xts_build_test_command.append("--build-target") xts_build_test_command.append(input_subsystem) + return False 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..495a490 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,10 +89,12 @@ 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: + # 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) @@ -99,8 +106,9 @@ 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 open(os.path.join(test_path, "List.test.js"), 'a') \ + 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 +121,9 @@ 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 open(i18n_path, 'w') as i18n_file: + 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 3c79b87..b7f60fe 100644 --- a/src/core/command/display.py +++ b/src/core/command/display.py @@ -198,7 +198,8 @@ 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..a666846 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,10 @@ 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: + # 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 0840c26..df75175 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,10 @@ class Gen(object): filepath = os.path.join(sys.source_code_root_path, "test", "developer_test", "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 open(filepath, "w") as gn_file: + 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 d16ec1e..1aff63b 100644 --- a/src/core/command/run.py +++ b/src/core/command/run.py @@ -430,7 +430,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 @@ -439,7 +439,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..cddcb2d 100755 --- a/src/core/common.py +++ b/src/core/common.py @@ -49,6 +49,6 @@ 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 + # 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 1340a59..492a717 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 9da4366..e74c6ad 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 + ############################################################################## ############################################################################## @@ -185,7 +188,8 @@ 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 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') @@ -232,7 +236,8 @@ 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 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') @@ -258,7 +263,8 @@ 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 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') @@ -710,7 +716,8 @@ class CppTestDriver(IDriver): striped_content = str_content striped_bt = striped_content.encode("utf-8") - with open(name, "wb") as f: + # with open(name, "wb") as f: + with os.fdopen(os.open(name, FLAGS, MODES), 'wb') as f: f.write(striped_bt) def _push_corpus_cov_if_exist(self, suite_file): @@ -1087,8 +1094,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 @@ -1110,7 +1115,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 diff --git a/src/core/testcase/testcase_manager.py b/src/core/testcase/testcase_manager.py index adf0221..7d91ad2 100644 --- a/src/core/testcase/testcase_manager.py +++ b/src/core/testcase/testcase_manager.py @@ -300,7 +300,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") @@ -309,6 +309,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): @@ -318,6 +321,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): @@ -327,13 +334,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 "" \ No newline at end of file diff --git a/src/core/testkit/kit_lite.py b/src/core/testkit/kit_lite.py index bb062d1..a9b7e01 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 "" \ No newline at end of file diff --git a/src/core/utils.py b/src/core/utils.py index 1938c14..316bf59 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 ca81577..f28b766 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 2eec1a522191f5e123ac33affdfd280454461f5e Mon Sep 17 00:00:00 2001 From: Teacher_Dong Date: Mon, 8 Jan 2024 04:02:00 +0000 Subject: [PATCH 2/6] Signed-off-by: Teacher_Dong Signed-off-by: Teacher_Dong --- libs/fuzzlib/fuzzer_helper.py | 13 ++++++++++++- libs/fuzzlib/tools/colored.py | 2 +- .../codeCoverage/mutilProcess_CodeCoverage.py | 2 +- .../interfaceCoverage/get_innerkits_json.py | 2 ++ .../interfaceCoverage_gcov_lcov.py | 2 ++ localCoverage/interfaceCoverage/make_report.py | 4 +++- .../restore_comment/build_before_generate.py | 2 +- src/core/driver/drivers.py | 2 ++ 8 files changed, 24 insertions(+), 5 deletions(-) diff --git a/libs/fuzzlib/fuzzer_helper.py b/libs/fuzzlib/fuzzer_helper.py index 60a6175..ffbc5be 100644 --- a/libs/fuzzlib/fuzzer_helper.py +++ b/libs/fuzzlib/fuzzer_helper.py @@ -134,27 +134,38 @@ def generate(args): 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 open(os.path.join(corpus_dir, 'init'), 'w') as filehandle: + with os.fdopen(os.open(os.path.join(corpus_dir, 'init'), FLAGS, MODES), 'w') as filehandle: filehandle.write("FUZZ") return 0 diff --git a/libs/fuzzlib/tools/colored.py b/libs/fuzzlib/tools/colored.py index 083d8cd..0f80aca 100644 --- a/libs/fuzzlib/tools/colored.py +++ b/libs/fuzzlib/tools/colored.py @@ -87,7 +87,7 @@ class Colored(object): "run.log" ) # with open(run_log, 'ab') as f: - with os.fdopen(os.open(run_log, FLAGS, MODES), 'ab') as fout: + with os.fdopen(os.open(run_log, FLAGS, MODES), 'ab') as f: f.write(msg + "\n") diff --git a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py index 4085cda..e06eb4c 100644 --- a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py +++ b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py @@ -69,7 +69,7 @@ def execute_command(command, printflag=False): # with open(coverage_log_path, 'a') as fd: if os.path.exists(coverage_log_path): os.remove(coverage_log_path) - with os.fdopen(os.open(coverage_log_path, FLAGS, MODES), 'a') as fout: + 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/interfaceCoverage/get_innerkits_json.py b/localCoverage/interfaceCoverage/get_innerkits_json.py index e0f2433..2502dab 100644 --- a/localCoverage/interfaceCoverage/get_innerkits_json.py +++ b/localCoverage/interfaceCoverage/get_innerkits_json.py @@ -42,6 +42,8 @@ def gen_parts_info_json(folder_list, output_json_path, target_cpu): 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: diff --git a/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py b/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py index 3d59388..6abed62 100644 --- a/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py +++ b/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py @@ -395,6 +395,8 @@ 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') diff --git a/localCoverage/interfaceCoverage/make_report.py b/localCoverage/interfaceCoverage/make_report.py index f6e1a21..d2bd473 100644 --- a/localCoverage/interfaceCoverage/make_report.py +++ b/localCoverage/interfaceCoverage/make_report.py @@ -95,7 +95,9 @@ def sort_by_field_element_data(elem): def create_html_start(reportpath): try: # with open(reportpath, "w") as report: - with os.fdopen(os.open(reportpath, FLAGS_WRITE, MODES), 'w') as fout: + 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): diff --git a/localCoverage/restore_comment/build_before_generate.py b/localCoverage/restore_comment/build_before_generate.py index 66d0e50..90ad331 100644 --- a/localCoverage/restore_comment/build_before_generate.py +++ b/localCoverage/restore_comment/build_before_generate.py @@ -60,7 +60,7 @@ def rewrite_source_file(source_path_list: list): # 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 read_fp: + with os.fdopen(os.open(f"{source_dir}_bk.{suffix_name}", FLAGS, MODES), 'w') as write_fp: for line in code_lines: sign_number = 0 for key in keys: diff --git a/src/core/driver/drivers.py b/src/core/driver/drivers.py index e74c6ad..c4ce4aa 100644 --- a/src/core/driver/drivers.py +++ b/src/core/driver/drivers.py @@ -717,6 +717,8 @@ class CppTestDriver(IDriver): 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) -- Gitee From 6b650988ab3d15b5c636027be94b5f8677e2a4c8 Mon Sep 17 00:00:00 2001 From: Teacher_Dong Date: Mon, 8 Jan 2024 07:16:31 +0000 Subject: [PATCH 3/6] Signed-off-by: Teacher_Dong Signed-off-by: Teacher_Dong --- libs/fuzzlib/fuzzer_helper.py | 2 +- localCoverage/codeCoverage/mutilProcess_CodeCoverage.py | 2 +- localCoverage/keyword_registration/keyword_filter.py | 2 +- localCoverage/resident_service/init_gcov.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/fuzzlib/fuzzer_helper.py b/libs/fuzzlib/fuzzer_helper.py index ffbc5be..f64647a 100644 --- a/libs/fuzzlib/fuzzer_helper.py +++ b/libs/fuzzlib/fuzzer_helper.py @@ -208,7 +208,7 @@ 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: - with os.fdopen(os.open(subsystem_src_flag_file_path, FLAGS, MODES), 'wb') as filehandle: + with os.fdopen(os.open(subsystem_src_flag_file_path, FLAGS, MODES), 'wb') as file_handle: file_handle.write(args.project_name.encode()) try: diff --git a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py index e06eb4c..831e295 100644 --- a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py +++ b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py @@ -68,7 +68,7 @@ def execute_command(command, printflag=False): CODEPATH, "test/testfwk/developer_test/localCoverage", "coverage.log") # with open(coverage_log_path, 'a') as fd: if os.path.exists(coverage_log_path): - os.remove(coverage_log_path) + os.remove(coverage_log_path) with os.fdopen(os.open(coverage_log_path, FLAGS, MODES), 'a') as fd: call(cmd_list, printflag, fd, fd) except IOError: diff --git a/localCoverage/keyword_registration/keyword_filter.py b/localCoverage/keyword_registration/keyword_filter.py index 1ed1fdb..4186ed3 100644 --- a/localCoverage/keyword_registration/keyword_filter.py +++ b/localCoverage/keyword_registration/keyword_filter.py @@ -67,7 +67,7 @@ span.branchnocovupdate background-color:#BBBBBB; }""" # with open(css_file_path, "a+", encoding="utf-8") as file: - with os.fdopen(os.open(css_file_path, FLAGS_WRITE, MODES), 'a+') as file: + 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): diff --git a/localCoverage/resident_service/init_gcov.py b/localCoverage/resident_service/init_gcov.py index de44f06..36a22f3 100644 --- a/localCoverage/resident_service/init_gcov.py +++ b/localCoverage/resident_service/init_gcov.py @@ -254,7 +254,7 @@ def create_service_cfg(serv, config_path, origin_cfg) -> str: # 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_WRITE, MODES), 'w') as f: + with os.fdopen(os.open(cfg_path, FLAGS_WRITE, MODES), 'w') as r: json.dump(json_obj, r, indent=4) return cfg_path -- Gitee From 425f778f2d234b94bb403271318f17445de8a3f6 Mon Sep 17 00:00:00 2001 From: Teacher_Dong Date: Thu, 11 Jan 2024 07:26:58 +0000 Subject: [PATCH 4/6] Signed-off-by: Teacher_Dong Signed-off-by: Teacher_Dong --- libs/benchmark/report/generate_report.py | 6 +++--- libs/fuzzlib/fuzzer_helper.py | 2 ++ .../codeCoverage/mutilProcess_CodeCoverage.py | 2 -- .../keyword_registration/keyword_filter.py | 11 +++++------ localCoverage/resident_service/init_gcov.py | 13 ++++++------- localCoverage/restore_comment/after_lcov_branch.py | 2 +- src/main/_init_global_config.py | 2 +- 7 files changed, 18 insertions(+), 20 deletions(-) diff --git a/libs/benchmark/report/generate_report.py b/libs/benchmark/report/generate_report.py index a358233..855e579 100644 --- a/libs/benchmark/report/generate_report.py +++ b/libs/benchmark/report/generate_report.py @@ -269,7 +269,7 @@ class BenchmarkReport(object): try: # with open(os.path.abspath(out_report_file_path), "w") \ - is os.path.exists(os.path.abspath(out_report_file_path)): + 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: @@ -278,7 +278,7 @@ class BenchmarkReport(object): except IOError as err_msg: print("Error5 for open failed:", out_report_file_path) except IOError as err_msg: - print("Error6 for open failed", tmpl_file_path)) + print("Error6 for open failed", tmpl_file_path) def _generate_all_benchmark_detail(self, dest_dir_parh): for benchmark_info in self.benchmark_list: @@ -332,7 +332,7 @@ class BenchmarkReport(object): try: # with open(os.path.abspath(out_report_file_path), "w") \ - is os.path.exists(os.path.abspath(out_report_file_path)): + 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: diff --git a/libs/fuzzlib/fuzzer_helper.py b/libs/fuzzlib/fuzzer_helper.py index f64647a..e79d184 100644 --- a/libs/fuzzlib/fuzzer_helper.py +++ b/libs/fuzzlib/fuzzer_helper.py @@ -208,6 +208,8 @@ 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()) diff --git a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py index 831e295..1c0d170 100644 --- a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py +++ b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py @@ -67,8 +67,6 @@ def execute_command(command, printflag=False): coverage_log_path = os.path.join( CODEPATH, "test/testfwk/developer_test/localCoverage", "coverage.log") # with open(coverage_log_path, 'a') as fd: - if os.path.exists(coverage_log_path): - os.remove(coverage_log_path) with os.fdopen(os.open(coverage_log_path, FLAGS, MODES), 'a') as fd: call(cmd_list, printflag, fd, fd) except IOError: diff --git a/localCoverage/keyword_registration/keyword_filter.py b/localCoverage/keyword_registration/keyword_filter.py index 4186ed3..ac7d5eb 100644 --- a/localCoverage/keyword_registration/keyword_filter.py +++ b/localCoverage/keyword_registration/keyword_filter.py @@ -67,8 +67,9 @@ span.branchnocovupdate background-color:#BBBBBB; }""" # with open(css_file_path, "a+", encoding="utf-8") as file: - with os.fdopen(os.open(css_file_path, FLAGS_ADD, MODES), 'a+') 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): """ @@ -211,9 +212,7 @@ class KeywordRegistration: keyword_branch_list_append(line) for key in keyword_branch_list: keyword_line_list_remove(key) - return keyword_line_list - else: - return + return keyword_line_list def code_body_judge(self, line, content): """ @@ -312,7 +311,7 @@ class KeywordRegistration: function_name = function_name_str.split()[-1] return function_name - return "" + return "" except (OSError, IndexError, TypeError) as error: print(f"覆盖率报告{branch_line}行获取函数名报错, error:{error}", traceback.format_exc()) diff --git a/localCoverage/resident_service/init_gcov.py b/localCoverage/resident_service/init_gcov.py index 36a22f3..fa3054b 100644 --- a/localCoverage/resident_service/init_gcov.py +++ b/localCoverage/resident_service/init_gcov.py @@ -26,8 +26,7 @@ import xml.etree.ElementTree as ET from public_method import get_server_dict, get_config_ip, get_sn_list import stat -FLAGS_WRITE = os.O_WRONLY | os.O_CREAT | os.O_EXCL -FLAGS_ADD = os.O_WRONLY | os.O_APPEND | os.O_CREAT +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL MODES = stat.S_IWUSR | stat.S_IRUSR @@ -69,7 +68,7 @@ def modify_init_file(developer_path, hdc_str): # 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_WRITE, MODES), 'w') as json_file: + 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") @@ -108,7 +107,7 @@ def modify_faultloggerd_file(developer_path, hdc_str): # 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_WRITE, MODES), 'w') as json_file: + 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/")) @@ -167,7 +166,7 @@ def modify_foundation_json(serv, config_path, origin_json) -> str: # 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_WRITE, MODES), 'w') as f: + with os.fdopen(os.open(new_json, FLAGS, MODES), 'w') as f: json.dump(f_dict, f, indent=4) return new_json @@ -197,7 +196,7 @@ def create_service_json(serv, config_path, origin_json) -> str: # 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_WRITE, MODES), 'w') as f: + with os.fdopen(os.open(new_json, FLAGS, MODES), 'w') as f: json.dump(f_dict, f, indent=4) return new_json @@ -254,7 +253,7 @@ def create_service_cfg(serv, config_path, origin_cfg) -> str: # 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_WRITE, MODES), 'w') as r: + 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/restore_comment/after_lcov_branch.py b/localCoverage/restore_comment/after_lcov_branch.py index 89f38a7..c0e98aa 100644 --- a/localCoverage/restore_comment/after_lcov_branch.py +++ b/localCoverage/restore_comment/after_lcov_branch.py @@ -61,7 +61,7 @@ def recover_source_file(cpp_list, 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: - is os.path.exists(f"{path.split('.')[0]}_bk.html"): + 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: diff --git a/src/main/_init_global_config.py b/src/main/_init_global_config.py index f28b766..499adba 100755 --- a/src/main/_init_global_config.py +++ b/src/main/_init_global_config.py @@ -128,7 +128,7 @@ def _load_internal_plugins(): try: import script.report _iter_module_plugins([script.report]) - except importError: + except ImportError: pass -- Gitee From 144699660f2631af59ef75fc6b36fbeb4a20dd4b Mon Sep 17 00:00:00 2001 From: Teacher_Dong Date: Fri, 12 Jan 2024 01:50:34 +0000 Subject: [PATCH 5/6] Signed-off-by: Teacher_Dong Signed-off-by: Teacher_Dong --- aw/python/distributed/common/common.py | 1 - aw/python/distributed/common/drivers.py | 1 - aw/python/distributed/distribute/distribute.py | 1 - examples/sleep/src/sleep_ex.cpp | 6 ++---- libs/benchmark/report/generate_report.py | 2 -- libs/fuzzlib/fuzzer_helper.py | 6 ------ libs/fuzzlib/tools/colored.py | 1 - libs/fuzzlib/tools/run_result.py | 1 - localCoverage/codeCoverage/codeCoverage_gcov_lcov.py | 1 - localCoverage/codeCoverage/mutilProcess_CodeCoverage.py | 1 - localCoverage/coverage_tools.py | 1 - localCoverage/interfaceCoverage/get_innerkits_json.py | 1 - .../interfaceCoverage/interfaceCoverage_gcov_lcov.py | 1 - localCoverage/interfaceCoverage/make_report.py | 6 +----- localCoverage/keyword_registration/keyword_filter.py | 7 ++----- localCoverage/resident_service/init_gcov.py | 5 ----- localCoverage/restore_comment/after_lcov_branch.py | 1 - localCoverage/restore_comment/build_before_generate.py | 3 --- src/core/build/build_manager.py | 1 - src/core/build/pretreat_targets.py | 3 --- src/core/command/distribute_utils.py | 1 - src/core/command/gen.py | 1 - src/core/command/run.py | 2 +- src/core/common.py | 3 --- src/core/driver/drivers.py | 4 ---- 25 files changed, 6 insertions(+), 55 deletions(-) diff --git a/aw/python/distributed/common/common.py b/aw/python/distributed/common/common.py index 5cd096c..16bcecb 100755 --- a/aw/python/distributed/common/common.py +++ b/aw/python/distributed/common/common.py @@ -85,7 +85,6 @@ 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()) diff --git a/aw/python/distributed/common/drivers.py b/aw/python/distributed/common/drivers.py index c564a7f..239238d 100755 --- a/aw/python/distributed/common/drivers.py +++ b/aw/python/distributed/common/drivers.py @@ -52,7 +52,6 @@ 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: diff --git a/aw/python/distributed/distribute/distribute.py b/aw/python/distributed/distribute/distribute.py index e8009b3..1e68bd5 100755 --- a/aw/python/distributed/distribute/distribute.py +++ b/aw/python/distributed/distribute/distribute.py @@ -311,7 +311,6 @@ 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: diff --git a/examples/sleep/src/sleep_ex.cpp b/examples/sleep/src/sleep_ex.cpp index e791f96..c441959 100644 --- a/examples/sleep/src/sleep_ex.cpp +++ b/examples/sleep/src/sleep_ex.cpp @@ -32,10 +32,8 @@ 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/libs/benchmark/report/generate_report.py b/libs/benchmark/report/generate_report.py index 855e579..264b51a 100644 --- a/libs/benchmark/report/generate_report.py +++ b/libs/benchmark/report/generate_report.py @@ -268,7 +268,6 @@ class BenchmarkReport(object): len(content_new)] try: - # with open(os.path.abspath(out_report_file_path), "w") \ 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), @@ -331,7 +330,6 @@ class BenchmarkReport(object): self._update_report_summary(content_new, detail_info) try: - # with open(os.path.abspath(out_report_file_path), "w") \ 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), diff --git a/libs/fuzzlib/fuzzer_helper.py b/libs/fuzzlib/fuzzer_helper.py index e79d184..632b418 100644 --- a/libs/fuzzlib/fuzzer_helper.py +++ b/libs/fuzzlib/fuzzer_helper.py @@ -133,27 +133,23 @@ 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: @@ -164,7 +160,6 @@ def generate(args): os.mkdir(corpus_dir) if os.path.exists(os.path.join(corpus_dir, 'init')): os.remove(os.path.join(corpus_dir, 'init')) - # with open(os.path.join(corpus_dir, 'init'), 'w') as filehandle: with os.fdopen(os.open(os.path.join(corpus_dir, 'init'), FLAGS, MODES), 'w') as filehandle: filehandle.write("FUZZ") return 0 @@ -207,7 +202,6 @@ 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: diff --git a/libs/fuzzlib/tools/colored.py b/libs/fuzzlib/tools/colored.py index 0f80aca..865c1f3 100644 --- a/libs/fuzzlib/tools/colored.py +++ b/libs/fuzzlib/tools/colored.py @@ -86,7 +86,6 @@ 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 ee3c05e..4da38ae 100644 --- a/libs/fuzzlib/tools/run_result.py +++ b/libs/fuzzlib/tools/run_result.py @@ -80,7 +80,6 @@ class RunResult(): pass def write_analysis_result(self, analysis_ressult_path, html_format=True): - # with open(analysis_ressult_path, "wb") as f: is os.path.exists(analysis_ressult_path): os.remove(analysis_ressult_path) with os.fdopen(os.open(analysis_ressult_path, FLAGS, MODES), 'wb') as f: diff --git a/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py b/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py index 257d119..ae82dbb 100644 --- a/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py +++ b/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py @@ -61,7 +61,6 @@ 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: diff --git a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py index 1c0d170..753b43b 100644 --- a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py +++ b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py @@ -66,7 +66,6 @@ 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: diff --git a/localCoverage/coverage_tools.py b/localCoverage/coverage_tools.py index e663bc3..83f17d0 100644 --- a/localCoverage/coverage_tools.py +++ b/localCoverage/coverage_tools.py @@ -49,7 +49,6 @@ def get_subsystem_config(part_list, developer_path): print("Error: 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: diff --git a/localCoverage/interfaceCoverage/get_innerkits_json.py b/localCoverage/interfaceCoverage/get_innerkits_json.py index 2502dab..e8484e3 100644 --- a/localCoverage/interfaceCoverage/get_innerkits_json.py +++ b/localCoverage/interfaceCoverage/get_innerkits_json.py @@ -41,7 +41,6 @@ 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: diff --git a/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py b/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py index 6abed62..86a7c80 100644 --- a/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py +++ b/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py @@ -394,7 +394,6 @@ 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: diff --git a/localCoverage/interfaceCoverage/make_report.py b/localCoverage/interfaceCoverage/make_report.py index d2bd473..b340b6a 100644 --- a/localCoverage/interfaceCoverage/make_report.py +++ b/localCoverage/interfaceCoverage/make_report.py @@ -94,7 +94,6 @@ 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: @@ -132,7 +131,6 @@ 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): @@ -168,7 +166,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) @@ -209,7 +207,6 @@ 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) @@ -246,7 +243,6 @@ 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) diff --git a/localCoverage/keyword_registration/keyword_filter.py b/localCoverage/keyword_registration/keyword_filter.py index ac7d5eb..d9335af 100644 --- a/localCoverage/keyword_registration/keyword_filter.py +++ b/localCoverage/keyword_registration/keyword_filter.py @@ -66,7 +66,6 @@ span.branchnocovupdate { background-color:#BBBBBB; }""" - # with open(css_file_path, "a+", encoding="utf-8") as file: if os.path.exists(css_file_path): with os.fdopen(os.open(css_file_path, FLAGS_ADD, MODES), 'a+') as file: file.write(text) @@ -479,7 +478,6 @@ 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) @@ -586,7 +584,6 @@ 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) @@ -879,7 +876,7 @@ 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) @@ -887,7 +884,7 @@ class KeywordRegistration: content = self.get_coverage_content(file_path) content = content.replace('> * ', '> ') os.remove(file_path) - # with open(file_path, "w", encoding="utf-8") as new_html: + with os.fdopen(os.open(file_path, FLAGS_WRITE, MODES), 'w') as new_html: new_html.write(content) diff --git a/localCoverage/resident_service/init_gcov.py b/localCoverage/resident_service/init_gcov.py index fa3054b..6bf9c79 100644 --- a/localCoverage/resident_service/init_gcov.py +++ b/localCoverage/resident_service/init_gcov.py @@ -65,7 +65,6 @@ 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: @@ -104,7 +103,6 @@ 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: @@ -163,7 +161,6 @@ 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: @@ -193,7 +190,6 @@ 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: @@ -250,7 +246,6 @@ 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: diff --git a/localCoverage/restore_comment/after_lcov_branch.py b/localCoverage/restore_comment/after_lcov_branch.py index c0e98aa..609a43c 100644 --- a/localCoverage/restore_comment/after_lcov_branch.py +++ b/localCoverage/restore_comment/after_lcov_branch.py @@ -60,7 +60,6 @@ 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: diff --git a/localCoverage/restore_comment/build_before_generate.py b/localCoverage/restore_comment/build_before_generate.py index 90ad331..df29066 100644 --- a/localCoverage/restore_comment/build_before_generate.py +++ b/localCoverage/restore_comment/build_before_generate.py @@ -56,8 +56,6 @@ 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: @@ -115,7 +113,6 @@ def get_part_config_json(part_list, system_info_path, part_path): else: print("Error: 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: diff --git a/src/core/build/build_manager.py b/src/core/build/build_manager.py index b7ac0a5..3c8ad7a 100644 --- a/src/core/build/build_manager.py +++ b/src/core/build/build_manager.py @@ -42,7 +42,6 @@ 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: diff --git a/src/core/build/pretreat_targets.py b/src/core/build/pretreat_targets.py index 495a490..5edc0f9 100644 --- a/src/core/build/pretreat_targets.py +++ b/src/core/build/pretreat_targets.py @@ -92,7 +92,6 @@ class PretreatTargets(object): 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 % @@ -106,7 +105,6 @@ 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') \ 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) @@ -122,7 +120,6 @@ class PretreatTargets(object): line = line.replace("TargetName", name) json_data += line os.remove(i18n_path) - # with open(i18n_path, 'w') as i18n_file: 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/distribute_utils.py b/src/core/command/distribute_utils.py index a666846..9073a5f 100755 --- a/src/core/command/distribute_utils.py +++ b/src/core/command/distribute_utils.py @@ -37,7 +37,6 @@ 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: diff --git a/src/core/command/gen.py b/src/core/command/gen.py index df75175..9a295e9 100644 --- a/src/core/command/gen.py +++ b/src/core/command/gen.py @@ -46,7 +46,6 @@ class Gen(object): LOG.info("The fuzzer list file path: %s" % filepath) if os.path.exists(filepath): os.remove(filepath) - # with open(filepath, "w") as gn_file: with os.fdopen(os.open(filepath, FLAGS, MODES), 'w') as gn_file: gn_file.truncate(0) if fuzzer_list: diff --git a/src/core/command/run.py b/src/core/command/run.py index 1aff63b..ee89702 100644 --- a/src/core/command/run.py +++ b/src/core/command/run.py @@ -298,7 +298,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 "fuzztest" == options.testtype[0] and options.coverage is False: report = get_plugin(plugin_type=Plugin.REPORTER, plugin_id="ALL")[0] latest_corpus_path = os.path.join(sys.framework_root_dir, "reports", "latest_corpus") diff --git a/src/core/common.py b/src/core/common.py index cddcb2d..6cdf1a9 100755 --- a/src/core/common.py +++ b/src/core/common.py @@ -49,6 +49,3 @@ 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/driver/drivers.py b/src/core/driver/drivers.py index c4ce4aa..eb78b14 100644 --- a/src/core/driver/drivers.py +++ b/src/core/driver/drivers.py @@ -188,7 +188,6 @@ 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()) @@ -236,7 +235,6 @@ 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()) @@ -263,7 +261,6 @@ 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()) @@ -716,7 +713,6 @@ 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) with os.fdopen(os.open(name, FLAGS, MODES), 'wb') as f: -- Gitee From 7484b17f81712319828baed071bf499520b7ab5a Mon Sep 17 00:00:00 2001 From: Teacher_Dong Date: Fri, 12 Jan 2024 02:12:17 +0000 Subject: [PATCH 6/6] Signed-off-by: Teacher_Dong Signed-off-by: Teacher_Dong --- examples/sleep/src/sleep_ex.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/sleep/src/sleep_ex.cpp b/examples/sleep/src/sleep_ex.cpp index c441959..5d57d29 100644 --- a/examples/sleep/src/sleep_ex.cpp +++ b/examples/sleep/src/sleep_ex.cpp @@ -32,8 +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); } -- Gitee