Skip to content

Commit 793e7bf

Browse files
committed
TCP test cases
Test script for tests defined in CHIP-Specifications/chip-test-plans#4243
1 parent 138fb4f commit 793e7bf

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

src/python_testing/TCP_Tests.py

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#
2+
# Copyright (c) 2023 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+
# test-runner-runs: run1
19+
# test-runner-run/run1/app: ${ALL_CLUSTERS_APP}
20+
# test-runner-run/run1/factoryreset: True
21+
# test-runner-run/run1/quiet: True
22+
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
23+
# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
24+
25+
import inspect
26+
import logging
27+
import random
28+
from dataclasses import dataclass
29+
30+
import chip.clusters as Clusters
31+
import chip.discovery as Discovery
32+
from chip import ChipDeviceCtrl, ChipUtility
33+
from chip.exceptions import ChipStackError
34+
from chip.interaction_model import InteractionModelError, Status
35+
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main, type_matches
36+
from mobly import asserts
37+
38+
39+
class TCP_Tests(MatterBaseTest):
40+
41+
@async_test_body
42+
async def test_TCPConnectionEstablishment(self):
43+
44+
try:
45+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
46+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
47+
except TimeoutError:
48+
asserts.fail("Unable to establish a CASE session over TCP to the device")
49+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
50+
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
51+
52+
@async_test_body
53+
async def test_LargePayloadSessionEstablishment(self):
54+
55+
try:
56+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
57+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
58+
except TimeoutError:
59+
asserts.fail("Unable to establish a CASE session over TCP to the device")
60+
asserts.assert_equal(device.sessionAllowsLargePayload, True, "Session does not have associated TCP connection")
61+
62+
@async_test_body
63+
async def test_SessionInactiveAfterTCPDisconnect(self):
64+
65+
try:
66+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
67+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
68+
except TimeoutError:
69+
asserts.fail("Unable to establish a CASE session over TCP to the device")
70+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
71+
72+
device.closeTCPConnectionWithPeer()
73+
asserts.assert_equal(device.isActiveSession, False,
74+
"Large Payload Session should not be active after TCP connection closure")
75+
76+
@async_test_body
77+
async def test_TCPConnectDisconnectThenConnectAgain(self):
78+
79+
try:
80+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
81+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
82+
except TimeoutError:
83+
asserts.fail("Unable to establish a CASE session over TCP to the device")
84+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
85+
86+
device.closeTCPConnectionWithPeer()
87+
asserts.assert_equal(device.isActiveSession, False,
88+
"Large Payload Session should not be active after TCP connection closure")
89+
90+
# Connect again
91+
try:
92+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
93+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
94+
except TimeoutError:
95+
asserts.fail("Unable to establish a CASE session over TCP to the device")
96+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
97+
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
98+
99+
@async_test_body
100+
async def test_OnOffToggleCommandOverTCPSession(self):
101+
102+
try:
103+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
104+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
105+
except TimeoutError:
106+
asserts.fail("Unable to establish a CASE session over TCP to the device")
107+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
108+
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
109+
asserts.assert_equal(device.sessionAllowsLargePayload, True, "Session does not have associated TCP connection")
110+
111+
commands = Clusters.Objects.OnOff.Commands
112+
try:
113+
await self.send_single_cmd(cmd=commands.Toggle(), endpoint=1,
114+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
115+
except InteractionModelError as e:
116+
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
117+
118+
@async_test_body
119+
async def test_WildCardReadOverTCPSession(self):
120+
121+
try:
122+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
123+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
124+
except TimeoutError:
125+
asserts.fail("Unable to establish a CASE session over TCP to the device")
126+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
127+
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
128+
asserts.assert_equal(device.sessionAllowsLargePayload, True, "Session does not have associated TCP connection")
129+
130+
try:
131+
wildcard_read = await self.default_controller.Read(self.dut_node_id, [()],
132+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
133+
except InteractionModelError as e:
134+
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
135+
136+
@async_test_body
137+
async def test_UseTCPSessionIfAvailableForMRPInteraction(self):
138+
139+
try:
140+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
141+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
142+
except TimeoutError:
143+
asserts.fail("Unable to establish a CASE session over TCP to the device")
144+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
145+
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
146+
asserts.assert_equal(device.sessionAllowsLargePayload, True, "Session does not have associated TCP connection")
147+
148+
commands = Clusters.Objects.OnOff.Commands
149+
try:
150+
await self.send_single_cmd(cmd=commands.Toggle(), endpoint=1,
151+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.MRP_OR_TCP_PAYLOAD)
152+
except InteractionModelError as e:
153+
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
154+
155+
156+
if __name__ == "__main__":
157+
default_matter_test_main()

0 commit comments

Comments
 (0)