@@ -69,14 +69,78 @@ class Filters:
69
69
MODULE = 'Module filter'
70
70
# in case of missing env. variable required for a platform
71
71
ENVIRONMENT = 'Environment filter'
72
-
73
-
74
72
class TestLevel :
75
73
name = None
76
74
levels = []
77
75
scenarios = []
76
+ class TestConfiguration :
77
+ tc_schema_path = os .path .join (
78
+ ZEPHYR_BASE ,
79
+ "scripts" ,
80
+ "schemas" ,
81
+ "twister" ,
82
+ "test-config-schema.yaml"
83
+ )
84
+
85
+ def __init__ (self , config_file ):
86
+ self .test_config = None
87
+ self .override_default_platforms = False
88
+ self .increased_platform_scope = True
89
+ self .default_platforms = []
90
+ self .parse (config_file )
91
+
92
+ def parse (self , config_file ):
93
+ if os .path .exists (config_file ):
94
+ tc_schema = scl .yaml_load (self .tc_schema_path )
95
+ self .test_config = scl .yaml_load_verify (config_file , tc_schema )
96
+ else :
97
+ raise TwisterRuntimeError (f"File { config_file } not found." )
98
+
99
+ platform_config = self .test_config .get ('platforms' , {})
100
+
101
+ self .override_default_platforms = platform_config .get ('override_default_platforms' , False )
102
+ self .increased_platform_scope = platform_config .get ('increased_platform_scope' , True )
103
+ self .default_platforms = platform_config .get ('default_platforms' , [])
104
+
105
+ self .options = self .test_config .get ('options' , {})
78
106
79
107
108
+ @staticmethod
109
+ def get_level (levels , name ):
110
+ level = next ((lvl for lvl in levels if lvl .name == name ), None )
111
+ return level
112
+
113
+ def get_levels (self , scenarios ):
114
+ levels = []
115
+ configured_levels = self .test_config .get ('levels' , [])
116
+
117
+ # Do first pass on levels to get initial data.
118
+ for level in configured_levels :
119
+ adds = []
120
+ for s in level .get ('adds' , []):
121
+ r = re .compile (s )
122
+ adds .extend (list (filter (r .fullmatch , scenarios )))
123
+
124
+ test_level = TestLevel ()
125
+ test_level .name = level ['name' ]
126
+ test_level .scenarios = adds
127
+ test_level .levels = level .get ('inherits' , [])
128
+ levels .append (test_level )
129
+
130
+ # Go over levels again to resolve inheritance.
131
+ for level in configured_levels :
132
+ inherit = level .get ('inherits' , [])
133
+ _level = self .get_level (levels , level ['name' ])
134
+ if inherit :
135
+ for inherted_level in inherit :
136
+ _inherited = self .get_level (levels , inherted_level )
137
+ assert _inherited , "Unknown inherited level {inherted_level}"
138
+ _inherited_scenarios = _inherited .scenarios
139
+ level_scenarios = _level .scenarios if _level else []
140
+ level_scenarios .extend (_inherited_scenarios )
141
+
142
+ return levels
143
+
80
144
class TestPlan :
81
145
__test__ = False # for pytest to skip this class when collects tests
82
146
config_re = re .compile ('(CONFIG_[A-Za-z0-9_]+)[=]\" ?([^\" ]*)\" ?$' )
@@ -89,14 +153,6 @@ class TestPlan:
89
153
os .path .join (ZEPHYR_BASE ,
90
154
"scripts" , "schemas" , "twister" , "quarantine-schema.yaml" ))
91
155
92
- tc_schema_path = os .path .join (
93
- ZEPHYR_BASE ,
94
- "scripts" ,
95
- "schemas" ,
96
- "twister" ,
97
- "test-config-schema.yaml"
98
- )
99
-
100
156
SAMPLE_FILENAME = 'sample.yaml'
101
157
TESTSUITE_FILENAME = 'testcase.yaml'
102
158
@@ -126,48 +182,10 @@ def __init__(self, env: Namespace):
126
182
127
183
self .run_individual_testsuite = []
128
184
self .levels = []
129
- self .test_config = {}
185
+ self .test_config = None
130
186
131
187
self .name = "unnamed"
132
188
133
- def get_level (self , name ):
134
- level = next ((lvl for lvl in self .levels if lvl .name == name ), None )
135
- return level
136
-
137
- def parse_configuration (self , config_file ):
138
- if os .path .exists (config_file ):
139
- tc_schema = scl .yaml_load (self .tc_schema_path )
140
- self .test_config = scl .yaml_load_verify (config_file , tc_schema )
141
- else :
142
- raise TwisterRuntimeError (f"File { config_file } not found." )
143
-
144
- levels = self .test_config .get ('levels' , [])
145
-
146
- # Do first pass on levels to get initial data.
147
- for level in levels :
148
- adds = []
149
- for s in level .get ('adds' , []):
150
- r = re .compile (s )
151
- adds .extend (list (filter (r .fullmatch , self .scenarios )))
152
-
153
- tl = TestLevel ()
154
- tl .name = level ['name' ]
155
- tl .scenarios = adds
156
- tl .levels = level .get ('inherits' , [])
157
- self .levels .append (tl )
158
-
159
- # Go over levels again to resolve inheritance.
160
- for level in levels :
161
- inherit = level .get ('inherits' , [])
162
- _level = self .get_level (level ['name' ])
163
- if inherit :
164
- for inherted_level in inherit :
165
- _inherited = self .get_level (inherted_level )
166
- assert _inherited , "Unknown inherited level {inherted_level}"
167
- _inherited_scenarios = _inherited .scenarios
168
- level_scenarios = _level .scenarios if _level else []
169
- level_scenarios .extend (_inherited_scenarios )
170
-
171
189
def find_subtests (self ):
172
190
sub_tests = self .options .sub_test
173
191
if sub_tests :
@@ -188,6 +206,8 @@ def discover(self):
188
206
if self .options .test :
189
207
self .run_individual_testsuite = self .options .test
190
208
209
+ self .test_config = TestConfiguration (self .env .test_config )
210
+
191
211
self .add_configurations ()
192
212
num = self .add_testsuites (testsuite_filter = self .run_individual_testsuite )
193
213
if num == 0 :
@@ -203,7 +223,7 @@ def discover(self):
203
223
self .scenarios .append (ts .id )
204
224
205
225
self .report_duplicates ()
206
- self .parse_configuration ( config_file = self .env . test_config )
226
+ self .levels = self .test_config . get_levels ( self . scenarios )
207
227
208
228
# handle quarantine
209
229
ql = self .options .quarantine_list
@@ -220,6 +240,10 @@ def discover(self):
220
240
logger .debug (f'Quarantine file { quarantine_file } is empty' )
221
241
self .quarantine = Quarantine (ql )
222
242
243
+ def get_level (self , name ):
244
+ level = next ((lvl for lvl in self .levels if lvl .name == name ), None )
245
+ return level
246
+
223
247
def load (self ):
224
248
225
249
if self .options .report_suffix :
@@ -440,19 +464,16 @@ def add_configurations(self):
440
464
soc_roots = self .env .soc_roots
441
465
arch_roots = self .env .arch_roots
442
466
443
- platform_config = self .test_config .get ('platforms' , {})
444
-
445
467
for platform in generate_platforms (board_roots , soc_roots , arch_roots ):
446
468
if not platform .twister :
447
469
continue
448
470
self .platforms .append (platform )
449
471
450
- if not platform_config . get ( ' override_default_platforms' , False ) :
472
+ if not self . test_config . override_default_platforms :
451
473
if platform .default :
452
474
self .default_platforms .append (platform .name )
453
- #logger.debug(f"adding {platform.name} to default platforms")
454
475
continue
455
- for pp in platform_config . get ( ' default_platforms' , []) :
476
+ for pp in self . test_config . default_platforms :
456
477
if pp in platform .aliases :
457
478
logger .debug (f"adding { platform .name } to default platforms (override mode)" )
458
479
self .default_platforms .append (platform .name )
@@ -767,9 +788,8 @@ def apply_filters(self, **kwargs):
767
788
else :
768
789
platforms = self .platforms
769
790
770
- platform_config = self .test_config .get ('platforms' , {})
771
791
# test configuration options
772
- test_config_options = self .test_config .get ( ' options' , {})
792
+ test_config_options = self .test_config .options
773
793
integration_mode_list = test_config_options .get ('integration_mode' , [])
774
794
775
795
logger .info ("Building initial testsuite list..." )
@@ -784,7 +804,7 @@ def apply_filters(self, **kwargs):
784
804
_integration_platforms = []
785
805
786
806
if (ts .build_on_all and not platform_filter and
787
- platform_config . get ( ' increased_platform_scope' , True ) ):
807
+ self . test_config . increased_platform_scope ):
788
808
# if build_on_all is set, we build on all platforms
789
809
platform_scope = self .platforms
790
810
elif ts .integration_platforms and self .options .integration :
@@ -808,7 +828,7 @@ def apply_filters(self, **kwargs):
808
828
ts .platform_allow
809
829
and not platform_filter
810
830
and not integration
811
- and platform_config . get ( ' increased_platform_scope' , True )
831
+ and self . test_config . increased_platform_scope
812
832
):
813
833
a = set (platform_scope )
814
834
b = set (filter (lambda item : item .name in ts .platform_allow , self .platforms ))
0 commit comments