Skip to content

Commit 1220907

Browse files
cecillerestyled-commits
authored andcommitted
Expose commissionerNodeId as a variable for yaml (#24197)
* Expose commissionerNodeId as a variable for yaml yaml can now use commissionerNodeId directly in an argument or response and the generated code will fill in the commissionerNodeId of the current commissioner. * Two more zap files. * Restyled by clang-format * Make node id useable for different identities - useable on response and argument - usable for different identities - added test * re-compile zap * Add comment * Restyled by prettier-yaml * Add commissioner node id to placeholder * Update src/app/tests/suites/TestCommissionerNodeId.yaml * Update zap Co-authored-by: Restyled.io <[email protected]>
1 parent b52fc9c commit 1220907

File tree

11 files changed

+14083
-340
lines changed

11 files changed

+14083
-340
lines changed

examples/chip-tool/commands/tests/TestCommand.h

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ class TestCommand : public TestRunner,
7878

7979
chip::Controller::DeviceCommissioner & GetCommissioner(const char * identity) override
8080
{
81+
// Best effort to get NodeId - if this fails, GetCommissioner will also fail
82+
chip::NodeId id;
83+
if (GetCommissionerNodeId(identity, &id) == CHIP_NO_ERROR)
84+
{
85+
mCommissionerNodeId.SetValue(id);
86+
}
8187
return CHIPCommand::GetCommissioner(identity);
8288
};
8389

@@ -95,6 +101,7 @@ class TestCommand : public TestRunner,
95101

96102
chip::Optional<char *> mPICSFilePath;
97103
chip::Optional<uint16_t> mTimeout;
104+
chip::Optional<chip::NodeId> mCommissionerNodeId;
98105
std::map<std::string, std::unique_ptr<chip::OperationalDeviceProxy>> mDevices;
99106

100107
// When set to false, prevents interaction model events from affecting the current test status.

examples/chip-tool/templates/tests/partials/test_cluster.zapt

+14
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ private:
4848

4949
void OnResponse(const chip::app::StatusIB & status, chip::TLV::TLVReader * data) override
5050
{
51+
52+
// Allow yaml to access the current commissioner node id.
53+
// Default to 0 (undefined node id) so we know if this isn't
54+
// set correctly.
55+
// Reset on every step in case it changed.
56+
chip::NodeId commissionerNodeId = mCommissionerNodeId.ValueOr(0);
57+
(void) commissionerNodeId;
58+
5159
bool shouldContinue = false;
5260

5361
switch (mTestIndex - 1)
@@ -72,6 +80,12 @@ private:
7280
CHIP_ERROR DoTestStep(uint16_t testIndex) override
7381
{
7482
using namespace chip::app::Clusters;
83+
// Allow yaml to access the current commissioner node id.
84+
// Default to 0 (undefined node id) so we know if this isn't
85+
// set correctly.
86+
// Reset on every step in case it changed.
87+
chip::NodeId commissionerNodeId = mCommissionerNodeId.ValueOr(0);
88+
(void) commissionerNodeId;
7589
switch (testIndex)
7690
{
7791
{{#chip_tests_items}}

examples/darwin-framework-tool/commands/tests/TestCommandBridge.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ class TestCommandBridge : public CHIPCommandBridge,
154154
VerifyOrReturnError(controller != nil, CHIP_ERROR_INCORRECT_STATE);
155155

156156
SetIdentity(identity);
157+
if (controller.controllerNodeId != nil) {
158+
mCommissionerNodeId.SetValue([controller.controllerNodeId unsignedLongLongValue]);
159+
}
157160

158161
// Invalidate our existing CASE session; otherwise trying to work with
159162
// our device will just reuse it without establishing a new CASE
@@ -181,6 +184,9 @@ class TestCommandBridge : public CHIPCommandBridge,
181184
VerifyOrReturnError(controller != nil, CHIP_ERROR_INCORRECT_STATE);
182185

183186
SetIdentity(identity);
187+
if (controller.controllerNodeId != nil) {
188+
mCommissionerNodeId.SetValue([controller.controllerNodeId unsignedLongLongValue]);
189+
}
184190

185191
[controller setDeviceControllerDelegate:mDeviceControllerDelegate queue:mCallbackQueue];
186192
[mDeviceControllerDelegate setDeviceId:value.nodeId];
@@ -215,7 +221,16 @@ class TestCommandBridge : public CHIPCommandBridge,
215221
return CHIP_NO_ERROR;
216222
}
217223

218-
MTRBaseDevice * _Nullable GetDevice(const char * _Nullable identity) { return mConnectedDevices[identity]; }
224+
MTRBaseDevice * _Nullable GetDevice(const char * _Nullable identity)
225+
{
226+
MTRDeviceController * controller = GetCommissioner(identity);
227+
228+
SetIdentity(identity);
229+
if (controller != nil && controller.controllerNodeId != nil) {
230+
mCommissionerNodeId.SetValue([controller.controllerNodeId unsignedLongLongValue]);
231+
}
232+
return mConnectedDevices[identity];
233+
}
219234

220235
// PairingDeleted and PairingComplete need to be public so our pairing
221236
// delegate can call them.
@@ -255,6 +270,7 @@ class TestCommandBridge : public CHIPCommandBridge,
255270
chip::Optional<char *> mPICSFilePath;
256271
chip::Optional<chip::EndpointId> mEndpointId;
257272
chip::Optional<uint16_t> mTimeout;
273+
chip::Optional<chip::NodeId> mCommissionerNodeId;
258274

259275
bool CheckConstraintStartsWith(
260276
const char * _Nonnull itemName, const NSString * _Nonnull current, const char * _Nonnull expected)

examples/darwin-framework-tool/templates/tests/partials/test_cluster.zapt

+8
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@ class {{filename}}: public TestCommandBridge
2323
{
2424
}
2525

26+
// Allow yaml to access the current commissioner node id.
27+
// Default to 0 (undefined node id) so we know if this isn't
28+
// set correctly.
29+
// Reset on every step in case it changed.
30+
chip::NodeId commissionerNodeId = mCommissionerNodeId.ValueOr(0);
31+
2632
/////////// TestCommand Interface /////////
2733
void NextTest() override
2834
{
2935
CHIP_ERROR err = CHIP_NO_ERROR;
36+
commissionerNodeId = mCommissionerNodeId.ValueOr(0);
3037

3138
if (0 == mTestIndex)
3239
{
@@ -136,6 +143,7 @@ class {{filename}}: public TestCommandBridge
136143
return {{command}}("{{identity}}", value);
137144
{{else}}
138145
MTRBaseDevice * device = GetDevice("{{identity}}");
146+
commissionerNodeId = mCommissionerNodeId.ValueOr(0);
139147
__auto_type * cluster = [[MTRBaseCluster{{>cluster}} alloc] initWithDevice:device endpointID:@({{endpoint}}) queue:mCallbackQueue];
140148
VerifyOrReturnError(cluster != nil, CHIP_ERROR_INCORRECT_STATE);
141149

examples/placeholder/linux/include/TestCommand.h

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class TestCommand : public TestRunner,
174174
protected:
175175
chip::app::ConcreteCommandPath mCommandPath;
176176
chip::app::ConcreteAttributePath mAttributePath;
177+
chip::Optional<chip::NodeId> mCommissionerNodeId;
177178
chip::Optional<chip::EndpointId> mEndpointId;
178179
void SetIdentity(const char * name){};
179180

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
# Copyright (c) 2022 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Test Commissioner Node ID
16+
17+
config:
18+
nodeId: 0x12344321
19+
endpoint: 0
20+
cluster: "Access Control"
21+
payload:
22+
type: char_string
23+
defaultValue: "MT:-24J0AFN00KA0648G00" # This value needs to be generated automatically
24+
25+
tests:
26+
- label: "Wait for the commissioned device to be retrieved for alpha"
27+
cluster: "DelayCommands"
28+
command: "WaitForCommissionee"
29+
arguments:
30+
values:
31+
- name: "nodeId"
32+
value: nodeId
33+
34+
- label: "Open Commissioning Window from alpha"
35+
cluster: "AdministratorCommissioning"
36+
command: "OpenBasicCommissioningWindow"
37+
timedInteractionTimeoutMs: 10000
38+
arguments:
39+
values:
40+
- name: "CommissioningTimeout"
41+
value: 180
42+
43+
- label: "Commission from beta"
44+
identity: "beta"
45+
cluster: "CommissionerCommands"
46+
command: "PairWithCode"
47+
arguments:
48+
values:
49+
- name: "nodeId"
50+
value: nodeId
51+
- name: "payload"
52+
value: payload
53+
54+
- label: "Wait for the commissioned device to be retrieved for beta"
55+
identity: "beta"
56+
cluster: "DelayCommands"
57+
command: "WaitForCommissionee"
58+
arguments:
59+
values:
60+
- name: "nodeId"
61+
value: nodeId
62+
63+
- label: "Open Commissioning Window from alpha"
64+
cluster: "AdministratorCommissioning"
65+
command: "OpenBasicCommissioningWindow"
66+
timedInteractionTimeoutMs: 10000
67+
arguments:
68+
values:
69+
- name: "CommissioningTimeout"
70+
value: 180
71+
72+
- label: "Commission from gamma"
73+
identity: "gamma"
74+
cluster: "CommissionerCommands"
75+
command: "PairWithCode"
76+
arguments:
77+
values:
78+
- name: "nodeId"
79+
value: nodeId
80+
- name: "payload"
81+
value: payload
82+
83+
- label: "Wait for the commissioned device to be retrieved for gamma"
84+
identity: "gamma"
85+
cluster: "DelayCommands"
86+
command: "WaitForCommissionee"
87+
arguments:
88+
values:
89+
- name: "nodeId"
90+
value: nodeId
91+
92+
- label: "Read the fabric ID from the alpha fabric"
93+
identity: "alpha"
94+
cluster: "Operational Credentials"
95+
command: "readAttribute"
96+
attribute: "CurrentFabricIndex"
97+
response:
98+
saveAs: alphaIndex
99+
100+
- label: "Read the fabric ID from the beta fabric"
101+
identity: "beta"
102+
cluster: "Operational Credentials"
103+
command: "readAttribute"
104+
attribute: "CurrentFabricIndex"
105+
response:
106+
saveAs: betaIndex
107+
108+
- label: "Read the fabric ID from the gamma fabric"
109+
identity: "gamma"
110+
cluster: "Operational Credentials"
111+
command: "readAttribute"
112+
attribute: "CurrentFabricIndex"
113+
response:
114+
saveAs: gammaIndex
115+
116+
- label: "Read the ACL from alpha and check commissioner node id"
117+
identity: "alpha"
118+
command: "readAttribute"
119+
attribute: "ACL"
120+
response:
121+
value: [
122+
{
123+
FabricIndex: alphaIndex,
124+
Privilege: 5, # administer
125+
AuthMode: 2, # case
126+
Subjects: [commissionerNodeId],
127+
Targets: null,
128+
},
129+
]
130+
131+
- label: "Read the ACL from beta and check commissioner node id"
132+
identity: "beta"
133+
command: "readAttribute"
134+
attribute: "ACL"
135+
response:
136+
value: [
137+
{
138+
FabricIndex: betaIndex,
139+
Privilege: 5, # administer
140+
AuthMode: 2, # case
141+
Subjects: [commissionerNodeId],
142+
Targets: null,
143+
},
144+
]
145+
146+
- label: "Read the ACL from gamma and check commissioner node id"
147+
identity: "gamma"
148+
command: "readAttribute"
149+
attribute: "ACL"
150+
response:
151+
value: [
152+
{
153+
FabricIndex: gammaIndex,
154+
Privilege: 5, # administer
155+
AuthMode: 2, # case
156+
Subjects: [commissionerNodeId],
157+
Targets: null,
158+
},
159+
]
160+
161+
- label: "Write the ACL using the commissioner node id value"
162+
identity: "beta"
163+
command: "writeAttribute"
164+
attribute: "ACL"
165+
arguments:
166+
value: [
167+
{
168+
FabricIndex: betaIndex,
169+
Privilege: 5, # administer
170+
AuthMode: 2, # case
171+
Subjects: [commissionerNodeId],
172+
Targets: null,
173+
},
174+
]
175+
176+
- label: "Write the ACL using the commissioner node id value"
177+
identity: "gamma"
178+
command: "writeAttribute"
179+
attribute: "ACL"
180+
arguments:
181+
value: [
182+
{
183+
FabricIndex: gammaIndex,
184+
Privilege: 5, # administer
185+
AuthMode: 2, # case
186+
Subjects: [commissionerNodeId],
187+
Targets: null,
188+
},
189+
]
190+
191+
- label: "Read the ACL from beta and check commissioner node id"
192+
identity: "beta"
193+
command: "readAttribute"
194+
attribute: "ACL"
195+
response:
196+
value: [
197+
{
198+
FabricIndex: betaIndex,
199+
Privilege: 5, # administer
200+
AuthMode: 2, # case
201+
Subjects: [commissionerNodeId],
202+
Targets: null,
203+
},
204+
]
205+
206+
- label: "Read the ACL from gamma and check commissioner node id"
207+
identity: "gamma"
208+
command: "readAttribute"
209+
attribute: "ACL"
210+
response:
211+
value: [
212+
{
213+
FabricIndex: gammaIndex,
214+
Privilege: 5, # administer
215+
AuthMode: 2, # case
216+
Subjects: [commissionerNodeId],
217+
Targets: null,
218+
},
219+
]
220+
221+
- label: "Remove beta fabric"
222+
cluster: "Operational Credentials"
223+
command: "RemoveFabric"
224+
arguments:
225+
values:
226+
- name: "FabricIndex"
227+
value: betaIndex
228+
229+
- label: "Remove gamma fabric"
230+
cluster: "Operational Credentials"
231+
command: "RemoveFabric"
232+
arguments:
233+
values:
234+
- name: "FabricIndex"
235+
value: gammaIndex

src/app/tests/suites/ciTests.json

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@
238238
"TestAccessControlConstraints",
239239
"TestLevelControlWithOnOffDependency",
240240
"TestCommissioningWindow",
241+
"TestCommissionerNodeId",
241242
"TestClientMonitoringCluster"
242243
],
243244
"MultiAdmin": ["TestMultiAdmin"],

0 commit comments

Comments
 (0)