From fff4a1ceb1f23e9137f84cacb9ecaac75b164c79 Mon Sep 17 00:00:00 2001 From: yuyan0428 Date: Wed, 12 Oct 2022 09:12:04 +0000 Subject: [PATCH] Signed-off-by: yuyan0428 Signed-off-by: yuyan0428 --- aw/python/distributed/common/drivers.py | 78 ++++++++++++++++--- .../distributed/distribute/distribute.py | 8 +- src/core/command/distribute_execute.py | 14 ++-- src/core/command/distribute_utils.py | 20 ++--- src/core/command/run.py | 25 ++---- src/core/driver/drivers.py | 3 +- 6 files changed, 98 insertions(+), 50 deletions(-) diff --git a/aw/python/distributed/common/drivers.py b/aw/python/distributed/common/drivers.py index 7bc4353..0649a62 100755 --- a/aw/python/distributed/common/drivers.py +++ b/aw/python/distributed/common/drivers.py @@ -17,6 +17,8 @@ # import os +import platform +import subprocess import tempfile from abc import ABCMeta from abc import abstractmethod @@ -53,6 +55,44 @@ def make_long_command_file(command, longcommand_path, filename): return sh_file_name, file_path +def is_exist_target_in_device(device, path, target): + command = "ls -l %s | grep %s" % (path, target) + check_result = False + stdout_info = device.shell_with_output(command) + if stdout_info != "" and stdout_info.find(target) != -1: + check_result = True + return check_result + + +def receive_coverage_data(device, result_path, suite_file, file_name): + file_dir = suite_file.split("distributedtest\\")[1].split("\\")[0] + target_name = "obj" + cxx_cov_path = os.path.abspath(os.path.join( + result_path, + "..", + "coverage", + "data", + "cxx", + file_name + '_' + file_dir + '_' + device.device_sn)) + + if is_exist_target_in_device(device, DEVICE_TEST_PATH, "obj"): + if not os.path.exists(cxx_cov_path): + os.makedirs(cxx_cov_path) + device.shell( + "cd %s; tar -czf %s.tar.gz %s" % (DEVICE_TEST_PATH, target_name, target_name)) + src_file_tar = os.path.join(DEVICE_TEST_PATH, "%s.tar.gz" % target_name) + device.pull_file(src_file_tar, cxx_cov_path) + tar_path = os.path.join(cxx_cov_path, "%s.tar.gz" % target_name) + if platform.system() == "Windows": + process = subprocess.Popen("tar -zxf %s -C %s" % (tar_path, cxx_cov_path), shell=True) + process.communicate() + os.remove(tar_path) + else: + subprocess.Popen("tar -zxf %s -C %s > /dev/null 2>&1" % + (tar_path, cxx_cov_path), shell=True) + subprocess.Popen("rm -rf %s" % tar_path, shell=True) + + ############################################################################## ############################################################################## @@ -61,7 +101,7 @@ class ITestDriver: __metaclass__ = ABCMeta @abstractmethod - def execute(self, suite_file, result_path, push_flag=False): + def execute(self, suite_file, result_path, options, push_flag=False): pass @@ -74,15 +114,29 @@ class CppTestDriver(ITestDriver): self.device = device self.hdc_tools = hdc_tools - def execute(self, suite_file, result_path, background=False): - file_name = os.path.basename(suite_file) - - long_command_path = tempfile.mkdtemp(prefix="long_command_", - dir=os.path.join(result_path, "temp")) - command = "cd %s; rm -rf %s.xml; chmod +x *; ./%s" % ( - DEVICE_TEST_PATH, - file_name, - file_name) + def execute(self, suite_file, result_path, options, background=False): + case_dir, file_name = os.path.split(suite_file) + dst_dir = case_dir.split("distributedtest\\")[1] + os.makedirs(os.path.join(result_path, "temp", dst_dir), exist_ok=True) + + long_command_path = tempfile.mkdtemp( + prefix="long_command_", + dir=os.path.join(result_path, "temp", dst_dir)) + if not options.coverage: + command = "cd %s; rm -rf %s.xml; chmod +x *; ./%s" % ( + DEVICE_TEST_PATH, + file_name, + file_name) + else: + coverage_outpath = options.coverage_outpath + strip_num = len(coverage_outpath.split("/")) - 1 + command = "cd %s; rm -rf %s.xml; chmod +x *; GCOV_PREFIX=. " \ + "GCOV_PREFIX_STRIP=%s ./%s" % \ + (DEVICE_TEST_PATH, + file_name, + str(strip_num), + file_name, + ) print("command: %s" % command) sh_file_name, file_path = make_long_command_file(command, @@ -103,8 +157,10 @@ class CppTestDriver(ITestDriver): else: sh_command = "sh %s" % ( os.path.join(DEVICE_TEST_PATH, sh_file_name)) + self.device.shell(sh_command) - return self.device.shell(sh_command) + if options.coverage: + receive_coverage_data(self.device, result_path, suite_file, file_name) ############################################################################## diff --git a/aw/python/distributed/distribute/distribute.py b/aw/python/distributed/distribute/distribute.py index 7f4a2b3..889c112 100755 --- a/aw/python/distributed/distribute/distribute.py +++ b/aw/python/distributed/distribute/distribute.py @@ -81,7 +81,7 @@ class Distribute: self.agent_list = agent_list self.hdc_tools = hdc_tools - def exec_agent(self, device, target_name, result_path): + def exec_agent(self, device, target_name, result_path, options): driver = get_current_driver(device, target_name, self.hdc_tools) if driver is None: print("Error: driver is None.") @@ -96,10 +96,10 @@ class Distribute: device.test_path) suite_path = os.path.join(self.suite_dir, target_name) - driver.execute(suite_path, result_path, background=True) + driver.execute(suite_path, result_path, options, background=True) return self._check_thread(device, target_name) - def exec_major(self, device, target_name, result_path): + def exec_major(self, device, target_name, result_path, options): driver = get_current_driver(device, target_name, self.hdc_tools) if driver is None: print("Error: driver is None.") @@ -113,7 +113,7 @@ class Distribute: device.test_path) suite_path = os.path.join(self.suite_dir, target_name) - return driver.execute(suite_path, result_path, background=False) + return driver.execute(suite_path, result_path, options, background=False) @staticmethod def pull_result(device, source_path, result_save_path): diff --git a/src/core/command/distribute_execute.py b/src/core/command/distribute_execute.py index 7694922..c7c83c3 100644 --- a/src/core/command/distribute_execute.py +++ b/src/core/command/distribute_execute.py @@ -16,7 +16,7 @@ # limitations under the License. # - +import os import unittest from distributed.common.manager import DeviceManager @@ -37,7 +37,7 @@ class DbinderTest(unittest.TestCase): self.angent_list = [self.manager.PHONE2] self.hdc = "hdc" - def test_distribute(self, major_target_name="", agent_target_name=""): + def test_distribute(self, major_target_name="", agent_target_name="", options=""): major_target_name = major_target_name agent_target_name = agent_target_name @@ -45,14 +45,18 @@ class DbinderTest(unittest.TestCase): distribute = Distribute(self.suits_dir, self.major, self.angent_list, self.hdc) for agent in self.angent_list: - if not distribute.exec_agent(agent, agent_target_name, self.result_path): + if not distribute.exec_agent(agent, agent_target_name, self.result_path, options): print(agent, agent_target_name) create_empty_result_file(self.result_path, major_target_name) return - distribute.exec_major(self.major, major_target_name, self.result_path) + distribute.exec_major(self.major, major_target_name, self.result_path, options) + result = os.path.join(self.result_path, 'result', + self.suits_dir.split("distributedtest\\")[1]) source_path = "%s/%s.xml" % (self.major.test_path, major_target_name) - distribute.pull_result(self.major, source_path, self.result_path) + if not os.path.exists(result): + os.makedirs(result) + distribute.pull_result(self.major, source_path, result) def tearDown(self): print('tearDown') diff --git a/src/core/command/distribute_utils.py b/src/core/command/distribute_utils.py index 3dfc629..8e26413 100755 --- a/src/core/command/distribute_utils.py +++ b/src/core/command/distribute_utils.py @@ -108,9 +108,6 @@ def check_zdn_network(device, device_ip=""): output = device.execute_shell_command(command) if "" == output: return False - iserror = re.findall(r"error", output) - if 0 != len(iserror): - return False packet_lose = re.findall(r"\d+%", output) LOG.info("packet lose=%s " % packet_lose[0]) if "0%" == packet_lose[0]: @@ -141,15 +138,14 @@ def query_device_ip(device): def get_test_case(test_case): - major_test_case = [] - agent_test_case = [] + result = {} for test in test_case: - test_case = test.split("\\")[-1] - test_agent = test_case.split("Test") - if "Agent" in test_agent: - agent_test_case.append(test_case) + case_dir, file_name = os.path.split(test) + if not result.get(case_dir): + result[case_dir] = {"suits_dir": case_dir} + if file_name.endswith("Test"): + result[case_dir]["major_target_name"] = file_name else: - major_test_case.append(test_case) - - return major_test_case, agent_test_case + result[case_dir]["agent_target_name"] = file_name + return list(result.values()) diff --git a/src/core/command/run.py b/src/core/command/run.py index fbe48c1..f1d6de9 100755 --- a/src/core/command/run.py +++ b/src/core/command/run.py @@ -206,25 +206,16 @@ class Run(object): Scheduler.start_task_log(log_path) make_device_info_file(tmp_path) - major_test = output_test[0] - agent_test = output_test[1] - - suits_dir = os.path.dirname(test_dict["CXX"][0]) - - for major in major_test: - major_target_name = major - major_lift = major.split("Test") - for agent in agent_test: - agent_lift = agent.split("Test") - if major_lift[0] == agent_lift[0]: - agent_target_name = agent - manager = DbinderTest(result_rootpath, suits_dir) - manager.setUp() - manager.test_distribute(major_target_name, agent_target_name) - manager.tearDown() + for case in output_test: + agent_target_name = case["agent_target_name"] + major_target_name = case["major_target_name"] + manager = DbinderTest(result_rootpath, case["suits_dir"]) + manager.setUp() + manager.test_distribute(major_target_name, agent_target_name, options) + manager.tearDown() make_reports(result_rootpath, start_time) - Scheduler.stop_task_log() + Scheduler.stop_task_logcat() else: options.testdict = test_dict options.target_outpath = self.get_target_out_path( diff --git a/src/core/driver/drivers.py b/src/core/driver/drivers.py index 7399715..e034b1c 100755 --- a/src/core/driver/drivers.py +++ b/src/core/driver/drivers.py @@ -411,7 +411,8 @@ class ResultManager(object): self.device.pull_file(src_file_tar, cxx_cov_path, is_create=True, timeout=TIME_OUT) tar_path = os.path.join(cxx_cov_path, "%s.tar.gz" % target_name) if platform.system() == "Windows": - subprocess.Popen("tar -zxf %s -C %s" % (tar_path, cxx_cov_path), shell=True) + process = subprocess.Popen("tar -zxf %s -C %s" % (tar_path, cxx_cov_path), shell=True) + process.communicate() os.remove(tar_path) else: subprocess.Popen("tar -zxf %s -C %s > /dev/null 2>&1" % -- Gitee