Skip to content

Commit

Permalink
[CI] UT results summary enhancement (#1356)
Browse files Browse the repository at this point in the history
  • Loading branch information
RUIJIEZHONG66166 authored Feb 19, 2025
1 parent e4ce4df commit 354725e
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 9 deletions.
115 changes: 115 additions & 0 deletions .github/scripts/check-ut.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import argparse
import sys
import os
from junitparser import JUnitXml, Error, Failure, Skipped

parser = argparse.ArgumentParser()
parser.add_argument('junitxml', nargs='+')
args = parser.parse_args()

failures = []
suites = []

def get_classname(case):
return ' '.join(case.classname.split())

def get_name(case):
return ' '.join(case.name.split())

def get_result(case):
result = "passed"
if case.result:
if isinstance(case.result[0], Error):
result = "error"
elif isinstance(case.result[0], Skipped):
result = "skipped"
elif isinstance(case.result[0], Failure):
result = "failed"
return result

def get_message(case):
if not case.result:
return ""
return f"{case.result[0].message.splitlines()[0]}"

def print_md_row(row, print_header):
if print_header:
header = " | ".join([f"{key}" for key, _ in row.items()])
print(f"| {header} |")
header = " | ".join(["-"*len(key) for key, _ in row.items()])
print(f"| {header} |")
row = " | ".join([f"{value}" for _, value in row.items()])
print(f"| {row} |")

def print_cases(cases):
print_header = True
for case in cases:
classname = get_classname(case)
name = get_name(case)
result = get_result(case)
message = get_message(case)
row = {
'Class name': classname,
'Test name': name,
'Status': result,
'Message': message,
}
print_md_row(row, print_header)
print_header = False

def print_suite(suite):
print_header = True
for suite in suites:
ut = args.junitxml[0]
del(args.junitxml[0])
ut = os.path.basename(ut).split('.')[0]
tests = suite.tests
skipped = suite.skipped
failures = suite.failures
errors = suite.errors
if ut == 'op_regression':
category = 'op_regression'
elif ut == 'op_regression_dev1':
category = 'op_regression_dev1'
elif ut == 'op_extended':
category = 'op_extended'
elif 'op_ut' in ut:
category = 'op_ut'
row = {
'Category': category,
'UT': ut,
'Test cases': tests,
'Passed': tests-skipped-failures-errors,
'Skipped': skipped,
'Failures': failures,
'Errors': errors,
}
print_md_row(row, print_header)
print_header = False

xmls = [ JUnitXml.fromfile(f) for f in args.junitxml ]
for idx, xml in enumerate(xmls):
for suite in xml:
suites.append(suite)
for case in suite:
classname = get_classname(case)
name = get_name(case)
result = get_result(case)
if result not in ["passed", "skipped"]:
failures.append(case)

printed = False
def print_break(needed):
if needed:
print("")

if failures:
print_break(printed)
print("### Failures")
print_cases(failures)
printed = True

print("### Results Summary")
print_suite(suites)

sys.exit(0)
12 changes: 10 additions & 2 deletions .github/workflows/_linux_ut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
cd ${{ github.workspace }}
cd test/regressions
pip install pytest
timeout 8000 pytest -v 2>${{ github.workspace }}/ut_log/op_regression/op_regression_test_error.log | tee ${{ github.workspace }}/ut_log/op_regression/op_regression_test.log
timeout 8000 pytest -v --junit-xml=${{ github.workspace }}/ut_log/op_regression.xml 2>${{ github.workspace }}/ut_log/op_regression/op_regression_test_error.log | tee ${{ github.workspace }}/ut_log/op_regression/op_regression_test.log
- name: Run XPU OP Regressions test on device 1
if: contains(inputs.ut, 'op_regression_dev1') || github.event_name == 'schedule'
run: |
Expand All @@ -169,7 +169,7 @@ jobs:
cd ${{ github.workspace }}
cd test/regressions
pip install pytest
timeout 8000 pytest -v test_operation_on_device_1.py 2>${{ github.workspace }}/ut_log/op_regression_dev1/op_regression_dev1_test_error.log | tee ${{ github.workspace }}/ut_log/op_regression_dev1/op_regression_dev1_test.log
timeout 8000 pytest -v --junit-xml=${{ github.workspace }}/ut_log/op_regression_dev1.xml test_operation_on_device_1.py 2>${{ github.workspace }}/ut_log/op_regression_dev1/op_regression_dev1_test_error.log | tee ${{ github.workspace }}/ut_log/op_regression_dev1/op_regression_dev1_test.log
export ZE_AFFINITY_MASK=${ZE_AFFINITY_MASK_OLD}
- name: Run XPU OP Extended UT
if: contains(inputs.ut, 'op_extended') || github.event_name == 'schedule'
Expand All @@ -181,6 +181,7 @@ jobs:
mkdir -p ut_log/op_extended
cd ../pytorch/third_party/torch-xpu-ops/test/xpu/extended/
timeout 10000 python run_test_with_skip.py 2>${{ github.workspace }}/ut_log/op_extended/op_extended_test_error.log | tee ${{ github.workspace }}/ut_log/op_extended/op_extended_test.log
cp op_extended.xml ${{ github.workspace }}/ut_log
- name: Run XPU OP UT
if: contains(inputs.ut, 'op_ut') || github.event_name == 'schedule'
run: |
Expand All @@ -192,11 +193,13 @@ jobs:
mkdir -p ut_log/op_ut
cd ../pytorch/third_party/torch-xpu-ops/test/xpu
timeout 10000 python run_test_with_skip.py 2>${{ github.workspace }}/ut_log/op_ut/op_ut_with_skip_test_error.log | tee ${{ github.workspace }}/ut_log/op_ut/op_ut_with_skip_test.log
cp *.xml ${{ github.workspace }}/ut_log
# Cases run with a on-demand white list, since some suites are too
# slow to go through all operators on CPU. So add cases on-demand
# when XPU implementatoin is done.
# test_foreach, test_decomp
timeout 10000 python run_test_with_only.py 2>${{ github.workspace }}/ut_log/op_ut/op_ut_with_only_test_error.log | tee ${{ github.workspace }}/ut_log/op_ut/op_ut_with_only_test.log
cp op_ut_with_only.xml ${{ github.workspace }}/ut_log
- name: Run Torch XPU UT
if: contains(inputs.ut, 'torch_xpu') || github.event_name == 'schedule'
run: |
Expand Down Expand Up @@ -249,6 +252,11 @@ jobs:
timeout 10000 python run_distributed.py 2>${{ github.workspace }}/ut_log/xpu_distributed/xpu_distributed_test_error.log | tee ${{ github.workspace }}/ut_log/xpu_distributed/xpu_distributed_test.log
cd ${{ github.workspace }}
sudo cp ptrace_scope.bk /proc/sys/kernel/yama/ptrace_scope
- name: UT Test Results Summary
run: |
source activate xpu_op_${ZE_AFFINITY_MASK}
pip install junitparser
python .github/scripts/check-ut.py ${{ github.workspace }}/ut_log/*.xml >> $GITHUB_STEP_SUMMARY || true
- name: UT Test Results Check
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion test/xpu/extended/run_test_with_skip.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
skip_options += '"'

os.environ["PYTORCH_TEST_WITH_SLOW"] = "1"
test_command = "pytest -v test_ops_xpu.py"
test_command = "pytest -v --junit-xml=./op_extended.xml test_ops_xpu.py"
test_command += skip_options
res = os.system(test_command)
sys.exit(res)
16 changes: 13 additions & 3 deletions test/xpu/run_test_with_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,28 @@ def launch_test(test_case, skip_list=None, exe_list=None):
skip_option = " and not " + skip_case
skip_options += skip_option
skip_options += '"'
test_command = "pytest -v " + test_case + skip_options
test_command = (
"pytest -v "
+ "--junit-xml=./op_ut_with_only.xml "
+ test_case
+ skip_options
)
return os.system(test_command)
elif exe_list is not None:
exe_options = ' -k "' + exe_list[0]
for exe_case in exe_list[1:]:
exe_option = " or " + exe_case
exe_options += exe_option
exe_options += '"'
test_command = "pytest -v " + test_case + exe_options
test_command = (
"pytest -v "
+ "--junit-xml=./op_ut_with_only.xml "
+ test_case
+ exe_options
)
return os.system(test_command)
else:
test_command = "pytest -v " + test_case
test_command = "pytest -v --junit-xml=./op_ut_with_only.xml " + test_case
return os.system(test_command)


Expand Down
12 changes: 9 additions & 3 deletions test/xpu/xpu_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,16 +1154,22 @@ def launch_test(test_case, skip_list=None, exe_list=None):
skip_option = " and not " + skip_case
skip_options += skip_option
skip_options += '"'
test_command = "pytest -v " + test_case
test_command = (
f"pytest -v --junit-xml=./op_ut_with_skip_{test_case}.xml " + test_case
)
test_command += skip_options
elif exe_list is not None:
exe_options = ' -k "' + exe_list[0]
for exe_case in exe_list[1:]:
exe_option = " or " + exe_case
exe_options += exe_option
exe_options += '"'
test_command = "pytest -v " + test_case
test_command = (
f"pytest -v --junit-xml=./op_ut_with_skip_{test_case}.xml " + test_case
)
test_command += exe_options
else:
test_command = "pytest -v " + test_case
test_command = (
f"pytest -v --junit-xml=./op_ut_with_skip_{test_case}.xml " + test_case
)
return os.system(test_command)

0 comments on commit 354725e

Please sign in to comment.