-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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 <[email protected]>
- Loading branch information
Showing
10 changed files
with
1,134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.