5
5
6
6
import copy
7
7
import warnings
8
+ from typing import Any
8
9
9
10
import scl
10
11
from twisterlib .error import ConfigurationError
11
12
12
13
13
- def extract_fields_from_arg_list (target_fields : set , arg_list : str | list ):
14
+ def extract_fields_from_arg_list (
15
+ target_fields : set , arg_list : str | list
16
+ ) -> tuple [dict [str , list [str ]], list [str ]]:
14
17
"""
15
18
Given a list of "FIELD=VALUE" args, extract values of args with a
16
19
given field name and return the remaining args separately.
17
20
"""
18
- extracted_fields = {f : list () for f in target_fields }
19
- other_fields = []
21
+ extracted_fields : dict [ str , list [ str ]] = {f : list () for f in target_fields }
22
+ other_fields : list [ str ] = []
20
23
21
24
if isinstance (arg_list , str ):
22
25
args = arg_list .strip ().split ()
@@ -39,64 +42,66 @@ def extract_fields_from_arg_list(target_fields: set, arg_list: str | list):
39
42
40
43
return extracted_fields , other_fields
41
44
45
+
42
46
class TwisterConfigParser :
43
47
"""Class to read testsuite yaml files with semantic checking
44
48
"""
45
49
46
- testsuite_valid_keys = {"tags" : {"type" : "set" , "required" : False },
47
- "type" : {"type" : "str" , "default" : "integration" },
48
- "extra_args" : {"type" : "list" },
49
- "extra_configs" : {"type" : "list" },
50
- "extra_conf_files" : {"type" : "list" , "default" : []},
51
- "extra_overlay_confs" : {"type" : "list" , "default" : []},
52
- "extra_dtc_overlay_files" : {"type" : "list" , "default" : []},
53
- "required_snippets" : {"type" : "list" },
54
- "build_only" : {"type" : "bool" , "default" : False },
55
- "build_on_all" : {"type" : "bool" , "default" : False },
56
- "skip" : {"type" : "bool" , "default" : False },
57
- "slow" : {"type" : "bool" , "default" : False },
58
- "timeout" : {"type" : "int" , "default" : 60 },
59
- "min_ram" : {"type" : "int" , "default" : 16 },
60
- "modules" : {"type" : "list" , "default" : []},
61
- "depends_on" : {"type" : "set" },
62
- "min_flash" : {"type" : "int" , "default" : 32 },
63
- "arch_allow" : {"type" : "set" },
64
- "arch_exclude" : {"type" : "set" },
65
- "vendor_allow" : {"type" : "set" },
66
- "vendor_exclude" : {"type" : "set" },
67
- "extra_sections" : {"type" : "list" , "default" : []},
68
- "integration_platforms" : {"type" : "list" , "default" : []},
69
- "integration_toolchains" : {"type" : "list" , "default" : []},
70
- "ignore_faults" : {"type" : "bool" , "default" : False },
71
- "ignore_qemu_crash" : {"type" : "bool" , "default" : False },
72
- "testcases" : {"type" : "list" , "default" : []},
73
- "platform_type" : {"type" : "list" , "default" : []},
74
- "platform_exclude" : {"type" : "set" },
75
- "platform_allow" : {"type" : "set" },
76
- "platform_key" : {"type" : "list" , "default" : []},
77
- "simulation_exclude" : {"type" : "list" , "default" : []},
78
- "toolchain_exclude" : {"type" : "set" },
79
- "toolchain_allow" : {"type" : "set" },
80
- "filter" : {"type" : "str" },
81
- "levels" : {"type" : "list" , "default" : []},
82
- "harness" : {"type" : "str" , "default" : "test" },
83
- "harness_config" : {"type" : "map" , "default" : {}},
84
- "seed" : {"type" : "int" , "default" : 0 },
85
- "sysbuild" : {"type" : "bool" , "default" : False }
86
- }
87
-
88
- def __init__ (self , filename , schema ):
50
+ testsuite_valid_keys : dict [str , dict [str , Any ]] = {
51
+ "tags" : {"type" : "set" , "required" : False },
52
+ "type" : {"type" : "str" , "default" : "integration" },
53
+ "extra_args" : {"type" : "list" },
54
+ "extra_configs" : {"type" : "list" },
55
+ "extra_conf_files" : {"type" : "list" , "default" : []},
56
+ "extra_overlay_confs" : {"type" : "list" , "default" : []},
57
+ "extra_dtc_overlay_files" : {"type" : "list" , "default" : []},
58
+ "required_snippets" : {"type" : "list" },
59
+ "build_only" : {"type" : "bool" , "default" : False },
60
+ "build_on_all" : {"type" : "bool" , "default" : False },
61
+ "skip" : {"type" : "bool" , "default" : False },
62
+ "slow" : {"type" : "bool" , "default" : False },
63
+ "timeout" : {"type" : "int" , "default" : 60 },
64
+ "min_ram" : {"type" : "int" , "default" : 16 },
65
+ "modules" : {"type" : "list" , "default" : []},
66
+ "depends_on" : {"type" : "set" },
67
+ "min_flash" : {"type" : "int" , "default" : 32 },
68
+ "arch_allow" : {"type" : "set" },
69
+ "arch_exclude" : {"type" : "set" },
70
+ "vendor_allow" : {"type" : "set" },
71
+ "vendor_exclude" : {"type" : "set" },
72
+ "extra_sections" : {"type" : "list" , "default" : []},
73
+ "integration_platforms" : {"type" : "list" , "default" : []},
74
+ "integration_toolchains" : {"type" : "list" , "default" : []},
75
+ "ignore_faults" : {"type" : "bool" , "default" : False },
76
+ "ignore_qemu_crash" : {"type" : "bool" , "default" : False },
77
+ "testcases" : {"type" : "list" , "default" : []},
78
+ "platform_type" : {"type" : "list" , "default" : []},
79
+ "platform_exclude" : {"type" : "set" },
80
+ "platform_allow" : {"type" : "set" },
81
+ "platform_key" : {"type" : "list" , "default" : []},
82
+ "simulation_exclude" : {"type" : "list" , "default" : []},
83
+ "toolchain_exclude" : {"type" : "set" },
84
+ "toolchain_allow" : {"type" : "set" },
85
+ "filter" : {"type" : "str" },
86
+ "levels" : {"type" : "list" , "default" : []},
87
+ "harness" : {"type" : "str" , "default" : "test" },
88
+ "harness_config" : {"type" : "map" , "default" : {}},
89
+ "seed" : {"type" : "int" , "default" : 0 },
90
+ "sysbuild" : {"type" : "bool" , "default" : False }
91
+ }
92
+
93
+ def __init__ (self , filename : str , schema : dict [str , Any ]) -> None :
89
94
"""Instantiate a new TwisterConfigParser object
90
95
91
96
@param filename Source .yaml file to read
92
97
"""
93
- self .data = {}
94
98
self .schema = schema
95
99
self .filename = filename
96
- self .scenarios = {}
97
- self .common = {}
100
+ self .data : dict [str , Any ] = {}
101
+ self .scenarios : dict [str , Any ] = {}
102
+ self .common : dict [str , Any ] = {}
98
103
99
- def load (self ):
104
+ def load (self ) -> dict [ str , Any ] :
100
105
data = scl .yaml_load_verify (self .filename , self .schema )
101
106
self .data = data
102
107
@@ -106,7 +111,7 @@ def load(self):
106
111
self .common = self .data ['common' ]
107
112
return data
108
113
109
- def _cast_value (self , value , typestr ) :
114
+ def _cast_value (self , value : Any , typestr : str ) -> Any :
110
115
if typestr == "str" :
111
116
return value .strip ()
112
117
@@ -142,7 +147,7 @@ def _cast_value(self, value, typestr):
142
147
else :
143
148
raise ConfigurationError (self .filename , f"unknown type '{ value } '" )
144
149
145
- def get_scenario (self , name ) :
150
+ def get_scenario (self , name : str ) -> dict [ str , Any ] :
146
151
"""Get a dictionary representing the keys/values within a scenario
147
152
148
153
@param name The scenario in the .yaml file to retrieve data from
@@ -152,10 +157,10 @@ def get_scenario(self, name):
152
157
153
158
# "CONF_FILE", "OVERLAY_CONFIG", and "DTC_OVERLAY_FILE" fields from each
154
159
# of the extra_args lines
155
- extracted_common = {}
156
- extracted_testsuite = {}
160
+ extracted_common : dict = {}
161
+ extracted_testsuite : dict = {}
157
162
158
- d = {}
163
+ d : dict [ str , Any ] = {}
159
164
for k , v in self .common .items ():
160
165
if k == "extra_args" :
161
166
# Pull out these fields and leave the rest
@@ -223,7 +228,7 @@ def get_scenario(self, name):
223
228
self .scenarios [name ].get ("extra_dtc_overlay_files" , [])
224
229
225
230
if any ({len (x ) > 0 for x in extracted_common .values ()}) or \
226
- any ({len (x ) > 0 for x in extracted_testsuite .values ()}):
231
+ any ({len (x ) > 0 for x in extracted_testsuite .values ()}):
227
232
warnings .warn (
228
233
"Do not specify CONF_FILE, OVERLAY_CONFIG, or DTC_OVERLAY_FILE "
229
234
"in extra_args. This feature is deprecated and will soon "
0 commit comments