7
7
import statistics
8
8
import subprocess
9
9
import sys
10
- from typing import TextIO , Callable
10
+ from typing import TextIO , Callable , Any
11
11
12
12
from e3 .fs import mkdir , rm
13
13
from e3 .testsuite import Testsuite , logger , TestsuiteCore
20
20
benchmarks_driver , refactor_driver
21
21
)
22
22
23
- class PerfTestFinder (YAMLTestFinder ):
23
+
24
+ class StandardTestFinder (YAMLTestFinder ):
24
25
"""
25
- Testcase finder to use in perf mode.
26
+ Testcase finder to use in stadard mode.
26
27
27
- This finder automatically discard tests that do not have performance
28
- measuring instructions. This is preferable to creating these tests but
29
- skipping them (SKIP status) as most tests do not support performance
30
- measurements: less noise in the testsuite report.
28
+ This finder exclude test cases from the 'tests/perf/' directory to avoid
29
+ running them in standard mode. This allow performance exclusive test
30
+ cases.
31
+ This finder doesn't exclude all performance compatible tests because
32
+ we want to be able to write baseline/performance hybrid tests.
31
33
"""
32
34
35
+ def __init__ (
36
+ self ,
37
+ env_constraints : dict [str , Callable [[Any ], bool ]] | None = None
38
+ ):
39
+ """
40
+ Create a new standard test finder, with a given list of constraints to
41
+ check on the test environment.
42
+ """
43
+ super ().__init__ ()
44
+ self .env_constraints = env_constraints
45
+
46
+ def verify_then_return (self , test : TestFinderResult ) -> TestFinderResult | None :
47
+ """
48
+ Check that the provided test environment is validating all constraints
49
+ attached to this test finder.
50
+ """
51
+ if self .env_constraints :
52
+ for field , predicate in self .env_constraints .items ():
53
+ if not predicate (test .test_env .get (field , None )):
54
+ return None
55
+ return test
56
+
33
57
def probe (self ,
34
58
testsuite : TestsuiteCore ,
35
59
dirpath : str ,
36
60
dirnames : list [str ],
37
- filenames : list [str ]) -> TestFinderResult :
61
+ filenames : list [str ]) -> TestFinderResult | None :
38
62
# Probe testcases as usual
39
63
result = super ().probe (testsuite , dirpath , dirnames , filenames )
40
64
41
- # Reject testcases which do not contain performance measuring
42
- # instructions.
43
- if result is None or P .join ("tests" , "perf" ) not in result .test_dir :
65
+ # Reject all tests which have 'tests/perf' in their directory name
66
+ if result is None or P .join ("tests" , "perf" ) in result .test_dir :
44
67
return None
45
68
46
- # Make sure that the driver supports performance measuring
47
- if not result .driver_cls .perf_supported :
48
- raise ProbingError (
49
- f"The '{ result .driver_cls .__name__ } ' driver does not support"
50
- " performance measuring"
51
- )
69
+ return self .verify_then_return (result )
52
70
53
- return result
54
71
55
-
56
- class StandardTestFinder (YAMLTestFinder ):
72
+ class PerfTestFinder (StandardTestFinder ):
57
73
"""
58
- Testcase finder to use in stadard mode.
74
+ Testcase finder to use in perf mode.
59
75
60
- This finder exclude test cases from the 'tests/perf/' directory to avoid
61
- running them in standard mode. This allow performance exclusive test
62
- cases.
63
- This finder doesn't exclude all performance compatible tests because
64
- we want to be able to write baseline/performance hybrid tests.
76
+ This finder automatically discard tests that do not have performance
77
+ measuring instructions. This is preferable to creating these tests but
78
+ skipping them (SKIP status) as most tests do not support performance
79
+ measurements: less noise in the testsuite report.
65
80
"""
66
81
67
82
def probe (self ,
@@ -72,11 +87,19 @@ def probe(self,
72
87
# Probe testcases as usual
73
88
result = super ().probe (testsuite , dirpath , dirnames , filenames )
74
89
75
- # Reject all tests which have 'tests/perf' in their directory name
76
- if result is None or P .join ("tests" , "perf" ) in result .test_dir :
90
+ # Reject testcases which do not contain performance measuring
91
+ # instructions.
92
+ if result is None or P .join ("tests" , "perf" ) not in result .test_dir :
77
93
return None
78
94
79
- return result
95
+ # Make sure that the driver supports performance measuring
96
+ if not result .driver_cls .perf_supported :
97
+ raise ProbingError (
98
+ f"The '{ result .driver_cls .__name__ } ' driver does not support"
99
+ " performance measuring"
100
+ )
101
+
102
+ return self .verify_then_return (result )
80
103
81
104
82
105
class LKQLTestsuite (Testsuite ):
@@ -137,12 +160,24 @@ def add_options(self, parser: ArgumentParser) -> None:
137
160
' to get feedback quickly during development.'
138
161
)
139
162
163
+ parser .add_argument (
164
+ '--only-with-auto-fix' ,
165
+ action = 'store_true' ,
166
+ help = 'Run only tests that uses the LKQL rewriting API through'
167
+ ' checkers auto-fixing function.'
168
+ )
169
+
140
170
@property
141
171
def test_finders (self ) -> list [TestFinder ]:
172
+ # Create the test environment constraint list
173
+ env_constraints = dict ()
174
+ if self .env .options .only_with_auto_fix :
175
+ env_constraints ["auto_fix" ] = lambda v : v == True
176
+
142
177
return [
143
- PerfTestFinder ()
178
+ PerfTestFinder (env_constraints )
144
179
if self .env .perf_mode else
145
- StandardTestFinder ()
180
+ StandardTestFinder (env_constraints )
146
181
]
147
182
148
183
def set_up (self ) -> None :
0 commit comments