Skip to content

Commit

Permalink
TC-TIMESYNC-2.<2-8> (#26580)
Browse files Browse the repository at this point in the history
* Add PICS

* Add a check-time function to python tests

* TC-TIMESYNC-2.2 - initial

* TC-TIMESYNC-2.4

* TC-TIMESYNC-2.5

* TC-TIMESYNC-2.6

* TC-TIMESYNC-2.7

* TC-TIMESYNC-2.8

* TC-TIMESYNC-2.9

* Restyled by isort

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Jul 7, 2023
1 parent 773da32 commit 1672178
Show file tree
Hide file tree
Showing 10 changed files with 1,134 additions and 1 deletion.
93 changes: 93 additions & 0 deletions src/app/tests/suites/certification/PICS.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7607,3 +7607,96 @@ PICS:
- label:
"Does the device implement sending the GoToTiltPercentage command ?"
id: WNCV.C.C08.Tx

# Time Synchronization Cluster Test Plan
- label:
"Does the device implement the Time Synchronization cluster as a
server?"
id: TIMESYNC.S

- label:
"Does the device implement the Time Synchronization cluster as a
client?"
id: TIMESYNC.C

#
# server / features
#
- label: "Does the DUT(server) support the TimeZone feature?"
id: TIMESYNC.S.F00

- label: "Does the DUT(server) support the NTPClient feature?"
id: TIMESYNC.S.F01

- label: "Does the DUT(server) support the NTPServer feature?"
id: TIMESYNC.S.F02

- label: "Does the DUT(server) support the TimeSyncClient feature?"
id: TIMESYNC.S.F03

#
# server / attributes
#
- label: "Does the device implement the UTCTime attribute ?"
id: TIMESYNC.S.A0000

- label: "Does the device implement the Granularity attribute ?"
id: TIMESYNC.S.A0001

- label: "Does the device implement the TimeSource attribute ?"
id: TIMESYNC.S.A0002

- label: "Does the device implement the TrustedTimeSource attribute ?"
id: TIMESYNC.S.A0003

- label: "Does the device implement the DefaultNTP attribute ?"
id: TIMESYNC.S.A0004

- label: "Does the device implement the TimeZone attribute ?"
id: TIMESYNC.S.A0005

- label: "Does the device implement the DSTOffset attribute ?"
id: TIMESYNC.S.A0006

- label: "Does the device implement the LocalTime attribute ?"
id: TIMESYNC.S.A0007

- label: "Does the device implement the TimeZoneDatabase attribute ?"
id: TIMESYNC.S.A0008

- label: "Does the device implement the NTPServerAvailable attribute ?"
id: TIMESYNC.S.A0009

- label: "Does the device implement the TimeZoneListMaxSize attribute ?"
id: TIMESYNC.S.A000a

- label: "Does the device implement the DSTOffsetListMaxSize attribute ?"
id: TIMESYNC.S.A000b

- label: "Does the device implement the SupportsDNSResolve attribute ?"
id: TIMESYNC.S.A000c

#
# server / commandsReceived
#
- label: "Does the device implement receiving the SetUTCTime command?"
id: TIMESYNC.S.C00.Rsp

- label:
"Does the device implement receiving the SetTrustedTimeSource command?"
id: TIMESYNC.S.C01.Rsp

- label: "Does the device implement receiving the SetTimeZone command?"
id: TIMESYNC.S.C02.Rsp

- label: "Does the device implement receiving the SetDSTOffset command?"
id: TIMESYNC.S.C04.Rsp

- label: "Does the device implement receiving the SetDefaultNTP command?"
id: TIMESYNC.S.C05.Rsp

#
# server / commandsGenerated
#
- label: "Does the DUT(server) support the SetTimeZoneResponse command?"
id: TIMESYNC.S.C03.Tx
27 changes: 27 additions & 0 deletions src/app/tests/suites/certification/ci-pics-values
Original file line number Diff line number Diff line change
Expand Up @@ -2066,3 +2066,30 @@ MCORE.IDM.C.SubscribeRequest.Attribute.DataType_Bool=1
MCORE.IDM.C.SubscribeRequest.MultipleAttributes=1
MCORE.IDM.S.LargeData=1
MCORE.IDM.S.PersistentSubscription=1

# Time Synchronization
TIMESYNC.S=1
TIMESYNC.S.F00=1
TIMESYNC.S.F01=1
TIMESYNC.S.F02=0
TIMESYNC.S.F03=1
TIMESYNC.S.A0000=1
TIMESYNC.S.A0001=1
TIMESYNC.S.A0002=1
TIMESYNC.S.A0003=1
TIMESYNC.S.A0004=1
TIMESYNC.S.A0005=1
TIMESYNC.S.A0006=1
TIMESYNC.S.A0007=1
TIMESYNC.S.A0008=1
TIMESYNC.S.A0009=0
TIMESYNC.S.A000a=1
TIMESYNC.S.A000b=1
TIMESYNC.S.A000c=1
TIMESYNC.S.C00.Rsp=1
TIMESYNC.S.C01.Rsp=1
TIMESYNC.S.C02.Rsp=1
TIMESYNC.S.C04.Rsp=1
TIMESYNC.S.C05.Rsp=1
TIMESYNC.S.C03.Tx=1
TIMESYNC.C=0
76 changes: 76 additions & 0 deletions src/python_testing/TC_TIMESYNC_2_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#
# Copyright (c) 2023 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.
#

from datetime import timedelta

import chip.clusters as Clusters
from chip.clusters.Types import NullValue
from chip.interaction_model import InteractionModelError
from matter_testing_support import MatterBaseTest, async_test_body, compare_time, default_matter_test_main, utc_time_in_matter_epoch
from mobly import asserts


class TC_TIMESYNC_2_2(MatterBaseTest):
async def read_ts_attribute_expect_success(self, endpoint, attribute):
cluster = Clusters.Objects.TimeSynchronization
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)

