Skip to content

Commit eadc3d0

Browse files
57300fabiobaltieri
authored andcommitted
twister: Fix inconsistency among DT compat filters
This small change concerns the following filter functions: 1. `dt_compat_enabled(C)`: There's a node with compatible `C` and status "okay". 2. `dt_enabled_alias_with_parent_compat(A, C)`: There's a node with alias `A` and status "okay", and its parent has compatible `C`. 3. `dt_label_with_parent_compat_enabled(L, C)`: There's a node with label `L`, and its parent has compatible `C` and status "okay". All three functions involve checking whether some node or its parent has a given compatible, but the way this has been checked is inconsistent. Function (1) has done it with this Python conditional: compat in node.compats while (2) and (3) have used: parent.matching_compat == compat The first check works well with nodes that have multiple compatibles, and it is more aligned with the notion of "has_compat" as seen in the devicetree macros for C, CMake, and Kconfig. Arguably, `matching_compat` shouldn't have been used here, because it is actually a property of a node's binding, moreso than of the node itself. In practice, it's usually equal to the first compatible for which edtlib has found a binding, which at first glance is just more constrained than the `node.compats` check. However, there also exist obscure cases where the `node.compats` are empty, while the `node.matching_compat` is not. For now, the three functions can use a combined check, to improve consistency and utility while avoiding breakage: node.matching_compat == compat or compat in node.compats Signed-off-by: Grzegorz Swiderski <[email protected]>
1 parent 89bf698 commit eadc3d0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

scripts/pylib/twister/expr_parser.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def ast_expr(ast, env, edt):
227227
elif ast[0] == "dt_compat_enabled":
228228
compat = ast[1][0]
229229
for node in edt.nodes:
230-
if compat in node.compats and node.status == "okay":
230+
if (node.matching_compat == compat or compat in node.compats) and node.status == "okay":
231231
return True
232232
return False
233233
elif ast[0] == "dt_alias_exists":
@@ -247,7 +247,8 @@ def ast_expr(ast, env, edt):
247247
parent = node.parent
248248
if parent is None:
249249
continue
250-
if node.status == "okay" and alias in node.aliases and parent.matching_compat == compat:
250+
if node.status == "okay" and alias in node.aliases and \
251+
(parent.matching_compat == compat or compat in parent.compats):
251252
return True
252253
return False
253254
elif ast[0] == "dt_label_with_parent_compat_enabled":
@@ -258,7 +259,8 @@ def ast_expr(ast, env, edt):
258259
parent = node.parent
259260
else:
260261
return False
261-
return parent is not None and parent.status == 'okay' and parent.matching_compat == compat
262+
return parent is not None and parent.status == 'okay' and \
263+
(parent.matching_compat == compat or compat in parent.compats)
262264
elif ast[0] == "dt_chosen_enabled":
263265
chosen = ast[1][0]
264266
node = edt.chosen_node(chosen)

0 commit comments

Comments
 (0)