Skip to content

Commit 98e4dd5

Browse files
Fix runnning arm unittests on FVP (#7178)
- Adds _test_options to pytest namespace which has a proper global scope - Removes test option enum which is not compatible with new approach - Adds back expectFailureOnFVPs which passed due to not running on FVP
1 parent 63238ab commit 98e4dd5

File tree

5 files changed

+28
-59
lines changed

5 files changed

+28
-59
lines changed

backends/arm/test/conftest.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import shutil
1212
import subprocess
1313
import sys
14-
from enum import auto, Enum
1514
from typing import Any
1615

1716
import pytest
@@ -22,30 +21,24 @@
2221
"""
2322

2423

25-
class arm_test_options(Enum):
26-
quantize_io = auto()
27-
corstone_fvp = auto()
28-
fast_fvp = auto()
29-
30-
31-
_test_options: dict[arm_test_options, Any] = {}
32-
3324
# ==== Pytest hooks ====
3425

3526

3627
def pytest_configure(config):
28+
pytest._test_options = {}
29+
3730
if config.option.arm_quantize_io:
3831
_load_libquantized_ops_aot_lib()
39-
_test_options[arm_test_options.quantize_io] = True
32+
pytest._test_options["quantize_io"] = True
4033
if config.option.arm_run_corstoneFVP:
4134
corstone300_exists = shutil.which("FVP_Corstone_SSE-300_Ethos-U55")
4235
corstone320_exists = shutil.which("FVP_Corstone_SSE-320")
4336
if not (corstone300_exists and corstone320_exists):
4437
raise RuntimeError(
4538
"Tests are run with --arm_run_corstoneFVP but corstone FVP is not installed."
4639
)
47-
_test_options[arm_test_options.corstone_fvp] = True
48-
_test_options[arm_test_options.fast_fvp] = config.option.fast_fvp
40+
pytest._test_options["corstone_fvp"] = True
41+
pytest._test_options["fast_fvp"] = config.option.fast_fvp
4942
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
5043

5144

@@ -131,9 +124,7 @@ def expectedFailureOnFVP(test_item):
131124
# ==== End of Custom Pytest decorators =====
132125

133126

134-
def is_option_enabled(
135-
option: str | arm_test_options, fail_if_not_enabled: bool = False
136-
) -> bool:
127+
def is_option_enabled(option: str, fail_if_not_enabled: bool = False) -> bool:
137128
"""
138129
Returns whether an option is successfully enabled, i.e. if the flag was
139130
given to pytest and the necessary requirements are available.
@@ -144,10 +135,8 @@ def is_option_enabled(
144135
The optional parameter 'fail_if_not_enabled' makes the function raise
145136
a RuntimeError instead of returning False.
146137
"""
147-
if isinstance(option, str):
148-
option = arm_test_options[option.lower()]
149138

150-
if option in _test_options and _test_options[option]:
139+
if option in pytest._test_options and pytest._test_options[option]:
151140
return True
152141
else:
153142
if fail_if_not_enabled:
@@ -156,15 +145,15 @@ def is_option_enabled(
156145
return False
157146

158147

159-
def get_option(option: arm_test_options) -> Any | None:
148+
def get_option(option: str) -> Any | None:
160149
"""
161150
Returns the value of an pytest option if it is set, otherwise None.
162151
163152
Args:
164-
option (arm_test_options): The option to check for.
153+
option (str): The option to check for.
165154
"""
166-
if option in _test_options:
167-
return _test_options[option]
155+
if option in pytest._test_options:
156+
return pytest._test_options[option]
168157
return None
169158

170159

backends/arm/test/ops/test_depthwise_conv.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,11 @@
156156
("two_dw_conv2d", two_dw_conv2d),
157157
]
158158

159-
testsuite_conv2d_u85 = [
159+
testsuite_conv2d_u85_xfails = [
160160
("2x2_1x6x4x4_gp6_st1", dw_conv2d_2x2_1x6x4x4_gp6_st1),
161161
("3x3_1x3x256x256_gp3_st1", dw_conv2d_3x3_1x3x256x256_gp3_st1),
162162
("3x3_1x4x256x256_gp4_st1", dw_conv2d_3x3_1x4x256x256_gp4_st1),
163163
("3x3_1x4x256x256_gp4_nobias", dw_conv2d_3x3_1x4x256x256_gp4_nobias),
164-
]
165-
166-
testsuite_conv2d_u85_xfails = [
167164
("3x3_2x8x198x198_gp8_st3", dw_conv2d_3x3_2x8x198x198_gp8_st3),
168165
("two_dw_conv2d", two_dw_conv2d),
169166
]
@@ -287,7 +284,7 @@ def test_dw_conv1d_u55_BI(
287284
model.get_inputs(),
288285
)
289286

290-
@parameterized.expand(testsuite_conv1d + testsuite_conv2d_u85)
287+
@parameterized.expand(testsuite_conv1d[2:])
291288
def test_dw_conv_u85_BI(
292289
self, test_name: str, model: torch.nn.Module, set_quantize_io: bool = False
293290
):
@@ -299,8 +296,12 @@ def test_dw_conv_u85_BI(
299296
model.get_inputs(),
300297
)
301298

299+
testsuite_conv2d_u85_xfails.remove(
300+
("3x3_1x3x256x256_gp3_st1", dw_conv2d_3x3_1x3x256x256_gp3_st1)
301+
) # Works
302+
302303
# All test cases except 3x3_1x3x256x256_gp3_st1 have numerical issues on FVP. MLETORCH-520
303-
@parameterized.expand(testsuite_conv2d_u85_xfails)
304+
@parameterized.expand(testsuite_conv2d_u85_xfails + testsuite_conv1d[:2])
304305
@conftest.expectedFailureOnFVP
305306
def test_dw_conv_u85_BI_xfails(
306307
self, test_name: str, model: torch.nn.Module, set_quantize_io: bool = False

backends/arm/test/ops/test_div.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -183,21 +183,8 @@ def test_div_tosa_BI(
183183
test_data = (input_, other_)
184184
self._test_div_tosa_BI_pipeline(self.Div(), test_data)
185185

186-
@parameterized.expand(test_data_suite[:2])
187-
def test_div_u55_BI(
188-
self,
189-
test_name: str,
190-
input_: Union[torch.Tensor, torch.types.Number],
191-
other_: Union[torch.Tensor, torch.types.Number],
192-
rounding_mode: Optional[str] = None,
193-
):
194-
test_data = (input_, other_)
195-
self._test_div_ethos_BI_pipeline(
196-
self.Div(), common.get_u55_compile_spec(), test_data
197-
)
198-
199186
# Numerical issues on FVP likely due to mul op, MLETORCH-521
200-
@parameterized.expand(test_data_suite[2:])
187+
@parameterized.expand(test_data_suite)
201188
@conftest.expectedFailureOnFVP
202189
def test_div_u55_BI_xfails(
203190
self,
@@ -211,21 +198,8 @@ def test_div_u55_BI_xfails(
211198
self.Div(), common.get_u55_compile_spec(), test_data
212199
)
213200

214-
@parameterized.expand(test_data_suite[:2])
215-
def test_div_u85_BI(
216-
self,
217-
test_name: str,
218-
input_: Union[torch.Tensor, torch.types.Number],
219-
other_: Union[torch.Tensor, torch.types.Number],
220-
rounding_mode: Optional[str] = None,
221-
):
222-
test_data = (input_, other_)
223-
self._test_div_ethos_BI_pipeline(
224-
self.Div(), common.get_u85_compile_spec(), test_data
225-
)
226-
227201
# Numerical issues on FVP likely due to mul op, MLETORCH-521
228-
@parameterized.expand(test_data_suite[2:])
202+
@parameterized.expand(test_data_suite)
229203
@conftest.expectedFailureOnFVP
230204
def test_div_u85_BI_xfails(
231205
self,

backends/arm/test/ops/test_mul.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ def test_mul_tosa_BI(
152152
test_data = (input_, other_)
153153
self._test_mul_tosa_BI_pipeline(self.Mul(), test_data)
154154

155+
# Numerical issues on FVP, MLETORCH-521
155156
@parameterized.expand(test_data_sute)
157+
@conftest.expectedFailureOnFVP
156158
def test_mul_u55_BI(
157159
self,
158160
test_name: str,
@@ -164,7 +166,10 @@ def test_mul_u55_BI(
164166
common.get_u55_compile_spec(), self.Mul(), test_data
165167
)
166168

167-
@parameterized.expand(test_data_sute)
169+
# Numerical issues on FVP, MLETORCH-521
170+
# test_data_sute[0] works on U85
171+
@parameterized.expand(test_data_sute[1:])
172+
@conftest.expectedFailureOnFVP
168173
def test_mul_u85_BI(
169174
self,
170175
test_name: str,

backends/arm/test/runner_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import numpy as np
1818
import torch
1919

20-
from executorch.backends.arm.test.conftest import arm_test_options, is_option_enabled
20+
from executorch.backends.arm.test.conftest import is_option_enabled
2121

2222
from torch.export import ExportedProgram
2323
from torch.fx.node import Node
@@ -251,7 +251,7 @@ def run_corstone(
251251
cmd_line += f" -i {input_path}"
252252

253253
ethos_u_extra_args = ""
254-
if is_option_enabled(arm_test_options.fast_fvp):
254+
if is_option_enabled("fast_fvp"):
255255
ethos_u_extra_args = ethos_u_extra_args + "--fast"
256256

257257
command_args = {

0 commit comments

Comments
 (0)