diff --git a/aw/cxx/distributed/distributed.h b/aw/cxx/distributed/distributed.h index 44c712f8ea2848ead9b1ee2b9221fcf4ae082745..a9fb144baf5fd7242a72d7ea8810694a39c159e5 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 afc79f4a5b0e8afaf0abb792678719a2db9d5682..54690b32937663f26e3ad1892b87d743c11f932c 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 e0c087bf77a643aa83d230c4f24000abb699faf7..8581ae89d22a6a382cc8ee29836d1fbf87e9f310 100755 --- a/aw/python/distributed/common/common.py +++ b/aw/python/distributed/common/common.py @@ -18,7 +18,10 @@ import os import time +import stat +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR ############################################################################## ############################################################################## @@ -81,7 +84,7 @@ def create_empty_result_file(savepath, filename, message=""): if filename.endswith(".hap"): filename = filename.split(".")[0] if not os.path.exists(savepath): - with open(savepath, "w", encoding='utf-8') as file_desc: + with os.fdopen(os.open(savepath, FLAGS, MODES), 'w') as file_desc: time_stamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) file_desc.write('\n') diff --git a/aw/python/distributed/common/devices.py b/aw/python/distributed/common/devices.py index 057d9c9b4165f0abd6d2b96cdc3ba85adf3779ac..913de009d938097999a7b15c213ca513725af88a 100755 --- a/aw/python/distributed/common/devices.py +++ b/aw/python/distributed/common/devices.py @@ -54,7 +54,7 @@ def get_package_name(hap_filepath): try: zf_desc.extractall(path=hap_bak_path) except RuntimeError as error: - print(error) + print("Unzip error", hap_bak_path) zf_desc.close() # verify config.json file @@ -215,15 +215,15 @@ class DeviceShell: stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) - + result = "" try: data, _ = proc.communicate() if isinstance(data, bytes): - data = data.decode('utf-8', 'ignore') + result = data.decode("utf-8", "ignore") finally: proc.stdout.close() proc.stderr.close() - return data + return data if result else data @classmethod def check_path_legal(cls, path): diff --git a/aw/python/distributed/common/drivers.py b/aw/python/distributed/common/drivers.py index c09ae3723e39e36f2150fd38571a91f16b749b93..2585ac71fb4d20f4c41669ec01a89bc2ccc4b4c1 100755 --- a/aw/python/distributed/common/drivers.py +++ b/aw/python/distributed/common/drivers.py @@ -20,6 +20,7 @@ import os import platform import subprocess import tempfile +import stat from abc import ABCMeta from abc import abstractmethod @@ -29,6 +30,9 @@ from core.config.resource_manager import ResourceManager ############################################################################## ############################################################################## +FLAGS = os.O_WRONLY | os.O_APPEND | os.O_CREAT +MODES = stat.S_IWUSR | stat.S_IRUSR + DEVICE_TEST_PATH = "/%s/%s/" % ("data", "test") @@ -48,10 +52,10 @@ def make_long_command_file(command, longcommand_path, filename): sh_file_name = '%s.sh' % filename file_path = os.path.join(longcommand_path, sh_file_name) try: - with open(file_path, "a") as file_desc: + with os.fdopen(os.open(file_path, FLAGS, MODES), 'a') as file_desc: file_desc.write(command) except(IOError, ValueError) as err_msg: - print("Error for make long command file: ", err_msg) + print(f"Error for make long command file: {err_msg}") return sh_file_name, file_path @@ -162,6 +166,9 @@ class CppTestDriver(ITestDriver): if options.coverage: receive_coverage_data(self.device, result_path, suite_file, file_name) + if os.path.exists(long_command_path): + os.remove(long_command_path) + ############################################################################## ############################################################################## diff --git a/aw/python/distributed/distribute/distribute.py b/aw/python/distributed/distribute/distribute.py index a4083f022a0d424c79ceb905e1ee4a03d14d2691..ad3e24c240dee16978c193a84b6020154a87c196 100755 --- a/aw/python/distributed/distribute/distribute.py +++ b/aw/python/distributed/distribute/distribute.py @@ -21,6 +21,10 @@ import sys import re import time import platform +import stat + +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR # insert src path for loading xdevice modules @@ -284,6 +288,8 @@ class Distribute: dev_nodeid_info = re.findall(r"Uuid = (.*?\r\n)", device_info) if dev_nodeid_info: return str(dev_nodeid_info[0]) + else: + return "" @staticmethod def _query_device_agent_uuid(device): @@ -296,6 +302,8 @@ class Distribute: dev_nodeid_info = re.findall(r"Uuid = (.*?\r\n)", device_info) if dev_nodeid_info: return str(dev_nodeid_info[0]) + else: + return "" @staticmethod def _write_device_config(device_info, file_path): @@ -303,11 +311,12 @@ class Distribute: final_file = os.path.join(file_dir, file_name.split('.')[0] + ".desc") if os.path.exists(final_file): os.remove(final_file) - with open(file_path, 'w') as file_desc: + if os.path.exists(file_path): + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS, MODES), 'w') as file_desc: file_desc.write(device_info) os.rename(file_path, final_file) - ############################################################################## ############################################################################## diff --git a/examples/sleep/src/sleep_ex.cpp b/examples/sleep/src/sleep_ex.cpp index 46444f10b38a8d8a548b10a424fa75a4226a84da..5d57d2903c9495e2087122b83298773692668e55 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 421ffded7912dd3a614aa45b4685361f12e591ee..fe3c56842078ddb9969ad62881d37fb49733b77b 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/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/Application/AbilityStage.ts b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/Application/AbilityStage.ts index 379bc0bda5994f317472d4e2d195cf8b5da5d154..e0732e916f734443f2a2457ef55192842fbd00ad 100644 --- a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/Application/AbilityStage.ts +++ b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/Application/AbilityStage.ts @@ -1,3 +1,16 @@ +// Copyright (c) 2023 Huawei Device Co., Ltd. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + import AbilityStage from "@ohos.app.ability.AbilityStage" export default class MyAbilityStage extends AbilityStage { diff --git a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/FormAbility/FormAbility.ts b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/FormAbility/FormAbility.ts index d443631109f5f73817ec907b36c1b7a3d353d357..0c95f0e562ab7422c657c2a288b1d7e5247c5d79 100644 --- a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/FormAbility/FormAbility.ts +++ b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/FormAbility/FormAbility.ts @@ -1,3 +1,16 @@ +// Copyright (c) 2023 Huawei Device Co., Ltd. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + import FormExtension from '@ohos.app.form.FormExtensionAbility'; import formBindingData from '@ohos.application.formBindingData'; import formInfo from '@ohos.application.formInfo'; diff --git a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/MainAbility/MainAbility.ts b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/MainAbility/MainAbility.ts index 6ee21a3c6af3d0362880d1bdcd9acd461bcdba10..3141c2eda6c7653c9ae1b68b2e130b4ffc0bb66e 100644 --- a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,3 +1,16 @@ +// Copyright (c) 2023 Huawei Device Co., Ltd. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + import Ability from '@ohos.app.ability.UIAbility' export default class MainAbility extends Ability { diff --git a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/ServiceAbility/FormAbility.ts b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/ServiceAbility/FormAbility.ts index d443631109f5f73817ec907b36c1b7a3d353d357..0c95f0e562ab7422c657c2a288b1d7e5247c5d79 100644 --- a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/ServiceAbility/FormAbility.ts +++ b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/ServiceAbility/FormAbility.ts @@ -1,3 +1,16 @@ +// Copyright (c) 2023 Huawei Device Co., Ltd. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + import FormExtension from '@ohos.app.form.FormExtensionAbility'; import formBindingData from '@ohos.application.formBindingData'; import formInfo from '@ohos.application.formInfo'; diff --git a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestAbility/TestAbility.ts b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestAbility/TestAbility.ts index 8f18d888e853da9a70d0b767e5963ae915083926..730e69474a6408407097252fe907fcfa65911adc 100644 --- a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestAbility/TestAbility.ts +++ b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestAbility/TestAbility.ts @@ -1,3 +1,16 @@ +// Copyright (c) 2023 Huawei Device Co., Ltd. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + import Ability from '@ohos.app.ability.UIAbility' export default class TestAbility extends Ability { diff --git a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts index 42f986744077e5832001eba2ce62d14eca2177a7..f3149068a37ad19e17ee429c973556b16152491a 100644 --- a/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts +++ b/examples/stagetest/actsbundlemanagerstagetest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -1,3 +1,16 @@ +// Copyright (c) 2023 Huawei Device Co., Ltd. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + import TestRunner from '@ohos.application.testRunner' import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' diff --git a/libs/benchmark/report/generate_report.py b/libs/benchmark/report/generate_report.py index 9cb5c232c04714712f954a8fbac35e8aba9e11f3..45ae6bd1288b2e718b40f21866405ba5f9a74331 100644 --- a/libs/benchmark/report/generate_report.py +++ b/libs/benchmark/report/generate_report.py @@ -20,6 +20,10 @@ import json import os import shutil import sys +import stat + +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR SETTING_RED_STYLE = """\033[33;31m%s\033[0m""" @@ -33,8 +37,7 @@ def load_json_data(json_file_path): print("Loading file \"%s\" error" % json_file_path) return {} except(IOError, ValueError) as err_msg: - print("Error for load_json_data: \"%s\"" % - json_file_path, err_msg) + print("Error for load_json_data: ", json_file_path) else: print("Info: \"%s\" not exist." % json_file_path) return json_data @@ -265,16 +268,16 @@ class BenchmarkReport(object): len(content_new)] try: - with open(os.path.abspath(out_report_file_path), "w") \ - as output_fd: + if os.path.exists(os.path.abspath(out_report_file_path)): + os.remove(os.path.abspath(out_report_file_path)) + with os.fdopen(os.open(os.path.abspath(out_report_file_path), + FLAGS, MODES), 'w') as output_fd: content_new = str(content_new) output_fd.write(content_new) except IOError as err_msg: - print("Error5 for open %s failed, with msg %s" % - (out_report_file_path, err_msg)) + print("Error5 for open %s failed:" % out_report_file_path) except IOError as err_msg: - print("Error6 for open %s failed, with msg %s" % - (tmpl_file_path, err_msg)) + print("Error6 for open %s failed:" % tmpl_file_path) def _generate_all_benchmark_detail(self, dest_dir_parh): for benchmark_info in self.benchmark_list: @@ -327,15 +330,15 @@ class BenchmarkReport(object): self._update_report_summary(content_new, detail_info) try: - with open(os.path.abspath(out_report_file_path), "w") \ - as output_fd: + if os.path.exists(os.path.abspath(out_report_file_path)): + os.remove(os.path.abspath(out_report_file_path)) + with os.fdopen(os.open(os.path.abspath(out_report_file_path), + FLAGS, MODES), 'w') as output_fd: output_fd.write(content_new) except IOError as err_msg: - print("Error5 for open %s failed, with msg %s" % - (out_report_file_path, err_msg)) + print("Error5 for open %s failed:" % out_report_file_path) except IOError as err_msg: - print("Error6 for open %s failed, with msg %s" % - (report_tmpl_file_path, err_msg)) + print("Error6 for open %s failed" % report_tmpl_file_path) def _get_detail_info(self, benchmark_info): detail_info = [] diff --git a/libs/fuzzlib/fuzzer_helper.py b/libs/fuzzlib/fuzzer_helper.py index df633f05c33e4879946d68e0321b3c7d2252de31..e451ee3e2d94f4b2ff8ccf8f553c2d86b0f18aa8 100644 --- a/libs/fuzzlib/fuzzer_helper.py +++ b/libs/fuzzlib/fuzzer_helper.py @@ -29,6 +29,7 @@ import time import copy import shutil from pprint import pprint +import stat from tools.colored import Colored from tools.templates import GN_ENTRY_TEMPLATE @@ -38,6 +39,9 @@ from tools.templates import PROJECT_HEADER_TEMPLATE from tools.templates import PROJECT_XML_TEMPLATE from tools.run_result import RunResult +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) SOURCE_ROOT_DIR = os.path.dirname( os.path.dirname( @@ -93,7 +97,7 @@ def _get_fuzzer_yaml_config(fuzzer_name): fuzzer_name, "project.yaml") if not os.path.exists(project_yaml_path): - return + return {} #log run stdout to fuzzlog dir with open(project_yaml_path) as filehandle: yaml_config = yaml.safe_load(filehandle) @@ -129,25 +133,36 @@ def generate(args): color_logger.green('Writing new files to %s' % project_dir_path) file_path = os.path.join(project_dir_path, 'project.xml') - with open(file_path, 'w') as filehandle: + if os.path.exists(file_path): + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS, MODES), 'w') as filehandle: filehandle.write(PROJECT_XML_TEMPLATE % template_args) file_path = os.path.join(project_dir_path, "%s.cpp" % args.project_name) - with open(file_path, 'w') as filehandle: + if os.path.exists(file_path): + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS, MODES), 'w') as filehandle: filehandle.write(PROJECT_DEMO_TEMPLATE % template_args) file_path = os.path.join(project_dir_path, "%s.h" % args.project_name) - with open(file_path, 'w') as filehandle: + if os.path.exists(file_path): + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS, MODES), 'w') as filehandle: filehandle.write(PROJECT_HEADER_TEMPLATE % template_args) file_path = os.path.join(project_dir_path, "BUILD.gn") - with open(file_path, 'w') as filehandle: + if os.path.exists(file_path): + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS, MODES), 'w') as filehandle: filehandle.write(PROJECT_GN_TEMPLATE % template_args) corpus_dir = os.path.join(project_dir_path, 'corpus') if not os.path.exists(corpus_dir): os.mkdir(corpus_dir) - with open(os.path.join(corpus_dir, 'init'), 'w') as filehandle: + if os.path.exists(os.path.join(corpus_dir, 'init')): + os.remove(os.path.join(corpus_dir, 'init')) + with os.fdopen(os.open(os.path.join(corpus_dir, 'init'), FLAGS, MODES), 'w') as filehandle: filehandle.write("FUZZ") + return 0 #complie fuzzer project @@ -187,7 +202,9 @@ def make(args, stdout=None): ) if not os.path.exists(os.path.dirname(subsystem_src_flag_file_path)): os.makedirs(os.path.dirname(subsystem_src_flag_file_path)) - with open(subsystem_src_flag_file_path, "wb") as file_handle: + if os.path.exists(subsystem_src_flag_file_path): + os.remove(subsystem_src_flag_file_path) + with os.fdopen(os.open(subsystem_src_flag_file_path, FLAGS, MODES), 'wb') as file_handle: file_handle.write(args.project_name.encode()) try: @@ -260,6 +277,10 @@ def main(): elif args.command == 'report': report(args) + return 1 + else: + return 0 + if __name__ == "__main__": main() diff --git a/libs/fuzzlib/tools/colored.py b/libs/fuzzlib/tools/colored.py index 63a488717074710c2d628c6ed12562bf4e2f30d9..865c1f3dd384723a9ef81dd7314a38642c4332ad 100644 --- a/libs/fuzzlib/tools/colored.py +++ b/libs/fuzzlib/tools/colored.py @@ -17,6 +17,10 @@ import sys import os import time +import stat + +FLAGS = os.O_WRONLY | os.O_APPEND | os.O_CREAT +MODES = stat.S_IWUSR | stat.S_IRUSR class Colored(object): @@ -82,7 +86,7 @@ class Colored(object): self.get_fuzz_current_project_log_dir(), "run.log" ) - with open(run_log, 'ab') as f: + with os.fdopen(os.open(run_log, FLAGS, MODES), 'ab') as f: f.write(msg + "\n") diff --git a/libs/fuzzlib/tools/run_result.py b/libs/fuzzlib/tools/run_result.py index 5fb2b6edc683e9f0a27568eccde9384378da423f..8c2490b2e72ae7a23402053a94b4f10c253c02d6 100644 --- a/libs/fuzzlib/tools/run_result.py +++ b/libs/fuzzlib/tools/run_result.py @@ -16,6 +16,11 @@ # import re +import os +import stat + +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR class RunResult(): @@ -75,7 +80,9 @@ class RunResult(): pass def write_analysis_result(self, analysis_ressult_path, html_format=True): - with open(analysis_ressult_path, "wb") as f: + if os.path.exists(analysis_ressult_path): + os.remove(analysis_ressult_path) + with os.fdopen(os.open(analysis_ressult_path, FLAGS, MODES), 'wb') as f: if html_format: f.write(RunResult.filter_log(render_detail(self.crash_info))) else: diff --git a/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py b/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py index 4edf5d44e34bc3d24eb9a65d62d190db4b615afb..ae82dbb706dc42902f5f8509283e2ec1b9cb5d1e 100644 --- a/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py +++ b/localCoverage/codeCoverage/codeCoverage_gcov_lcov.py @@ -23,6 +23,10 @@ import shutil import shlex import subprocess import sys +import stat + +FLAGS = os.O_WRONLY | os.O_APPEND | os.O_CREAT +MODES = stat.S_IWUSR | stat.S_IRUSR # 子系统json目录 SYSTEM_JSON = "build/subsystem_config.json" @@ -57,7 +61,7 @@ def execute_command(command, printflag=False): cmd_list = shlex.split(command) coverage_log_path = os.path.join( CODEPATH, "test/testfwk/developer_test/localCoverage", "coverage.log") - with open(coverage_log_path, 'a') as fd: + with os.fdopen(os.open(coverage_log_path, FLAGS, MODES), 'a') as fd: call(cmd_list, printflag, fd, fd) except IOError: print("Error: Exception occur in open err") diff --git a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py index 1acba905d46f1978c05d80fa6f44cb30457116aa..753b43b4e72a8660de2221ca4a0ca67bdd035b82 100644 --- a/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py +++ b/localCoverage/codeCoverage/mutilProcess_CodeCoverage.py @@ -23,8 +23,13 @@ import shlex import subprocess import multiprocessing import sys +import stat + from multiprocessing import Process +FLAGS = os.O_WRONLY | os.O_APPEND | os.O_CREAT +MODES = stat.S_IWUSR | stat.S_IRUSR + # 子系统json目录 SYSTEM_JSON = "test/testfwk/developer_test/localCoverage/codeCoverage/subsystem_config.json" # 覆盖率gcda @@ -61,7 +66,7 @@ def execute_command(command, printflag=False): cmd_list = shlex.split(command) coverage_log_path = os.path.join( CODEPATH, "test/testfwk/developer_test/localCoverage", "coverage.log") - with open(coverage_log_path, 'a') as fd: + with os.fdopen(os.open(coverage_log_path, FLAGS, MODES), 'a') as fd: call(cmd_list, printflag, fd, fd) except IOError: print("Error: Exception occur in open error") diff --git a/localCoverage/coverage_tools.py b/localCoverage/coverage_tools.py index 1aee796b2f03af4913dbef48de59e0b33163b9f6..f1c5ea95092757b068c0150bbcaa838c1f9145e1 100644 --- a/localCoverage/coverage_tools.py +++ b/localCoverage/coverage_tools.py @@ -22,10 +22,14 @@ import sys import json import shutil import subprocess +import stat from shutil import copyfile from utils import get_product_name, coverage_command +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + def get_subsystem_config(part_list, developer_path): all_system_info_path = os.path.join( @@ -45,7 +49,9 @@ def get_subsystem_config(part_list, developer_path): print("part not in all_subsystem_config.json") new_json = json.dumps(new_json_text, indent=4) - with open(system_info_path, "w") as out_file: + if os.path.exists(system_info_path): + os.remove(system_info_path) + with os.fdopen(os.open(system_info_path, FLAGS, MODES), 'w') as out_file: out_file.write(new_json) else: print("%s not exists.", all_system_info_path) diff --git a/localCoverage/interfaceCoverage/get_innerkits_json.py b/localCoverage/interfaceCoverage/get_innerkits_json.py index 27a362162789640f9ff4a4f71a53ed71c1f046be..e8484e358e868cfe470718d82034a3aec74cca6d 100644 --- a/localCoverage/interfaceCoverage/get_innerkits_json.py +++ b/localCoverage/interfaceCoverage/get_innerkits_json.py @@ -20,6 +20,10 @@ import os import json import sys +import stat + +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR def _init_sys_config(): @@ -37,7 +41,9 @@ def gen_parts_info_json(folder_list, output_json_path, target_cpu): data_dict[folder_str] = f"innerkits/ohos-{target_cpu}/{folder_str}" output_json_path = os.path.join(output_json_path, "kits_modules_info.json") json_str = json.dumps(data_dict, indent=2) - with open(output_json_path, "w") as json_file: + if os.path.exists(output_json_path): + os.remove(output_json_path) + with os.fdopen(os.open(output_json_path, FLAGS, MODES), 'w') as json_file: json_file.write(json_str) else: print("part_name list information is null") diff --git a/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py b/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py index b88b01bf2bc9031e60b06de3221fd65134db142b..47cc669a181fdb3fcdfc68a51a5a65ce7b07b2f5 100644 --- a/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py +++ b/localCoverage/interfaceCoverage/interfaceCoverage_gcov_lcov.py @@ -22,10 +22,14 @@ import sys import json import shutil import subprocess +import stat import CppHeaderParser import get_innerkits_json import make_report +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + filter_file_name_list = [ "appexecfwk/libjnikit/include/jni.h", ] @@ -389,7 +393,9 @@ def get_summary_data(interface_data_list): def make_summary_file(summary_list, output_path): report_path = os.path.join(output_path, "coverage_summary_file.xml") try: - with open(report_path, "w") as fd: + if os.path.exists(report_path): + os.remove(report_path) + with os.fdopen(os.open(report_path, FLAGS, MODES), 'w') as fd: fd.write('\n') fd.write('\n') for item in summary_list: diff --git a/localCoverage/interfaceCoverage/make_report.py b/localCoverage/interfaceCoverage/make_report.py index c9a6d5e865f90b1c805b89403ccff65ea5987cc3..1a06513315626111b49a3a9e4663d88e944b398c 100644 --- a/localCoverage/interfaceCoverage/make_report.py +++ b/localCoverage/interfaceCoverage/make_report.py @@ -19,9 +19,14 @@ import sys import datetime +import os +import stat from importlib import reload reload(sys) +FLAGS_WRITE = os.O_WRONLY | os.O_CREAT | os.O_EXCL +FLAGS_ADD = os.O_WRONLY | os.O_APPEND | os.O_CREAT +MODES = stat.S_IWUSR | stat.S_IRUSR html_head = """ @@ -88,7 +93,9 @@ def sort_by_field_element_data(elem): def create_html_start(reportpath): try: - with open(reportpath, "w") as report: + if os.path.exists(reportpath): + os.remove(reportpath) + with os.fdopen(os.open(reportpath, FLAGS_WRITE, MODES), 'w') as report: report.write(html_head) report.write(html_body_start) except(IOError, ValueError): @@ -123,7 +130,7 @@ def create_title(reportpath, title_name, summary_list): nocoverd = item[1] - item[2] report_title = report_title % (item[1], item[2], nocoverd) try: - with open(reportpath, "a") as report: + with os.fdopen(os.open(reportpath, FLAGS_ADD, MODES), 'a') as report: report.write(report_title) except(IOError, ValueError): print("Error for create html title") @@ -158,7 +165,7 @@ def create_summary(reportpath, summary_list): try: if len(summary_list) == 0: return - with open(reportpath, "a") as report: + with os.fdopen(os.open(reportpath, FLAGS_ADD, MODES), 'a') as report: report.write(table_title) report.write(table_start) report.write(table_head) @@ -198,7 +205,7 @@ def create_table_test(reportpath, subsystem_name, datalist, total_count, covered table_ended = """ """ try: - with open(reportpath, "a") as report: + with os.fdopen(os.open(reportpath, FLAGS_ADD, MODES), 'a') as report: print("part_name==" + subsystem_name) tabletitle = table_title % (subsystem_name) print("tabletitle==" + tabletitle) @@ -234,7 +241,7 @@ def create_table_test(reportpath, subsystem_name, datalist, total_count, covered def create_html_ended(reportpath): try: - with open(reportpath, "a") as report: + with os.fdopen(os.open(reportpath, FLAGS_ADD, MODES), 'a') as report: report.write(html_body_ended) report.write(html_ended) except(IOError, ValueError): diff --git a/localCoverage/interfaceCoverage/results/coverage/interface_kits/coverage_summary_file.xml b/localCoverage/interfaceCoverage/results/coverage/interface_kits/coverage_summary_file.xml index fb67817031aa6dee4ca08551f6eba93a9649ed24..fc3d4ae06386b7db8974be7a107d0602a742ece9 100644 --- a/localCoverage/interfaceCoverage/results/coverage/interface_kits/coverage_summary_file.xml +++ b/localCoverage/interfaceCoverage/results/coverage/interface_kits/coverage_summary_file.xml @@ -1,4 +1,18 @@ + diff --git a/localCoverage/interfaceCoverage/results/coverage/interface_kits/ohos_interfaceCoverage.html b/localCoverage/interfaceCoverage/results/coverage/interface_kits/ohos_interfaceCoverage.html index e506f9b41058743fd5414c45b414c886218e7bd4..0de8cbbc6dd898a18969218860312e3088e71d36 100644 --- a/localCoverage/interfaceCoverage/results/coverage/interface_kits/ohos_interfaceCoverage.html +++ b/localCoverage/interfaceCoverage/results/coverage/interface_kits/ohos_interfaceCoverage.html @@ -49,7 +49,6 @@
-

