Skip to content

Commit be51048

Browse files
committed
[Backend Tester] Add subtest index field
ghstack-source-id: e22a46b ghstack-comment-id: 3177697272 Pull-Request: #13311
1 parent 5b434a2 commit be51048

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
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/flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22

3-
from dataclasses import dataclass, field
3+
from dataclasses import dataclass
44
from typing import Callable
55

66
from executorch.backends.test.harness import Tester

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,

0 commit comments

Comments
 (0)