Skip to content

TC-IDM-13.1: Add check for default fixed labels #38805

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 29 additions & 7 deletions src/python_testing/TC_DefaultWarnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===
Expand All @@ -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):
Expand Down Expand Up @@ -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():
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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")
Expand Down
61 changes: 54 additions & 7 deletions src/python_testing/TestDefaultWarnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})")
Expand All @@ -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()
Loading