Skip to content

Commit 1a0f455

Browse files
authored
Several issues fix of QA helper script (#1564)
Fixes SWDEV-475071: https://ontrack-internal.amd.com/browse/SWDEV-475071
1 parent f2ada4e commit 1a0f455

File tree

2 files changed

+50
-19
lines changed

2 files changed

+50
-19
lines changed

.automation_scripts/parse_xml_results.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,15 @@ def parse_xml_report(
108108
test_cases[ ( case["invoking_file"], case["classname"], case["name"], case["work_flow_name"] ) ] = case
109109
elif tag == 'testsuite':
110110
case["work_flow_name"] = work_flow_name
111-
case["invoking_file"] = report.parent.name
112111
case["invoking_xml"] = report.name
113112
case["running_time_xml"] = case["time"]
113+
case_name = report.parent.name
114+
for ind in range(len(BACKENDS_LIST)):
115+
if BACKENDS_LIST[ind] in report.parts:
116+
case_name = case_name + "_" + BACKENDS_LIST[ind]
117+
break
118+
case["invoking_file"] = case_name
119+
114120
test_cases[ ( case["invoking_file"], case["invoking_xml"], case["work_flow_name"] ) ] = case
115121

116122
return test_cases

.automation_scripts/run_pytorch_unit_tests.py

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def summarize_xml_files(path, workflow_name):
144144
res = {}
145145
res_item_list = [ "PASSED", "SKIPPED", "XFAILED", "FAILED", "ERROR" ]
146146
test_file_items = set()
147-
for (k,v) in list(test_cases.items()):
147+
for (k,v) in list(test_suites.items()):
148148
file_name = k[0]
149149
if not file_name in test_file_items:
150150
test_file_items.add(file_name)
@@ -154,13 +154,14 @@ def summarize_xml_files(path, workflow_name):
154154
res[temp_item] = {}
155155
temp_item_statistics = test_file_and_status(file_name, "STATISTICS")
156156
res[temp_item_statistics] = {'TOTAL': 0, 'PASSED': 0, 'SKIPPED': 0, 'XFAILED': 0, 'FAILED': 0, 'ERROR': 0, 'EXECUTION_TIME': 0}
157-
158-
for (k,v) in list(test_suites.items()):
159-
file_name = k[0]
160-
test_tuple_key_statistics = test_file_and_status(file_name, "STATISTICS")
161-
test_running_time = get_test_file_running_time(v)
162-
res[test_tuple_key_statistics]["EXECUTION_TIME"] += test_running_time
163-
TOTAL_EXECUTION_TIME += test_running_time
157+
test_running_time = get_test_file_running_time(v)
158+
res[temp_item_statistics]["EXECUTION_TIME"] += test_running_time
159+
TOTAL_EXECUTION_TIME += test_running_time
160+
else:
161+
test_tuple_key_statistics = test_file_and_status(file_name, "STATISTICS")
162+
test_running_time = get_test_file_running_time(v)
163+
res[test_tuple_key_statistics]["EXECUTION_TIME"] += test_running_time
164+
TOTAL_EXECUTION_TIME += test_running_time
164165

165166
for (k,v) in list(test_cases.items()):
166167
file_name = k[0]
@@ -326,13 +327,17 @@ def run_selected_tests(workflow_name, test_run_test_path, overall_logs_path_curr
326327

327328
return selected_results_dict
328329

329-
def run_test_and_summarize_results(
330-
pytorch_root_dir: str,
331-
priority_tests: bool,
332-
test_config: List[str],
333-
default_list: List[str],
334-
distributed_list: List[str],
335-
inductor_list: List[str]) -> Dict[str, Any]:
330+
def run_test_and_summarize_results() -> Dict[str, Any]:
331+
# parse args
332+
args = parse_args()
333+
pytorch_root_dir = str(args.pytorch_root)
334+
priority_tests = bool(args.priority_tests)
335+
test_config = list[str](args.test_config)
336+
default_list = list[str](args.default_list)
337+
distributed_list = list[str](args.distributed_list)
338+
inductor_list = list[str](args.inductor_list)
339+
skip_rerun = bool(args.skip_rerun)
340+
336341
# copy current environment variables
337342
_environ = dict(os.environ)
338343

@@ -341,13 +346,18 @@ def run_test_and_summarize_results(
341346
test_run_test_path = pytorch_root_dir + "/test/run_test.py"
342347
repo_test_log_folder_path = pytorch_root_dir + "/.automation_logs/"
343348
test_reports_src = pytorch_root_dir + "/test/test-reports/"
349+
run_test_python_file = pytorch_root_dir + "/test/run_test.py"
344350

345351
# change directory to pytorch root
346352
os.chdir(pytorch_root_dir)
347353

348354
# all test results dict
349355
res_all_tests_dict = {}
350356

357+
# patterns
358+
search_text = "--reruns=2"
359+
replace_text = "--reruns=0"
360+
351361
# create logs folder
352362
if not os.path.exists(repo_test_log_folder_path):
353363
os.mkdir(repo_test_log_folder_path)
@@ -358,6 +368,13 @@ def run_test_and_summarize_results(
358368
os.environ['HSA_FORCE_FINE_GRAIN_PCIE'] = '1'
359369
os.environ['PYTORCH_TESTING_DEVICE_ONLY_FOR'] = 'cuda'
360370
os.environ['CONTINUE_THROUGH_ERROR'] = 'True'
371+
if skip_rerun:
372+
# modify run_test.py in-place
373+
with open(run_test_python_file, 'r') as file:
374+
data = file.read()
375+
data = data.replace(search_text, replace_text)
376+
with open(run_test_python_file, 'w') as file:
377+
file.write(data)
361378

362379
# Time stamp
363380
current_datetime = datetime.now().strftime("%Y%m%d_%H-%M-%S")
@@ -455,6 +472,15 @@ def run_test_and_summarize_results(
455472
os.environ.clear()
456473
os.environ.update(_environ)
457474

475+
# restore files
476+
if skip_rerun:
477+
# modify run_test.py in-place
478+
with open(run_test_python_file, 'r') as file:
479+
data = file.read()
480+
data = data.replace(replace_text, search_text)
481+
with open(run_test_python_file, 'w') as file:
482+
file.write(data)
483+
458484
return res_all_tests_dict
459485

460486
def parse_args():
@@ -465,6 +491,7 @@ def parse_args():
465491
parser.add_argument('--distributed_list', nargs='+', default=[], help="space-separated list of 'distributed' config test suites/files to be executed eg. 'distributed/test_c10d_common distributed/test_c10d_nccl'")
466492
parser.add_argument('--inductor_list', nargs='+', default=[], help="space-separated list of 'inductor' config test suites/files to be executed eg. 'inductor/test_torchinductor test_ops'")
467493
parser.add_argument('--pytorch_root', default='.', type=str, help="PyTorch root directory")
494+
parser.add_argument('--skip_rerun', action='store_true', help="skip rerun process")
468495
parser.add_argument('--example_output', type=str, help="{'workflow_name': {\n"
469496
" test_file_and_status(file_name='workflow_aggregate', status='STATISTICS'): {}, \n"
470497
" test_file_and_status(file_name='test_file_name_1', status='ERROR'): {}, \n"
@@ -484,9 +511,7 @@ def check_num_gpus_for_distributed():
484511
assert num_gpus_visible > 1, "Number of visible GPUs should be >1 to run distributed unit tests"
485512

486513
def main():
487-
global args
488-
args = parse_args()
489-
all_tests_results = run_test_and_summarize_results(args.pytorch_root, args.priority_tests, args.test_config, args.default_list, args.distributed_list, args.inductor_list)
514+
all_tests_results = run_test_and_summarize_results()
490515
pprint(dict(all_tests_results))
491516

492517
if __name__ == "__main__":

0 commit comments

Comments
 (0)