ONE - On-device Neural Engine
Loading...
Searching...
No Matches
conftest.py
Go to the documentation of this file.
1import re
2
3
4def extract_test_args(s):
5 p = re.compile('eval\\((.*)\\)')
6 result = p.search(s)
7 return result.group(1)
8
9
10def pytest_addoption(parser):
11 parser.addoption("--test_list", action="store", help="Path to test list")
12 parser.addoption("--artifacts", action="store", help="Path to test artifacts")
13 parser.addoption("--target_artifacts",
14 action="store",
15 help="Path to test target artifacts")
16 parser.addoption("--luci_eval_driver",
17 action="store",
18 help="Path to luci eval driver")
19
20
21def pytest_generate_tests(metafunc):
22 list_path = metafunc.config.getoption('test_list')
23 artifacts_path = metafunc.config.getoption('artifacts')
24 target_artifacts_path = metafunc.config.getoption('target_artifacts')
25 eval_driver_path = metafunc.config.getoption('luci_eval_driver')
26 if list_path is None:
27 tests_default_tol = []
28 tests_with_tol = []
29 ref_tests_default_tol = []
30 ref_tests_with_tol = []
31 else:
32 with open(list_path) as f:
33 contents = [line.rstrip() for line in f]
34
35 comment_removed = [line for line in contents if not line.startswith('#')]
36 newline_removed = [line for line in comment_removed if line.startswith('eval(')]
37 test_args = [extract_test_args(line) for line in newline_removed]
38 # eval(TEST_NAME)
39 tests_default_tol = [(arg, artifacts_path, eval_driver_path) for arg in test_args
40 if len(arg.split()) == 1]
41 # eval(TEST_NAME RTOL ATOL)
42 tests_with_tol = [(arg.split()[0], artifacts_path, eval_driver_path,
43 arg.split()[1], arg.split()[2]) for arg in test_args
44 if len(arg.split()) == 3]
45
46 if 'default_test_name' in metafunc.fixturenames:
47 metafunc.parametrize('default_test_name,artifacts_path,eval_driver_path',
48 tests_default_tol)
49
50 if 'tol_test_name' in metafunc.fixturenames:
51 metafunc.parametrize(
52 'tol_test_name,artifacts_path,eval_driver_path,rtolf32,atolf32',
53 tests_with_tol)
54
55 if target_artifacts_path is not None:
56 # eval(TEST_NAME)
57 ref_tests_default_tol = [(arg, artifacts_path, target_artifacts_path,
58 eval_driver_path) for arg in test_args
59 if len(arg.split()) == 1]
60 # eval(TEST_NAME RTOL ATOL)
61 ref_tests_with_tol = [(arg.split()[0], artifacts_path, target_artifacts_path,
62 eval_driver_path, arg.split()[1], arg.split()[2])
63 for arg in test_args if len(arg.split()) == 3]
64 #
65 # for cross platform test
66 #
67 if 'default_ref_test_name' in metafunc.fixturenames:
68 metafunc.parametrize(
69 'default_ref_test_name,ref_artifacts_path,target_artifacts_path,eval_driver_path',
70 ref_tests_default_tol)
71
72 if 'tol_ref_test_name' in metafunc.fixturenames:
73 metafunc.parametrize(
74 'tol_ref_test_name,ref_artifacts_path,target_artifacts_path,eval_driver_path,rtolf32,atolf32',
75 ref_tests_with_tol)