Skip to content

Commit 6e31453

Browse files
j-ororkerestyled-commitscecille
authored
[Fix] Proposed resolution of issue #230: remove PICS from timesync tests (#33953)
* Created proposed resolution of Github issue #230: * Removed PICS from TC_TIMESYNC_2_1 and TC_TIMESYNC_2_2 in python_testing folder * Added using the wait_for_user_input() to allow user to inform if certain features are present on DUT * Updated TC_TIMESYNC_2_1 test: * Now utilizes Clusters.TimeSynchronization.Bitmaps.Feature to check supported features on DUT in place of PICS or waiting for user input. * Restyled by autopep8 * Applied stylization fix to TC_TIMESYNC_2_2 test module as mentioned in restyled.io check. * Restyled by autopep8 * Removed unnecessary pics_TC_TIMESYNC_2_1() from TC_TIMESYNC_2_1 class as no longer needed with recent changes implemented. * Updates to TC_TIMESYNC_2_1 and 2_2 test modules: - Restored pics_TC_TIMESYNC_2_1 and pics_TC_TIMESYNC_2_2 functions - Added if check for timesource attribute ID for test step 3 in TC_TIMESYNC_2_1 test module - Updated endpoint variable to statically be set to 0 * Restyled by autopep8 * Updated TC_TIMESYNC_2_1 and TC_TIMESYNC_2_2: - Changed method for getting attribute_list -- now using get_single_attribute_expect_success() from matter_testing_support module - Updated time source test step 5 to include if check in TC_TIMESYNC_2_2 test module to match with TC_TIMESYNC_2_1 * Restyled by autopep8 * Updated TC_TIMESYNC_2_2 with suggestions from Cecille - Changed class name value assigned to time_cluster variable - Updated timesync_attr_list and timesource_attr_id variables to contain time_cluster in value in place of Clusters.TimeSynchronization * Apply suggestions from code review from Cecille Adding these suggestions from Cecille after testing in local dev env Co-authored-by: C Freeman <cecille@google.com> --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: C Freeman <cecille@google.com>
1 parent bd2fef3 commit 6e31453

File tree

2 files changed

+44
-55
lines changed

2 files changed

+44
-55
lines changed

src/python_testing/TC_TIMESYNC_2_1.py

+39-53
Original file line numberDiff line numberDiff line change
@@ -41,40 +41,47 @@ def pics_TC_TIMESYNC_2_1(self) -> list[str]:
4141

4242
@async_test_body
4343
async def test_TC_TIMESYNC_2_1(self):
44+
endpoint = 0
4445

45-
endpoint = self.user_params.get("endpoint", 0)
46+
features = await self.read_single_attribute(dev_ctrl=self.default_controller, node_id=self.dut_node_id,
47+
endpoint=endpoint, attribute=Clusters.TimeSynchronization.Attributes.FeatureMap)
48+
49+
self.supports_time_zone = bool(features & Clusters.TimeSynchronization.Bitmaps.Feature.kTimeZone)
50+
self.supports_ntpc = bool(features & Clusters.TimeSynchronization.Bitmaps.Feature.kNTPClient)
51+
self.supports_ntps = bool(features & Clusters.TimeSynchronization.Bitmaps.Feature.kNTPServer)
52+
self.supports_trusted_time_source = bool(features & Clusters.TimeSynchronization.Bitmaps.Feature.kTimeSyncClient)
53+
54+
time_cluster = Clusters.TimeSynchronization
55+
timesync_attr_list = time_cluster.Attributes.AttributeList
56+
attribute_list = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=time_cluster, attribute=timesync_attr_list)
57+
timesource_attr_id = time_cluster.Attributes.TimeSource.attribute_id
4658

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

