Skip to content

Commit 8949797

Browse files
authored
Improve run.py of regression (#4417)
* Improve run.py of regression 1. Fix script interruption on case failure 2. improve statistics logic 3. enable select specific issue ids
1 parent 38fe056 commit 8949797

File tree

2 files changed

+126
-42
lines changed

2 files changed

+126
-42
lines changed

tests/regression/ba-issues/README.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,22 +218,57 @@ simply run `run.py`
218218
./run.py
219219
```
220220

221+
Specify a specific issue with option `--issues`/`-i`
222+
223+
```shell
224+
./run.py --issues 2833 # test 1 issue #2833
225+
./run.py -i 2833,2834,2835 # test 3 issues #2833 #2834 #2835
226+
```
227+
221228
If everything went well, you should see similarly output in your command line output
222229

223230
```shell
224-
Finish testing, 22/22 of test cases passed, no more issues should further test
231+
==== Test results ====
232+
Total: 22
233+
Passed: 22
234+
Failed: 0
235+
Left issues in folder: no more
236+
Cases in JSON but not found in folder: no more
225237
```
226238

227239
If you add the test case under directory `issues` but forget to add the running config in json file, the output can be something like
228240

229241
```shell
230-
Finish testing, 21/21 of test cases passed, {2945} issue(s) should further test
242+
==== Test results ====
243+
Total: 21
244+
Passed: 21
245+
Failed: 0
246+
missed: 0
247+
Left issues in folder: #3022
248+
Cases in JSON but not found in folder: no more
249+
```
250+
251+
If you add the test case in `running_config.json` but used the wrong id or forget to add the test case under directory `issues`, the output can be someting like
252+
253+
```shell
254+
==== Test results ====
255+
Total: 21
256+
Passed: 21
257+
Failed: 0
258+
missed: 0
259+
Left issues in folder: #2855
260+
Cases in JSON but not found in folder: #12345
231261
```
232262

233263
If some test case are failing, then it will be something like
234264

235265
```shell
236-
Finish testing, 21/22 of test cases passed, no more issue(s) should further test
266+
==== Test results ====
267+
Total: 22
268+
Passed: 21
269+
Failed: 1
270+
Left issues in folder: no more
271+
Cases in JSON but not found in folder: no more
237272
```
238273

239274
And a log file named `issues_tests.log` will be generated and inside it will display the details of the failing cases, for example:

tests/regression/ba-issues/run.py

Lines changed: 88 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import subprocess
1111
import glob
1212
import re
13-
from typing import Dict
13+
import argparse
14+
15+
from typing import Dict, Optional, List
1416

1517
WORK_DIR = os.getcwd()
1618
TEST_WASM_COMMAND = (
@@ -45,7 +47,12 @@ def dump_error_log(failing_issue_id, command_lists, exit_code_cmp, stdout_cmp):
4547
)
4648

4749

48-
def get_issue_ids_should_test():
50+
def get_issue_ids_should_test(selected_ids: Optional[List[int]] = None):
51+
"""Find all issue IDs that should be tested in folder issues."""
52+
# If specific issue IDs are provided, return them as a set
53+
if selected_ids:
54+
return set(selected_ids)
55+
4956
# Define the path pattern
5057
path_pattern = "issues/issue-*"
5158

@@ -60,8 +67,8 @@ def get_issue_ids_should_test():
6067
# Extract the issue number using regular expression
6168
match = re.search(pattern, dir_path)
6269
if match:
63-
issue_number = match.group(1)
64-
issue_numbers.add(int(issue_number))
70+
issue_number = int(match.group(1))
71+
issue_numbers.add(issue_number)
6572

6673
# Print the set of issue numbers
6774
return issue_numbers
@@ -77,10 +84,10 @@ def get_and_check(d, key, default=None, nullable=False):
7784

7885

7986
def run_and_compare_results(
80-
passed_ids, failed_ids, issue_id, cmd, description, ret_code, stdout_content
81-
):
87+
issue_id, cmd, description, ret_code, stdout_content
88+
) -> bool:
8289
print(f"####################################")
83-
print(f"test BA issue #{issue_id} `{description}`: {cmd}")
90+
print(f"test BA issue #{issue_id} `{description}`...")
8491
command_list = cmd.split()
8592
result = subprocess.run(
8693
command_list,
@@ -95,35 +102,33 @@ def run_and_compare_results(
95102

96103
exit_code_cmp = f"exit code (actual, expected) : {actual_exit_code, ret_code}"
97104
stdout_cmp = f"stdout (actual, expected) : {actual_output, stdout_content}"
98-
print(exit_code_cmp)
99-
print(stdout_cmp)
100105

101106
if actual_exit_code == ret_code and (
102107
actual_output == stdout_content
103-
or (stdout_content == "Compile success"
104-
and actual_output.find(stdout_content) != -1)
108+
or (
109+
stdout_content == "Compile success"
110+
and actual_output.find(stdout_content) != -1
111+
)
105112
or (len(stdout_content) > 30 and actual_output.find(stdout_content) != -1)
106113
):
107-
passed_ids.add(issue_id)
108114
print("== PASS ==")
115+
return True
109116
else:
110-
failed_ids.add(issue_id)
117+
print(cmd)
118+
print(exit_code_cmp)
119+
print(stdout_cmp)
111120
print(f"== FAILED: {issue_id} ==")
112121
dump_error_log(
113122
issue_id,
114123
command_list,
115124
exit_code_cmp,
116125
stdout_cmp,
117126
)
127+
return False
118128

119-
print("")
120129

121-
122-
def run_issue_test_wamrc(
123-
passed_ids, failed_ids, issue_id, compile_options, stdout_only_cmp_last_line=False
124-
):
130+
def run_issue_test_wamrc(issue_id, compile_options):
125131
compiler = get_and_check(compile_options, "compiler")
126-
only_compile = get_and_check(compile_options, "only compile")
127132
in_file = get_and_check(compile_options, "in file")
128133
out_file = get_and_check(compile_options, "out file")
129134
options = get_and_check(compile_options, "options")
@@ -145,14 +150,10 @@ def run_issue_test_wamrc(
145150
compiler=compiler, options=options, out_file=out_file_path, in_file=in_file_path
146151
)
147152

148-
run_and_compare_results(
149-
passed_ids, failed_ids, issue_id, cmd, description, ret_code, stdout_content
150-
)
151-
152-
return only_compile
153+
return run_and_compare_results(issue_id, cmd, description, ret_code, stdout_content)
153154

154155

155-
def run_issue_test_iwasm(passed_ids, failed_ids, issue_id, test_case):
156+
def run_issue_test_iwasm(issue_id, test_case) -> bool:
156157
runtime = get_and_check(test_case, "runtime")
157158
mode = get_and_check(test_case, "mode")
158159
file = get_and_check(test_case, "file")
@@ -194,17 +195,19 @@ def run_issue_test_iwasm(passed_ids, failed_ids, issue_id, test_case):
194195
argument=argument,
195196
)
196197

197-
run_and_compare_results(
198-
passed_ids, failed_ids, issue_id, cmd, description, ret_code, stdout_content
199-
)
198+
return run_and_compare_results(issue_id, cmd, description, ret_code, stdout_content)
200199

201200

202-
def process_and_run_test_cases(data: Dict[str, Dict]):
203-
issue_ids_should_test = get_issue_ids_should_test()
201+
def process_and_run_test_cases(
202+
data: Dict[str, Dict], selected_ids: Optional[List[int]] = None
203+
):
204+
issue_ids_should_test = get_issue_ids_should_test(selected_ids)
204205

205206
passed_ids = set()
206207
failed_ids = set()
208+
json_only_ids = set()
207209

210+
# Iterate through each test case in the json data
208211
for test_case in data.get("test cases", []):
209212
is_deprecated = get_and_check(test_case, "deprecated")
210213
issue_ids = get_and_check(test_case, "ids", default=[])
@@ -214,33 +217,79 @@ def process_and_run_test_cases(data: Dict[str, Dict]):
214217
continue
215218

216219
compile_options = get_and_check(test_case, "compile_options", nullable=True)
220+
217221
for issue_id in issue_ids:
222+
if issue_id not in issue_ids_should_test:
223+
json_only_ids.add(issue_id)
224+
continue
225+
226+
# cross out the this issue_id in the should test set
227+
issue_ids_should_test.remove(issue_id)
228+
218229
only_compile = False
230+
219231
# if this issue needs to test wamrc to compile the test case first
220232
if compile_options:
221233
only_compile = compile_options["only compile"]
222-
run_issue_test_wamrc(passed_ids, failed_ids, issue_id, compile_options)
234+
compile_res = run_issue_test_wamrc(issue_id, compile_options)
235+
if only_compile:
236+
if compile_res:
237+
passed_ids.add(issue_id)
238+
else:
239+
failed_ids.add(issue_id)
240+
continue
241+
else:
242+
# if compile success, then continue to test iwasm
243+
if not compile_res:
244+
failed_ids.add(issue_id)
245+
continue
223246

224247
# if this issue requires to test iwasm to run the test case
225248
if not only_compile:
226-
run_issue_test_iwasm(passed_ids, failed_ids, issue_id, test_case)
227-
228-
# cross out the this issue_id in the should test set
229-
issue_ids_should_test.remove(issue_id)
249+
if run_issue_test_iwasm(issue_id, test_case):
250+
passed_ids.add(issue_id)
251+
else:
252+
failed_ids.add(issue_id)
230253

231254
total = len(passed_ids) + len(failed_ids)
232255
passed = len(passed_ids)
233256
failed = len(failed_ids)
234-
issue_ids_should_test = (
235-
issue_ids_should_test if issue_ids_should_test else "no more"
257+
258+
format_issue_ids_should_test = (
259+
" ".join(f"#{x}" for x in issue_ids_should_test)
260+
if issue_ids_should_test
261+
else "no more"
262+
)
263+
format_json_only_ids = (
264+
" ".join(f"#{x}" for x in json_only_ids) if json_only_ids else "no more"
236265
)
266+
267+
print(f"####################################")
237268
print(f"==== Test results ====")
238-
print(f" Total: {total}")
269+
print(f" Total: {total}")
239270
print(f" Passed: {passed}")
240271
print(f" Failed: {failed}")
272+
if not selected_ids:
273+
print(f" Left issues in folder: {format_issue_ids_should_test}")
274+
print(f" Cases in JSON but not found in folder: {format_json_only_ids}")
275+
else:
276+
print(f" Issues not found in folder: {format_issue_ids_should_test}")
241277

242278

243279
def main():
280+
parser = argparse.ArgumentParser(description="Run BA issue tests.")
281+
parser.add_argument(
282+
"-i",
283+
"--issues",
284+
type=str,
285+
help="Comma separated list of issue ids to run, e.g. 1,2,3. Default: all.",
286+
)
287+
args = parser.parse_args()
288+
289+
selected_ids = None
290+
if args.issues:
291+
selected_ids = [int(x) for x in args.issues.split(",") if x.strip().isdigit()]
292+
244293
# Path to the JSON file
245294
file_path = "running_config.json"
246295

@@ -256,7 +305,7 @@ def main():
256305
os.remove(LOG_FILE)
257306

258307
# Process the data
259-
process_and_run_test_cases(data)
308+
process_and_run_test_cases(data, selected_ids)
260309

261310

262311
if __name__ == "__main__":

0 commit comments

Comments
 (0)