forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_runner.py
More file actions
76 lines (63 loc) · 2.33 KB
/
test_runner.py
File metadata and controls
76 lines (63 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import argparse
import unittest
import nncf.torch # type: ignore[import-untyped,import-not-found]
class OpenvinoTestSuite(unittest.TestSuite):
test_params: dict[str, str] = {}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def addTest(self, test):
# Set test parameters if this is an instance of TestOpenvino
from executorch.backends.openvino.tests.ops.base_openvino_op_test import (
BaseOpenvinoOpTest,
)
if isinstance(test, BaseOpenvinoOpTest):
if "device" in self.test_params:
test.device = self.test_params["device"]
# Call the original addTest method to actually add the test to the suite
super().addTest(test)
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument(
"-s",
"--device",
help="OpenVINO device to execute the model on",
type=str,
default="CPU",
)
parser.add_argument(
"-p",
"--pattern",
help="Pattern to match test files. Provide complete file name to run individual tests",
type=str,
default="test_*.py",
)
parser.add_argument(
"-t",
"--test_type",
help="Specify the type of tests ('ops' or 'models')",
type=str,
default="ops",
choices={"ops", "models"},
)
args, ns_args = parser.parse_known_args(namespace=unittest)
test_params: dict[str, str] = {}
test_params["device"] = args.device
test_params["pattern"] = args.pattern
test_params["test_type"] = args.test_type
return test_params
if __name__ == "__main__":
loader = unittest.TestLoader()
# Replace the default test suite with a custom test suite to be able to
# pass test parameter to the test cases
loader.suiteClass = OpenvinoTestSuite
test_params = parse_arguments()
loader.suiteClass.test_params = test_params
# Discover all existing op tests in "ops" folder
suite = loader.discover(test_params["test_type"], pattern=test_params["pattern"])
# Start running tests
with nncf.torch.disable_patching():
result = unittest.TextTestRunner().run(suite)
if result.wasSuccessful():
print("OpenVINO backend tests completed successfully")
else:
print("OpenVINO backend tests completed with failures")