5062
self.print_step(2, "Read Granularity attribute")
51-
if self.check_pics("TIMESYNC.S.A0001"):
52-
granularity_dut = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.Granularity)
53-
asserts.assert_less(granularity_dut, Clusters.TimeSynchronization.Enums.GranularityEnum.kUnknownEnumValue,
54-
"Granularity is not in valid range")
55-
else:
56-
asserts.assert_true(False, "Granularity is a mandatory attribute and must be present in the PICS file")
63+
granularity_dut = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.Granularity)
64+
asserts.assert_less(granularity_dut, Clusters.TimeSynchronization.Enums.GranularityEnum.kUnknownEnumValue,
65+
"Granularity is not in valid range")
5766

5867
self.print_step(3, "Read TimeSource")
59-
if self.check_pics("TIMESYNC.S.A0002"):
68+
if timesource_attr_id in attribute_list:
6069
time_source = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.TimeSource)
6170
asserts.assert_less(time_source, Clusters.TimeSynchronization.Enums.TimeSourceEnum.kUnknownEnumValue,
6271
"TimeSource is not in valid range")
6372

6473
self.print_step(4, "Read TrustedTimeSource")
65-
if self.check_pics("TIMESYNC.S.A0003"):
74+
if self.supports_trusted_time_source:
6675
trusted_time_source = await self.read_ts_attribute_expect_success(endpoint=endpoint,
6776
attribute=attributes.TrustedTimeSource)
6877
if trusted_time_source is not NullValue:
6978
asserts.assert_less_equal(trusted_time_source.fabricIndex, 0xFE,
7079
"FabricIndex for the TrustedTimeSource is out of range")
7180
asserts.assert_greater_equal(trusted_time_source.fabricIndex, 1,
7281
"FabricIndex for the TrustedTimeSource is out of range")
73-
elif self.check_pics("TIMESYNC.S.F03"):
74-
asserts.assert_true(False, "TrustedTimeSource is mandatory if the TSC feature (TIMESYNC.S.F03) is supported")
7582

7683
self.print_step(5, "Read DefaultNTP")
77-
if self.check_pics("TIMESYNC.S.A0004"):
84+
if self.supports_ntpc:
7885
default_ntp = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.DefaultNTP)
7986
if default_ntp is not NullValue:
8087
asserts.assert_less_equal(len(default_ntp), 128, "DefaultNTP length must be less than 128")
@@ -87,11 +94,9 @@ async def test_TC_TIMESYNC_2_1(self):
8794
is_ip_addr = False
8895
pass
8996
asserts.assert_true(is_web_addr or is_ip_addr, "Returned DefaultNTP value is not a IP address or web address")
90-
elif self.check_pics("TIMESYNC.S.F01"):
91-
asserts.assert_true(False, "DefaultNTP is mandatory if the NTPC (TIMESYNC.S.F01) feature is supported")
9297

9398
self.print_step(6, "Read TimeZone")
94-
if self.check_pics("TIMESYNC.S.A0005"):
99+
if self.supports_time_zone:
95100
tz_dut = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.TimeZone)
96101
asserts.assert_greater_equal(len(tz_dut), 1, "TimeZone must have at least one entry in the list")
97102
asserts.assert_less_equal(len(tz_dut), 2, "TimeZone may have a maximum of two entries in the list")
@@ -104,11 +109,9 @@ async def test_TC_TIMESYNC_2_1(self):
104109
asserts.assert_equal(tz_dut[0].validAt, 0, "TimeZone list first entry must have a 0 ValidAt time")
105110
if len(tz_dut) > 1:
106111
asserts.assert_not_equal(tz_dut[1].validAt, 0, "TimeZone list second entry must have a non-zero ValidAt time")
107-
elif self.check_pics("TIMESYNC.S.F00"):
108-
asserts.assert_true(False, "TimeZone is mandatory if the TZ (TIMESYNC.S.F00) feature is supported")
109112

