Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timesync commissioner: Fix TrustedTimeSource. #28284

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2678,7 +2678,7 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio
return;
}
TimeSynchronization::Commands::SetTrustedTimeSource::Type request;
request.trustedTimeSource.SetNull();
request.trustedTimeSource = params.GetTrustedTimeSource().Value();
SendCommand(proxy, request, OnBasicSuccess, OnBasicFailure, endpoint, timeout);
break;
}
Expand Down
27 changes: 25 additions & 2 deletions src/python_testing/TestCommissioningTimeSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ async def commission_stages(self, time_zone: bool, dst: bool, default_ntp: bool,
self.commissioner.SetTimeZone(offset=3600, validAt=0)
if dst:
six_months = 1.577e+13 # in us
self.commissioner.SetDSTOffset(offset=3600, validStarting=0, validUntil=utc_time_in_matter_epoch() + int(six_months))
dst_valid_until = utc_time_in_matter_epoch() + int(six_months)
self.commissioner.SetDSTOffset(offset=3600, validStarting=0, validUntil=dst_valid_until)
if default_ntp:
self.commissioner.SetDefaultNTP("fe80::1")
if trusted_time_source:
Expand All @@ -130,7 +131,6 @@ async def commission_stages(self, time_zone: bool, dst: bool, default_ntp: bool,
should_set_default_ntp = bool(self.supports_default_ntp and default_ntp)
should_set_trusted_time = bool(self.supports_trusted_time_source and trusted_time_source)

print(f'{should_set_time_zone} {should_set_dst} {should_set_default_ntp} {should_set_trusted_time}')
asserts.assert_equal(self.commissioner.CheckStageSuccessful(kConfigureTimeZone),
should_set_time_zone, 'Incorrect value for time zone stage check')
asserts.assert_equal(self.commissioner.CheckStageSuccessful(kConfigureDSTOffset),
Expand All @@ -140,6 +140,29 @@ async def commission_stages(self, time_zone: bool, dst: bool, default_ntp: bool,
asserts.assert_equal(self.commissioner.CheckStageSuccessful(kConfigureTrustedTimeSource),
should_set_trusted_time, 'Incorrect value for kConfigureTrustedTimeSource stage')

if should_set_time_zone:
received = await self.read_single_attribute_check_success(cluster=Clusters.TimeSynchronization, attribute=Clusters.TimeSynchronization.Attributes.TimeZone)
expected = [Clusters.TimeSynchronization.Structs.TimeZoneStruct(offset=3600, validAt=0)]
asserts.assert_equal(received, expected, "Time zone was not correctly set by commissioner")

if should_set_dst:
received = await self.read_single_attribute_check_success(cluster=Clusters.TimeSynchronization, attribute=Clusters.TimeSynchronization.Attributes.DSTOffset)
expected = [Clusters.TimeSynchronization.Structs.DSTOffsetStruct(
offset=3600, validStarting=0, validUntil=dst_valid_until)]
asserts.assert_equal(received, expected, "DST was not set correctly by the commissioner")

if should_set_trusted_time:
fabric_idx = await self.read_single_attribute_check_success(cluster=Clusters.OperationalCredentials, attribute=Clusters.OperationalCredentials.Attributes.CurrentFabricIndex, dev_ctrl=self.commissioner)
received = await self.read_single_attribute_check_success(cluster=Clusters.TimeSynchronization, attribute=Clusters.TimeSynchronization.Attributes.TrustedTimeSource)
expected = Clusters.TimeSynchronization.Structs.TrustedTimeSourceStruct(
fabricIndex=fabric_idx, nodeID=self.commissioner.nodeId, endpoint=0)
asserts.assert_equal(received, expected, "Trusted Time source was not set properly")

if should_set_default_ntp:
received = await self.read_single_attribute_check_success(cluster=Clusters.TimeSynchronization, attribute=Clusters.TimeSynchronization.Attributes.DefaultNTP)
expected = "fe80::1"
asserts.assert_equal(received, expected, "Default NTP was not set properly")

@async_test_body
async def test_CommissioningAllBasic(self):
# We want to assess all combos (ie, all flags in the range of 0b0000 to 0b1111)
Expand Down