Skip to content

Commit 038e494

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

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

.github/workflows/tests.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ jobs:
578578
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_RVCOPSTATE_2_4.py'
579579
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_SC_7_1.py'
580580
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_SWTCH.py'
581+
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TCP_Tests.py'
581582
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TestConformanceSupport.py" --script-args "--trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
582583
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TestMatterTestingSupport.py" --script-args "--trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
583584
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TestSpecParsingSupport.py" --script-args "--trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'

src/python_testing/TCP_Tests.py

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

0 commit comments

Comments
 (0)