110113
self.print_step(7, "Read DSTOffset")
111-
if self.check_pics("TIMESYNC.S.A0006"):
114+
if self.supports_time_zone:
112115
dst_dut = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.DSTOffset)
113116
last_valid_until = -1
114117
last_valid_starting = -1
@@ -121,28 +124,23 @@ async def test_TC_TIMESYNC_2_1(self):
121124
last_valid_until = dst.validUntil
122125
if dst.validUntil is NullValue or dst.validUntil is None:
123126
asserts.assert_equal(dst, dst_dut[-1], "DSTOffset list must have Null ValidUntil at the end")
124-
elif self.check_pics("TIMESYNC.S.F00"):
125-
asserts.assert_true(False, "DSTOffset is mandatory if the TZ (TIMESYNC.S.F00) feature is supported")
126127

127128
self.print_step(8, "Read UTCTime")
128-
if self.check_pics("TIMESYNC.S.A0000"):
129-
utc_dut = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.UTCTime)
130-
if utc_dut is NullValue:
131-
asserts.assert_equal(granularity_dut, Clusters.TimeSynchronization.Enums.GranularityEnum.kNoTimeGranularity)
132-
else:
133-
asserts.assert_not_equal(granularity_dut, Clusters.TimeSynchronization.Enums.GranularityEnum.kNoTimeGranularity)
134-
if granularity_dut is Clusters.TimeSynchronization.Enums.GranularityEnum.kMinutesGranularity:
135-
toleranace = timedelta(minutes=10)
136-
else:
137-
toleranace = timedelta(minutes=1)
138-
delta_us = abs(utc_dut - utc_time_in_matter_epoch())
139-
delta = timedelta(microseconds=delta_us)
140-
asserts.assert_less_equal(delta, toleranace, "UTC time is not within tolerance of TH")
129+
utc_dut = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.UTCTime)
130+
if utc_dut is NullValue:
131+
asserts.assert_equal(granularity_dut, Clusters.TimeSynchronization.Enums.GranularityEnum.kNoTimeGranularity)
141132
else:
142-
asserts.assert_true(False, "UTCTime is a mandatory attribute and must be present in the PICS file")
133+
asserts.assert_not_equal(granularity_dut, Clusters.TimeSynchronization.Enums.GranularityEnum.kNoTimeGranularity)
134+
if granularity_dut is Clusters.TimeSynchronization.Enums.GranularityEnum.kMinutesGranularity:
135+
toleranace = timedelta(minutes=10)
136+
else:
137+
toleranace = timedelta(minutes=1)
138+
delta_us = abs(utc_dut - utc_time_in_matter_epoch())
139+
delta = timedelta(microseconds=delta_us)
140+
asserts.assert_less_equal(delta, toleranace, "UTC time is not within tolerance of TH")
143141

144142
self.print_step(9, "Read LocalTime")
145-
if self.check_pics("TIMESYNC.S.A0007"):
143+
if self.supports_time_zone:
146144
utc_dut = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.UTCTime)
147145
local_dut = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.LocalTime)
148146
if utc_dut is NullValue:
@@ -155,45 +153,33 @@ async def test_TC_TIMESYNC_2_1(self):
155153
delta = timedelta(microseconds=delta_us)
156154
toleranace = timedelta(minutes=1)
157155
asserts.assert_less_equal(delta, toleranace, "Local time caluclation is not within tolerance of calculated value")
158-
elif self.check_pics("TIMESYNC.S.F00"):
159-
asserts.assert_true(False, "LocalTime is mandatory if the TZ (TIMESYNC.S.F00) feature is supported")
160156

161157
self.print_step(10, "Read TimeZoneDatabase")
162-
if self.check_pics("TIMESYNC.S.A0008"):
158+
if self.supports_time_zone:
163159
tz_db_dut = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.TimeZoneDatabase)
164160
asserts.assert_less(tz_db_dut, Clusters.TimeSynchronization.Enums.TimeZoneDatabaseEnum.kUnknownEnumValue,
165161
"TimeZoneDatabase is not in valid range")
166-
elif self.check_pics("TIMESYNC.S.F00"):
167-
asserts.assert_true(False, "TimeZoneDatabase is mandatory if the TZ (TIMESYNC.S.F00) feature is supported")
168162

