forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCP_Tests.py
164 lines (140 loc) · 8.59 KB
/
TCP_Tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#
# Copyright (c) 2024 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# === BEGIN CI TEST ARGUMENTS ===
# test-runner-runs:
# run1:
# app: ${ALL_CLUSTERS_APP}
# app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
# 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
# factory-reset: true
# quiet: true
# === END CI TEST ARGUMENTS ===
#
import chip.clusters as Clusters
from chip import ChipDeviceCtrl
from chip.interaction_model import InteractionModelError
from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main
from mobly import asserts
class TCP_Tests(MatterBaseTest):
# TCP Connection Establishment
@async_test_body
async def test_TC_SC_8_1(self):
try:
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
except TimeoutError:
asserts.fail("Unable to establish a CASE session over TCP to the device")
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
# Large Payload Session Establishment
@async_test_body
async def test_TC_SC_8_2(self):
try:
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
except TimeoutError:
asserts.fail("Unable to establish a CASE session over TCP to the device")
asserts.assert_equal(device.sessionAllowsLargePayload, True, "Session does not have associated TCP connection")
# Session Inactive After TCP Disconnect
@async_test_body
async def test_TC_SC_8_3(self):
try:
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
except TimeoutError:
asserts.fail("Unable to establish a CASE session over TCP to the device")
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
device.closeTCPConnectionWithPeer()
asserts.assert_equal(device.isActiveSession, False,
"Large Payload Session should not be active after TCP connection closure")
# TCP Connect, Disconnect, Then Connect Again
@async_test_body
async def test_TC_SC_8_4(self):
try:
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
except TimeoutError:
asserts.fail("Unable to establish a CASE session over TCP to the device")
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
device.closeTCPConnectionWithPeer()
asserts.assert_equal(device.isActiveSession, False,
"Large Payload Session should not be active after TCP connection closure")
# Connect again
try:
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
except TimeoutError:
asserts.fail("Unable to establish a CASE session over TCP to the device")
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
# OnOff Cluster Toggle Command Over TCP Session
@async_test_body
async def test_TC_SC_8_5(self):
try:
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
except TimeoutError:
asserts.fail("Unable to establish a CASE session over TCP to the device")
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
asserts.assert_equal(device.sessionAllowsLargePayload, True, "Session does not have associated TCP connection")
commands = Clusters.Objects.OnOff.Commands
try:
await self.send_single_cmd(cmd=commands.Toggle(), endpoint=1,
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
except InteractionModelError:
asserts.fail("Unexpected error returned by DUT")
# WildCard Read Over TCP Session
@async_test_body
async def test_TC_SC_8_6(self):
try:
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
except TimeoutError:
asserts.fail("Unable to establish a CASE session over TCP to the device")
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
asserts.assert_equal(device.sessionAllowsLargePayload, True, "Session does not have associated TCP connection")
try:
await self.default_controller.Read(self.dut_node_id, [()], payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
except InteractionModelError:
asserts.fail("Unexpected error returned by DUT")
# Use TCP Session If Available For MRP Interaction
@async_test_body
async def test_TC_SC_8_7(self):
try:
device = await self.default_controller.GetConnectedDevice(nodeid=self.dut_node_id, allowPASE=False, timeoutMs=1000,
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.LARGE_PAYLOAD)
except TimeoutError:
asserts.fail("Unable to establish a CASE session over TCP to the device")
asserts.assert_equal(device.isSessionOverTCPConnection, True, "Session does not have associated TCP connection")
asserts.assert_equal(device.isActiveSession, True, "Large Payload Session should be active over TCP connection")
asserts.assert_equal(device.sessionAllowsLargePayload, True, "Session does not have associated TCP connection")
commands = Clusters.Objects.OnOff.Commands
try:
await self.send_single_cmd(cmd=commands.Toggle(), endpoint=1,
payloadCapability=ChipDeviceCtrl.TransportPayloadCapability.MRP_OR_TCP_PAYLOAD)
except InteractionModelError:
asserts.fail("Unexpected error returned by DUT")
if __name__ == "__main__":
default_matter_test_main()