Skip to content

Commit

Permalink
Timesync commissioner: Fix TrustedTimeSource. (#28284)
Browse files Browse the repository at this point in the history
Turns out I never set it, and the tests didn't catch it because I
was so preocupied with validating the state machine that I never
checked the actual values. Whoops.

Test: Please see test included in PR.
  • Loading branch information
cecille authored and pull[bot] committed Nov 6, 2023
1 parent 282f3b2 commit 9564385
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
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

0 comments on commit 9564385

Please sign in to comment.