@@ -1566,7 +1566,6 @@ def async_runner(self: MatterBaseTest, *args, **kwargs):
1566
1566
return async_runner
1567
1567
1568
1568
def per_node_test (body ):
1569
-
1570
1569
""" Decorator to be used for PICS-free tests that apply to the entire node.
1571
1570
1572
1571
Use this decorator when your script needs to be run once to validate the whole node.
@@ -1587,6 +1586,26 @@ def _has_cluster(wildcard, endpoint, cluster: ClusterObjects.Cluster) -> bool:
1587
1586
return False
1588
1587
1589
1588
def has_cluster (cluster : ClusterObjects .ClusterObjectDescriptor ) -> EndpointCheckFunction :
1589
+ """ EndpointCheckFunction that can be passed as a parameter to the per_endpoint_test decorator.
1590
+
1591
+ Use this function with the per_endpoint_test decorator to run this test on all endpoints with
1592
+ the specified cluster. For example, given a device with the following conformance
1593
+
1594
+ EP0: cluster A, B, C
1595
+ EP1: cluster D, E
1596
+ EP2, cluster D
1597
+ EP3, cluster E
1598
+
1599
+ And the following test specification:
1600
+ @per_endpoint_test(has_cluster(Clusters.D))
1601
+ test_mytest(self):
1602
+ ...
1603
+
1604
+ The test would be run on endpoint 1 and on endpoint 2.
1605
+
1606
+ If the cluster is not found on any endpoint the decorator will call the on_skip function to
1607
+ notify the test harness that the test is not applicable to this node and the test will not be run.
1608
+ """
1590
1609
return partial (_has_cluster , cluster = cluster )
1591
1610
1592
1611
def _has_attribute (wildcard , endpoint , attribute : ClusterObjects .ClusterAttributeDescriptor ) -> bool :
@@ -1598,13 +1617,67 @@ def _has_attribute(wildcard, endpoint, attribute: ClusterObjects.ClusterAttribut
1598
1617
return False
1599
1618
1600
1619
def has_attribute (attribute : ClusterObjects .ClusterAttributeDescriptor ) -> EndpointCheckFunction :
1620
+ """ EndpointCheckFunction that can be passed as a parameter to the per_endpoint_test decorator.
1621
+
1622
+ Use this function with the per_endpoint_test decorator to run this test on all endpoints with
1623
+ the specified attribute. For example, given a device with the following conformance
1624
+
1625
+ EP0: cluster A, B, C
1626
+ EP1: cluster D with attribute d, E
1627
+ EP2, cluster D with attribute d
1628
+ EP3, cluster D without attribute d
1629
+
1630
+ And the following test specification:
1631
+ @per_endpoint_test(has_attribute(Clusters.D.Attributes.d))
1632
+ test_mytest(self):
1633
+ ...
1634
+
1635
+ The test would be run on endpoint 1 and on endpoint 2.
1636
+
1637
+ If the cluster is not found on any endpoint the decorator will call the on_skip function to
1638
+ notify the test harness that the test is not applicable to this node and the test will not be run.
1639
+ """
1601
1640
return partial (_has_attribute , attribute = attribute )
1602
1641
1603
- async def get_accepted_endpoints_for_test (self :MatterBaseTest , accept_function : EndpointCheckFunction ):
1642
+ async def get_accepted_endpoints_for_test (self :MatterBaseTest , accept_function : EndpointCheckFunction ) -> list [uint ]:
1643
+ """ Helper function for the per_endpoint_test decorator.
1644
+
1645
+ Returns a list of endpoints on which the test should be run given the accept_function for the test.
1646
+ """
1604
1647
wildcard = await self .default_controller .Read (self .dut_node_id , [()])
1605
1648
return [e for e in wildcard .attributes .keys () if accept_function (wildcard , e )]
1606
1649
1607
- def per_endpoint_test (accept_function ):
1650
+ def per_endpoint_test (accept_function : EndpointCheckFunction ):
1651
+ """ Test decorator for a test that needs to be run once per endpoint that meets the accept_function criteria.
1652
+
1653
+ Place this decorator above the test_ method to have the test framework run this test once per endpoint.
1654
+ This decorator takes an EndpointCheckFunction to assess whether a test needs to be run on a particular
1655
+ endpoint.
1656
+
1657
+ For example, given the following device conformance:
1658
+
1659
+ EP0: cluster A, B, C
1660
+ EP1: cluster D, E
1661
+ EP2, cluster D
1662
+ EP3, cluster E
1663
+
1664
+ And the following test specification:
1665
+ @per_endpoint_test(has_cluster(Clusters.D))
1666
+ test_mytest(self):
1667
+ ...
1668
+
1669
+ The test would be run on endpoint 1 and on endpoint 2.
1670
+
1671
+ If the cluster is not found on any endpoint the decorator will call the on_skip function to
1672
+ notify the test harness that the test is not applicable to this node and the test will not be run.
1673
+
1674
+ The decorator works by setting the self.matter_test_config.endpoint value and running the test function.
1675
+ Therefore, tests that make use of this decorator should call controller functions against that endpoint.
1676
+ Support functions in this file default to this endpoint.
1677
+
1678
+ Tests that use this decorator cannot use a pics_ method for test selection and should not reference any
1679
+ PICS values internally.
1680
+ """
1608
1681
def per_endpoint_test_internal (body ):
1609
1682
def per_endpoint_runner (self : MatterBaseTest , * args , ** kwargs ):
1610
1683
asserts .assert_false (self .get_test_pics (self .current_test_info .name ), "pics_ method supplied for per_endpoint_test." )
0 commit comments