@async_test_body
async def test_TC_TIMESYNC_2_2(self):

endpoint = self.user_params.get("endpoint", 0)

time_cluster = Clusters.Objects.TimeSynchronization

self.print_step(1, "Commissioning, already done")
attributes = Clusters.TimeSynchronization.Attributes

self.print_step(2, "Read UTCTime attribute")
utc_dut_initial = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.UTCTime)
th_utc = utc_time_in_matter_epoch()
try:
await self.send_single_cmd(cmd=time_cluster.Commands.SetUTCTime(UTCTime=th_utc, granularity=time_cluster.Enums.GranularityEnum.kMillisecondsGranularity), endpoint=endpoint)
code = 0
except InteractionModelError as e:
# The python layer discards the cluster specific portion of the status IB, so for now we just expect a generic FAILURE error
# see #26521
code = e.status
pass

if utc_dut_initial is NullValue:
asserts.assert_equal(code, 0, "Unexpected error returned for null UTCTime")
else:
asserts.assert_true(code in [0, 1], "Unexpected error returned for non-null UTCTime")

self.print_step(3, "Read Granulatiry attribute")
granularity_dut = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.Granularity)
asserts.assert_less(granularity_dut, time_cluster.Enums.GranularityEnum.kUnknownEnumValue,
"Granularity out of expected range")
asserts.assert_not_equal(granularity_dut, time_cluster.Enums.GranularityEnum.kNoTimeGranularity)

th_utc = utc_time_in_matter_epoch()
utc_dut = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.UTCTime)
asserts.assert_is_not(utc_dut, NullValue, "Received null value for UTCTime after set")
if granularity_dut == time_cluster.Enums.GranularityEnum.kMinutesGranularity:
tolerance = timedelta(minutes=10)
else:
tolerance = timedelta(minutes=1)
compare_time(received=utc_dut, utc=th_utc, tolerance=tolerance)


if __name__ == "__main__":
default_matter_test_main()
145 changes: 145 additions & 0 deletions src/python_testing/TC_TIMESYNC_2_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#
# Copyright (c) 2023 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 typing
from datetime import timedelta

import chip.clusters as Clusters
from chip.interaction_model import InteractionModelError, Status
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main, type_matches, utc_time_in_matter_epoch
from mobly import asserts


class TC_TIMESYNC_2_4(MatterBaseTest):
async def read_ts_attribute_expect_success(self, attribute):
cluster = Clusters.Objects.TimeSynchronization
return await self.read_single_attribute_check_success(endpoint=self.endpoint, cluster=cluster, attribute=attribute)

async def send_set_time_zone_cmd(self, tz: typing.List[Clusters.Objects.TimeSynchronization.Structs.TimeZoneStruct]) -> Clusters.Objects.TimeSynchronization.Commands.SetTimeZoneResponse:
ret = await self.send_single_cmd(cmd=Clusters.Objects.TimeSynchronization.Commands.SetTimeZone(timeZone=tz), endpoint=self.endpoint)
asserts.assert_true(type_matches(ret, Clusters.Objects.TimeSynchronization.Commands.SetTimeZoneResponse),
"Unexpected return type for SetTimeZone")
return ret

async def send_set_time_zone_cmd_expect_error(self, tz: typing.List[Clusters.Objects.TimeSynchronization.Structs.TimeZoneStruct], error: Status) -> None:
try:
await self.send_single_cmd(cmd=Clusters.Objects.TimeSynchronization.Commands.SetTimeZone(timeZone=tz), endpoint=self.endpoint)
asserts.assert_true(False, "Unexpected SetTimeZone command success")
except InteractionModelError as e:
asserts.assert_equal(e.status, error, "Unexpected error returned")
pass

@async_test_body
async def test_TC_TIMESYNC_2_4(self):

self.endpoint = self.user_params.get("endpoint", 0)

time_cluster = Clusters.Objects.TimeSynchronization
tz_struct = time_cluster.Structs.TimeZoneStruct

self.print_step(0, "Commissioning, already done")
attributes = Clusters.TimeSynchronization.Attributes

self.print_step(1, "Read TimeZoneDatabase attribute")
tz_database_dut = await self.read_ts_attribute_expect_success(attribute=attributes.TimeZoneDatabase)

