1313from typing import Any
1414
1515import pytest
16- import torch
16+
17+ try :
18+ import tosa_reference_model
19+ except ImportError :
20+ logging .warning ("tosa_reference_model not found, can't run reference model tests" )
21+ tosa_reference_model = None
1722
1823"""
1924This file contains the pytest hooks, fixtures etc. for the Arm test suite.
2429
2530
2631def pytest_configure (config ):
27-
2832 pytest ._test_options = {} # type: ignore[attr-defined]
29-
30- if config .option .arm_run_corstoneFVP :
33+ pytest ._test_options ["corstone_fvp" ] = False # type: ignore[attr-defined]
34+ if (
35+ getattr (config .option , "arm_run_corestoneFVP" , False )
36+ and config .option .arm_run_corstoneFVP
37+ ):
3138 corstone300_exists = shutil .which ("FVP_Corstone_SSE-300_Ethos-U55" )
3239 corstone320_exists = shutil .which ("FVP_Corstone_SSE-320" )
3340 if not (corstone300_exists and corstone320_exists ):
3441 raise RuntimeError (
3542 "Tests are run with --arm_run_corstoneFVP but corstone FVP is not installed."
3643 )
44+ # Only enable if we also have the TOSA reference model available.
3745 pytest ._test_options ["corstone_fvp" ] = True # type: ignore[attr-defined]
38- pytest ._test_options ["fast_fvp" ] = config .option .fast_fvp # type: ignore[attr-defined]
46+
47+ pytest ._test_options ["fast_fvp" ] = False # type: ignore[attr-defined]
48+ if getattr (config .option , "fast_fvp" , False ):
49+ pytest ._test_options ["fast_fvp" ] = config .option .fast_fvp # type: ignore[attr-defined]
50+
51+ # TODO: remove this flag once we have a way to run the reference model tests with Buck
52+ pytest ._test_options ["tosa_ref_model" ] = False # type: ignore[attr-defined]
53+ if tosa_reference_model is not None :
54+ pytest ._test_options ["tosa_ref_model" ] = True # type: ignore[attr-defined]
3955 logging .basicConfig (level = logging .INFO , stream = sys .stdout )
4056
4157
@@ -44,9 +60,15 @@ def pytest_collection_modifyitems(config, items):
4460
4561
4662def pytest_addoption (parser ):
47- parser .addoption ("--arm_quantize_io" , action = "store_true" , help = "Deprecated." )
48- parser .addoption ("--arm_run_corstoneFVP" , action = "store_true" )
49- parser .addoption ("--fast_fvp" , action = "store_true" )
63+ def try_addoption (* args , ** kwargs ):
64+ try :
65+ parser .addoption (* args , ** kwargs )
66+ except Exception :
67+ pass
68+
69+ try_addoption ("--arm_quantize_io" , action = "store_true" , help = "Deprecated." )
70+ try_addoption ("--arm_run_corstoneFVP" , action = "store_true" , help = "Deprecated." )
71+ try_addoption ("--fast_fvp" , action = "store_true" )
5072
5173
5274def pytest_sessionstart (session ):
@@ -78,6 +100,8 @@ def set_random_seed():
78100 Rerun with a specific seed found under a random seed test
79101 ARM_TEST_SEED=3478246 pytest --config-file=/dev/null --verbose -s --color=yes backends/arm/test/ops/test_avg_pool.py -k <TESTCASE>
80102 """
103+ import torch
104+
81105 if os .environ .get ("ARM_TEST_SEED" , "RANDOM" ) == "RANDOM" :
82106 random .seed () # reset seed, in case any other test has fiddled with it
83107 seed = random .randint (0 , 2 ** 32 - 1 )
@@ -161,6 +185,8 @@ def _load_libquantized_ops_aot_lib():
161185 res = subprocess .run (find_lib_cmd , capture_output = True )
162186 if res .returncode == 0 :
163187 library_path = res .stdout .decode ().strip ()
188+ import torch
189+
164190 torch .ops .load_library (library_path )
165191 else :
166192 raise RuntimeError (
0 commit comments