Summary Report

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

diff --git a/localCoverage/interfaceCoverage/results/coverage/interface_kits/test.png b/localCoverage/interfaceCoverage/results/coverage/interface_kits/test.png deleted file mode 100644 index 9926563cf3090c93597c170f83e1951d9fabb462..0000000000000000000000000000000000000000 Binary files a/localCoverage/interfaceCoverage/results/coverage/interface_kits/test.png and /dev/null differ diff --git a/localCoverage/keyword_registration/keyword_filter.py b/localCoverage/keyword_registration/keyword_filter.py index 0c1e886a248cc5142c19aaa7011636a86e00e0ce..35b36464c975106e1975d7d5da6450f68f6c200e 100644 --- a/localCoverage/keyword_registration/keyword_filter.py +++ b/localCoverage/keyword_registration/keyword_filter.py @@ -20,6 +20,7 @@ import os import re import time import json +import stat import fcntl import platform import linecache @@ -28,6 +29,10 @@ from multiprocessing import Pool from lxml import html from selectolax.parser import HTMLParser +FLAGS_WRITE = os.O_WRONLY | os.O_CREAT | os.O_EXCL +FLAGS_ADD = os.O_WRONLY | os.O_APPEND | os.O_CREAT +MODES = stat.S_IWUSR | stat.S_IRUSR + class CoverageReportPath: def __init__(self, report_path): @@ -61,8 +66,9 @@ span.branchnocovupdate { background-color:#BBBBBB; }""" - with open(css_file_path, "a+", encoding="utf-8") as file: - file.write(text) + if os.path.exists(css_file_path): + with os.fdopen(os.open(css_file_path, FLAGS_ADD, MODES), 'a+') as file: + file.write(text) def get_statistic_path(self, gcov_file_path: str): """ @@ -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,7 @@ class KeywordRegistration: 获取覆盖率文件内容 """ if not os.path.exists(file_path): - return + return "" with open(file_path, "r", encoding="utf-8") as file: content = file.read() return content @@ -153,7 +160,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 +280,7 @@ class KeywordRegistration: while previous_line: child_count += 1 if child_count > 200: - return + return "" previous_line -= 1 html_text = get_tag(content, previous_line) source_code = HTMLParser(html_text).text()[39:].strip() @@ -285,19 +294,22 @@ 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 +337,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 +350,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 +473,8 @@ class KeywordRegistration: if replace_tag in content: content = content.replace(replace_tag, update_tag) - with open(file_path, "w", encoding="utf-8") as file: + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS_WRITE, MODES), 'w') as file: file.write(content) # 修改数据统计页面 @@ -565,7 +579,8 @@ class KeywordRegistration: content = content.replace(replace_tag, update_tag) if file_tag in content: content = content.replace(file_tag, update_branch_tag) - with open(index_path, "w", encoding="utf-8") as file: + os.remove(index_path) + with os.fdopen(os.open(index_path, FLAGS_WRITE, MODES), 'w') as file: file.write(content) fcntl.flock(file.fileno(), fcntl.LOCK_UN) time.sleep(1) @@ -641,7 +656,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 +685,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 +719,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 +764,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 +871,15 @@ class KeywordRegistration: update_source_code_tag_list) content = content.replace( source_code_tag_html, update_source_code_tag_html) - with open(file_path, "w", encoding="utf-8") as new_html: + os.remove(file_path) + with os.fdopen(os.open(file_path, FLAGS_WRITE, MODES), 'w') as new_html: new_html.write(content) content = self.get_coverage_content(file_path) content = content.replace('> * ', '> ') - with open(file_path, "w", encoding="utf-8") as new_html: + os.remove(file_path) + + with os.fdopen(os.open(file_path, FLAGS_WRITE, MODES), 'w') as new_html: new_html.write(content) def keyword_registration(self, file_path, keyword_list): diff --git a/localCoverage/resident_service/config/ams/ams.xml b/localCoverage/resident_service/config/ams/ams.xml index 9fbe4b6bca8156173ff88a0bf400a1f463433a74..64894c734131f790c800ceecc11070fd6ed3ef71 100644 --- a/localCoverage/resident_service/config/ams/ams.xml +++ b/localCoverage/resident_service/config/ams/ams.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/ams/foundation.xml b/localCoverage/resident_service/config/ams/foundation.xml index 6b8da40fff9804eee374185e77c4a0b10b9e013c..11d2a92046f8a59977b23ebf8d6d1c0ae67503cc 100644 --- a/localCoverage/resident_service/config/ams/foundation.xml +++ b/localCoverage/resident_service/config/ams/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/bms/bms.xml b/localCoverage/resident_service/config/bms/bms.xml index 6086c2212b3160a16041767d028d7540313629d2..d74a33ec2cdcc33b4d6e0e2199aeeeabeb31dfd4 100644 --- a/localCoverage/resident_service/config/bms/bms.xml +++ b/localCoverage/resident_service/config/bms/bms.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/bms/foundation.xml b/localCoverage/resident_service/config/bms/foundation.xml index 845b3c34e13fc68a2fc0e2c7264c5fcd7c3f4f8f..c7be367c0de6ac02bfd60cfdd8282993ea135cb5 100644 --- a/localCoverage/resident_service/config/bms/foundation.xml +++ b/localCoverage/resident_service/config/bms/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/call/call.xml b/localCoverage/resident_service/config/call/call.xml index e8d279d29cce1e111fd11792c5e41f69be786ce7..e6f850f613dc16d0fed532b8437195b75b059868 100644 --- a/localCoverage/resident_service/config/call/call.xml +++ b/localCoverage/resident_service/config/call/call.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/call/foundation.xml b/localCoverage/resident_service/config/call/foundation.xml index a8e632c46106d976c1dbedbfcc5bd58c48058c62..d25e2e2c395836bc2b5ebbe3bab8682504be9489 100644 --- a/localCoverage/resident_service/config/call/foundation.xml +++ b/localCoverage/resident_service/config/call/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/fms/fms.xml b/localCoverage/resident_service/config/fms/fms.xml index abecd7684dd0a334329fc664a453c34ffbcb5e6d..e5f521122231cab248ee8154e62a0677b2ceb9ed 100644 --- a/localCoverage/resident_service/config/fms/fms.xml +++ b/localCoverage/resident_service/config/fms/fms.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/fms/foundation.xml b/localCoverage/resident_service/config/fms/foundation.xml index aae2385e475e903b7df1e2e7368961e76f8c5afb..b4514eb020e506a8ef6893ed1518e5b02738923a 100644 --- a/localCoverage/resident_service/config/fms/foundation.xml +++ b/localCoverage/resident_service/config/fms/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/notification/foundation.xml b/localCoverage/resident_service/config/notification/foundation.xml index ffcb838bffaabd045d2ce54484d6fc8577809bc2..1951918c690fac8c85822f309524079f57c76d1b 100644 --- a/localCoverage/resident_service/config/notification/foundation.xml +++ b/localCoverage/resident_service/config/notification/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/notification/notification.xml b/localCoverage/resident_service/config/notification/notification.xml index 259bc9ed9603201ac91063bbe30f5cc172a55068..cc6ad897955ee0835f6e2d6d3faa86ad9e7fabac 100644 --- a/localCoverage/resident_service/config/notification/notification.xml +++ b/localCoverage/resident_service/config/notification/notification.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/power/foundation.xml b/localCoverage/resident_service/config/power/foundation.xml index 8df55e11385800b422a98d234dad49eb058f8480..38a0e7f18b543ae785cff7ce94362d235f174864 100644 --- a/localCoverage/resident_service/config/power/foundation.xml +++ b/localCoverage/resident_service/config/power/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/power/power.xml b/localCoverage/resident_service/config/power/power.xml index a9f99c8597bb42e3d259c7f8c2fe024112c21920..04e901a21682c5190103e4f3d241509f36ca5eb1 100644 --- a/localCoverage/resident_service/config/power/power.xml +++ b/localCoverage/resident_service/config/power/power.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/state/foundation.xml b/localCoverage/resident_service/config/state/foundation.xml index d72b395825f1dbd88290a3f8b58337c465258c93..864ada0fb74db8c1bd21f9f5765588e6328158e1 100644 --- a/localCoverage/resident_service/config/state/foundation.xml +++ b/localCoverage/resident_service/config/state/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/state/state.xml b/localCoverage/resident_service/config/state/state.xml index 4fb86e21b20a53d97871ddc486f75ca5065e34ed..0ddb3d9102bff0f92246f65a5d6b179cffe121d3 100644 --- a/localCoverage/resident_service/config/state/state.xml +++ b/localCoverage/resident_service/config/state/state.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/wms/foundation.xml b/localCoverage/resident_service/config/wms/foundation.xml index f653b6fa902f697f66364817f690703b21eefde3..9cc08186b2ef05e54d55dac26bf2d2af2a436601 100644 --- a/localCoverage/resident_service/config/wms/foundation.xml +++ b/localCoverage/resident_service/config/wms/foundation.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/config/wms/wms.xml b/localCoverage/resident_service/config/wms/wms.xml index e74b72ea3d5189b724b08a84bc10158272d98687..826c37f4c51bfb2cc336d350d66cf53d9fa3f354 100644 --- a/localCoverage/resident_service/config/wms/wms.xml +++ b/localCoverage/resident_service/config/wms/wms.xml @@ -1,4 +1,18 @@ + foundation diff --git a/localCoverage/resident_service/init_gcov.py b/localCoverage/resident_service/init_gcov.py index b42d11cd5e639af6ce96f6b28d8093997fbcb7d5..a5848dc9fb99236519df43d444e0d3a473690f60 100644 --- a/localCoverage/resident_service/init_gcov.py +++ b/localCoverage/resident_service/init_gcov.py @@ -22,9 +22,13 @@ import subprocess import json import sys import time +import stat import xml.etree.ElementTree as ET from public_method import get_server_dict, get_config_ip, get_sn_list +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + def _init_sys_config(): sys.localcoverage_path = os.path.join(current_path, "..") @@ -61,7 +65,9 @@ def modify_init_file(developer_path, hdc_str): else: return json_str = json.dumps(json_data, indent=2) - with open(cfg_file_path, "w") as json_file: + if os.path.exists(cfg_file_path): + os.remove(cfg_file_path) + with os.fdopen(os.open(cfg_file_path, FLAGS, MODES), 'w') as json_file: json_file.write(json_str) else: print("init.cfg file not exists") @@ -97,7 +103,9 @@ def modify_faultloggerd_file(developer_path, hdc_str): ] }) json_str = json.dumps(json_data, indent=4) - with open(cfg_file_path, "w") as json_file: + if os.path.exists(cfg_file_path): + os.remove(cfg_file_path) + with os.fdopen(os.open(cfg_file_path, FLAGS, MODES), 'w') as json_file: json_file.write(json_str) print("%s file send %s %s" % (hdc_str, cfg_file_path, "/system/etc/init/")) coverage_command("%s file send %s %s" % (hdc_str, cfg_file_path, "/system/etc/init/")) @@ -153,7 +161,9 @@ def modify_foundation_json(serv, config_path, origin_json) -> str: f_dict["systemability"] = tmp_list new_json = os.path.join(config_path, 'foundation.json') - with open(new_json, "w", encoding="utf-8") as f: + if os.path.exists(new_json): + os.remove(new_json) + with os.fdopen(os.open(new_json, FLAGS, MODES), 'w') as f: json.dump(f_dict, f, indent=4) return new_json @@ -180,7 +190,9 @@ def create_service_json(serv, config_path, origin_json) -> str: f_dict["process"] = "{}".format(serv) new_json = os.path.join(config_path, '{}.json'.format(serv)) - with open(new_json, "w", encoding="utf-8") as f: + if os.path.exists(new_json): + os.remove(new_json) + with os.fdopen(os.open(new_json, FLAGS, MODES), 'w') as f: json.dump(f_dict, f, indent=4) return new_json @@ -234,7 +246,9 @@ def create_service_cfg(serv, config_path, origin_cfg) -> str: json_obj["services"][0]["jobs"]["on-start"] = "services:{}".format(serv) cfg_path = os.path.join(config_path, "{}.cfg".format(serv)) - with open(cfg_path, 'w') as r: + if os.path.exists(cfg_path): + os.remove(cfg_path) + with os.fdopen(os.open(cfg_path, FLAGS, MODES), 'w') as r: json.dump(json_obj, r, indent=4) return cfg_path diff --git a/localCoverage/resident_service/public_method.py b/localCoverage/resident_service/public_method.py index f203c2c27552873b384668e5d45fa6fbaf7f268a..7714459dd062f69e1139b326b24c6c243ef02c73 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 1ea9227e9b1af76565a34a987073129d35c053b1..e8b2ac774403ba95efe7b14734f395475ba2bec6 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 7c8198cef533ae04f380ac2b441d2de20fccdd3e..609a43c089e571f8a45ac863248be884cf762cc5 100644 --- a/localCoverage/restore_comment/after_lcov_branch.py +++ b/localCoverage/restore_comment/after_lcov_branch.py @@ -18,6 +18,10 @@ import os import subprocess +import stat + +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR def get_file_list(find_path, postfix=""): @@ -56,7 +60,9 @@ def recover_source_file(cpp_list, keys): for key in keys: with open(path, "r") as read_fp: code_lines = read_fp.readlines() - with open(f"{path.split('.')[0]}_bk.html", "w") as write_fp: + if os.path.exists(f"{path.split('.')[0]}_bk.html"): + os.remove(f"{path.split('.')[0]}_bk.html") + with os.fdopen(os.open(f"{path.split('.')[0]}_bk.html", FLAGS, MODES), 'w') as write_fp: for line in code_lines: if key in line: write_fp.write(line.strip("\n").strip("\n\r").replace(" //LCOV_EXCL_BR_LINE", "")) diff --git a/localCoverage/restore_comment/build_before_generate.py b/localCoverage/restore_comment/build_before_generate.py index 4f79506f2726217eca843759c4c2c39a735f1124..9d5e00e63d1f28f4680953589976d7a0dbff94c4 100644 --- a/localCoverage/restore_comment/build_before_generate.py +++ b/localCoverage/restore_comment/build_before_generate.py @@ -19,31 +19,10 @@ import os import subprocess import json +import stat - -def get_file_list(find_path, postfix=""): - file_names = os.listdir(find_path) - file_list = [] - if len(file_names) > 0: - for fn in file_names: - if postfix != "": - if fn.find(postfix) != -1 and fn[-len(postfix):] == postfix: - file_list.append(fn) - else: - file_list.append(fn) - return - - -def get_file_list_by_postfix(path, postfix=""): - file_list = [] - for dirs in os.walk(path): - files = get_file_list(find_path=dirs[0], postfix=postfix) - for file_name in files: - if "" != file_name and -1 == file_name.find(__file__): - file_name = os.path.join(dirs[0], file_name) - if os.path.isfile(file_name): - file_list.append(file_name) - return file_list +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR def get_source_file_list(path): @@ -77,9 +56,9 @@ def rewrite_source_file(source_path_list: list): with open(path, "r", encoding="utf-8", errors="ignore") as read_fp: code_lines = read_fp.readlines() source_dir, suffix_name = os.path.splitext(path) - with open(f"{source_dir}_bk.{suffix_name}", "w", - encoding="utf-8", errors="ignore") as write_fp: - + if os.path.exists(f"{source_dir}_bk.{suffix_name}"): + os.remove(f"{source_dir}_bk.{suffix_name}") + with os.fdopen(os.open(f"{source_dir}_bk.{suffix_name}", FLAGS, MODES), 'w') as write_fp: for line in code_lines: for key in keys: if key in line and line.strip().startswith(key): @@ -129,7 +108,9 @@ def get_part_config_json(part_list, system_info_path, part_path): else: print("part not in all_subsystem_config.json") new_json = json.dumps(new_json_text, indent=4) - with open(part_path, "w") as out_file: + if os.path.exists(part_path): + os.remove(part_path) + with os.fdopen(os.open(part_path, FLAGS, MODES), 'w') as out_file: out_file.write(new_json) else: print("%s not exists.", system_info_path) diff --git a/src/core/build/build_manager.py b/src/core/build/build_manager.py index b7ca0e22b5e91e57e9a100aee24dbf9bef919ce7..3c8ad7a310fa55309e97e90e162d13de17fd60fb 100644 --- a/src/core/build/build_manager.py +++ b/src/core/build/build_manager.py @@ -17,6 +17,8 @@ # import os +import stat + from xdevice import platform_logger from core.utils import scan_support_product from core.config.config_manager import UserConfigManager, FrameworkConfigManager @@ -26,6 +28,9 @@ from core.build.build_testcases import BuildTestcases from core.command.gen import Gen from core.command.run import Run +FLAGS = os.O_WRONLY | os.O_APPEND | os.O_CREAT +MODES = stat.S_IWUSR | stat.S_IRUSR + LOG = platform_logger("BuildManager") @@ -37,7 +42,9 @@ class BuildManager(object): @classmethod def _make_gn_file(cls, filepath, target_list): LOG.info("The gn file path: %s" % filepath) - with open(filepath, "w") as gn_file: + if os.path.exists(filepath): + os.remove(filepath) + with os.fdopen(os.open(filepath, FLAGS, MODES), 'w') as gn_file: gn_file.write("group(\"make_temp_test\") {\n") gn_file.write(" testonly = true\n") gn_file.write(" deps = []\n") diff --git a/src/core/build/build_testcases.py b/src/core/build/build_testcases.py index 4973aecadc77fbe73e497b970c28832f9375a73c..24f9ff3c4722a928aef99cb6dcdb493fdb3239e9 100644 --- a/src/core/build/build_testcases.py +++ b/src/core/build/build_testcases.py @@ -346,7 +346,7 @@ class BuildTestcases(object): self._delete_xts_testcase_dir(para) xts_build_command = [] if para.productform == "rk3568": - pass + False else: xts_build_test_command = ["--abi-type", "generic_generic_arm_64only", "--device-type", get_output_path().split("/")[-1], "--build-variant", "root", "--gn-args", @@ -357,7 +357,7 @@ class BuildTestcases(object): xts_build_test_command.append(input_subsystem) if para.testsuit != "" and len(para.subsystem) == 0: LOG.error("Please specify subsystem.") - return + return False xts_build_command.extend(xts_build_test_command) xts_build_command.append("--ccache") build_result = self._execute_build_xts_command(para, xts_build_command) diff --git a/src/core/build/pretreat_targets.py b/src/core/build/pretreat_targets.py index 7d30c9e13f36535c69eee352b617173dca10004d..a5113df03648bcc1cda776075f3eeb64639edf3e 100644 --- a/src/core/build/pretreat_targets.py +++ b/src/core/build/pretreat_targets.py @@ -19,11 +19,16 @@ import os import sys import json +import stat import shutil from core.constants import JsTestConst from xdevice import platform_logger +FLAGS_WRITE = os.O_WRONLY | os.O_CREAT | os.O_EXCL +FLAGS_ADD = os.O_WRONLY | os.O_APPEND | os.O_CREAT +MODES = stat.S_IWUSR | stat.S_IRUSR + LOG = platform_logger("PretreatTargets") @@ -84,14 +89,15 @@ class PretreatTargets(object): output_path = self._parse_output_path_in_gn(gn_path) if output_path == "": LOG.error(" BUILD.gn needs 'module_output_path'") - return + return False os.rename(gn_path, gn_bak_path) template_args = {'output_path': output_path, 'suite_name': name} - with open(gn_path, 'w') as filehandle: + os.remove(gn_path) + with os.fdopen(os.open(gn_path, FLAGS_WRITE, MODES), 'w') as filehandle: filehandle.write(JsTestConst.BUILD_GN_FILE_TEMPLATE % template_args) - #copy js hap template to target path + # copy js hap template to target path shutil.copytree(template_path, os.path.join(target_path, "src")) shutil.copy(config_path, os.path.join(target_path, "src", "main")) file_name = os.listdir(target_path) @@ -99,8 +105,8 @@ class PretreatTargets(object): if file.endswith(".js"): LOG.info("file: %s" % file) shutil.copy(os.path.join(target_path, file), test_path) - with open(os.path.join(test_path, "List.test.js"), 'a') \ - as list_data: + with os.fdopen(os.open(os.path.join(test_path, "List.test.js"), + FLAGS_ADD, MODES), 'a') as list_data: list_data.write("require('./%s')\n" % file) #modify i18n json file @@ -113,7 +119,8 @@ class PretreatTargets(object): if "TargetName" in line: line = line.replace("TargetName", name) json_data += line - with open(i18n_path, 'w') as i18n_file: + os.remove(i18n_path) + with os.fdopen(os.open(i18n_path, FLAGS_WRITE, MODES), 'w') as i18n_file: i18n_file.write(json_data) return True diff --git a/src/core/command/console.py b/src/core/command/console.py index 249defa1ec782373a51707b1b41f3b582c30b14d..84624f77399c99d647158ad53f81ca60d058c278 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 c0ce5dbf27b992ce23ff89af37491f0025d96190..a762f47d8c90b1e3b6022b58045c89db1b6d71a3 100644 --- a/src/core/command/display.py +++ b/src/core/command/display.py @@ -198,7 +198,7 @@ def select_user_input(data_list): exit the frame.") quit() sys.exit(0) - return select_item_value, select_item_index + return select_item_value, select_item_index # 选择productform diff --git a/src/core/command/distribute_utils.py b/src/core/command/distribute_utils.py index ffd167911e49a5816d3c842e04c79ce9883c3cf5..9073a5f2f58c74669d5edfe636dad3318b39ede5 100755 --- a/src/core/command/distribute_utils.py +++ b/src/core/command/distribute_utils.py @@ -20,11 +20,16 @@ import os import subprocess import sys import re +import stat + from xdevice import platform_logger from xdevice import EnvironmentManager from xdevice import ResultReporter from xdevice import ExecInfo +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + LOG = platform_logger("distribute_utils") @@ -32,7 +37,9 @@ def make_device_info_file(tmp_path): env_manager = EnvironmentManager() device_info_file_path = os.path.join(tmp_path, "device_info_file.txt") - with open(device_info_file_path, "w") as file_handle: + if os.path.exists(device_info_file_path): + os.remove(device_info_file_path) + with os.fdopen(os.open(device_info_file_path, FLAGS, MODES), 'w') as file_handle: if not env_manager.managers: return if list(env_manager.managers.values())[0].devices_list: diff --git a/src/core/command/gen.py b/src/core/command/gen.py index 4bc0fee92cdda6edadb5b1d5c03001d387d80931..332ed4024a6f81f690cb6126391416e78ad04cd3 100644 --- a/src/core/command/gen.py +++ b/src/core/command/gen.py @@ -19,9 +19,13 @@ import os import sys import subprocess +import stat from xdevice import platform_logger +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + LOG = platform_logger("Gen") class Gen(object): @@ -40,7 +44,9 @@ class Gen(object): filepath = os.path.join(sys.source_code_root_path, "test", "developertest", "libs", "fuzzlib", "fuzzer_list.txt") LOG.info("The fuzzer list file path: %s" % filepath) - with open(filepath, "w") as gn_file: + if os.path.exists(filepath): + os.remove(filepath) + with os.fdopen(os.open(filepath, FLAGS, MODES), 'w') as gn_file: gn_file.truncate(0) if fuzzer_list: for target in fuzzer_list: diff --git a/src/core/command/run.py b/src/core/command/run.py index 20bb93f83bcbefd7fa3fc13de39e261d69042ccb..1e33641d15d65b1a826a678e3d5fda23c006ffd5 100644 --- a/src/core/command/run.py +++ b/src/core/command/run.py @@ -297,7 +297,7 @@ class Run(object): if len(self.history_cmd_list) >= 10: del self.history_cmd_list[0] self.history_cmd_list.append(cmd_record) - print("-------------run end: ", self.history_cmd_list) + if options.coverage and platform.system() != "Windows": pull_service_gcov_path = os.path.join( sys.framework_root_dir, "localCoverage/resident_service/pull_service_gcda.py") @@ -422,7 +422,7 @@ class Run(object): xts_test_case_path = self.get_xts_tests_out_path(options.productform, options.testtype) if not os.path.exists(xts_test_case_path): LOG.error("%s is not exist." % xts_test_case_path) - return + return {} xts_test_dict = TestCaseManager().get_xts_test_files(xts_test_case_path, options) return xts_test_dict @@ -431,7 +431,7 @@ class Run(object): test_case_path = self.get_tests_out_path(options.productform) if not os.path.exists(test_case_path): LOG.error("%s is not exist." % test_case_path) - return + return {} test_dict = TestCaseManager().get_test_files(test_case_path, options) return test_dict diff --git a/src/core/common.py b/src/core/common.py index e46dbc9bfd41057acf4877da5fcacbbd77067167..878aa1021ebf3150c2f398ab385664cfa181b2cb 100755 --- a/src/core/common.py +++ b/src/core/common.py @@ -49,6 +49,4 @@ def get_source_code_root_path(path): def is_open_source_product(product_name): open_source_products = ["Hi3516DV300"] return True - if product_name in open_source_products: - return True - return False + diff --git a/src/core/config/config_manager.py b/src/core/config/config_manager.py index 7f0554322f7c0d85e628cd9569e963a1805b9fe4..b9d12fa368e02ec09429fccd874d0041d50d4b47 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 f77f8b8ed2d4e420ce70622b96139c8354381729..57e6bfa03c73836667754a65a1348bd0bf07d303 100644 --- a/src/core/driver/drivers.py +++ b/src/core/driver/drivers.py @@ -61,6 +61,9 @@ TIME_OUT = 900 * 1000 JS_TIMEOUT = 10 CYCLE_TIMES = 30 +FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL +MODES = stat.S_IWUSR | stat.S_IRUSR + ############################################################################## ############################################################################## @@ -184,7 +187,7 @@ def _create_empty_result_file(filepath, filename, error_message): if filename.endswith(".hap"): filename = filename.split(".")[0] if not os.path.exists(filepath): - with open(filepath, "w", encoding='utf-8') as file_desc: + with os.fdopen(os.open(filepath, FLAGS, MODES), 'w') as file_desc: time_stamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) file_desc.write('\n') @@ -231,7 +234,7 @@ def _sleep_according_to_result(result): def _create_fuzz_crash_file(filepath, filename): if not os.path.exists(filepath): - with open(filepath, "w", encoding='utf-8') as file_desc: + with os.fdopen(os.open(filepath, FLAGS, MODES), 'w') as file_desc: time_stamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) file_desc.write('\n') @@ -257,7 +260,7 @@ def _create_fuzz_crash_file(filepath, filename): def _create_fuzz_pass_file(filepath, filename): if not os.path.exists(filepath): - with open(filepath, "w", encoding='utf-8') as file_desc: + with os.fdopen(os.open(filepath, FLAGS, MODES), 'w') as file_desc: time_stamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) file_desc.write('\n') @@ -685,16 +688,28 @@ class CppTestDriver(IDriver): @staticmethod def _alter_init(name): - lines = list() - with open(name, "r") as f: - for line in f: - line_strip = line.strip() - if not line_strip: - continue - if line_strip[0] != "#" and line_strip[0] != "/" and line_strip[0] != "*": - lines.append(line_strip) - with open(name, "w") as f: - f.writelines(lines) + with open(name, "rb") as f: + lines = f.read() + str_content = lines.decode("utf-8") + + pattern_sharp = '^\s*#.*$(\n|\r\n)' + pattern_star = '/\*.*?\*/(\n|\r\n)+' + pattern_xml = '(\n|\r\n)+' + + if re.match(pattern_sharp, str_content, flags=re.M): + striped_content = re.sub(pattern_sharp, '', str_content, flags=re.M) + elif re.findall(pattern_star, str_content, flags=re.S): + striped_content = re.sub(pattern_star, '', str_content, flags=re.S) + elif re.findall(pattern_xml, str_content, flags=re.S): + striped_content = re.sub(pattern_xml, '', str_content, flags=re.S) + else: + striped_content = str_content + + striped_bt = striped_content.encode("utf-8") + if os.path.exists(name): + os.remove(name) + with os.fdopen(os.open(name, FLAGS, MODES), 'wb') as f: + f.write(striped_bt) def _push_corpus_cov_if_exist(self, suite_file): cov_file = suite_file + "_corpus.tar.gz" @@ -1068,8 +1083,6 @@ class JSUnitTestDriver(IDriver): driver_dict = data_dic.get("driver") if driver_dict and "test-timeout" in driver_dict.keys(): test_timeout = int(driver_dict["shell-timeout"]) / 1000 - else: - return return test_timeout except JSONDecodeError: return test_timeout @@ -1091,7 +1104,7 @@ class JSUnitTestDriver(IDriver): try: zf_desc.extractall(path=hap_bak_path) except RuntimeError as error: - print(error) + print("Unzip error:", hap_bak_path) zf_desc.close() # verify config.json file @@ -1132,7 +1145,6 @@ class JSUnitTestDriver(IDriver): return package_name, ability_name - @Plugin(type=Plugin.DRIVER, id=DeviceTestType.oh_rust_test) class OHRustTestDriver(IDriver): def __init__(self): diff --git a/src/core/testcase/testcase_manager.py b/src/core/testcase/testcase_manager.py index 428b5410d01cd3acafc0932f2bac8dad9b0385a7..41cb2e10a93baa461685fcbc7d7def34d31e0f3c 100644 --- a/src/core/testcase/testcase_manager.py +++ b/src/core/testcase/testcase_manager.py @@ -296,7 +296,7 @@ class TestCaseManager(object): def get_hap_test_driver(cls, hap_file_path): data_dic = cls.get_hap_json(hap_file_path) if not data_dic: - return False + return "" else: if "driver" in data_dic.keys(): driver_dict = data_dic.get("driver") @@ -305,6 +305,9 @@ class TestCaseManager(object): return driver_type else: LOG.error("%s has not set driver." % hap_file_path) + return "" + else: + return "" @classmethod def get_hap_json(cls, hap_file_path): @@ -314,6 +317,10 @@ class TestCaseManager(object): with open(json_file_path, 'r') as json_file: data_dic = json.load(json_file) return data_dic + else: + return {} + else: + return {} @classmethod def get_hap_part_json(cls, hap_file_path): @@ -323,13 +330,19 @@ class TestCaseManager(object): with open(json_file_path, 'r') as json_file: data_dic = json.load(json_file) return data_dic + else: + return {} + else: + return {} @classmethod def get_part_name_test_file(cls, hap_file_path): data_dic = cls.get_hap_part_json(hap_file_path) if not data_dic: - return False + return "" else: if "part" in data_dic.keys(): part_name = data_dic["part"] - return part_name \ No newline at end of file + return part_name + else: + return "" diff --git a/src/core/testkit/kit_lite.py b/src/core/testkit/kit_lite.py index bb062d1b2493d84f7c6d245249f62068e52296e6..35fafdedf59036a2b2bf6aad8c6c061871754bef 100755 --- a/src/core/testkit/kit_lite.py +++ b/src/core/testkit/kit_lite.py @@ -142,4 +142,6 @@ class DeployKit(ITestKit): new_temp_tool_path = '{}_{}{}'.format( os.path.splitext(original_file)[0], "".join(random_str), os.path.splitext(original_file)[1]) - return shutil.copyfile(original_file, new_temp_tool_path) \ No newline at end of file + return shutil.copyfile(original_file, new_temp_tool_path) + else: + return "" diff --git a/src/core/utils.py b/src/core/utils.py index 7be7853f6a09a49e3a42134f46a328c7b66d7f1d..fdab9dba7874af223336badfcea74ba27001e695 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 7dddbf5a13a0a5915a4aa76c00abb88cbe707cee..e79ee0ed618c687ed64726da654a311fbe5e5dc1 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