|
1 |
| -# |
2 |
| -# Copyright (c) 2024 Project CHIP Authors |
3 |
| -# All rights reserved. |
4 |
| -# |
5 |
| -# Licensed under the Apache License, Version 2.0 (the "License"); |
6 |
| -# you may not use this file except in compliance with the License. |
7 |
| -# You may obtain a copy of the License at |
8 |
| -# |
9 |
| -# http://www.apache.org/licenses/LICENSE-2.0 |
10 |
| -# |
11 |
| -# Unless required by applicable law or agreed to in writing, software |
12 |
| -# distributed under the License is distributed on an "AS IS" BASIS, |
13 |
| -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
| -# See the License for the specific language governing permissions and |
15 |
| -# limitations under the License. |
16 |
| -# |
17 |
| - |
18 |
| -# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments |
19 |
| -# for details about the block below. |
20 |
| -# |
21 |
| -# === BEGIN CI TEST ARGUMENTS === |
22 |
| -# test-runner-runs: run1 |
23 |
| -# test-runner-run/run1/app: ${ALL_CLUSTERS_APP} |
24 |
| -# test-runner-run/run1/factoryreset: True |
25 |
| -# test-runner-run/run1/quiet: True |
26 |
| -# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json |
27 |
| -# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto |
28 |
| -# === END CI TEST ARGUMENTS === |
29 |
| - |
30 |
| -import chip.clusters as Clusters |
31 |
| -from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main |
32 |
| -from mobly import asserts |
33 |
| - |
34 |
| - |
35 |
| -class TC_OCC_2_2(MatterBaseTest): |
36 |
| - async def read_occ_attribute_expect_success(self, endpoint, attribute): |
37 |
| - cluster = Clusters.Objects.OccupancySensing |
38 |
| - return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute) |
39 |
| - |
40 |
| - def desc_TC_OCC_2_2(self) -> str: |
41 |
| - return "[TC-OCC-2.2] OccupancySensorTypeBitmap and OccupancySensorType interdependency with server as DUT" |
42 |
| - |
43 |
| - def steps_TC_OCC_2_2(self) -> list[TestStep]: |
44 |
| - steps = [ |
45 |
| - TestStep(1, "Commissioning, already done", is_commissioning=True), |
46 |
| - TestStep(2, "Read OccupancySensorType attribute selection based on FeatureMap Bitmap."), |
47 |
| - TestStep(3, "Read OccupancySensorTypeBitmap attribute selection based on FeatureMap Bitmap.") |
48 |
| - ] |
49 |
| - return steps |
50 |
| - |
51 |
| - def pics_TC_OCC_2_2(self) -> list[str]: |
52 |
| - pics = [ |
53 |
| - "OCC.S", |
54 |
| - ] |
55 |
| - return pics |
56 |
| - |
57 |
| - @async_test_body |
58 |
| - async def test_TC_OCC_2_2(self): |
59 |
| - |
60 |
| - endpoint = self.user_params.get("endpoint", 1) |
61 |
| - |
62 |
| - attributes = Clusters.OccupancySensing.Attributes |
63 |
| - feature_map = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.FeatureMap) |
64 |
| - |
65 |
| - self.step(1) |
66 |
| - attribute_list = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.AttributeList) |
67 |
| - |
68 |
| - self.step(2) |
69 |
| - # OccupancySensorType will be determined by FeatureMap matching table at 2.7.6.2. |
70 |
| - asserts.assert_in(attributes.OccupancySensorType.attribute_id, attribute_list, |
71 |
| - "OccupancySensorType attribute is a mandatory attribute.") |
72 |
| - occupancy_sensor_type_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.OccupancySensorType) |
73 |
| - |
74 |
| - # For validation purposes, 2.7.6.2 table describes what feature flags map to what type of sensors |
75 |
| - TypeEnum = Clusters.OccupancySensing.Enums.OccupancySensorTypeEnum |
76 |
| - |
77 |
| - Y = True |
78 |
| - N = False |
79 |
| - # Map is PIR, US, PHY => expected sensor type |
80 |
| - # odd Y/N mapping to make the table align nicely |
81 |
| - mappings = { |
82 |
| - (N, N, N): TypeEnum.kPir, |
83 |
| - (Y, N, N): TypeEnum.kPir, |
84 |
| - (N, Y, N): TypeEnum.kUltrasonic, |
85 |
| - (Y, Y, N): TypeEnum.kPIRAndUltrasonic, |
86 |
| - (N, N, Y): TypeEnum.kPhysicalContact, |
87 |
| - (Y, N, Y): TypeEnum.kPir, |
88 |
| - (N, Y, Y): TypeEnum.kUltrasonic, |
89 |
| - (Y, Y, Y): TypeEnum.kPIRAndUltrasonic, |
90 |
| - } |
91 |
| - |
92 |
| - FeatureBit = Clusters.OccupancySensing.Bitmaps.Feature |
93 |
| - expected = mappings.get( |
94 |
| - ( |
95 |
| - (feature_map & FeatureBit.kPassiveInfrared) != 0, |
96 |
| - (feature_map & FeatureBit.kUltrasonic) != 0, |
97 |
| - (feature_map & FeatureBit.kPhysicalContact) != 0 |
98 |
| - )) |
99 |
| - |
100 |
| - asserts.assert_equal( |
101 |
| - occupancy_sensor_type_dut, |
102 |
| - expected, |
103 |
| - f"Sensor Type should be f{expected}" |
104 |
| - ) |
105 |
| - |
106 |
| - self.step(3) |
107 |
| - # OccupancySensorTypeBitmap will be determined by FeatureMap matching table at 2.7.6.2. |
108 |
| - asserts.assert_in(attributes.OccupancySensorTypeBitmap.attribute_id, attribute_list, |
109 |
| - "OccupancySensorTypeBitmap attribute is a mandatory attribute.") |
110 |
| - |
111 |
| - occupancy_sensor_type_bitmap_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.OccupancySensorTypeBitmap) |
112 |
| - |
113 |
| - # Feature map must match the sensor type bitmap |
114 |
| - must_match_bits = [ |
115 |
| - (Clusters.OccupancySensing.Bitmaps.OccupancySensorTypeBitmap.kPir, |
116 |
| - Clusters.OccupancySensing.Bitmaps.Feature.kPassiveInfrared, "PIR"), |
117 |
| - (Clusters.OccupancySensing.Bitmaps.OccupancySensorTypeBitmap.kUltrasonic, |
118 |
| - Clusters.OccupancySensing.Bitmaps.Feature.kUltrasonic, "Ultrasonic"), |
119 |
| - (Clusters.OccupancySensing.Bitmaps.OccupancySensorTypeBitmap.kPhysicalContact, |
120 |
| - Clusters.OccupancySensing.Bitmaps.Feature.kPhysicalContact, "Physical contact"), |
121 |
| - ] |
122 |
| - |
123 |
| - for sensor_bit, feature_bit, name in must_match_bits: |
124 |
| - asserts.assert_equal( |
125 |
| - (occupancy_sensor_type_bitmap_dut & sensor_bit) != 0, |
126 |
| - (feature_map & feature_bit) != 0, |
127 |
| - f"Feature bit and sensor bitmap must be equal for {name} (BITMAP: 0x{occupancy_sensor_type_bitmap_dut:02X}, FEATUREMAP: 0x{feature_map:02X})" |
128 |
| - ) |
129 |
| - |
130 |
| - |
131 |
| -if __name__ == "__main__": |
132 |
| - default_matter_test_main() |
| 1 | +# |
| 2 | +# Copyright (c) 2024 Project CHIP Authors |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments |
| 19 | +# for details about the block below. |
| 20 | +# |
| 21 | +# === BEGIN CI TEST ARGUMENTS === |
| 22 | +# test-runner-runs: run1 |
| 23 | +# test-runner-run/run1/app: ${ALL_CLUSTERS_APP} |
| 24 | +# test-runner-run/run1/factoryreset: True |
| 25 | +# test-runner-run/run1/quiet: True |
| 26 | +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json |
| 27 | +# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto --endpoint 1 |
| 28 | +# === END CI TEST ARGUMENTS === |
| 29 | + |
| 30 | +import chip.clusters as Clusters |
| 31 | +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main |
| 32 | +from mobly import asserts |
| 33 | + |
| 34 | + |
| 35 | +class TC_OCC_2_2(MatterBaseTest): |
| 36 | + async def read_occ_attribute_expect_success(self, endpoint, attribute): |
| 37 | + cluster = Clusters.Objects.OccupancySensing |
| 38 | + return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute) |
| 39 | + |
| 40 | + def desc_TC_OCC_2_2(self) -> str: |
| 41 | + return "[TC-OCC-2.2] OccupancySensorTypeBitmap and OccupancySensorType interdependency with server as DUT" |
| 42 | + |
| 43 | + def steps_TC_OCC_2_2(self) -> list[TestStep]: |
| 44 | + steps = [ |
| 45 | + TestStep(1, "Commissioning, already done", is_commissioning=True), |
| 46 | + TestStep(2, "Read OccupancySensorType attribute selection based on FeatureMap Bitmap."), |
| 47 | + TestStep(3, "Read OccupancySensorTypeBitmap attribute selection based on FeatureMap Bitmap.") |
| 48 | + ] |
| 49 | + return steps |
| 50 | + |
| 51 | + def pics_TC_OCC_2_2(self) -> list[str]: |
| 52 | + pics = [ |
| 53 | + "OCC.S", |
| 54 | + ] |
| 55 | + return pics |
| 56 | + |
| 57 | + @async_test_body |
| 58 | + async def test_TC_OCC_2_2(self): |
| 59 | + endpoint = self.matter_test_config.endpoint |
| 60 | + |
| 61 | + self.step(1) # Already done, immediately go to step 2 |
| 62 | + |
| 63 | + self.step(2) |
| 64 | + |
| 65 | + attributes = Clusters.OccupancySensing.Attributes |
| 66 | + feature_map = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.FeatureMap) |
| 67 | + attribute_list = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.AttributeList) |
| 68 | + |
| 69 | + # OccupancySensorType will be determined by FeatureMap matching table at 2.7.6.2. |
| 70 | + asserts.assert_in(attributes.OccupancySensorType.attribute_id, attribute_list, |
| 71 | + "OccupancySensorType attribute is a mandatory attribute.") |
| 72 | + occupancy_sensor_type_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.OccupancySensorType) |
| 73 | + |
| 74 | + # For validation purposes, 2.7.6.2 table describes what feature flags map to what type of sensors |
| 75 | + TypeEnum = Clusters.OccupancySensing.Enums.OccupancySensorTypeEnum |
| 76 | + |
| 77 | + Y = True |
| 78 | + N = False |
| 79 | + # Map is PIR, US, PHY => expected sensor type |
| 80 | + # odd Y/N mapping to make the table align nicely |
| 81 | + mappings = { |
| 82 | + (N, N, N): TypeEnum.kPir, |
| 83 | + (Y, N, N): TypeEnum.kPir, |
| 84 | + (N, Y, N): TypeEnum.kUltrasonic, |
| 85 | + (Y, Y, N): TypeEnum.kPIRAndUltrasonic, |
| 86 | + (N, N, Y): TypeEnum.kPhysicalContact, |
| 87 | + (Y, N, Y): TypeEnum.kPir, |
| 88 | + (N, Y, Y): TypeEnum.kUltrasonic, |
| 89 | + (Y, Y, Y): TypeEnum.kPIRAndUltrasonic, |
| 90 | + } |
| 91 | + |
| 92 | + FeatureBit = Clusters.OccupancySensing.Bitmaps.Feature |
| 93 | + expected = mappings.get( |
| 94 | + ( |
| 95 | + (feature_map & FeatureBit.kPassiveInfrared) != 0, |
| 96 | + (feature_map & FeatureBit.kUltrasonic) != 0, |
| 97 | + (feature_map & FeatureBit.kPhysicalContact) != 0 |
| 98 | + )) |
| 99 | + |
| 100 | + asserts.assert_equal( |
| 101 | + occupancy_sensor_type_dut, |
| 102 | + expected, |
| 103 | + f"Sensor Type should be f{expected}" |
| 104 | + ) |
| 105 | + |
| 106 | + self.step(3) |
| 107 | + # OccupancySensorTypeBitmap will be determined by FeatureMap matching table at 2.7.6.2. |
| 108 | + asserts.assert_in(attributes.OccupancySensorTypeBitmap.attribute_id, attribute_list, |
| 109 | + "OccupancySensorTypeBitmap attribute is a mandatory attribute.") |
| 110 | + |
| 111 | + occupancy_sensor_type_bitmap_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.OccupancySensorTypeBitmap) |
| 112 | + |
| 113 | + # Feature map must match the sensor type bitmap |
| 114 | + must_match_bits = [ |
| 115 | + (Clusters.OccupancySensing.Bitmaps.OccupancySensorTypeBitmap.kPir, |
| 116 | + Clusters.OccupancySensing.Bitmaps.Feature.kPassiveInfrared, "PIR"), |
| 117 | + (Clusters.OccupancySensing.Bitmaps.OccupancySensorTypeBitmap.kUltrasonic, |
| 118 | + Clusters.OccupancySensing.Bitmaps.Feature.kUltrasonic, "Ultrasonic"), |
| 119 | + (Clusters.OccupancySensing.Bitmaps.OccupancySensorTypeBitmap.kPhysicalContact, |
| 120 | + Clusters.OccupancySensing.Bitmaps.Feature.kPhysicalContact, "Physical contact"), |
| 121 | + ] |
| 122 | + |
| 123 | + for sensor_bit, feature_bit, name in must_match_bits: |
| 124 | + asserts.assert_equal( |
| 125 | + (occupancy_sensor_type_bitmap_dut & sensor_bit) != 0, |
| 126 | + (feature_map & feature_bit) != 0, |
| 127 | + f"Feature bit and sensor bitmap must be equal for {name} (BITMAP: 0x{occupancy_sensor_type_bitmap_dut:02X}, FEATUREMAP: 0x{feature_map:02X})" |
| 128 | + ) |
| 129 | + |
| 130 | + |
| 131 | +if __name__ == "__main__": |
| 132 | + default_matter_test_main() |
0 commit comments