Skip to content

Commit 17da29a

Browse files
committed
[Backend Tester] Add subtest index field
ghstack-source-id: 94683fc ghstack-comment-id: 3177697272 Pull-Request: #13311
1 parent d8aac36 commit 17da29a

File tree

6 files changed

+19
-0
lines changed

6 files changed

+19
-0
lines changed

backends/test/suite/context.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# Test run context management. This is used to determine the test context for reporting
22
# purposes.
33
class TestContext:
4+
subtest_index: int
5+
46
def __init__(
57
self, test_name: str, test_base_name: str, flow_name: str, params: dict | None
68
):
79
self.test_name = test_name
810
self.test_base_name = test_base_name
911
self.flow_name = flow_name
1012
self.params = params
13+
self.subtest_index = 0
1114

1215
def __enter__(self):
1316
global _active_test_context

backends/test/suite/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def run_model_test(
119119
flow,
120120
context.test_name,
121121
context.test_base_name,
122+
0, # subtest_index - currently unused for model tests
122123
context.params,
123124
dynamic_shapes=dynamic_shapes,
124125
)

backends/test/suite/operators/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,16 @@ def _test_op(
152152
flow,
153153
context.test_name,
154154
context.test_base_name,
155+
context.subtest_index,
155156
context.params,
156157
generate_random_test_inputs=generate_random_test_inputs,
157158
)
158159

159160
log_test_summary(run_summary)
160161

162+
# This is reset when a new test is started - it creates the context per-test.
163+
context.subtest_index = context.subtest_index + 1
164+
161165
if not run_summary.result.is_success():
162166
if run_summary.result.is_backend_failure():
163167
raise RuntimeError("Test failure.") from run_summary.error

backends/test/suite/reporting.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
CSV_FIELD_NAMES = [
2222
"Test ID",
2323
"Test Case",
24+
"Subtest",
2425
"Flow",
2526
"Params",
2627
"Result",
@@ -163,6 +164,9 @@ class TestCaseSummary:
163164
name: str
164165
""" The full name of test, including flow and parameter suffixes. """
165166

167+
subtest_index: int
168+
""" The subtest number. If a test case runs multiple tests, this field can be used to disambiguate. """
169+
166170
params: dict | None
167171
""" Test-specific parameters, such as dtype. """
168172

@@ -356,6 +360,7 @@ def write_csv_row(record: TestCaseSummary, output: TextIO):
356360
row = {
357361
"Test ID": record.name,
358362
"Test Case": record.base_name,
363+
"Subtest": record.subtest_index,
359364
"Flow": record.flow,
360365
"Params": _serialize_params(record.params),
361366
"Result": record.result.to_short_str(),

backends/test/suite/runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def run_test( # noqa: C901
4545
flow: TestFlow,
4646
test_name: str,
4747
test_base_name: str,
48+
subtest_index: int,
4849
params: dict | None,
4950
dynamic_shapes: Any | None = None,
5051
generate_random_test_inputs: bool = True,
@@ -64,6 +65,7 @@ def build_result(
6465
return TestCaseSummary(
6566
backend=flow.backend,
6667
base_name=test_base_name,
68+
subtest_index=subtest_index,
6769
flow=flow.name,
6870
name=test_name,
6971
params=params,

backends/test/suite/tests/test_reporting.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
base_name="test1",
2525
flow="flow1",
2626
name="test1_backend1_flow1",
27+
subtest_index=0,
2728
params=None,
2829
result=TestResult.SUCCESS,
2930
error=None,
@@ -34,6 +35,7 @@
3435
base_name="test1",
3536
flow="flow1",
3637
name="test1_backend2_flow1",
38+
subtest_index=0,
3739
params=None,
3840
result=TestResult.LOWER_FAIL,
3941
error=None,
@@ -44,6 +46,7 @@
4446
base_name="test2",
4547
flow="flow1",
4648
name="test2_backend1_flow1",
49+
subtest_index=0,
4750
params={"dtype": torch.float32},
4851
result=TestResult.SUCCESS_UNDELEGATED,
4952
error=None,
@@ -54,6 +57,7 @@
5457
base_name="test2",
5558
flow="flow1",
5659
name="test2_backend2_flow1",
60+
subtest_index=0,
5761
params={"use_dynamic_shapes": True},
5862
result=TestResult.SKIPPED,
5963
error=None,

0 commit comments

Comments
 (0)