From 1a217726e0a72947bbde3c95999d2191ed9158ef Mon Sep 17 00:00:00 2001 From: cecille Date: Tue, 6 May 2025 10:25:22 -0400 Subject: [PATCH] TC-IDM-13.1: Add check for default fixed labels These appear a LOT in production data. Add a warning. These don't actually make any sense to have as fixed labels - there is no way to tell a-priori that a device will always reside in bedroom 2, on the second floor on the north side facing upwards. --- src/python_testing/TC_DefaultWarnings.py | 36 ++++++++++--- src/python_testing/TestDefaultWarnings.py | 61 ++++++++++++++++++++--- 2 files changed, 83 insertions(+), 14 deletions(-) diff --git a/src/python_testing/TC_DefaultWarnings.py b/src/python_testing/TC_DefaultWarnings.py index b85af2c11e373c..b3f18d91c77dd1 100644 --- a/src/python_testing/TC_DefaultWarnings.py +++ b/src/python_testing/TC_DefaultWarnings.py @@ -29,7 +29,7 @@ # --commissioning-method on-network # --discriminator 1234 # --passcode 20202021 -# --bool-arg pixit_allow_test_in_product_name:True pixit_allow_test_in_vendor_name:True pixit_allow_default_vendor_id:True +# --bool-arg pixit_allow_test_in_product_name:True pixit_allow_test_in_vendor_name:True pixit_allow_default_vendor_id:True pixit_allow_fixed_label_default_values:True # --trace-to json:${TRACE_TEST_JSON}.json # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS === @@ -49,7 +49,14 @@ FLAG_UNIT_TESTING = "pixit_allow_unit_testing_cluster" FLAG_FAULT_INJECTION = "pixit_allow_fault_injection_cluster" FLAG_SAMPLE_MEI = "pixit_allow_sample_mei_cluster" -FLAG_FIXED_LABEL = "pixit_allow_empty_fixed_label_list" +FLAG_FIXED_LABEL_EMPTY = "pixit_allow_empty_fixed_label_list" +FLAG_FIXED_LABEL_DEFAULT_VALUES = "pixit_allow_fixed_label_default_values" + + +DEFAULT_FIXED_LABEL_VALUES = [Clusters.FixedLabel.Structs.LabelStruct(label='room', value='bedroom 2'), + Clusters.FixedLabel.Structs.LabelStruct(label='orientation', value='North'), + Clusters.FixedLabel.Structs.LabelStruct(label='floor', value='2'), + Clusters.FixedLabel.Structs.LabelStruct(label='direction', value='up')] def _problem(location: ProblemLocation, msg: str): @@ -124,8 +131,8 @@ def check_fault_injection_cluster_presence(self): def check_sample_mei_cluster_presence(self): return self._check_testing_cluster_presence(Clusters.SampleMei) - @warning_wrapper(FLAG_FIXED_LABEL) - def check_fixed_label_cluster(self): + @warning_wrapper(FLAG_FIXED_LABEL_EMPTY) + def check_fixed_label_cluster_empty(self): cluster = Clusters.FixedLabel attr = cluster.Attributes.LabelList if cluster in self.endpoints[0].keys(): @@ -135,6 +142,18 @@ def check_fixed_label_cluster(self): else: self.mark_current_step_skipped() + @warning_wrapper(FLAG_FIXED_LABEL_DEFAULT_VALUES) + def check_fixed_label_cluster_defaults(self): + cluster = Clusters.FixedLabel + attr = cluster.Attributes.LabelList + if cluster in self.endpoints[0].keys(): + label_list = self.endpoints[0][cluster][attr] + + if any([label for label in label_list if label in DEFAULT_FIXED_LABEL_VALUES]): + return _problem(AttributePathLocation(0, cluster.id, attr.attribute_id), f"Fixed label list contains default labels:\ndefaults {DEFAULT_FIXED_LABEL_VALUES}\nlist={label_list}") + else: + self.mark_current_step_skipped() + class TC_DefaultChecker(MatterBaseTest, DefaultChecker): @async_test_body @@ -163,8 +182,9 @@ def steps_TC_IDM_13_1(self): TestStep(8, f"If the {FLAG_SAMPLE_MEI} flag is not set, check for the presence of a sample mei cluster on any endpoint", "Sample MEI cluster does not appear on any endpoint"), TestStep( - 9, f"If the {FLAG_FIXED_LABEL} flag is not set, and the FixedLabel cluster is present on the device, ,check that the fixed label cluster list is not empty", "List is not empty"), - TestStep(10, "Fail on any problems") + 9, f"If the {FLAG_FIXED_LABEL_EMPTY} flag is not set, and the FixedLabel cluster is present on the device, check that the fixed label cluster list is not empty", "List is not empty"), + TestStep(10, f"If the {FLAG_FIXED_LABEL_DEFAULT_VALUES} flag is not set, and the FixedLabel cluster is present on the device, check that the fixed label cluster list does not contain any of the default labels", "List does not contain default labels"), + TestStep(11, "Fail on any problems") ] return steps @@ -189,8 +209,10 @@ def test_TC_IDM_13_1(self): self.step(8) self.check_sample_mei_cluster_presence() self.step(9) - self.check_fixed_label_cluster() + self.check_fixed_label_cluster_empty() self.step(10) + self.check_fixed_label_cluster_defaults() + self.step(11) if self.problems: asserts.fail("One or more default values found on device") diff --git a/src/python_testing/TestDefaultWarnings.py b/src/python_testing/TestDefaultWarnings.py index 8446e1c4d0eae3..8ae56dd8445793 100644 --- a/src/python_testing/TestDefaultWarnings.py +++ b/src/python_testing/TestDefaultWarnings.py @@ -223,12 +223,12 @@ def test_sample_mei_is_not_present_check(self): self._cluster_presence_test(Clusters.SampleMei, self.test.check_sample_mei_cluster_presence, TC_DefaultWarnings.FLAG_SAMPLE_MEI) - def test_fixed_label_is_not_default_check(self): + def test_fixed_label_is_not_empty_check(self): def run_check(label_list: list[Clusters.FixedLabel.Structs.LabelStruct], set_override: bool, expect_problem: bool): - self.test.user_params = {TC_DefaultWarnings.FLAG_FIXED_LABEL: set_override} + self.test.user_params = {TC_DefaultWarnings.FLAG_FIXED_LABEL_EMPTY: set_override} self.test.problems = [] self.test.endpoints = {0: {Clusters.FixedLabel: {Clusters.FixedLabel.Attributes.LabelList: label_list}}} - self.test.check_fixed_label_cluster() + self.test.check_fixed_label_cluster_empty() if expect_problem: asserts.assert_equal(len(self.test.problems), 1, f"did not generate expected problem when testing with empty fixed label list (override = {set_override})") @@ -248,21 +248,68 @@ def run_check(label_list: list[Clusters.FixedLabel.Structs.LabelStruct], set_ove self.test.problems = [] self.test.user_params = {} self.test.endpoints = {0: {}} - self.test.check_fixed_label_cluster() + self.test.check_fixed_label_cluster_empty() asserts.assert_equal(len(self.test.problems), 0, - "Unexpected problem when testing device with no TimeFormatLocalization cluster") + "Unexpected problem when testing device with no FixedLabel cluster") # Should have marked this as skipped asserts.assert_equal(self.skipped, 1, "Some override tests did not mark steps skipped") # Flag should also work here self.skipped = 0 - self.test.user_params = {TC_DefaultWarnings.FLAG_FIXED_LABEL: True} - self.test.check_fixed_label_cluster() + self.test.user_params = {TC_DefaultWarnings.FLAG_FIXED_LABEL_EMPTY: True} + self.test.check_fixed_label_cluster_empty() asserts.assert_equal(len(self.test.problems), 0, "Unexpected problem when testing device with no TimeFormatLocalization cluster and override") # Should have marked this as skipped asserts.assert_equal(self.skipped, 1, "Some override tests did not mark steps skipped") + def test_fixed_label_is_not_default_check(self): + def run_check(label_list: list[Clusters.FixedLabel.Structs.LabelStruct], set_override: bool, expect_problem: bool): + self.skipped = 0 + self.test.user_params = {TC_DefaultWarnings.FLAG_FIXED_LABEL_DEFAULT_VALUES: set_override} + self.test.problems = [] + self.test.endpoints = {0: {Clusters.FixedLabel: {Clusters.FixedLabel.Attributes.LabelList: label_list}}} + self.test.check_fixed_label_cluster_defaults() + if expect_problem: + asserts.assert_equal(len(self.test.problems), 1, + f"did not generate expected problem when testing with empty fixed label list (override = {set_override})") + else: + asserts.assert_equal(len(self.test.problems), 0, + f"Unexpected problem when testing with non-empty fixed label list (override = {set_override})") + if set_override: + asserts.assert_equal(self.skipped, 1, "Test with override did not mark steps skipped") + + asserts.assert_equal(self.skipped, 0, "Skip not reset properly") + for default_label in TC_DefaultWarnings.DEFAULT_FIXED_LABEL_VALUES: + run_check([default_label], set_override=False, expect_problem=True) + run_check([default_label], set_override=True, expect_problem=False) + + run_check(TC_DefaultWarnings.DEFAULT_FIXED_LABEL_VALUES, set_override=False, expect_problem=True) + run_check(TC_DefaultWarnings.DEFAULT_FIXED_LABEL_VALUES, set_override=True, expect_problem=False) + + run_check([Clusters.FixedLabel.Structs.LabelStruct("test", "val")], set_override=False, expect_problem=False) + run_check([Clusters.FixedLabel.Structs.LabelStruct("test", "val")], set_override=True, expect_problem=False) + + # Cluster not present + self.skipped = 0 + self.test.problems = [] + self.test.user_params = {} + self.test.endpoints = {0: {}} + self.test.check_fixed_label_cluster_defaults() + asserts.assert_equal(len(self.test.problems), 0, + "Unexpected problem when testing device with no FixedLabel cluster") + # Should have marked this as skipped + asserts.assert_equal(self.skipped, 1, "Some override tests did not mark steps skipped") + + # Flag should also work here + self.skipped = 0 + self.test.user_params = {TC_DefaultWarnings.FLAG_FIXED_LABEL_DEFAULT_VALUES: True} + self.test.check_fixed_label_cluster_defaults() + asserts.assert_equal(len(self.test.problems), 0, + "Unexpected problem when testing device with no FixedLabel cluster and override") + # Should have marked this as skipped + asserts.assert_equal(self.skipped, 1, "Some override tests did not mark steps skipped") + if __name__ == "__main__": default_matter_test_main()