diff --git a/test/README.md b/test/README.md index bc590f7cf3c6d2a38ba0e7f4ccac343f19870f31..021c0c1ee7bc33a6f570c0848e159e706717b6ee 100644 --- a/test/README.md +++ b/test/README.md @@ -2,22 +2,23 @@ ## 目录结构 -``` +```shell test -├── main.py 运行测试套路口 -├── README.md -├── testsuite/irbuild_test Maple测试套 -└── maple_test 测试框架代码 - ├── compare.py 结果校验模块 - ├── configs.py - ├── __init__.py - ├── main.py - ├── maple_test.cfg - ├── run.py - ├── template.cfg - ├── task.py - ├── test.py - └── utils.py +├── main.py 运行测试套入口 +├── maple_test 测试框架代码 +│   ├── compare.py 结果校验模块 +│   ├── configs.py 参数设置与框架配置文件模块 +│   ├── __init__.py +│   ├── main.py 内部入口 +│   ├── maple_test.cfg 测试框架配置文件 +│   ├── run.py 命令运行模块 +│   ├── task.py 测试任务准备与运行模块 +│   ├── template.cfg 测试套配置文件模板 +│   ├── test.py 测试用例模块 +│   └── utils.py 通用模块 +├── README.md 测试框架说明 +└── testsuite + └── irbuild_test irbuild测试套 ``` ## 运行要求 @@ -72,9 +73,9 @@ python3 test/main.py -j20 --timeout=120 usage: main.py [-h] [--cfg CFG] [-j ] [--retry ] [--output ] [--debug] [-p {PASS,FAIL,XFAIL,XPASS,NOT_RUN,UNRESOLVED,UNSUPPORTED}] - [--progress {silent,normal,no_flush_progress}] + [--progress {silent,normal,no_flush_progress}] [--dry_run] [--test_cfg ] [--test_list ] - [-c config_set_name] [-C key=value] [-E key=value] + [-c config set path] [-C key=value] [-E key=value] [--temp_dir ] [--timeout TIMEOUT] [--encoding ENCODING] [--log_dir ] [--log_level LOG_LEVEL] [--verbose] @@ -97,6 +98,8 @@ Test FrameWork arguments: normal: one line progress bar, update per second,no_flush_progress: print test progress per 10 seconds + --dry_run enable dry run, will generate test.sh under test case + temp dir Test Suite arguments: test_paths Test suite path @@ -105,8 +108,8 @@ Test Suite arguments: or with --test_list --test_list testlist path for filter test cases - -c config_set_name, --config_set config_set_name - Run a test set with the specified config set name + -c config set path, --config_set config set path + Run a test set with the specified config set path -C key=value, --config key=value Add 'key' = 'val' to the user defined configs -E key=value, --env key=value diff --git a/test/maple_test/configs.py b/test/maple_test/configs.py index 2f4162cf8fe65a10931692c3670545e201f1d518..83adc64be89fe453b3f40e251f35414a9ce0ff5e 100644 --- a/test/maple_test/configs.py +++ b/test/maple_test/configs.py @@ -83,6 +83,11 @@ def parse_args(): "normal: one line progress bar, update per second," "no_flush_progress: print test progress per 10 seconds", ) + test_framework_parser.add_argument( + "--dry_run", + action="store_true", + help="enable dry run, will generate test.sh under test case temp dir", + ) test_suite_parser = parser.add_argument_group("Test Suite arguments") test_suite_parser.add_argument( @@ -185,6 +190,7 @@ def parse_args(): "debug": args.debug, "print_type": args.print_type, "progress": args.progress, + "dry_run": args.dry_run, } test_suite_config = { diff --git a/test/maple_test/main.py b/test/maple_test/main.py index e9579f1e03d992f1bdcae06f71eff0667c75b3d9..cd22bd9847243cf61e00c064667a7bf51cd9860b 100644 --- a/test/maple_test/main.py +++ b/test/maple_test/main.py @@ -38,7 +38,7 @@ def main(): cli_running_config = test_suite_config.get("cli_running_config") retry = configs.get_val("retry") - result = [] + result = None for test in test_paths: if test.exists(): if not test_cfg: @@ -53,7 +53,7 @@ def main(): 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([])) + result = task.gen_summary([]) else: logger.info("Test path: {} does not exist, please check".format(test)) @@ -69,8 +69,7 @@ def main(): shutil.move(str(output), str(output.parent / name)) logger.info("Save test result at: {}".format(output)) with output.open("w") as f: - for summary in result: - f.write(summary) + f.write(result) temp_dir = running_config.get("temp_dir") if configs.get_val("debug"): diff --git a/test/maple_test/run.py b/test/maple_test/run.py index c2ba33a7c8ef32e80906de2dcad29f04130c2b60..1d2258fa38b121414b1c01305e791590c65a793e 100644 --- a/test/maple_test/run.py +++ b/test/maple_test/run.py @@ -22,8 +22,8 @@ import time import timeit from textwrap import indent, shorten -from maple_test.configs import construct_logger -from maple_test.utils import PASS, FAIL, UNRESOLVED, ENCODING +from maple_test.configs import construct_logger, get_val +from maple_test.utils import PASS, FAIL, UNRESOLVED, NOT_RUN, ENCODING from maple_test.utils import add_run_path @@ -86,6 +86,16 @@ def run_commands( remain_time = timeout result = (PASS, None) logger.debug("Work directory: {}".format(work_dir)) + if get_val("dry_run"): + with (work_dir / "test.sh").open("w") as f: + f.write("#!/bin/bash\n") + f.write("cd {}\n".format(work_dir)) + for command in commands[:-1]: + f.write(command) + f.write(" && \\\n") + f.write(commands[-1]) + return position, (NOT_RUN, None) + for command in commands: start = timeit.default_timer()