Skip to content

Commit 51f55b4

Browse files
mbolivar-nordicnashif
authored andcommitted
twister: replace dt_compat_enabled_with_alias filter
Originally added in 7733b94. This filter is not well-formed. It's meant to match nodes like /leds/led_0 in this DTS: / { aliases { led0 = &led0; }; leds { compatible = "gpio-leds"; led0: led_0 { gpios = <...>; label = "LED 0"; }; }; }; Uses look like this: filter: dt_compat_enabled_with_alias("gpio-leds", "led0") But notice how the led_0 node doesn't have compatible "gpio-leds"; it's actually the *parent* node that has that compatible. Replace this with a new filter, dt_enabled_alias_with_parent_compat(), which is used like this: filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds") This has a name and argument order that makes the meaning of the filter clearer. Replace in-tree users with the new filter. Deprecate the old filter and warn about its use using the standard logging module. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
1 parent d802fc3 commit 51f55b4

File tree

7 files changed

+49
-11
lines changed

7 files changed

+49
-11
lines changed

samples/basic/blinky/sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sample:
33
tests:
44
sample.basic.blinky:
55
tags: LED gpio
6-
filter: dt_compat_enabled_with_alias("gpio-leds", "led0")
6+
filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds")
77
depends_on: gpio
88
harness: led
99
integration_platforms:

samples/basic/button/sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ sample:
33
tests:
44
sample.basic.button:
55
tags: button gpio
6-
filter: dt_compat_enabled_with_alias("gpio-keys", "sw0")
6+
filter: dt_enabled_alias_with_parent_compat("sw0", "gpio-keys")
77
depends_on: gpio
88
harness: button

samples/basic/threads/sample.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ sample:
55
tests:
66
sample.basic.threads:
77
tags: kernel threads gpio
8-
filter: dt_compat_enabled_with_alias("gpio-leds", "led0") and
9-
dt_compat_enabled_with_alias("gpio-leds", "led1")
8+
filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds") and
9+
dt_enabled_alias_with_parent_compat("led1", "gpio-leds")
1010
depends_on: gpio
1111
harness: console
1212
harness_config:

samples/subsys/mgmt/osdp/control_panel/sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sample:
44
tests:
55
sample.mgmt.osdp.control_panel:
66
tags: osdp
7-
filter: dt_compat_enabled_with_alias("gpio-leds", "led0") and CONFIG_SERIAL
7+
filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds") and CONFIG_SERIAL
88
harness: osdp
99
integration_platforms:
1010
- frdm_k64f

samples/subsys/mgmt/osdp/peripheral_device/sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sample:
44
tests:
55
sample.mgmt.osdp.peripheral_device:
66
tags: osdp
7-
filter: dt_compat_enabled_with_alias("gpio-leds", "led0") and CONFIG_SERIAL
7+
filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds") and CONFIG_SERIAL
88
harness: osdp
99
integration_platforms:
1010
- frdm_k64f

scripts/pylib/twister/expr_parser.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# SPDX-License-Identifier: Apache-2.0
66

77
import copy
8+
import logging
89
import os
910
import re
1011
import sys
@@ -18,6 +19,8 @@
1819
"Please install the ply package using your workstation's\n"
1920
"package manager or the 'pip' tool.")
2021

22+
_logger = logging.getLogger('twister')
23+
2124
reserved = {
2225
'and' : 'AND',
2326
'or' : 'OR',
@@ -233,20 +236,55 @@ def ast_expr(ast, env, edt):
233236
if alias in node.aliases and node.status == "okay":
234237
return True
235238
return False
239+
elif ast[0] == "dt_enabled_alias_with_parent_compat":
240+
# Checks if the DT has an enabled alias node whose parent has
241+
# a given compatible. For matching things like gpio-leds child
242+
# nodes, which do not have compatibles themselves.
243+
#
244+
# The legacy "dt_compat_enabled_with_alias" form is still
245+
# accepted but is now deprecated and causes a warning. This is
246+
# meant to give downstream users some time to notice and
247+
# adjust. Its argument order only made sense under the (bad)
248+
# assumption that the gpio-leds child node has the same compatible
249+
250+
alias = ast[1][0]
251+
compat = ast[1][1]
252+
253+
return ast_handle_dt_enabled_alias_with_parent_compat(edt, alias,
254+
compat)
236255
elif ast[0] == "dt_compat_enabled_with_alias":
237256
compat = ast[1][0]
238257
alias = ast[1][1]
239-
for node in edt.nodes:
240-
if node.status == "okay" and alias in node.aliases and node.matching_compat == compat:
241-
return True
242-
return False
258+
259+
_logger.warning('dt_compat_enabled_with_alias("%s", "%s"): '
260+
'this is deprecated, use '
261+
'dt_enabled_alias_with_parent_compat("%s", "%s") '
262+
'instead',
263+
compat, alias, alias, compat)
264+
265+
return ast_handle_dt_enabled_alias_with_parent_compat(edt, alias,
266+
compat)
243267
elif ast[0] == "dt_chosen_enabled":
244268
chosen = ast[1][0]
245269
node = edt.chosen_node(chosen)
246270
if node and node.status == "okay":
247271
return True
248272
return False
249273

274+
def ast_handle_dt_enabled_alias_with_parent_compat(edt, alias, compat):
275+
# Helper shared with the now deprecated
276+
# dt_compat_enabled_with_alias version.
277+
278+
for node in edt.nodes:
279+
parent = node.parent
280+
if parent is None:
281+
continue
282+
if (node.status == "okay" and alias in node.aliases and
283+
parent.matching_compat == compat):
284+
return True
285+
286+
return False
287+
250288
mutex = threading.Lock()
251289

252290
def parse(expr_text, env, edt):

tests/drivers/gpio/gpio_api_1pin/testcase.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ tests:
55
min_flash: 48
66
# Fix exclude when we can exclude just sim run
77
platform_exclude: mps2_an385 mps2_an521
8-
filter: dt_compat_enabled_with_alias("gpio-leds", "led0")
8+
filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds")

0 commit comments

Comments
 (0)