-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathTC_PAVSTTestBase.py
More file actions
430 lines (374 loc) · 20.2 KB
/
TC_PAVSTTestBase.py
File metadata and controls
430 lines (374 loc) · 20.2 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
#
# Copyright (c) 2025 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.
import logging
import random
from mobly import asserts
import matter.clusters as Clusters
from matter import ChipDeviceCtrl
from matter.clusters.Types import Nullable
from matter.interaction_model import InteractionModelError, Status
log = logging.getLogger(__name__)
class PAVSTTestBase:
DEFAULT_AV_TRANSPORT_EXPIRY_TIME_SEC = 150 # 150 seconds
async def read_pavst_attribute_expect_success(self, endpoint, attribute):
cluster = Clusters.Objects.PushAvStreamTransport
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)
async def allocate_one_audio_stream(self):
endpoint = self.get_endpoint()
cluster = Clusters.CameraAvStreamManagement
attr = Clusters.CameraAvStreamManagement.Attributes
commands = Clusters.CameraAvStreamManagement.Commands
# First verify that ADO is supported
aFeatureMap = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attr.FeatureMap)
log.info(f"Rx'd FeatureMap: {aFeatureMap}")
adoSupport = aFeatureMap & cluster.Bitmaps.Feature.kAudio
asserts.assert_equal(adoSupport, cluster.Bitmaps.Feature.kAudio, "Audio Feature is not supported.")
# Check if audio stream has already been allocated
aAllocatedAudioStreams = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.AllocatedAudioStreams
)
log.info(f"Rx'd AllocatedAudioStreams: {aAllocatedAudioStreams}")
if len(aAllocatedAudioStreams) > 0:
return aAllocatedAudioStreams[0].audioStreamID
# Allocate one for the test steps based on SnapshotCapabilities
aMicrophoneCapabilities = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.MicrophoneCapabilities
)
log.info(f"Rx'd MicrophoneCapabilities: {aMicrophoneCapabilities}")
aStreamUsagePriorities = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.StreamUsagePriorities
)
log.info(f"Rx'd StreamUsagePriorities : {aStreamUsagePriorities}")
asserts.assert_greater(len(aStreamUsagePriorities), 0, "StreamUsagePriorities is empty")
try:
adoStreamAllocateCmd = commands.AudioStreamAllocate(
streamUsage=aStreamUsagePriorities[0],
audioCodec=aMicrophoneCapabilities.supportedCodecs[0],
channelCount=aMicrophoneCapabilities.maxNumberOfChannels,
sampleRate=aMicrophoneCapabilities.supportedSampleRates[0],
bitRate=1024,
bitDepth=aMicrophoneCapabilities.supportedBitDepths[0],
)
audioStreamAllocateResponse = await self.send_single_cmd(endpoint=endpoint, cmd=adoStreamAllocateCmd)
log.info(f"Rx'd AudioStreamAllocateResponse: {audioStreamAllocateResponse}")
asserts.assert_is_not_none(
audioStreamAllocateResponse.audioStreamID, "AudioStreamAllocateResponse does not contain StreamID"
)
return [audioStreamAllocateResponse.audioStreamID]
except InteractionModelError as e:
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
async def allocate_one_video_stream(self):
endpoint = self.get_endpoint()
cluster = Clusters.CameraAvStreamManagement
attr = Clusters.CameraAvStreamManagement.Attributes
commands = Clusters.CameraAvStreamManagement.Commands
# First verify that VDO is supported
aFeatureMap = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attr.FeatureMap)
log.info(f"Rx'd FeatureMap: {aFeatureMap}")
vdoSupport = aFeatureMap & cluster.Bitmaps.Feature.kVideo
asserts.assert_equal(vdoSupport, cluster.Bitmaps.Feature.kVideo, "Video Feature is not supported.")
# Check if video stream has already been allocated
aAllocatedVideoStreams = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.AllocatedVideoStreams
)
log.info(f"Rx'd AllocatedVideoStreams: {aAllocatedVideoStreams}")
if len(aAllocatedVideoStreams) > 0:
return aAllocatedVideoStreams[0].videoStreamID
# Allocate one for the test steps
aStreamUsagePriorities = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.StreamUsagePriorities
)
log.info(f"Rx'd StreamUsagePriorities: {aStreamUsagePriorities}")
aRateDistortionTradeOffPoints = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.RateDistortionTradeOffPoints
)
log.info(f"Rx'd RateDistortionTradeOffPoints: {aRateDistortionTradeOffPoints}")
aMinViewport = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.MinViewportResolution
)
log.info(f"Rx'd MinViewport: {aMinViewport}")
aVideoSensorParams = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.VideoSensorParams
)
log.info(f"Rx'd VideoSensorParams: {aVideoSensorParams}")
aMaxEncodedPixelRate = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.MaxEncodedPixelRate
)
log.info(f"Rx'd MaxEncodedPixelRate: {aMaxEncodedPixelRate}")
# Check for Watermark and OSD features
watermark = True if (aFeatureMap & cluster.Bitmaps.Feature.kWatermark) != 0 else None
osd = True if (aFeatureMap & cluster.Bitmaps.Feature.kOnScreenDisplay) != 0 else None
try:
asserts.assert_greater(len(aStreamUsagePriorities), 0, "StreamUsagePriorities is empty")
asserts.assert_greater(len(aRateDistortionTradeOffPoints), 0, "RateDistortionTradeOffPoints is empty")
videoStreamAllocateCmd = commands.VideoStreamAllocate(
streamUsage=aStreamUsagePriorities[0],
videoCodec=aRateDistortionTradeOffPoints[0].codec,
minFrameRate=min(self.matter_test_config.min_frame_rate, aVideoSensorParams.maxFPS),
maxFrameRate=aVideoSensorParams.maxFPS,
minResolution=aMinViewport,
maxResolution=cluster.Structs.VideoResolutionStruct(
width=aVideoSensorParams.sensorWidth, height=aVideoSensorParams.sensorHeight
),
minBitRate=aRateDistortionTradeOffPoints[0].minBitRate,
maxBitRate=aRateDistortionTradeOffPoints[0].minBitRate,
keyFrameInterval=4000,
watermarkEnabled=watermark,
OSDEnabled=osd
)
videoStreamAllocateResponse = await self.send_single_cmd(endpoint=endpoint, cmd=videoStreamAllocateCmd)
log.info(f"Rx'd VideoStreamAllocateResponse: {videoStreamAllocateResponse}")
asserts.assert_is_not_none(
videoStreamAllocateResponse.videoStreamID, "VideoStreamAllocateResponse does not contain StreamID"
)
return [videoStreamAllocateResponse.videoStreamID]
except InteractionModelError as e:
asserts.assert_equal(e.status, Status.Success, "Unexpected error returned")
async def validate_allocated_video_stream(self, videoStreamID):
endpoint = self.get_endpoint()
cluster = Clusters.CameraAvStreamManagement
attr = Clusters.CameraAvStreamManagement.Attributes
# Make sure the DUT allocated sterams as requested
aAllocatedVideoStreams = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.AllocatedVideoStreams
)
if not any(stream.videoStreamID == videoStreamID for stream in aAllocatedVideoStreams):
asserts.fail(f"Video Stream with ID {videoStreamID} not found as expected")
async def validate_allocated_audio_stream(self, audioStreamID):
endpoint = self.get_endpoint()
cluster = Clusters.CameraAvStreamManagement
attr = Clusters.CameraAvStreamManagement.Attributes
# Make sure the DUT allocated sterams as requested
aAllocatedAudioStreams = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=cluster, attribute=attr.AllocatedAudioStreams
)
if not any(stream.audioStreamID == audioStreamID for stream in aAllocatedAudioStreams):
asserts.fail(f"Audio Stream with ID {audioStreamID} not found as expected")
async def allocate_one_pushav_transport(self, endpoint, triggerType=Clusters.PushAvStreamTransport.Enums.TransportTriggerTypeEnum.kContinuous,
trigger_Options=None, ingestMethod=Clusters.PushAvStreamTransport.Enums.IngestMethodsEnum.kCMAFIngest,
url="https://localhost:1234/streams/1/", stream_Usage=None, container_Options=None,
videoStream_ID=None, audioStream_ID=None, expected_cluster_status=None, tlsEndPoint=1, expiryTime=DEFAULT_AV_TRANSPORT_EXPIRY_TIME_SEC):
endpoint = self.get_endpoint()
cluster = Clusters.PushAvStreamTransport
# First verify that ADO is supported
aFeatureMap = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=Clusters.CameraAvStreamManagement, attribute=Clusters.CameraAvStreamManagement.Attributes.FeatureMap)
log.info(f"Rx'd FeatureMap: {aFeatureMap}")
adoSupport = aFeatureMap & Clusters.CameraAvStreamManagement.Bitmaps.Feature.kAudio
asserts.assert_equal(adoSupport, Clusters.CameraAvStreamManagement.Bitmaps.Feature.kAudio,
"Audio Feature is not supported.")
# Check if audio stream has already been allocated
aAllocatedAudioStream = await self.allocate_one_audio_stream()
log.info(f"Rx'd AllocatedAudioStream: {aAllocatedAudioStream}")
# Check if video stream has already been allocated
aAllocatedVideoStream = await self.allocate_one_video_stream()
log.info(f"Rx'd AllocatedVideoStream: {aAllocatedVideoStream}")
aStreamUsagePriorities = await self.read_single_attribute_check_success(
endpoint=endpoint, cluster=Clusters.CameraAvStreamManagement, attribute=Clusters.CameraAvStreamManagement.Attributes.StreamUsagePriorities
)
asserts.assert_greater(len(aStreamUsagePriorities), 0, "StreamUsagePriorities is empty")
streamUsage = aStreamUsagePriorities[0]
if (stream_Usage is not None):
streamUsage = stream_Usage
videoStreamID = aAllocatedVideoStream
if (videoStream_ID is not None):
if (videoStream_ID == Nullable()):
videoStreamID = videoStream_ID
else:
videoStreamID = aAllocatedVideoStream + 1
audioStreamID = aAllocatedAudioStream
if (audioStream_ID is not None):
if (audioStream_ID == Nullable()):
audioStreamID = audioStream_ID
else:
audioStreamID = aAllocatedAudioStream + 1
containerOptions = {
"containerType": cluster.Enums.ContainerFormatEnum.kCmaf,
"CMAFContainerOptions": {"CMAFInterface": cluster.Enums.CMAFInterfaceEnum.kInterface1, "chunkDuration": 4, "segmentDuration": 4000,
"sessionGroup": 3, "trackName": "media"},
}
if (container_Options is not None):
containerOptions = container_Options
triggerOptions = {"triggerType": triggerType}
if (trigger_Options is not None):
triggerOptions = trigger_Options
try:
await self.send_single_cmd(
cmd=cluster.Commands.AllocatePushTransport(
{
"streamUsage": streamUsage,
"videoStreamID": videoStreamID,
"audioStreamID": audioStreamID,
"TLSEndpointID": tlsEndPoint,
"url": url,
"triggerOptions": triggerOptions,
"ingestMethod": ingestMethod,
"containerOptions": containerOptions,
"expiryTime": expiryTime,
}
),
endpoint=endpoint,
)
return Status.Success
except InteractionModelError as e:
asserts.assert_not_equal(e.status, Status.Success, "Unexpected error returned")
if (expected_cluster_status is not None):
asserts.assert_true(
e.clusterStatus == expected_cluster_status, "Unexpected error returned"
)
return e.clusterStatus
if (e.status == Status.ResourceExhausted):
asserts.fail("RESOURCE_EXHAUSTED")
return e.status
return None
async def check_and_delete_all_push_av_transports(self, endpoint, attribute):
pvcluster = Clusters.PushAvStreamTransport
transportConfigs = await self.read_pavst_attribute_expect_success(
endpoint,
attribute.CurrentConnections,
)
for config in transportConfigs:
if config.connectionID != 0:
try:
await self.send_single_cmd(
cmd=pvcluster.Commands.DeallocatePushTransport(
connectionID=config.connectionID
),
endpoint=endpoint,
)
except InteractionModelError as e:
asserts.assert_true(
e.status == Status.Success, "Unexpected error returned"
)
return Status.Success
async def psvt_modify_push_transport(self, cmd, devCtrl=None):
endpoint = self.get_endpoint()
dev_ctrl = self.default_controller
if (devCtrl is not None):
dev_ctrl = devCtrl
try:
await self.send_single_cmd(cmd=cmd, endpoint=endpoint, dev_ctrl=dev_ctrl)
return Status.Success
except InteractionModelError as e:
if (e.status == Status.Busy):
asserts.fail("Transport is busy, currently uploading data")
else:
asserts.assert_true(
e.status == Status.NotFound, "Unexpected error returned"
)
return e.status
return None
async def psvt_deallocate_push_transport(self, cmd, devCtrl=None):
endpoint = self.get_endpoint()
dev_ctrl = self.default_controller
if (devCtrl is not None):
dev_ctrl = devCtrl
try:
await self.send_single_cmd(cmd=cmd, endpoint=endpoint, dev_ctrl=dev_ctrl)
return Status.Success
except InteractionModelError as e:
if (e.status == Status.Busy):
asserts.fail("Transport is busy, currently uploading data")
else:
asserts.assert_true(
e.status == Status.NotFound, "Unexpected error returned"
)
return e.status
return None
async def psvt_set_transport_status(self, cmd, expected_status=None, devCtrl=None):
endpoint = self.get_endpoint()
dev_ctrl = self.default_controller
if (devCtrl is not None):
dev_ctrl = devCtrl
try:
await self.send_single_cmd(cmd=cmd, endpoint=endpoint, dev_ctrl=dev_ctrl)
return Status.Success
except InteractionModelError as e:
if (expected_status is not None):
asserts.assert_true(e.status, expected_status, "Unexpected error returned")
else:
asserts.assert_true(e.status == Status.NotFound, "Unexpected error returned")
return e.status
return None
async def psvt_find_transport(self, cmd, expected_connectionID=None, devCtrl=None):
endpoint = self.get_endpoint()
dev_ctrl = self.default_controller
if (devCtrl is not None):
dev_ctrl = devCtrl
try:
status = await self.send_single_cmd(cmd=cmd, endpoint=endpoint, dev_ctrl=dev_ctrl)
asserts.assert_equal(
status.transportConfigurations[0].connectionID, expected_connectionID, "Unexpected connection ID returned"
)
return Status.Success
except InteractionModelError as e:
asserts.assert_true(
e.status == Status.NotFound, "Unexpected error returned"
)
return e.status
return None
async def psvt_manually_trigger_transport(self, cmd, expected_cluster_status=None, expected_status=None, devCtrl=None):
endpoint = self.get_endpoint()
dev_ctrl = self.default_controller
if (devCtrl is not None):
dev_ctrl = devCtrl
try:
await self.send_single_cmd(cmd=cmd, endpoint=endpoint, dev_ctrl=dev_ctrl)
return Status.Success
except InteractionModelError as e:
if (expected_cluster_status is not None):
asserts.assert_true(
e.clusterStatus == expected_cluster_status, "Unexpected error returned"
)
return e.clusterStatus
if (e.status == Status.Busy):
asserts.fail("Transport is busy, currently uploading data")
else:
if (expected_status is not None):
asserts.assert_true(
e.status == expected_status, "Unexpected error returned"
)
return e.status
asserts.assert_true(
e.status == Status.NotFound, "Unexpected error returned"
)
return e.status
return None
async def psvt_create_test_harness_controller(self):
self.th1 = self.default_controller
self.discriminator = random.randint(0, 4095)
params = await self.th1.OpenCommissioningWindow(
nodeId=self.dut_node_id, timeout=900, iteration=10000, discriminator=self.discriminator, option=1)
th2_certificate_authority = (
self.certificate_authority_manager.NewCertificateAuthority()
)
th2_fabric_admin = th2_certificate_authority.NewFabricAdmin(
vendorId=0xFFF1, fabricId=self.th1.fabricId + 1
)
self.th2 = th2_fabric_admin.NewController(
nodeId=2, useTestCommissioner=True)
setupPinCode = params.setupPinCode
await self.th2.CommissionOnNetwork(
nodeId=self.dut_node_id, setupPinCode=setupPinCode,
filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=self.discriminator)
return self.th2
async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int:
cluster = Clusters.Objects.OperationalCredentials
attribute = Clusters.OperationalCredentials.Attributes.CurrentFabricIndex
return await self.read_single_attribute_check_success(dev_ctrl=th, endpoint=0, cluster=cluster, attribute=attribute)
async def psvt_remove_current_fabric(self, devCtrl):
fabric_idx_cr2_2 = await self.read_currentfabricindex(th=devCtrl)
removeFabricCmd2 = Clusters.OperationalCredentials.Commands.RemoveFabric(fabric_idx_cr2_2)
return await self.th1.SendCommand(nodeId=self.dut_node_id, endpoint=0, payload=removeFabricCmd2)