Skip to content

Commit 286f235

Browse files
Implement test plan TC_DGWIFI_2_3 (#37057)
* Implement test plan TC_DGWIFI_2_3 * Update src/python_testing/TC_DGWIFI_2_3.py Co-authored-by: Andrei Litvin <andy314@gmail.com> * Address review comment * Update test step description --------- Co-authored-by: Andrei Litvin <andy314@gmail.com>
1 parent 9b58c27 commit 286f235

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

src/python_testing/TC_DGWIFI_2_3.py

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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+
# === BEGIN CI TEST ARGUMENTS ===
19+
# test-runner-runs:
20+
# run1:
21+
# app: ${ALL_CLUSTERS_APP}
22+
# app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
23+
# script-args: >
24+
# --storage-path admin_storage.json
25+
# --commissioning-method on-network
26+
# --discriminator 1234
27+
# --passcode 20202021
28+
# --trace-to json:${TRACE_TEST_JSON}.json
29+
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
30+
# factory-reset: true
31+
# quiet: true
32+
# === END CI TEST ARGUMENTS ===
33+
#
34+
35+
import chip.clusters as Clusters
36+
from chip.clusters.Types import Nullable, NullValue
37+
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
38+
from mobly import asserts
39+
40+
41+
class TC_DGWIFI_2_3(MatterBaseTest):
42+
"""
43+
[TC-DGWIFI-2.3] Wi-Fi Network Diagnostics Cluster - Command Verification
44+
45+
This test case verifies the ResetCounts command and subsequent behavior.
46+
"""
47+
48+
@staticmethod
49+
def is_valid_uint32(value):
50+
"""Validates a uint32 value."""
51+
return isinstance(value, int) and 0 <= value <= 0xFFFFFFFF
52+
53+
async def send_reset_counts_command(self, endpoint):
54+
"""Sends the ResetCounts command to the DUT."""
55+
cluster = Clusters.Objects.WiFiNetworkDiagnostics
56+
await self.send_single_cmd(cluster.Commands.ResetCounts(), endpoint=endpoint)
57+
58+
async def read_attribute_and_validate(self, endpoint, attribute, validation_func, field_name):
59+
"""Reads an attribute and validates it using the provided function."""
60+
value = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=Clusters.Objects.WiFiNetworkDiagnostics, attribute=attribute)
61+
if value is None:
62+
return
63+
asserts.assert_true(isinstance(value, Nullable), f"{field_name} must be of type 'Nullable' when not None.")
64+
if value == NullValue:
65+
return
66+
asserts.assert_true(validation_func(value.Value), f"{field_name} has an invalid value: {value.Value}")
67+
68+
def desc_TC_DGWIFI_2_3(self) -> str:
69+
"""Returns a description of this test."""
70+
return "[TC-DGWIFI-2.3] Wi-Fi Diagnostics Command Verification with Server as DUT"
71+
72+
def pics_TC_DGWIFI_2_3(self) -> list[str]:
73+
return ["DGWIFI.S"]
74+
75+
def steps_TC_DGWIFI_2_3(self) -> list[TestStep]:
76+
steps = [
77+
TestStep("1", "Commission DUT to TH (already done)", is_commissioning=True),
78+
TestStep("2", "Send ResetCounts command to DUT"),
79+
TestStep("2a", "Verify BeaconLostCount attribute after reset"),
80+
TestStep("2b", "Verify BeaconRxCount attribute after reset"),
81+
TestStep("2c", "Verify PacketMulticastRxCount attribute after reset"),
82+
TestStep("2d", "Verify PacketMulticastTxCount attribute after reset"),
83+
TestStep("2e", "Verify PacketUnicastRxCount attribute after reset"),
84+
TestStep("2f", "Verify PacketUnicastTxCount attribute after reset"),
85+
]
86+
return steps
87+
88+
@async_test_body
89+
async def test_TC_DGWIFI_2_3(self):
90+
endpoint = self.get_endpoint(default=0)
91+
92+
# STEP 1: Commission DUT (already done)
93+
self.step("1")
94+
# Typically, we assume commissioning was performed by harness scripts.
95+
attributes = Clusters.WiFiNetworkDiagnostics.Attributes
96+
97+
# STEP 2: Send ResetCounts command
98+
self.step("2")
99+
await self.send_reset_counts_command(endpoint)
100+
101+
# STEP 2a: Verify BeaconLostCount attribute
102+
self.step("2a")
103+
await self.read_attribute_and_validate(
104+
endpoint,
105+
attributes.BeaconLostCount,
106+
self.is_valid_uint32,
107+
"BeaconLostCount"
108+
)
109+
110+
# STEP 2b: Verify BeaconRxCount attribute
111+
self.step("2b")
112+
await self.read_attribute_and_validate(
113+
endpoint,
114+
attributes.BeaconRxCount,
115+
self.is_valid_uint32,
116+
"BeaconRxCount"
117+
)
118+
119+
# STEP 2c: Verify PacketMulticastRxCount attribute
120+
self.step("2c")
121+
await self.read_attribute_and_validate(
122+
endpoint,
123+
attributes.PacketMulticastRxCount,
124+
self.is_valid_uint32,
125+
"PacketMulticastRxCount"
126+
)
127+
128+
# STEP 2d: Verify PacketMulticastTxCount attribute
129+
self.step("2d")
130+
await self.read_attribute_and_validate(
131+
endpoint,
132+
attributes.PacketMulticastTxCount,
133+
self.is_valid_uint32,
134+
"PacketMulticastTxCount"
135+
)
136+
137+
# STEP 2e: Verify PacketUnicastRxCount attribute
138+
self.step("2e")
139+
await self.read_attribute_and_validate(
140+
endpoint,
141+
attributes.PacketUnicastRxCount,
142+
self.is_valid_uint32,
143+
"PacketUnicastRxCount"
144+
)
145+
146+
# STEP 2f: Verify PacketUnicastTxCount attribute
147+
self.step("2f")
148+
await self.read_attribute_and_validate(
149+
endpoint,
150+
attributes.PacketUnicastTxCount,
151+
self.is_valid_uint32,
152+
"PacketUnicastTxCount"
153+
)
154+
155+
156+
if __name__ == "__main__":
157+
default_matter_test_main()

0 commit comments

Comments
 (0)