1
+ #
2
+ # Copyright (c) 2024 Project CHIP Authors
3
+ # All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ # See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments
19
+ # for details about the block below.
20
+ #
21
+ # === BEGIN CI TEST ARGUMENTS ===
22
+ # test-runner-runs:
23
+ # run1:
24
+ # app: ${ALL_CLUSTERS_APP}
25
+ # app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
26
+ # script-args: >
27
+ # --storage-path admin_storage.json
28
+ # --commissioning-method on-network
29
+ # --discriminator 1234
30
+ # --passcode 20202021
31
+ # --PICS src/app/tests/suites/certification/ci-pics-values
32
+ # --trace-to json:${TRACE_TEST_JSON}.json
33
+ # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
34
+ # factory-reset: true
35
+ # quiet: true
36
+ # === END CI TEST ARGUMENTS ===
37
+
38
+ import chip .clusters as Clusters
39
+ from chip .interaction_model import Status
40
+ from chip .testing .matter_testing import MatterBaseTest , TestStep , async_test_body , default_matter_test_main
41
+ from mobly import asserts
42
+
43
+ class TC_G_2_3 (MatterBaseTest ):
44
+ def desc_TC_G_2_3 (self ):
45
+ return "Commands - GetGroupMembership, AddGroupIfIdentifying [DUT-Server]"
46
+
47
+ def steps_TC_G_2_3 (self ):
48
+ return [TestStep (0 , "Comissioning, already done" , is_commissioning = True ),
49
+ TestStep ("1a" , "TH sends KeySetWrite command in the GroupKeyManagement cluster to DUT on EP0 using a key that is pre-installed on the TH. GroupKeySet fields are as follows:" ),
50
+ TestStep ("1b" , "TH writes the GroupKeyMap attribute in the GroupKeyManagement cluster of DUT on EP0 with maxgroups entries binding GroupId(0x0002 to (maxgroups+1)) with GroupKeySetID 1" ),
51
+ TestStep ("1c" , "TH cleans up the groups by sending the RemoveAllGroups command to the DUT on PIXIT.G.ENDPOINT" ),
52
+ TestStep ("1d" , "TH sends AddGroup command to DUT on PIXIT.G.ENDPOINT as unicast with the following fields : 1. GroupID as 0x0002 2. GroupName as Gp2" ),
53
+ TestStep ("2a" , "TH reads GroupTable attribute from the GroupKeyManagement cluster from DUT on EP0" )]
54
+
55
+ @async_test_body
56
+ async def test_TC_G_2_3 (self ):
57
+ # Pre-Conditions: Commissioning
58
+ self .step (0 )
59
+ th1 = self .default_controller
60
+
61
+ self .step ("1a" )
62
+ kGroupKeySetID = 1
63
+ kGroupKeySecurityPolicy = Clusters .GroupKeyManagement .Enums .GroupKeySecurityPolicyEnum .kTrustFirst
64
+ groupKey = Clusters .GroupKeyManagement .Structs .GroupKeySetStruct (
65
+ groupKeySetID = kGroupKeySetID ,
66
+ groupKeySecurityPolicy = kGroupKeySecurityPolicy ,
67
+ epochKey0 = "0123456789abcdef" .encode (),
68
+ epochStartTime0 = 1110000 ,
69
+ epochKey1 = "0123456789abcdef" .encode (),
70
+ epochStartTime1 = 1110001 ,
71
+ epochKey2 = "0123456789abcdef" .encode (),
72
+ epochStartTime2 = 1110002 )
73
+
74
+ cmd = Clusters .GroupKeyManagement .Commands .KeySetWrite (groupKey )
75
+ resp = await self .send_single_cmd (dev_ctrl = th1 , node_id = self .dut_node_id , cmd = cmd )
76
+
77
+ self .step ("1b" )
78
+ kGroupId1 = 0x0001
79
+ kGroupId2 = 0x0002
80
+ kGroupId3 = 0x0003
81
+ kGroupId4 = 0x0004
82
+ kGroupId5 = 0x0005
83
+ kGroupId6 = 0x0006
84
+ kGroupId7 = 0x0007
85
+ kGroupId8 = 0x0008
86
+ kGroupId9 = 0x0009
87
+ kGroupId10 = 0x000A
88
+ kGroupId11 = 0x000B
89
+ kGroupId12 = 0x000C
90
+ groupKeyMapStruct : List [Clusters .GroupKeyManagement .Structs .GroupKeyMapStruct ] = []
91
+ groupKeyMapStruct .append (Clusters .GroupKeyManagement .Structs .GroupKeyMapStruct (
92
+ groupId = kGroupId1 ,
93
+ groupKeySetID = kGroupKeySetID ))
94
+ groupKeyMapStruct .append (Clusters .GroupKeyManagement .Structs .GroupKeyMapStruct (
95
+ groupId = kGroupId2 ,
96
+ groupKeySetID = kGroupKeySetID ))
97
+ groupKeyMapStruct .append (Clusters .GroupKeyManagement .Structs .GroupKeyMapStruct (
98
+ groupId = kGroupId3 ,
99
+ groupKeySetID = kGroupKeySetID ))
100
+ groupKeyMapStruct .append (Clusters .GroupKeyManagement .Structs .GroupKeyMapStruct (
101
+ groupId = kGroupId4 ,
102
+ groupKeySetID = kGroupKeySetID ))
103
+ groupKeyMapStruct .append (Clusters .GroupKeyManagement .Structs .GroupKeyMapStruct (
104
+ groupId = kGroupId5 ,
105
+ groupKeySetID = kGroupKeySetID ))
106
+ groupKeyMapStruct .append (Clusters .GroupKeyManagement .Structs .GroupKeyMapStruct (
107
+ groupId = kGroupId6 ,
108
+ groupKeySetID = kGroupKeySetID ))
109
+ groupKeyMapStruct .append (Clusters .GroupKeyManagement .Structs .GroupKeyMapStruct (
110
+ groupId = kGroupId7 ,
111
+ groupKeySetID = kGroupKeySetID ))
112
+ groupKeyMapStruct .append (Clusters .GroupKeyManagement .Structs .GroupKeyMapStruct (
113
+ groupId = kGroupId8 ,
114
+ groupKeySetID = kGroupKeySetID ))
115
+ groupKeyMapStruct .append (Clusters .GroupKeyManagement .Structs .GroupKeyMapStruct (
116
+ groupId = kGroupId9 ,
117
+ groupKeySetID = kGroupKeySetID ))
118
+ groupKeyMapStruct .append (Clusters .GroupKeyManagement .Structs .GroupKeyMapStruct (
119
+ groupId = kGroupId10 ,
120
+ groupKeySetID = kGroupKeySetID ))
121
+ groupKeyMapStruct .append (Clusters .GroupKeyManagement .Structs .GroupKeyMapStruct (
122
+ groupId = kGroupId11 ,
123
+ groupKeySetID = kGroupKeySetID ))
124
+ groupKeyMapStruct .append (Clusters .GroupKeyManagement .Structs .GroupKeyMapStruct (
125
+ groupId = kGroupId12 ,
126
+ groupKeySetID = kGroupKeySetID ))
127
+ resp = await th1 .WriteAttribute (self .dut_node_id , [(0 , Clusters .GroupKeyManagement .Attributes .GroupKeyMap (groupKeyMapStruct ))])
128
+ asserts .assert_equal (resp [0 ].Status , Status .Success , "GroupKeyMap attribute write failed" )
129
+
130
+ self .step ("1c" )
131
+ cmd = Clusters .Groups .Commands .RemoveAllGroups ()
132
+ await th1 .SendCommand (self .dut_node_id , 0 , Clusters .Groups .Commands .RemoveAllGroups ())
133
+
134
+ self .step ("1d" )
135
+ kGroupNameGp2 = "Gp2"
136
+ cmd = Clusters .Groups .Commands .AddGroup (kGroupId2 , kGroupNameGp2 )
137
+ groupTableList : List [Clusters .GroupKeyManagement .Attributes .GroupTable ] = await self .read_single_attribute (
138
+ dev_ctrl = th1 , node_id = self .dut_node_id , endpoint = 0 , attribute = Clusters .GroupKeyManagement .Attributes .GroupTable )
139
+ result = await th1 .SendCommand (self .dut_node_id , 0 , Clusters .Groups .Commands .AddGroup (kGroupId2 , kGroupNameGp2 ))
140
+ asserts .assert_equal (result .status , Status .Success , "Adding Group 0x0002 failed" )
141
+
142
+ self .step ("2a" )
143
+ groupTableList : List [Clusters .GroupKeyManagement .Attributes .GroupTable ] = await self .read_single_attribute (
144
+ dev_ctrl = th1 , node_id = self .dut_node_id , endpoint = 0 , attribute = Clusters .GroupKeyManagement .Attributes .GroupTable )
145
+ asserts .assert_equal (groupTableList [0 ].groupId , kGroupId2 , "Found groupId does not match written value" )
146
+
147
+ if __name__ == "__main__" :
148
+ default_matter_test_main ()
0 commit comments