From 7526a9bb58ebc16b43be5209c1adc7b329616a2c Mon Sep 17 00:00:00 2001 From: XiaGuochao Date: Fri, 17 Apr 2020 10:50:07 +0800 Subject: [PATCH] add args fail_exit to support if any tests fail exit with a non-zero exit --- test/maple_test/compare.py | 3 --- test/maple_test/configs.py | 6 ++++++ test/maple_test/main.py | 12 +++++++++++- test/maple_test/task.py | 11 ++++++++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/test/maple_test/compare.py b/test/maple_test/compare.py index 13c9e6259d..b63206acb7 100644 --- a/test/maple_test/compare.py +++ b/test/maple_test/compare.py @@ -259,9 +259,6 @@ def gen_compare_regex(comment, assert_flags, expected_flag): def extract_compare_lines(file_path, regex): with file_path.open() as f: content = f.read() - print(regex) - print(regex) - print(regex) matches = re.finditer(regex, content, re.MULTILINE) compare_lines = [] diff --git a/test/maple_test/configs.py b/test/maple_test/configs.py index 83adc64be8..14fe513014 100644 --- a/test/maple_test/configs.py +++ b/test/maple_test/configs.py @@ -65,6 +65,11 @@ def parse_args(): test_framework_parser.add_argument( "--debug", action="store_true", help="keep test temp file" ) + test_framework_parser.add_argument( + "--fail_exit", + action="store_true", + help="Execute test framework with a non-zero exit code if any tests fail", + ) test_framework_parser.add_argument( "-p", type=str, @@ -188,6 +193,7 @@ def parse_args(): "retry": args.retry, "output": args.output, "debug": args.debug, + "fail_exit": args.fail_exit, "print_type": args.print_type, "progress": args.progress, "dry_run": args.dry_run, diff --git a/test/maple_test/main.py b/test/maple_test/main.py index c44f3784e1..94515a1f4b 100644 --- a/test/maple_test/main.py +++ b/test/maple_test/main.py @@ -38,7 +38,9 @@ def main(): retry = configs.get_val("retry") result = None + failed = False for test in test_paths: + test_failed = False if test.exists(): if not test_cfg: test_cfg = test / "test.cfg" @@ -51,8 +53,13 @@ def main(): continue for run_time in range(1, retry + 2): logger.info("Run {} times".format(run_time)) - task.run(configs.get_val("processes")) + failed_num = task.run(configs.get_val("processes")) + if failed_num > 0: + test_failed = True + else: + test_failed = False result = task.gen_summary([]) + failed |= test_failed else: logger.info("Test path: {} does not exist, please check".format(test)) @@ -77,6 +84,9 @@ def main(): logger.debug("remove temp_dir %s", temp_dir) shutil.rmtree(str(temp_dir)) + if configs.get_val("fail_exit") and failed: + exit(1) + if __name__ == "__main__": main() diff --git a/test/maple_test/task.py b/test/maple_test/task.py index be5b900856..da482f23e7 100644 --- a/test/maple_test/task.py +++ b/test/maple_test/task.py @@ -155,7 +155,15 @@ class TestSuiteTask: if not cfg.exists(): logger.error("Error: cfg file: {} not found, will skip".format(cfg)) continue - raw_config = read_config(cfg) + try: + raw_config = read_config(cfg) + except: + logger.error( + "The found configuration file {} has an error and will " + "skip the test configuration file, please modify the " + "configuration file or ignore the message. ".format(cfg) + ) + continue config = TaskConfig(cfg, raw_config, top_config, user_config, user_env) name = config.name base_dir = config.base_dir @@ -274,6 +282,7 @@ class TestSuiteTask: print_type = configs.get_val("print_type") for line in self.gen_summary(print_type).splitlines(): logger.info(line) + return self.result["FAIL"] def gen_brief_summary(self): total = sum(self.result.values()) -- Gitee