|
34 | 34 | # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto |
35 | 35 | # === END CI TEST ARGUMENTS === |
36 | 36 |
|
37 | | -from typing import Optional |
38 | | - |
39 | 37 | from mobly import asserts |
| 38 | +from test_testing.DefaultChecker import (FLAG_DEFAULT_CALENDAR_FORMAT, FLAG_FAULT_INJECTION, FLAG_FIXED_LABEL_DEFAULT_VALUES, |
| 39 | + FLAG_FIXED_LABEL_EMPTY, FLAG_PRODUCT_NAME, FLAG_SAMPLE_MEI, FLAG_UNIT_TESTING, |
| 40 | + FLAG_VENDOR_ID, FLAG_VENDOR_NAME, DefaultChecker) |
40 | 41 |
|
41 | | -import matter.clusters as Clusters |
42 | | -from matter.testing.basic_composition import BasicCompositionTests |
43 | 42 | from matter.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main |
44 | | -from matter.testing.problem_notices import (AttributePathLocation, ClusterPathLocation, ProblemLocation, ProblemNotice, |
45 | | - ProblemSeverity) |
46 | | - |
47 | | -FLAG_PRODUCT_NAME = "pixit_allow_test_in_product_name" |
48 | | -FLAG_VENDOR_NAME = "pixit_allow_test_in_vendor_name" |
49 | | -FLAG_VENDOR_ID = "pixit_allow_default_vendor_id" |
50 | | -FLAG_DEFAULT_CALENDAR_FORMAT = "pixit_allow_default_calendar_format" |
51 | | -FLAG_UNIT_TESTING = "pixit_allow_unit_testing_cluster" |
52 | | -FLAG_FAULT_INJECTION = "pixit_allow_fault_injection_cluster" |
53 | | -FLAG_SAMPLE_MEI = "pixit_allow_sample_mei_cluster" |
54 | | -FLAG_FIXED_LABEL_EMPTY = "pixit_allow_empty_fixed_label_list" |
55 | | -FLAG_FIXED_LABEL_DEFAULT_VALUES = "pixit_allow_fixed_label_default_values" |
56 | | - |
57 | | - |
58 | | -DEFAULT_FIXED_LABEL_VALUES = [Clusters.FixedLabel.Structs.LabelStruct(label='room', value='bedroom 2'), |
59 | | - Clusters.FixedLabel.Structs.LabelStruct(label='orientation', value='North'), |
60 | | - Clusters.FixedLabel.Structs.LabelStruct(label='floor', value='2'), |
61 | | - Clusters.FixedLabel.Structs.LabelStruct(label='direction', value='up')] |
62 | | - |
63 | | - |
64 | | -def _problem(location: ProblemLocation, msg: str): |
65 | | - return ProblemNotice("Default Value Checker", location, ProblemSeverity.ERROR, msg) |
66 | | - |
67 | | - |
68 | | -def warning_wrapper(override_flag: str): |
69 | | - def warning_wrapper_internal(body): |
70 | | - def runner(self: MatterBaseTest): |
71 | | - skip = self.user_params.get(override_flag, False) |
72 | | - if not skip: |
73 | | - problem: ProblemNotice = body(self) |
74 | | - if problem: |
75 | | - problem.problem += f"\nIf this is intended, you may disable this check using the {override_flag}" |
76 | | - self.problems.append(problem) |
77 | | - else: |
78 | | - self.mark_current_step_skipped() |
79 | | - return runner |
80 | | - return warning_wrapper_internal |
81 | | - |
82 | | - |
83 | | -class DefaultChecker(BasicCompositionTests): |
84 | | - @warning_wrapper(FLAG_PRODUCT_NAME) |
85 | | - def check_default_product_name(self): |
86 | | - cluster = Clusters.BasicInformation |
87 | | - attr = cluster.Attributes.ProductName |
88 | | - val = self.endpoints[0][cluster][attr] |
89 | | - if "test" in val.lower(): |
90 | | - return _problem(AttributePathLocation(0, cluster.id, attr.attribute_id), f"Product name contains test ({val})") |
91 | | - |
92 | | - @warning_wrapper(FLAG_VENDOR_NAME) |
93 | | - def check_default_vendor_name(self): |
94 | | - cluster = Clusters.BasicInformation |
95 | | - attr = cluster.Attributes.VendorName |
96 | | - val = self.endpoints[0][cluster][attr] |
97 | | - if "test" in val.lower(): |
98 | | - return _problem(AttributePathLocation(0, cluster.id, attr.attribute_id), f"Vendor name contains test ({val})") |
99 | | - |
100 | | - @warning_wrapper(FLAG_VENDOR_ID) |
101 | | - def check_default_vendor_id(self): |
102 | | - cluster = Clusters.BasicInformation |
103 | | - attr = cluster.Attributes.VendorID |
104 | | - val = self.endpoints[0][cluster][attr] |
105 | | - if val == 0x0000 or val > 0xFFF0: |
106 | | - return _problem(AttributePathLocation(0, cluster.id, attr.attribute_id), f"Vendor is not in manufacturer code range ({val})") |
107 | | - |
108 | | - @warning_wrapper(FLAG_DEFAULT_CALENDAR_FORMAT) |
109 | | - def check_default_calendar_format(self): |
110 | | - cluster = Clusters.TimeFormatLocalization |
111 | | - attr = cluster.Attributes.ActiveCalendarType |
112 | | - if cluster in self.endpoints[0].keys() and attr in self.endpoints[0][cluster].keys(): |
113 | | - val = self.endpoints[0][cluster][attr] |
114 | | - if val == cluster.Enums.CalendarTypeEnum.kBuddhist: |
115 | | - return _problem(AttributePathLocation(0, cluster.id, attr.attribute_id), "Calendar format is set to default (Buddhist)") |
116 | | - else: |
117 | | - self.mark_current_step_skipped() |
118 | | - |
119 | | - def _check_testing_cluster_presence(self, cluster: Clusters.ClusterObjects.Cluster) -> Optional[ProblemNotice]: |
120 | | - for endpoint_num, endpoint in self.endpoints.items(): |
121 | | - if cluster.id in endpoint[Clusters.Descriptor][Clusters.Descriptor.Attributes.ServerList]: |
122 | | - return _problem(ClusterPathLocation(endpoint_num, cluster.id), f"{cluster.__name__} cluster found on device.") |
123 | | - |
124 | | - @warning_wrapper(FLAG_UNIT_TESTING) |
125 | | - def check_unit_testing_cluster_presence(self): |
126 | | - return self._check_testing_cluster_presence(Clusters.UnitTesting) |
127 | | - |
128 | | - @warning_wrapper(FLAG_FAULT_INJECTION) |
129 | | - def check_fault_injection_cluster_presence(self): |
130 | | - return self._check_testing_cluster_presence(Clusters.FaultInjection) |
131 | | - |
132 | | - @warning_wrapper(FLAG_SAMPLE_MEI) |
133 | | - def check_sample_mei_cluster_presence(self): |
134 | | - return self._check_testing_cluster_presence(Clusters.SampleMei) |
135 | | - |
136 | | - @warning_wrapper(FLAG_FIXED_LABEL_EMPTY) |
137 | | - def check_fixed_label_cluster_empty(self): |
138 | | - cluster = Clusters.FixedLabel |
139 | | - attr = cluster.Attributes.LabelList |
140 | | - if cluster in self.endpoints[0].keys(): |
141 | | - val = self.endpoints[0][cluster][attr] |
142 | | - if val == []: |
143 | | - return _problem(AttributePathLocation(0, cluster.id, attr.attribute_id), "Fixed label list is empty") |
144 | | - else: |
145 | | - self.mark_current_step_skipped() |
146 | | - |
147 | | - @warning_wrapper(FLAG_FIXED_LABEL_DEFAULT_VALUES) |
148 | | - def check_fixed_label_cluster_defaults(self): |
149 | | - cluster = Clusters.FixedLabel |
150 | | - attr = cluster.Attributes.LabelList |
151 | | - if cluster in self.endpoints[0].keys(): |
152 | | - label_list = self.endpoints[0][cluster][attr] |
153 | | - |
154 | | - if any([label for label in label_list if label in DEFAULT_FIXED_LABEL_VALUES]): |
155 | | - return _problem(AttributePathLocation(0, cluster.id, attr.attribute_id), f"Fixed label list contains default labels:\ndefaults {DEFAULT_FIXED_LABEL_VALUES}\nlist={label_list}") |
156 | | - else: |
157 | | - self.mark_current_step_skipped() |
158 | 43 |
|
159 | 44 |
|
160 | 45 | class TC_DefaultChecker(MatterBaseTest, DefaultChecker): |
|
0 commit comments