169163
self.print_step(11, "Read NTPServerAvailable")
170-
if self.check_pics("TIMESYNC.S.A0009"):
164+
if self.supports_ntps:
171165
# bool typechecking happens in the test read functions, so all we need to do here is do the read
172166
await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.NTPServerAvailable)
173-
elif self.check_pics("TIMESYNC.S.F02"):
174-
asserts.assert_true(False, "NTPServerAvailable is mandatory if the NTPS (TIMESYNC.S.F02) feature is supported")
175167

176168
self.print_step(12, "Read TimeZoneListMaxSize")
177-
if self.check_pics("TIMESYNC.S.A000a"):
169+
if self.supports_time_zone:
178170
size = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.TimeZoneListMaxSize)
179171
asserts.assert_greater_equal(size, 1, "TimeZoneListMaxSize must be at least 1")
180172
asserts.assert_less_equal(size, 2, "TimeZoneListMaxSize must be max 2")
181-
elif self.check_pics("TIMESYNC.S.F00"):
182-
asserts.assert_true(False, "TimeZoneListMaxSize is mandatory if the TZ (TIMESYNC.S.F00) feature is supported")
183173

184174
self.print_step(13, "Read DSTOffsetListMaxSize")
185-
if self.check_pics("TIMESYNC.S.A000b"):
175+
if self.supports_time_zone:
186176
size = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.DSTOffsetListMaxSize)
187177
asserts.assert_greater_equal(size, 1, "DSTOffsetListMaxSize must be at least 1")
188-
elif self.check_pics("TIMESYNC.S.F00"):
189-
asserts.assert_true(False, "DSTOffsetListMaxSize is mandatory if the TZ (TIMESYNC.S.F00) feature is supported")
190178

191179
self.print_step(14, "Read SupportsDNSResolve")
192-
if self.check_pics("TIMESYNC.S.A0004"):
193-
# bool typechecking happens in the test read functions, so all we need to do here is do the read
180+
# bool typechecking happens in the test read functions, so all we need to do here is do the read
181+
if self.supports_ntpc:
194182
await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.SupportsDNSResolve)
195-
elif self.check_pics("TIMESYNC.S.F01"):
196-
asserts.assert_true(False, "SupportsDNSResolve is mandatory if the NTPC (TIMESYNC.S.F01) feature is supported")
197183

198184

199185
if __name__ == "__main__":

src/python_testing/TC_TIMESYNC_2_2.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ async def test_TC_TIMESYNC_2_2(self):
4545
# Time sync is required to be on endpoint 0 if it is present
4646
endpoint = 0
4747

48-
time_cluster = Clusters.Objects.TimeSynchronization
48+
time_cluster = Clusters.TimeSynchronization
49+
timesync_attr_list = time_cluster.Attributes.AttributeList
50+
attribute_list = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=time_cluster, attribute=timesync_attr_list)
51+
timesource_attr_id = time_cluster.Attributes.TimeSource.attribute_id
4952

5053
self.print_step(1, "Commissioning, already done")
5154
attributes = Clusters.TimeSynchronization.Attributes
@@ -85,7 +88,7 @@ async def test_TC_TIMESYNC_2_2(self):
8588
compare_time(received=utc_dut, utc=th_utc, tolerance=tolerance)
8689

8790
self.print_step(5, "Read time source")
88-
if self.check_pics("TIMESYNC.S.A0002"):
91+
if timesource_attr_id in attribute_list:
8992
source = await self.read_ts_attribute_expect_success(endpoint=endpoint, attribute=attributes.TimeSource)
9093
if utc_dut_initial is NullValue:
9194
asserts.assert_equal(source, Clusters.Objects.TimeSynchronization.Enums.TimeSourceEnum.kAdmin)

0 commit comments

Comments
 (0)