diff --git a/test/maple_test/configs.py b/test/maple_test/configs.py index 8745897d0564bbf86ebebfa01cc99ff0b6f57a79..5b65e3a18941399ad3472a9dbe36629a9559bb4d 100644 --- a/test/maple_test/configs.py +++ b/test/maple_test/configs.py @@ -23,8 +23,8 @@ import logging import sys from pathlib import Path -from maple_test.utils import ALL, ENCODING -from maple_test.utils import complete_path, read_config, get_config_value, BASE_DIR +from maple_test.utils import ALL, ENCODING, BASE_DIR +from maple_test.utils import complete_path, read_config, get_config_value, is_relative TEST_CONFIG = {} LOGGER = None @@ -104,6 +104,7 @@ def parse_args(): test_suite_parser.add_argument( "-c", "--config_set", + action="append", dest="user_config_set", metavar="config_set_name", help="Run a test set with the specified config set name", @@ -166,14 +167,6 @@ def parse_args(): ) args = parser.parse_args() - if args.test_paths: - for path in args.test_paths: - if path.is_file and not args.test_cfg: - print( - "Error: When specify test case, need also specify test configure file\n" - ) - parser.print_help() - sys.exit(0) if args.test_list and not args.test_cfg: print("Error: When specify test list, need also specify test configure file\n") parser.print_help() @@ -195,10 +188,10 @@ def parse_args(): test_suite_config = { "test_paths": args.test_paths or None, + "test_cfg": args.test_cfg or None, "cli_running_config": { - "test_cfg": args.test_cfg or None, "test_list": args.test_list or None, - "user_config_set": args.user_config_set or None, + "user_config_set": args.user_config_set or [], "user_config": args.user_config or {}, "user_env": args.user_env or {}, }, @@ -221,15 +214,13 @@ def parse_args(): def parser_maple_test_config_file(maple_test_cfg_file): raw_config = read_config(maple_test_cfg_file) + test_paths = get_config_value(raw_config, "test-home", "dir") + if test_paths: + test_paths = test_paths.replace("\n", "").split(":") + else: + test_paths = [] test_suite_config = { - "test_paths": [ - BASE_DIR / path - for path in get_config_value(raw_config, "test-home", "dir") - .replace("\n", "") - .split(":") - if path - ] - or None, + "test_paths": [BASE_DIR / path for path in test_paths if path] or [], } log_config = { "dir": complete_path( @@ -265,6 +256,18 @@ def init_config(): file_log_config, ) = parser_maple_test_config_file(TEST_CONFIG.get("cfg")) + cli_test_paths = cli_test_suite_config.get("test_paths") or [] + file_test_paths = file_test_suite_config.get("test_paths") or [] + + for path1 in cli_test_paths: + for path2 in file_test_paths: + if is_relative(path1, path2): + user_test_cfg = cli_test_suite_config.get("test_cfg") + if not user_test_cfg: + cli_test_suite_config["test_cfg"] = complete_path( + path2 / "test.cfg" + ) + test_suite_config = merge_config(cli_test_suite_config, file_test_suite_config) running_config = merge_config(cli_running_config, file_running_config) log_config = merge_config(cli_log_config, file_log_config) diff --git a/test/maple_test/main.py b/test/maple_test/main.py index 446ef65cb382419356e0e2c9d9f7ce5b430a3a1c..07b6ee8d4e606c1aeedf6f08fa2911314d9461f1 100644 --- a/test/maple_test/main.py +++ b/test/maple_test/main.py @@ -25,6 +25,7 @@ import time from maple_test import configs from maple_test.task import TestSuiteTask from maple_test.utils import timer +from maple_test.run import TestError @timer @@ -33,22 +34,28 @@ def main(): logger = configs.LOGGER test_paths = test_suite_config.get("test_paths") + test_cfg = test_suite_config.get("test_cfg") cli_running_config = test_suite_config.get("cli_running_config") retry = configs.get_val("retry") result = [] for test in test_paths: if test.exists(): - task = TestSuiteTask( - test, test / "test.cfg", running_config, cli_running_config - ) + if not test_cfg: + test_cfg = test / "test.cfg" + try: + task = TestSuiteTask(test, test_cfg, running_config, cli_running_config) + except TestError as e: + logger.info(e) + continue if not task.task_set: continue - for run_times in range(1, retry + 2): + for run_time in range(1, retry + 2): + logger.info("Run {} times".format(run_time)) task.run(configs.get_val("processes")) result.append(task.gen_summary([])) else: - print("Test path: {} does not exist, please check".format(test)) + logger.info("Test path: {} does not exist, please check".format(test)) output = configs.get_val("output") if output: diff --git a/test/maple_test/task.py b/test/maple_test/task.py index 4d2e47866f3722ce6e0457e1bfd55d25084af188..142be03cca4e956edf5e381eb914470e0e83f670 100644 --- a/test/maple_test/task.py +++ b/test/maple_test/task.py @@ -89,14 +89,13 @@ class TestSuiteTask: def __init__(self, test_path, cfg_path, running_config, cli_running_config=None): if cli_running_config is None: cli_running_config = {} - user_test_cfg = cli_running_config.get("test_cfg") user_test_list = cli_running_config.get("test_list") user_config_set = cli_running_config.get("user_config_set") user_config = cli_running_config.get("user_config") user_env = cli_running_config.get("user_env") self.path = test_path - self.cfg_path = user_test_cfg or cfg_path + self.cfg_path = cfg_path config = read_config(self.cfg_path) if config is None: @@ -129,19 +128,24 @@ class TestSuiteTask: def _form_config(self, test_path, config, user_config_set, user_config, user_env): top_config = TaskConfig(self.name, self.cfg_path, None, user_config, user_env) - if not user_config_set: + if ( + not user_config_set + or "default" in user_config_set + or self.name in user_config_set + ): self.config_set[self.name] = top_config + cfg_base = self.cfg_path.parent for name, config_path in config_section_to_dict(config, "config-set").items(): - if not user_config_set or name == user_config_set: + if not user_config_set or name in user_config_set: self.config_set[name] = TaskConfig( - name, test_path / config_path, top_config, user_config, user_env + name, cfg_base / config_path, top_config, user_config, user_env ) def _form_testlist( self, test_path, config, encoding, user_config_set, user_test_list ): for name, testlist_path in config_section_to_dict(config, "testlist").items(): - if not user_config_set or name == user_config_set: + if not user_config_set or name in user_config_set: if user_test_list is None: self.testlist_set[name] = read_list( test_path / testlist_path, encoding @@ -149,14 +153,15 @@ class TestSuiteTask: else: self.testlist_set[name] = read_list(user_test_list, encoding) if self.testlist_set.get("default") is None: - self.testlist_set["default"] = set("*"), set() - if test_path.is_file(): - self.testlist_set["default"] = set("."), set() - if (test_path / "testlist").exists(): - testlist = read_list(test_path / "testlist", encoding) - else: - testlist = self.testlist_set["default"] - self.testlist_set[self.name] = testlist + testlist = set("*"), set() + if (test_path / "testlist").exists(): + testlist = read_list(test_path / "testlist", encoding) + if test_path.is_file(): + testlist = set("."), set() + if user_test_list: + testlist = read_list(user_test_list, encoding) + self.testlist_set["default"] = testlist + self.testlist_set[self.name] = self.testlist_set["default"] self.all_cases = {} self._search_list(test_path, encoding) @@ -180,7 +185,7 @@ class TestSuiteTask: case = Case(case_file, test_path, comment, encoding,) self.all_cases[case_name] = case self.testlist_set[name].append(self.all_cases[case_name]) - + @staticmethod def _search_case(include, exclude, test_path, suffixes): case_files = set() @@ -188,8 +193,8 @@ class TestSuiteTask: for include_path in test_path.glob(glob_pattern): case_files.update(ls_all(include_path, suffixes)) for glob_pattern in exclude: - for exclude_path in test_path.glob(glob_pattern): - case_files -= set(ls_all(exclude_path, suffixes)) + for exclude_path in test_path.glob(glob_pattern): + case_files -= set(ls_all(exclude_path, suffixes)) return case_files def _form_task_set(self, running_config): diff --git a/test/maple_test/utils.py b/test/maple_test/utils.py index d00fd74d55773046bbbb97e3ab8c27bed7153743..12eb164dd145d22a72dc8621658441dbe5200160 100644 --- a/test/maple_test/utils.py +++ b/test/maple_test/utils.py @@ -192,3 +192,15 @@ def timer(func): return result return wrapper + + +def is_relative(path1, path2): + """Is path1 relative to path2""" + _p1 = complete_path(path1) + _p2 = complete_path(path2) + try: + _p1.relative_to(_p2) + except ValueError: + return 0 + else: + return 1