self.print_step(2, "Read TimeZoneListMaxSize attribute")
tz_max_size_dut = await self.read_ts_attribute_expect_success(attribute=attributes.TimeZoneListMaxSize)

self.print_step(3, "Send SetTimeZone command")
tz = [tz_struct(offset=0, validAt=0)]
ret = await self.send_set_time_zone_cmd(tz=tz)
asserts.assert_true(ret.DSTOffsetRequired, "DSTOffsetRequired not set to true")

self.print_step(4, "Send SetTimeZone command")
tz = [tz_struct(offset=0, validAt=0, name="")]
ret = await self.send_set_time_zone_cmd(tz=tz)
asserts.assert_true(ret.DSTOffsetRequired, "DSTOffsetRequired not set to true")

self.print_step(5, "Send SetTimeZone command")
tz = [tz_struct(offset=-43200, validAt=0)]
ret = await self.send_set_time_zone_cmd(tz=tz)
asserts.assert_true(ret.DSTOffsetRequired, "DSTOffsetRequired not set to true")

self.print_step(6, "Send SetTimeZone command")
tz = [tz_struct(offset=50400, validAt=0)]
ret = await self.send_set_time_zone_cmd(tz=tz)
asserts.assert_true(ret.DSTOffsetRequired, "DSTOffsetRequired not set to true")

self.print_step(7, "Send SetTimeZone command")
tz = [tz_struct(offset=3600, validAt=0, name="FakeCountry/FakeCity")]
ret = await self.send_set_time_zone_cmd(tz=tz)
asserts.assert_true(ret.DSTOffsetRequired, "DSTOffsetRequired not set to true")

self.print_step(8, "Send SetTimeZone command")
tz = [tz_struct(offset=3600, validAt=0, name="Europe/Dublin")]
ret = await self.send_set_time_zone_cmd(tz=tz)
if tz_database_dut is time_cluster.Enums.TimeZoneDatabaseEnum.kNone:
asserts.assert_true(ret.DSTOffsetRequired, "DSTOffsetRequired not set to true")

self.print_step(9, "Send SetTimeZone command")
if tz_max_size_dut == 2:
tz = [tz_struct(offset=3600, validAt=0, name="Europe/Dublin"),
tz_struct(offset=7200, validAt=utc_time_in_matter_epoch() + timedelta(minutes=2).microseconds, name="Europe/Athens")]
ret = await self.send_set_time_zone_cmd(tz=tz)

self.print_step(10, "Send SetTimeZone command - bad validAt time")
tz = [tz_struct(offset=3600, validAt=0, name="Europe/Dublin")]
await self.send_set_time_zone_cmd_expect_error(tz=tz, error=Status.ConstraintError)

self.print_step(11, "Send SetTimeZone command - bad second entry")
if tz_max_size_dut == 2:
tz = [tz_struct(offset=3600, validAt=0, name="Europe/Dublin"), tz_struct(offset=0, validAt=0, name="Europe/Athens")]
await self.send_set_time_zone_cmd_expect_error(tz=tz, error=Status.ConstraintError)

self.print_step(12, "Send SetTimeZone command - bad offset (low)")
tz = [tz_struct(offset=-43201, validAt=0)]
await self.send_set_time_zone_cmd_expect_error(tz=tz, error=Status.ConstraintError)

self.print_step(13, "Send SetTimeZone command - bad offset (high)")
tz = [tz_struct(offset=50401, validAt=0)]
await self.send_set_time_zone_cmd_expect_error(tz=tz, error=Status.ConstraintError)

self.print_step(14, "Send SetTimeZone command - too long name")
tz = [tz_struct(offset=50401, validAt=0, name="AVeryLongStringWithSixtyFiveChars/ThisIsSomeExtraPaddingForTheStr")]
await self.send_set_time_zone_cmd_expect_error(tz=tz, error=Status.ConstraintError)

self.print_step(15, "Send SetTimeZone command - too many entries")
if tz_max_size_dut == 2:
tz = [tz_struct(offset=3600, validAt=0, name="Europe/Dublin"),
tz_struct(offset=7200, validAt=utc_time_in_matter_epoch() +
timedelta(minutes=2).microseconds, name="Europe/Athens"),
tz_struct(offset=10800, validAt=utc_time_in_matter_epoch() +
timedelta(minutes=4).microseconds, name="Europe/Istanbul")
]
await self.send_set_time_zone_cmd_expect_error(tz=tz, error=Status.ResourceExhausted)

self.print_step(16, "Send SetTimeZone command - too many entries")
if tz_max_size_dut == 1:
tz = [tz_struct(offset=3600, validAt=0, name="Europe/Dublin"),
tz_struct(offset=7200, validAt=utc_time_in_matter_epoch() +
timedelta(minutes=2).microseconds, name="Europe/Athens")
]
await self.send_set_time_zone_cmd_expect_error(tz=tz, error=Status.ResourceExhausted)

self.print_step(17, "Reset time zone")
tz = [tz_struct(offset=0, validAt=0)]
await self.send_set_time_zone_cmd(tz=tz)


if __name__ == "__main__":
default_matter_test_main()
Loading

0 comments on commit 1672178

Please sign in to comment.