@@ -666,7 +666,11 @@ filter: <expression>
666666 }
667667
668668 Twister will first evaluate the expression to find if a "limited" cmake call, i.e. using package_helper cmake script,
669- can be done. Existence of "dt_*" entries indicates devicetree is needed.
669+ can be done.
670+
671+ Existence of "dt_*" entries indicates devicetree is needed. Refer to :ref: `twister_dt_filter_expressions `
672+ for detailed description of the different DT expressions available.
673+
670674 Existence of "CONFIG*" entries indicates kconfig is needed.
671675 If there are no other types of entries in the expression a filtration can be done without creating a complete build system.
672676 If there are entries of other types a full cmake is required.
@@ -805,6 +809,119 @@ line break instead of white spaces.
805809
806810Most everyday users will run with no arguments.
807811
812+ .. _twister_dt_filter_expressions :
813+
814+ Devicetree Filtering Expressions
815+ ================================
816+
817+ Expressions starting with "dt_*" are used to filter boards based on specific
818+ devicetree properties, such as compatibles, aliases, node labels, node
819+ properties, chosen nodes, etc. when selecting test scenarios.
820+
821+ .. note ::
822+
823+ The source code for these expressions can be found at
824+ :zephyr_file: `scripts/pylib/twister/expr_parser.py `.
825+
826+ Expressions
827+ -----------
828+
829+ ``dt_compat_enabled(compat) ``
830+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
831+
832+ **Purpose: **
833+ Checks if any DT node with the specified compatible string (``compat ``) is enabled.
834+
835+ **Parameters: **
836+ - ``compat ``: The compatible string to match.
837+
838+ ``dt_alias_exists(alias) ``
839+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
840+
841+ **Purpose: **
842+ Checks if any DT node with the specified alias exists and is enabled.
843+
844+ **Parameters: **
845+ - ``alias ``: The alias (defined in ``aliases `` node) to match.
846+
847+ ``dt_enabled_alias_with_parent_compat(alias, compat) ``
848+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
849+
850+ **Purpose: **
851+ Checks if the DT has an enabled alias node whose parent has the specified compatible string.
852+ Useful for nodes like ``gpio-leds `` child nodes, which may not have their own compatible.
853+
854+ **Parameters: **
855+ - ``alias ``: The alias (defined in ``aliases `` node) to match.
856+ - ``compat ``: The parent node’s compatible string to match.
857+
858+ ``dt_label_with_parent_compat_enabled(label, compat) ``
859+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
860+
861+ **Purpose: **
862+ Checks if a DT node with the specified label exists, is enabled, and its parent has the
863+ specified compatible string.
864+
865+ **Parameters: **
866+ - ``label ``: The node label to match.
867+ - ``compat ``: The parent node’s compatible string to match.
868+
869+ ``dt_chosen_enabled(chosen) ``
870+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
871+
872+ **Purpose: **
873+ Checks if a DT chosen property with the specified name exists and the node assigned to it
874+ is enabled.
875+
876+ **Parameters: **
877+ - ``chosen ``: The name of the chosen property.
878+
879+ ``dt_nodelabel_enabled(label) ``
880+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
881+
882+ **Purpose: **
883+ Checks if a DT node with the specified label exists and is enabled.
884+
885+ **Parameters: **
886+ - ``label ``: The node label to match.
887+
888+ ``dt_nodelabel_prop_enabled(label, prop) ``
889+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
890+
891+ **Purpose: **
892+ Checks if a DT node with the specified label exists, is enabled, and has the specified property
893+ with a non-empty value.
894+
895+ **Parameters: **
896+ - ``label ``: The node label to match.
897+ - ``prop ``: The node's property to check.
898+
899+ ``dt_node_has_prop(node_id, prop) ``
900+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
901+
902+ **Purpose: **
903+ Checks if a DT node (specified by alias or path) has the specified property, regardless of its
904+ status. Useful for nodes that do not have a status, like ``zephyr,user `` node.
905+
906+ **Parameters: **
907+ - ``node_id ``: The node alias (defined in ``aliases `` node) or node path to match.
908+ - ``prop ``: The node's property to check.
909+
910+ Usage
911+ -----
912+
913+ These expressions are used in Twister’s test scenarios filtering logic to select boards that match
914+ specific DT conditions. For example:
915+
916+ .. code-block :: yaml
917+
918+ tests :
919+ - test : my_test
920+ filter : dt_compat_enabled("my-compat-string")
921+
922+ The test scenario ``my_test `` will only build for boards where a DT node with ``my-compat-string ``
923+ is enabled.
924+
808925.. _twister_harnesses :
809926
810927Harnesses
0 commit comments