diff --git a/samples/basic/blinky/sample.yaml b/samples/basic/blinky/sample.yaml index 9c8ac6ff646..88fa2756b2b 100644 --- a/samples/basic/blinky/sample.yaml +++ b/samples/basic/blinky/sample.yaml @@ -3,7 +3,7 @@ sample: tests: sample.basic.blinky: tags: LED gpio - filter: dt_compat_enabled_with_alias("gpio-leds", "led0") + filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds") depends_on: gpio harness: led integration_platforms: diff --git a/samples/basic/button/sample.yaml b/samples/basic/button/sample.yaml index a99aca40595..8fb3b78c12d 100644 --- a/samples/basic/button/sample.yaml +++ b/samples/basic/button/sample.yaml @@ -3,6 +3,6 @@ sample: tests: sample.basic.button: tags: button gpio - filter: dt_compat_enabled_with_alias("gpio-keys", "sw0") + filter: dt_enabled_alias_with_parent_compat("sw0", "gpio-keys") depends_on: gpio harness: button diff --git a/samples/basic/threads/sample.yaml b/samples/basic/threads/sample.yaml index d550ee98248..e6605a0fbba 100644 --- a/samples/basic/threads/sample.yaml +++ b/samples/basic/threads/sample.yaml @@ -5,8 +5,8 @@ sample: tests: sample.basic.threads: tags: kernel threads gpio - filter: dt_compat_enabled_with_alias("gpio-leds", "led0") and - dt_compat_enabled_with_alias("gpio-leds", "led1") + filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds") and + dt_enabled_alias_with_parent_compat("led1", "gpio-leds") depends_on: gpio harness: console harness_config: diff --git a/samples/subsys/mgmt/osdp/control_panel/sample.yaml b/samples/subsys/mgmt/osdp/control_panel/sample.yaml index 3eb99f1a3f9..9684e5ee11e 100644 --- a/samples/subsys/mgmt/osdp/control_panel/sample.yaml +++ b/samples/subsys/mgmt/osdp/control_panel/sample.yaml @@ -4,7 +4,7 @@ sample: tests: sample.mgmt.osdp.control_panel: tags: osdp - filter: dt_compat_enabled_with_alias("gpio-leds", "led0") and CONFIG_SERIAL + filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds") and CONFIG_SERIAL harness: osdp integration_platforms: - frdm_k64f diff --git a/samples/subsys/mgmt/osdp/peripheral_device/sample.yaml b/samples/subsys/mgmt/osdp/peripheral_device/sample.yaml index f358aeb0b04..385a0e0012b 100644 --- a/samples/subsys/mgmt/osdp/peripheral_device/sample.yaml +++ b/samples/subsys/mgmt/osdp/peripheral_device/sample.yaml @@ -4,7 +4,7 @@ sample: tests: sample.mgmt.osdp.peripheral_device: tags: osdp - filter: dt_compat_enabled_with_alias("gpio-leds", "led0") and CONFIG_SERIAL + filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds") and CONFIG_SERIAL harness: osdp integration_platforms: - frdm_k64f diff --git a/scripts/pylib/twister/expr_parser.py b/scripts/pylib/twister/expr_parser.py index cb54d34580c..95a2785ecd8 100644 --- a/scripts/pylib/twister/expr_parser.py +++ b/scripts/pylib/twister/expr_parser.py @@ -5,6 +5,7 @@ # SPDX-License-Identifier: Apache-2.0 import copy +import logging import os import re import sys @@ -18,6 +19,8 @@ except ImportError: "Please install the ply package using your workstation's\n" "package manager or the 'pip' tool.") +_logger = logging.getLogger('twister') + reserved = { 'and' : 'AND', 'or' : 'OR', @@ -233,13 +236,34 @@ def ast_expr(ast, env, edt): if alias in node.aliases and node.status == "okay": return True return False + elif ast[0] == "dt_enabled_alias_with_parent_compat": + # Checks if the DT has an enabled alias node whose parent has + # a given compatible. For matching things like gpio-leds child + # nodes, which do not have compatibles themselves. + # + # The legacy "dt_compat_enabled_with_alias" form is still + # accepted but is now deprecated and causes a warning. This is + # meant to give downstream users some time to notice and + # adjust. Its argument order only made sense under the (bad) + # assumption that the gpio-leds child node has the same compatible + + alias = ast[1][0] + compat = ast[1][1] + + return ast_handle_dt_enabled_alias_with_parent_compat(edt, alias, + compat) elif ast[0] == "dt_compat_enabled_with_alias": compat = ast[1][0] alias = ast[1][1] - for node in edt.nodes: - if node.status == "okay" and alias in node.aliases and node.matching_compat == compat: - return True - return False + + _logger.warning('dt_compat_enabled_with_alias("%s", "%s"): ' + 'this is deprecated, use ' + 'dt_enabled_alias_with_parent_compat("%s", "%s") ' + 'instead', + compat, alias, alias, compat) + + return ast_handle_dt_enabled_alias_with_parent_compat(edt, alias, + compat) elif ast[0] == "dt_chosen_enabled": chosen = ast[1][0] node = edt.chosen_node(chosen) @@ -247,6 +271,20 @@ def ast_expr(ast, env, edt): return True return False +def ast_handle_dt_enabled_alias_with_parent_compat(edt, alias, compat): + # Helper shared with the now deprecated + # dt_compat_enabled_with_alias version. + + for node in edt.nodes: + parent = node.parent + if parent is None: + continue + if (node.status == "okay" and alias in node.aliases and + parent.matching_compat == compat): + return True + + return False + mutex = threading.Lock() def parse(expr_text, env, edt): diff --git a/tests/drivers/gpio/gpio_api_1pin/testcase.yaml b/tests/drivers/gpio/gpio_api_1pin/testcase.yaml index 32f814913b0..e97f73f7e42 100644 --- a/tests/drivers/gpio/gpio_api_1pin/testcase.yaml +++ b/tests/drivers/gpio/gpio_api_1pin/testcase.yaml @@ -5,4 +5,4 @@ tests: min_flash: 48 # Fix exclude when we can exclude just sim run platform_exclude: mps2_an385 mps2_an521 - filter: dt_compat_enabled_with_alias("gpio-leds", "led0") + filter: dt_enabled_alias_with_parent_compat("led0", "gpio-leds")