Skip to content

Commit 87cb181

Browse files
committed
TCP test cases
Test script for tests defined in CHIP-Specifications/chip-test-plans#4243
1 parent ba949bf commit 87cb181

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed

src/python_testing/TCP_Tests.py

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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 chip.clusters as Clusters
26+
from chip import ChipDeviceCtrl
27+
from chip.interaction_model import InteractionModelError, Status
28+
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main
29+
from mobly import asserts
30+
31+
32+
class TCP_Tests(MatterBaseTest):
33+
34+
@async_test_body
35+
async def test_TCPConnectionEstablishment(self):
36+
37+
try:
38+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
39+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
40+
except TimeoutError:
41+
asserts.fail("Unable to establish a CASE session over TCP to the device")
42+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
43+
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
44+
45+
@async_test_body
46+
async def test_LargePayloadSessionEstablishment(self):
47+
48+
try:
49+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
50+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
51+
except TimeoutError:
52+
asserts.fail("Unable to establish a CASE session over TCP to the device")
53+
asserts.assert_equal(device.sessionAllowsLargePayload, True, "Session does not have associated TCP connection")
54+
55+
@async_test_body
56+
async def test_SessionInactiveAfterTCPDisconnect(self):
57+
58+
try:
59+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
60+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
61+
except TimeoutError:
62+
asserts.fail("Unable to establish a CASE session over TCP to the device")
63+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
64+
65+
device.closeTCPConnectionWithPeer()
66+
asserts.assert_equal(device.isActiveSession, False,
67+
"Large Payload Session should not be active after TCP connection closure")
68+
69+
@async_test_body
70+
async def test_TCPConnectDisconnectThenConnectAgain(self):
71+
72+
try:
73+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
74+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
75+
except TimeoutError:
76+
asserts.fail("Unable to establish a CASE session over TCP to the device")
77+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
78+
79+
device.closeTCPConnectionWithPeer()
80+
asserts.assert_equal(device.isActiveSession, False,
81+
"Large Payload Session should not be active after TCP connection closure")
82+
83+
# Connect again
84+
try:
85+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
86+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
87+
except TimeoutError:
88+
asserts.fail("Unable to establish a CASE session over TCP to the device")
89+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
90+
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
91+
92+
@async_test_body
93+
async def test_OnOffToggleCommandOverTCPSession(self):
94+
95+
try:
96+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
97+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
98+
except TimeoutError:
99+
asserts.fail("Unable to establish a CASE session over TCP to the device")
100+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
101+
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
102+
asserts.assert_equal(device.sessionAllowsLargePayload, True, "Session does not have associated TCP connection")
103+
104+
commands = Clusters.Objects.OnOff.Commands
105+
try:
106+
await self.send_single_cmd(cmd=commands.Toggle(), endpoint=1,
107+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
108+
except InteractionModelError as e:
109+
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
110+
111+
@async_test_body
112+
async def test_WildCardReadOverTCPSession(self):
113+
114+
try:
115+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
116+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
117+
except TimeoutError:
118+
asserts.fail("Unable to establish a CASE session over TCP to the device")
119+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
120+
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
121+
asserts.assert_equal(device.sessionAllowsLargePayload, True, "Session does not have associated TCP connection")
122+
123+
try:
124+
wildcard_read = await self.default_controller.Read(self.dut_node_id, [()],
125+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
126+
except InteractionModelError as e:
127+
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
128+
129+
@async_test_body
130+
async def test_UseTCPSessionIfAvailableForMRPInteraction(self):
131+
132+
try:
133+
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
134+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
135+
except TimeoutError:
136+
asserts.fail("Unable to establish a CASE session over TCP to the device")
137+
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
138+
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
139+
asserts.assert_equal(device.sessionAllowsLargePayload, True, "Session does not have associated TCP connection")
140+
141+
commands = Clusters.Objects.OnOff.Commands
142+
try:
143+
await self.send_single_cmd(cmd=commands.Toggle(), endpoint=1,
144+
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.MRP_OR_TCP_PAYLOAD)
145+
except InteractionModelError as e:
146+
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
147+
148+
149+
if __name__ == "__main__":
150+
default_matter_test_main()

0 commit comments

Comments
 (0)