From da6dd903e6f4f9c0503a51884861fd358fcfe363 Mon Sep 17 00:00:00 2001 From: Terence Hampson Date: Fri, 2 Aug 2024 19:57:00 -0400 Subject: [PATCH 1/7] Migrate Ecosystem Information Cluster to use global structs (#34744) * Migrate Ecosystem Information Cluster to use global structs * Restyled by clang-format --------- Co-authored-by: Restyled.io --- .../ecosystem-information-server.cpp | 8 +++++--- .../ecosystem-information-server.h | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp b/src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp index 26f1c96cd65fa6..4d7f7b8ddf754e 100644 --- a/src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp +++ b/src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp @@ -66,9 +66,10 @@ CHIP_ERROR AttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeVa // TODO(#33223) To improve safety we could make GetEncodableLocationDescriptorStruct a private // memeber method where we explicitly delete member method for the parameter that matches // (LocationDescriptorStruct && aLocationDescriptor). -Structs::LocationDescriptorStruct::Type GetEncodableLocationDescriptorStruct(const LocationDescriptorStruct & aLocationDescriptor) +Globals::Structs::LocationDescriptorStruct::Type +GetEncodableLocationDescriptorStruct(const LocationDescriptorStruct & aLocationDescriptor) { - Structs::LocationDescriptorStruct::Type locationDescriptor; + Globals::Structs::LocationDescriptorStruct::Type locationDescriptor; // This would imply data is either not properly validated before being // stored here or corruption has occurred. VerifyOrDie(!aLocationDescriptor.mLocationName.empty()); @@ -199,7 +200,8 @@ EcosystemLocationStruct::Builder & EcosystemLocationStruct::Builder::SetFloorNum return *this; } -EcosystemLocationStruct::Builder & EcosystemLocationStruct::Builder::SetAreaTypeTag(std::optional aAreaTypeTag) +EcosystemLocationStruct::Builder & +EcosystemLocationStruct::Builder::SetAreaTypeTag(std::optional aAreaTypeTag) { VerifyOrDie(!mIsAlreadyBuilt); mLocationDescriptor.mAreaType = aAreaTypeTag; diff --git a/src/app/clusters/ecosystem-information-server/ecosystem-information-server.h b/src/app/clusters/ecosystem-information-server/ecosystem-information-server.h index f8407861992d3c..58c64262166403 100644 --- a/src/app/clusters/ecosystem-information-server/ecosystem-information-server.h +++ b/src/app/clusters/ecosystem-information-server/ecosystem-information-server.h @@ -96,7 +96,7 @@ struct LocationDescriptorStruct { std::string mLocationName; std::optional mFloorNumber; - std::optional mAreaType; + std::optional mAreaType; }; // This intentionally mirrors Structs::EcosystemLocationStruct::Type but has ownership @@ -111,7 +111,7 @@ class EcosystemLocationStruct Builder & SetLocationName(std::string aLocationName); Builder & SetFloorNumber(std::optional aFloorNumber); - Builder & SetAreaTypeTag(std::optional aAreaTypeTag); + Builder & SetAreaTypeTag(std::optional aAreaTypeTag); Builder & SetLocationDescriptorLastEdit(uint64_t aLocationDescriptorLastEditEpochUs); // Upon success this object will have moved all ownership of underlying From 6ba96555aeaad66fc1a0156f13275b7052d8ab6a Mon Sep 17 00:00:00 2001 From: Lazar Kovacic Date: Sat, 3 Aug 2024 02:10:01 +0200 Subject: [PATCH 2/7] TV App: Add validation logic for supported clusters and response commands (#34454) * Add validation logic * Restyled by google-java-format * Restyled by clang-format --------- Co-authored-by: Restyled.io --- .../matter/tv/server/utils/ResourceUtils.java | 67 ++++++++++--------- .../java/ContentAppCommandDelegate.cpp | 39 +++++++++++ 2 files changed, 75 insertions(+), 31 deletions(-) diff --git a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/utils/ResourceUtils.java b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/utils/ResourceUtils.java index 1a04c5294d2f30..f0feb70d529677 100644 --- a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/utils/ResourceUtils.java +++ b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/utils/ResourceUtils.java @@ -58,38 +58,43 @@ public Set getSupportedClusters(final Resources resources, fin SupportedCluster cluster = new SupportedCluster(); while (reader.hasNext()) { String name = reader.nextName(); - if (name.equals(KEY_CLUSTER_ID)) { - cluster.clusterIdentifier = reader.nextInt(); - } else if (name.equals(KEY_FEATURE_FLAGS)) { - cluster.features = reader.nextInt(); - } else if (name.equals(KEY_OPTIONAL_COMMANDS)) { - List commands = new ArrayList<>(); - reader.beginArray(); - while (reader.hasNext()) { - commands.add(reader.nextInt()); + try { + if (name.equals(KEY_CLUSTER_ID)) { + cluster.clusterIdentifier = reader.nextInt(); + } else if (name.equals(KEY_FEATURE_FLAGS)) { + cluster.features = reader.nextInt(); + } else if (name.equals(KEY_OPTIONAL_COMMANDS)) { + List commands = new ArrayList<>(); + reader.beginArray(); + while (reader.hasNext()) { + commands.add(reader.nextInt()); + } + reader.endArray(); + int[] commandIds = new int[commands.size()]; + int i = 0; + for (Integer command : commands) { + commandIds[i++] = command; + } + cluster.optionalCommandIdentifiers = commandIds; + } else if (name.equals(KEY_OPTIONAL_ATTRIBUTES)) { + List attributes = new ArrayList<>(); + reader.beginArray(); + while (reader.hasNext()) { + attributes.add(reader.nextInt()); + } + reader.endArray(); + int[] attributeIds = new int[attributes.size()]; + int i = 0; + for (Integer command : attributes) { + attributeIds[i++] = command; + } + cluster.optionalAttributesIdentifiers = attributeIds; + } else { + reader.skipValue(); } - reader.endArray(); - int[] commandIds = new int[commands.size()]; - int i = 0; - for (Integer command : commands) { - commandIds[i++] = command; - } - cluster.optionalCommandIdentifiers = commandIds; - } else if (name.equals(KEY_OPTIONAL_ATTRIBUTES)) { - List attributes = new ArrayList<>(); - reader.beginArray(); - while (reader.hasNext()) { - attributes.add(reader.nextInt()); - } - reader.endArray(); - int[] attributeIds = new int[attributes.size()]; - int i = 0; - for (Integer command : attributes) { - attributeIds[i++] = command; - } - cluster.optionalAttributesIdentifiers = attributeIds; - } else { - reader.skipValue(); + } catch (NumberFormatException | IllegalStateException e) { + Log.e(TAG, "Invalid number format in JSON for key: " + name, e); + reader.skipValue(); // Skip the invalid entry } } supportedClusters.add(cluster); diff --git a/examples/tv-app/android/java/ContentAppCommandDelegate.cpp b/examples/tv-app/android/java/ContentAppCommandDelegate.cpp index 199ec7761be0c8..8d459588a7a8d6 100644 --- a/examples/tv-app/android/java/ContentAppCommandDelegate.cpp +++ b/examples/tv-app/android/java/ContentAppCommandDelegate.cpp @@ -133,6 +133,26 @@ Status ContentAppCommandDelegate::InvokeCommand(EndpointId epId, ClusterId clust JniUtfString respStr(env, resp); ChipLogProgress(Zcl, "ContentAppCommandDelegate::InvokeCommand got response %s", respStr.c_str()); + Json::CharReaderBuilder readerBuilder; + std::string errors; + + std::unique_ptr testReader(readerBuilder.newCharReader()); + + if (!testReader->parse(respStr.c_str(), respStr.c_str() + std::strlen(respStr.c_str()), &value, &errors)) + { + ChipLogError(Zcl, "Failed to parse JSON: %s\n", errors.c_str()); + env->DeleteLocalRef(resp); + return chip::Protocols::InteractionModel::Status::Failure; + } + + // Validate and access JSON data safely + if (!value.isObject()) + { + ChipLogError(Zcl, "Invalid JSON structure: not an object"); + env->DeleteLocalRef(resp); + return chip::Protocols::InteractionModel::Status::Failure; + } + Json::Reader reader; if (!reader.parse(respStr.c_str(), value)) { @@ -166,7 +186,26 @@ void ContentAppCommandDelegate::FormatResponseData(CommandHandlerInterface::Hand { handlerContext.SetCommandHandled(); Json::Reader reader; + + Json::CharReaderBuilder readerBuilder; + std::string errors; + Json::Value value; + std::unique_ptr testReader(readerBuilder.newCharReader()); + + if (!testReader->parse(response, response + std::strlen(response), &value, &errors)) + { + ChipLogError(Zcl, "Failed to parse JSON: %s\n", errors.c_str()); + return; + } + + // Validate and access JSON data safely + if (!value.isObject()) + { + ChipLogError(Zcl, "Invalid JSON structure: not an object"); + return; + } + if (!reader.parse(response, value)) { return; From ae25a08849eaf8ef321946add264eeef0f0ce8f1 Mon Sep 17 00:00:00 2001 From: Tennessee Carmel-Veilleux Date: Sat, 3 Aug 2024 10:38:34 -0400 Subject: [PATCH 3/7] Fix TC-OCC-3.1 and TC-OCC-3.2 runtime errors (#34747) * Fix TC-OCC-3.1 and TC-OCC-3.2 runtime errors - Refactor common code to be clearer in TC-OCC-3.1/3.2 - Fix runtime errors - Move `await_sequence_of_reports` to matter_testing_support.py - Make a helper to write attributes: `write_single_attribute` Fixes #34730 Testing done: - TC-OCC-3.1 and 3.2 no longer break locally (CI integration pending named pipe update in follow-up) - TC_SWTCH still works * Fix lint * restyle * poke styler * restyle --- src/python_testing/TC_OCC_3_1.py | 52 +++--- src/python_testing/TC_OCC_3_2.py | 161 +++++++------------ src/python_testing/TC_SWTCH.py | 48 +----- src/python_testing/matter_testing_support.py | 74 ++++++++- 4 files changed, 168 insertions(+), 167 deletions(-) diff --git a/src/python_testing/TC_OCC_3_1.py b/src/python_testing/TC_OCC_3_1.py index 4380866333f339..3fd082a62bc974 100644 --- a/src/python_testing/TC_OCC_3_1.py +++ b/src/python_testing/TC_OCC_3_1.py @@ -16,11 +16,11 @@ # # === BEGIN CI TEST ARGUMENTS === # test-runner-runs: run1 -# test-runner-run/run1/app: ${TYPE_OF_APP} +# test-runner-run/run1/app: ${ALL_CLUSTERS_APP} # test-runner-run/run1/factoryreset: True # test-runner-run/run1/quiet: True # test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json -# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto +# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto --endpoint 1 # === END CI TEST ARGUMENTS === # There are CI issues to be followed up for the test cases below that implements manually controlling sensor device for # the occupancy state ON/OFF change. @@ -29,19 +29,29 @@ import logging import time +from typing import Any, Optional import chip.clusters as Clusters -from chip import ChipDeviceCtrl from chip.interaction_model import Status from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts class TC_OCC_3_1(MatterBaseTest): - async def read_occ_attribute_expect_success(self, endpoint, attribute): + async def read_occ_attribute_expect_success(self, attribute): cluster = Clusters.Objects.OccupancySensing + endpoint = self.matter_test_config.endpoint return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute) + async def write_hold_time(self, hold_time: Optional[Any]) -> Status: + dev_ctrl = self.default_controller + node_id = self.dut_node_id + endpoint = self.matter_test_config.endpoint + + cluster = Clusters.OccupancySensing + write_result = await dev_ctrl.WriteAttribute(node_id, [(endpoint, cluster.Attributes.HoldTime(hold_time))]) + return write_result[0].Status + def desc_TC_OCC_3_1(self) -> str: return "[TC-OCC-3.1] Primary functionality with server as DUT" @@ -63,39 +73,37 @@ def pics_TC_OCC_3_1(self) -> list[str]: @async_test_body async def test_TC_OCC_3_1(self): - - endpoint = self.user_params.get("endpoint", 1) - node_id = self.matter_test_config.dut_node_ids[0] hold_time = 10 # 10 seconds for occupancy state hold time self.step(1) # commissioning and getting cluster attribute list - attributes = Clusters.OccupancySensing.Attributes - attribute_list = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.AttributeList) + cluster = Clusters.OccupancySensing + attributes = cluster.Attributes + attribute_list = await self.read_occ_attribute_expect_success(attribute=attributes.AttributeList) - self.step(2) - if attributes.HoldTime.attribute_id in attribute_list: - # write 10 as a HoldTime attibute - write_res = await ChipDeviceCtrl.WriteAttribute(node_id, [(endpoint, attributes.HoldTime(hold_time))]) - asserts.assert_equal(write_res[0].status, Status.Success, "Write HoldTime failed") + has_hold_time = attributes.HoldTime.attribute_id in attribute_list + self.step(2) + if has_hold_time: + # write 10 as a HoldTime attribute + await self.write_single_attribute(cluster.Attributes.HoldTime(hold_time)) else: logging.info("No HoldTime attribute supports. Will test only occupancy attribute triggering functionality") self.step(3) # check if Occupancy attribute is 0 - occupancy_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.Occupancy) + occupancy_dut = await self.read_occ_attribute_expect_success(attribute=attributes.Occupancy) # if occupancy is on, then wait until the sensor occupancy state is 0. if occupancy_dut == 1: # Don't trigger occupancy sensor to render occupancy attribute to 0 - if attributes.HoldTime.attribute_id in attribute_list: - time.sleep(hold_time + 2) # add some extra 2 seconds to ensure hold time has passed. + if has_hold_time: + time.sleep(hold_time + 2.0) # add some extra 2 seconds to ensure hold time has passed. else: # a user wait until a sensor specific time to change occupancy attribute to 0. This is the case where the sensor doesn't support HoldTime. self.wait_for_user_input( prompt_msg="Type any letter and press ENTER after the sensor occupancy is detection ready state (occupancy attribute = 0)") # check sensor occupancy state is 0 for the next test step - occupancy_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.Occupancy) + occupancy_dut = await self.read_occ_attribute_expect_success(attribute=attributes.Occupancy) asserts.assert_equal(occupancy_dut, 0, "Occupancy attribute is still 1.") self.step(4) @@ -103,18 +111,18 @@ async def test_TC_OCC_3_1(self): self.wait_for_user_input(prompt_msg="Type any letter and press ENTER after a sensor occupancy is triggered.") # And then check if Occupancy attribute has changed. - occupancy_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.Occupancy) + occupancy_dut = await self.read_occ_attribute_expect_success(attribute=attributes.Occupancy) asserts.assert_equal(occupancy_dut, 1, "Occupancy state is not changed to 1") self.step(5) # check if Occupancy attribute is back to 0 after HoldTime attribute period # Tester should not be triggering the sensor for this test step. - if attributes.HoldTime.attribute_id in attribute_list: + if has_hold_time: # Start a timer based on HoldTime - time.sleep(hold_time+2) # add some extra 2 seconds to ensure hold time has passed. + time.sleep(hold_time + 2.0) # add some extra 2 seconds to ensure hold time has passed. - occupancy_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.Occupancy) + occupancy_dut = await self.read_occ_attribute_expect_success(attribute=attributes.Occupancy) asserts.assert_equal(occupancy_dut, 0, "Occupancy state is not 0 after HoldTime period") else: diff --git a/src/python_testing/TC_OCC_3_2.py b/src/python_testing/TC_OCC_3_2.py index 3624f1044c40e8..7e811362e2e2a4 100644 --- a/src/python_testing/TC_OCC_3_2.py +++ b/src/python_testing/TC_OCC_3_2.py @@ -19,72 +19,31 @@ # # === BEGIN CI TEST ARGUMENTS === # test-runner-runs: run1 -# test-runner-run/run1/app: ${TYPE_OF_APP} +# test-runner-run/run1/app: ${ALL_CLUSTERS_APP} # test-runner-run/run1/factoryreset: True # test-runner-run/run1/quiet: True # test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json -# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto +# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto --endpoint 1 # === END CI TEST ARGUMENTS === + # TODO: There are CI issues to be followed up for the test cases below that implements manually controlling sensor device for # the occupancy state ON/OFF change. # [TC-OCC-3.1] test procedure step 4 # [TC-OCC-3.2] test precedure step 3a, 3c import logging -import queue -import time -from typing import Any import chip.clusters as Clusters -from chip import ChipDeviceCtrl -from chip.clusters.Attribute import TypedAttributePath -from matter_testing_support import (AttributeValue, ClusterAttributeChangeAccumulator, MatterBaseTest, TestStep, async_test_body, - default_matter_test_main) +from matter_testing_support import (ClusterAttributeChangeAccumulator, MatterBaseTest, TestStep, async_test_body, + await_sequence_of_reports, default_matter_test_main) from mobly import asserts class TC_OCC_3_2(MatterBaseTest): - async def read_occ_attribute_expect_success(self, endpoint, attribute): + async def read_occ_attribute_expect_success(self, attribute): cluster = Clusters.Objects.OccupancySensing - return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute) - - def _await_sequence_of_reports(self, report_queue: queue.Queue, endpoint_id: int, attribute: TypedAttributePath, sequence: list[Any], timeout_sec: float): - start_time = time.time() - elapsed = 0.0 - time_remaining = timeout_sec - - sequence_idx = 0 - actual_values = [] - - while time_remaining > 0: - expected_value = sequence[sequence_idx] - logging.info(f"Expecting value {expected_value} for attribute {attribute} on endpoint {endpoint_id}") - try: - item: AttributeValue = report_queue.get(block=True, timeout=time_remaining) - - # Track arrival of all values for the given attribute. - if item.endpoint_id == endpoint_id and item.attribute == attribute: - actual_values.append(item.value) - - if item.value == expected_value: - logging.info(f"Got expected attribute change {sequence_idx+1}/{len(sequence)} for attribute {attribute}") - sequence_idx += 1 - else: - asserts.assert_equal(item.value, expected_value, - msg="Did not get expected attribute value in correct sequence.") - - # We are done waiting when we have accumulated all results. - if sequence_idx == len(sequence): - logging.info("Got all attribute changes, done waiting.") - return - except queue.Empty: - # No error, we update timeouts and keep going - pass - - elapsed = time.time() - start_time - time_remaining = timeout_sec - elapsed - - asserts.fail(f"Did not get full sequence {sequence} in {timeout_sec:.1f} seconds. Got {actual_values} before time-out.") + endpoint_id = self.matter_test_config.endpoint + return await self.read_single_attribute_check_success(endpoint=endpoint_id, cluster=cluster, attribute=attribute) def desc_TC_OCC_3_2(self) -> str: return "[TC-OCC-3.2] Subscription Report Verification with server as DUT" @@ -124,22 +83,32 @@ def pics_TC_OCC_3_2(self) -> list[str]: @async_test_body async def test_TC_OCC_3_2(self): - - endpoint = self.user_params.get("endpoint", 1) endpoint_id = self.matter_test_config.endpoint - node_id = self.matter_test_config.dut_node_ids[0] + node_id = self.dut_node_id + dev_ctrl = self.default_controller + post_prompt_settle_delay_seconds = 10.0 cluster = Clusters.Objects.OccupancySensing - attributes = Clusters.OccupancySensing.Attributes - occupancy_sensor_type_bitmap_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.OccupancySensorTypeBitmap) + attributes = cluster.Attributes self.step(1) - attribute_list = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.AttributeList) + + occupancy_sensor_type_bitmap_dut = await self.read_occ_attribute_expect_success(attribute=attributes.OccupancySensorTypeBitmap) + has_type_pir = ((occupancy_sensor_type_bitmap_dut & cluster.Enums.OccupancySensorTypeEnum.kPir) != 0) or \ + ((occupancy_sensor_type_bitmap_dut & cluster.Enums.OccupancySensorTypeEnum.kPIRAndUltrasonic) != 0) + has_type_ultrasonic = ((occupancy_sensor_type_bitmap_dut & cluster.Enums.OccupancySensorTypeEnum.kUltrasonic) != 0) or \ + ((occupancy_sensor_type_bitmap_dut & cluster.Enums.OccupancySensorTypeEnum.kPIRAndUltrasonic) != 0) + has_type_contact = (occupancy_sensor_type_bitmap_dut & cluster.Enums.OccupancySensorTypeEnum.kPhysicalContact) != 0 + + attribute_list = await self.read_occ_attribute_expect_success(attribute=attributes.AttributeList) + has_pir_timing_attrib = attributes.PIROccupiedToUnoccupiedDelay.attribute_id in attribute_list + has_ultrasonic_timing_attrib = attributes.UltrasonicOccupiedToUnoccupiedDelay.attribute_id in attribute_list + has_contact_timing_attrib = attributes.PhysicalContactOccupiedToUnoccupiedDelay.attribute_id in attribute_list self.step(2) # min interval = 0, and max interval = 30 seconds attrib_listener = ClusterAttributeChangeAccumulator(Clusters.Objects.OccupancySensing) - await attrib_listener.start(ChipDeviceCtrl, node_id, endpoint=endpoint_id) + await attrib_listener.start(dev_ctrl, node_id, endpoint=endpoint_id, min_interval_sec=0, max_interval_sec=30) # TODO - Will add Namepiped to assimilate the manual sensor untrigger here self.step("3a") @@ -147,7 +116,7 @@ async def test_TC_OCC_3_2(self): self.step("3b") if attributes.Occupancy.attribute_id in attribute_list: - initial_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.Occupancy) + initial_dut = await self.read_occ_attribute_expect_success(attribute=attributes.Occupancy) asserts.assert_equal(initial_dut, 0, "Occupancy attribute is still detected state") # TODO - Will add Namepiped to assimilate the manual sensor trigger here @@ -156,8 +125,8 @@ async def test_TC_OCC_3_2(self): prompt_msg="Type any letter and press ENTER after the sensor occupancy is triggered and its occupancy state changed.") self.step("3d") - self._await_sequence_of_reports(report_queue=attrib_listener.attribute_queue, endpoint_id=endpoint_id, attribute=cluster.Attributes.Occupancy, sequence=[ - 0, 1], timeout_sec=post_prompt_settle_delay_seconds) + await_sequence_of_reports(report_queue=attrib_listener.attribute_queue, endpoint_id=endpoint_id, attribute=cluster.Attributes.Occupancy, sequence=[ + 0, 1], timeout_sec=post_prompt_settle_delay_seconds) self.step("4a") if attributes.HoldTime.attribute_id not in attribute_list: @@ -165,83 +134,73 @@ async def test_TC_OCC_3_2(self): self.skip_all_remaining_steps("4b") self.step("4b") - initial_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.HoldTime) + initial_dut = await self.read_occ_attribute_expect_success(attribute=attributes.HoldTime) self.step("4c") - # write a different a HoldTime attibute + # write a different a HoldTime attribute value diff_val = 12 - await ChipDeviceCtrl.WriteAttribute(node_id, [(endpoint, attributes.HoldTime(diff_val))]) + await self.write_single_attribute(attributes.HoldTime(diff_val)) self.step("4d") - self._await_sequence_of_reports(report_queue=attrib_listener.attribute_queue, endpoint_id=endpoint_id, attribute=cluster.Attributes.HoldTime, sequence=[ - initial_dut, diff_val], timeout_sec=post_prompt_settle_delay_seconds) + await_sequence_of_reports(report_queue=attrib_listener.attribute_queue, endpoint_id=endpoint_id, attribute=cluster.Attributes.HoldTime, sequence=[ + initial_dut, diff_val], timeout_sec=post_prompt_settle_delay_seconds) self.step("5a") - if (occupancy_sensor_type_bitmap_dut & Clusters.OccupancySensing.Enums.OccupancySensorTypeEnum.kPir) == 0: - logging.info("No PIR timing attribute supports. Skip this test cases, 5b, 5c, 5d") + if not has_type_pir or not has_pir_timing_attrib: + logging.info("No PIR timing attribute support. Skip this steps 5b, 5c, 5d") self.skip_step("5b") - self.skip_test("5c") + self.skip_step("5c") self.skip_step("5d") else: self.step("5b") - if attributes.PIROccupiedToUnoccupiedDelay.attribute_id in attribute_list: - initial_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.PIROccupiedToUnoccupiedDelay) - - else: - logging.info("No PIROccupiedToUnoccupiedDelay attribute supports. Terminate this test case") + initial_dut = await self.read_occ_attribute_expect_success(attribute=attributes.PIROccupiedToUnoccupiedDelay) self.step("5c") # write the new attribute value diff_val = 11 - await ChipDeviceCtrl.WriteAttribute(node_id, [(endpoint, attributes.PIROccupiedToUnoccupiedDelay(diff_val))]) + await self.write_single_attribute(attributes.PIROccupiedToUnoccupiedDelay(diff_val)) self.step("5d") - self._await_sequence_of_reports(report_queue=attrib_listener.attribute_queue, endpoint_id=endpoint_id, attribute=cluster.Attributes.PIROccupiedToUnoccupiedDelay, sequence=[ - initial_dut, diff_val], timeout_sec=post_prompt_settle_delay_seconds) + await_sequence_of_reports(report_queue=attrib_listener.attribute_queue, endpoint_id=endpoint_id, attribute=cluster.Attributes.PIROccupiedToUnoccupiedDelay, sequence=[ + initial_dut, diff_val], timeout_sec=post_prompt_settle_delay_seconds) self.step("6a") - if (occupancy_sensor_type_bitmap_dut & Clusters.OccupancySensing.Enums.OccupancySensorTypeEnum.kUltrasonic) == 0: - logging.info("No Ultrasonic timing attribute supports. Skip this test cases, 6b, 6c, 6d") + if not has_type_ultrasonic or not has_ultrasonic_timing_attrib: + logging.info("No Ultrasonic timing attribute supports. Skip steps 6b, 6c, 6d") self.skip_step("6b") - self.skip_test("6c") + self.skip_step("6c") self.skip_step("6d") else: self.step("6b") - if attributes.UltrasonicOccupiedToUnoccupiedDelay.attribute_id in attribute_list: - initial_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.UltrasonicOccupiedToUnoccupiedDelay) - - else: - logging.info("No UltrasonicOccupiedToUnoccupiedDelay attribute supports. Skip this test case") + initial_dut = await self.read_occ_attribute_expect_success(attribute=attributes.UltrasonicOccupiedToUnoccupiedDelay) self.step("6c") # write the new attribute value diff_val = 14 - await ChipDeviceCtrl.WriteAttribute(node_id, [(endpoint, attributes.UltrasonicOccupiedToUnoccupiedDelay(diff_val))]) + await self.write_single_attribute(attributes.UltrasonicOccupiedToUnoccupiedDelay(diff_val)) self.step("6d") - self._await_sequence_of_reports(report_queue=attrib_listener.attribute_queue, endpoint_id=endpoint_id, attribute=cluster.Attributes.UltrasonicOccupiedToUnoccupiedDelay, sequence=[ - initial_dut, diff_val], timeout_sec=post_prompt_settle_delay_seconds) + await_sequence_of_reports(report_queue=attrib_listener.attribute_queue, endpoint_id=endpoint_id, attribute=cluster.Attributes.UltrasonicOccupiedToUnoccupiedDelay, sequence=[ + initial_dut, diff_val], timeout_sec=post_prompt_settle_delay_seconds) self.step("7a") - if (occupancy_sensor_type_bitmap_dut & Clusters.OccupancySensing.Enums.OccupancySensorTypeEnum.kPhysicalContact) == 0: + if not has_type_contact or not has_contact_timing_attrib: logging.info("No Physical contact timing attribute supports. Skip this test case") - self.skip_all_remaining_steps("7b") - - self.step("7b") - if attributes.PhysicalContactOccupiedToUnoccupiedDelay.attribute_id in attribute_list: - initial_dut = await self.t_success(endpoint=endpoint, attribute=attributes.PhysicalContactOccupiedToUnoccupiedDelay) - + self.skip_step("7b") + self.skip_step("7c") + self.skip_step("7d") else: - logging.info("No PhysicalContactOccupiedToUnoccupiedDelay attribute supports. Skip this test case") + self.step("7b") + initial_dut = await self.read_occ_attribute_expect_success(attribute=attributes.PhysicalContactOccupiedToUnoccupiedDelay) - self.step("7c") - # write the new attribute value - diff_val = 9 - await ChipDeviceCtrl.WriteAttribute(node_id, [(endpoint, attributes.PhysicalContactOccupiedToUnoccupiedDelay(diff_val))]) + self.step("7c") + # write the new attribute value + diff_val = 9 + await self.write_single_attribute(attributes.PhysicalContactOccupiedToUnoccupiedDelay(diff_val)) - self.step("7d") - self._await_sequence_of_reports(report_queue=attrib_listener.attribute_queue, endpoint_id=endpoint_id, attribute=cluster.Attributes.PhysicalContactOccupiedToUnoccupiedDelay, sequence=[ - initial_dut, diff_val], timeout_sec=post_prompt_settle_delay_seconds) + self.step("7d") + await_sequence_of_reports(report_queue=attrib_listener.attribute_queue, endpoint_id=endpoint_id, attribute=cluster.Attributes.PhysicalContactOccupiedToUnoccupiedDelay, sequence=[ + initial_dut, diff_val], timeout_sec=post_prompt_settle_delay_seconds) if __name__ == "__main__": diff --git a/src/python_testing/TC_SWTCH.py b/src/python_testing/TC_SWTCH.py index 08bf23d91c30d4..e2ef307973003b 100644 --- a/src/python_testing/TC_SWTCH.py +++ b/src/python_testing/TC_SWTCH.py @@ -36,10 +36,10 @@ import chip.clusters as Clusters import test_plan_support from chip.clusters import ClusterObjects as ClusterObjects -from chip.clusters.Attribute import EventReadResult, TypedAttributePath +from chip.clusters.Attribute import EventReadResult from chip.tlv import uint -from matter_testing_support import (AttributeValue, ClusterAttributeChangeAccumulator, EventChangeCallback, MatterBaseTest, - TestStep, default_matter_test_main, has_feature, per_endpoint_test) +from matter_testing_support import (ClusterAttributeChangeAccumulator, EventChangeCallback, MatterBaseTest, TestStep, + await_sequence_of_reports, default_matter_test_main, has_feature, per_endpoint_test) from mobly import asserts logger = logging.getLogger(__name__) @@ -170,44 +170,6 @@ def _ask_for_release(self): else: time.sleep(self.keep_pressed_delay/1000) - def _await_sequence_of_reports(self, report_queue: queue.Queue, endpoint_id: int, attribute: TypedAttributePath, sequence: list[Any], timeout_sec: float): - start_time = time.time() - elapsed = 0.0 - time_remaining = timeout_sec - - sequence_idx = 0 - actual_values = [] - - while time_remaining > 0: - expected_value = sequence[sequence_idx] - logging.info(f"Expecting value {expected_value} for attribute {attribute} on endpoint {endpoint_id}") - try: - item: AttributeValue = report_queue.get(block=True, timeout=time_remaining) - - # Track arrival of all values for the given attribute. - if item.endpoint_id == endpoint_id and item.attribute == attribute: - actual_values.append(item.value) - - if item.value == expected_value: - logging.info(f"Got expected attribute change {sequence_idx+1}/{len(sequence)} for attribute {attribute}") - sequence_idx += 1 - else: - asserts.assert_equal(item.value, expected_value, - msg="Did not get expected attribute value in correct sequence.") - - # We are done waiting when we have accumulated all results. - if sequence_idx == len(sequence): - logging.info("Got all attribute changes, done waiting.") - return - except queue.Empty: - # No error, we update timeouts and keep going - pass - - elapsed = time.time() - start_time - time_remaining = timeout_sec - elapsed - - asserts.fail(f"Did not get full sequence {sequence} in {timeout_sec:.1f} seconds. Got {actual_values} before time-out.") - def _await_sequence_of_events(self, event_queue: queue.Queue, endpoint_id: int, sequence: list[ClusterObjects.ClusterEvent], timeout_sec: float): start_time = time.time() elapsed = 0.0 @@ -511,8 +473,8 @@ async def test_TC_SWTCH_2_4(self): # - TH expects report of CurrentPosition 1, followed by a report of Current Position 0. logging.info( f"Starting to wait for {post_prompt_settle_delay_seconds:.1f} seconds for CurrentPosition to go {switch_pressed_position}, then 0.") - self._await_sequence_of_reports(report_queue=attrib_listener.attribute_queue, endpoint_id=endpoint_id, attribute=cluster.Attributes.CurrentPosition, sequence=[ - switch_pressed_position, 0], timeout_sec=post_prompt_settle_delay_seconds) + await_sequence_of_reports(report_queue=attrib_listener.attribute_queue, endpoint_id=endpoint_id, attribute=cluster.Attributes.CurrentPosition, sequence=[ + switch_pressed_position, 0], timeout_sec=post_prompt_settle_delay_seconds) # - TH expects at least InitialPress with NewPosition = 1 logging.info(f"Starting to wait for {post_prompt_settle_delay_seconds:.1f} seconds for InitialPress event.") diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py index 273ffe94b5f821..8275b8f0f83326 100644 --- a/src/python_testing/matter_testing_support.py +++ b/src/python_testing/matter_testing_support.py @@ -27,6 +27,7 @@ import random import re import sys +import time import typing import uuid from binascii import hexlify, unhexlify @@ -331,6 +332,58 @@ def wait_for_report(self): asserts.fail("[AttributeChangeCallback] Attribute {expected_attribute} not found in returned report") +def await_sequence_of_reports(report_queue: queue.Queue, endpoint_id: int, attribute: TypedAttributePath, sequence: list[Any], timeout_sec: float): + """Given a queue.Queue hooked-up to an attribute change accumulator, await a given expected sequence of attribute reports. + + Args: + - report_queue: the queue that receives all the reports. + - endpoint_id: endpoint ID to match for reports to check. + - attribute: attribute to match for reports to check. + - sequence: list of attribute values in order that are expected. + - timeout_sec: number of seconds to wait for. + + This will fail current Mobly test with assertion failure if the data is not as expected in order. + + Returns nothing on success so the test can go on. + """ + start_time = time.time() + elapsed = 0.0 + time_remaining = timeout_sec + + sequence_idx = 0 + actual_values = [] + + while time_remaining > 0: + expected_value = sequence[sequence_idx] + logging.info(f"Expecting value {expected_value} for attribute {attribute} on endpoint {endpoint_id}") + try: + item: AttributeValue = report_queue.get(block=True, timeout=time_remaining) + + # Track arrival of all values for the given attribute. + if item.endpoint_id == endpoint_id and item.attribute == attribute: + actual_values.append(item.value) + + if item.value == expected_value: + logging.info(f"Got expected attribute change {sequence_idx+1}/{len(sequence)} for attribute {attribute}") + sequence_idx += 1 + else: + asserts.assert_equal(item.value, expected_value, + msg="Did not get expected attribute value in correct sequence.") + + # We are done waiting when we have accumulated all results. + if sequence_idx == len(sequence): + logging.info("Got all attribute changes, done waiting.") + return + except queue.Empty: + # No error, we update timeouts and keep going + pass + + elapsed = time.time() - start_time + time_remaining = timeout_sec - elapsed + + asserts.fail(f"Did not get full sequence {sequence} in {timeout_sec:.1f} seconds. Got {actual_values} before time-out.") + + @dataclass class AttributeValue: endpoint_id: int @@ -360,7 +413,7 @@ async def start(self, dev_ctrl, node_id: int, endpoint: int, fabric_filtered: bo self._subscription = await dev_ctrl.ReadAttribute( nodeid=node_id, attributes=[(endpoint, self._expected_cluster)], - reportInterval=(min_interval_sec, max_interval_sec), + reportInterval=(int(min_interval_sec), int(max_interval_sec)), fabricFiltered=fabric_filtered, keepSubscriptions=True ) @@ -977,6 +1030,25 @@ async def read_single_attribute_expect_error( return attr_ret + async def write_single_attribute(self, attribute_value: object, endpoint_id: int = None, expect_success: bool = True) -> Status: + """Write a single `attribute_value` on a given `endpoint_id` and assert on failure. + + If `endpoint_id` is None, the default DUT endpoint for the test is selected. + + If `expect_success` is True, a test assertion fails on error status codes + + Status code is returned. + """ + dev_ctrl = self.default_controller + node_id = self.dut_node_id + endpoint = self.matter_test_config.endpoint if endpoint_id is None else endpoint_id + + write_result = await dev_ctrl.WriteAttribute(node_id, [(endpoint, attribute_value)]) + if expect_success: + asserts.assert_equal(write_result[0].Status, Status.Success, + f"Expected write success for write to attribute {attribute_value} on endpoint {endpoint}") + return write_result[0].Status + async def send_single_cmd( self, cmd: Clusters.ClusterObjects.ClusterCommand, dev_ctrl: ChipDeviceCtrl = None, node_id: int = None, endpoint: int = None, From 3331708d64f8d7e9183895749df20d8bc640ef08 Mon Sep 17 00:00:00 2001 From: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com> Date: Sat, 3 Aug 2024 23:08:48 -0400 Subject: [PATCH 4/7] [ICD] Add ICDM 3.3 Automation Scripts (#34741) * Add automated script for the ICDM 3.3 test case * Delete manual scripts * Add test to CI run * Restyled by isort * Fix Linter error --------- Co-authored-by: Restyled.io --- .github/workflows/tests.yaml | 1 + .../certification/Test_TC_ICDM_3_3.yaml | 267 ------------ src/app/tests/suites/manualTests.json | 1 - src/python_testing/TC_ICDM_3_3.py | 380 ++++++++++++++++++ 4 files changed, 381 insertions(+), 268 deletions(-) delete mode 100644 src/app/tests/suites/certification/Test_TC_ICDM_3_3.yaml create mode 100644 src/python_testing/TC_ICDM_3_3.py diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index adf04727976032..996b8a6178a57c 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -549,6 +549,7 @@ jobs: scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_FAN_3_5.py' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDM_2_1.py' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDM_3_1.py' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDM_3_3.py' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDManagementCluster.py' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_IDM_1_2.py' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_IDM_1_4.py' diff --git a/src/app/tests/suites/certification/Test_TC_ICDM_3_3.yaml b/src/app/tests/suites/certification/Test_TC_ICDM_3_3.yaml deleted file mode 100644 index dcf55057b7b9a9..00000000000000 --- a/src/app/tests/suites/certification/Test_TC_ICDM_3_3.yaml +++ /dev/null @@ -1,267 +0,0 @@ -# Copyright (c) 2024 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# Auto-generated scripts for harness use only, please review before automation. The endpoints and cluster names are currently set to default - -name: 217.2.4. [TC-ICDM-3.3] Verify UnregisterClient command with DUT as Server - -PICS: - - ICDM.S - - ICDM.S.C00.Rsp - - ICDM.S.C02.Rsp - -config: - nodeId: 0x12344321 - cluster: "Basic Information" - endpoint: 0 - -tests: - - label: "Preconditions" - verification: | - 1.Commission DUT to TH (can be skipped if done in a preceding test). - 2a.TH reads from the DUT the RegisteredClients attribute. - 2b.If list of registered clients is not empty, unregister existing client(s) - 2c.TH reads from the DUT the RegisteredClients attribute. Verify that the DUT response contains empty list of registered clients. - disabled: true - - - label: - "Step 1: TH sends UnregisterClient command with the CheckInNodeID - (CheckInNodeID1)." - PICS: ICDM.S.C02.Rsp - verification: | - ./chip-tool icdmanagement unregister-client 1 1 0 - - [1702437560.584692][2341:2343] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0002 Status=0x8b - [1702437560.584811][2341:2343] CHIP:TOO: Error: IM Error 0x0000058B: General error: 0x8b (NOT_FOUND) - disabled: true - - - label: - "Step 2a: TH sends RegisterClient command. - CheckInNodeID: - registering clients node ID (CheckInNodeID2) - MonitoredSubject: - monitored subject ID (MonitorSubID2) - Key: shared secret between the - client and the ICD (Key2)" - PICS: ICDM.S.C00.Rsp - verification: | - ./chip-tool icdmanagement register-client 2 2 hex:1234567890abcdef1234567890abcdef 1 0 - On TH(chip-tool) verify that DUT responds with status code as success - - [1702437824.926527][2361:2363] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0001 - [1702437824.926625][2361:2363] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0046 Command 0x0000_0001 - [1702437824.926835][2361:2363] CHIP:TOO: RegisterClientResponse: { - [1702437824.926901][2361:2363] CHIP:TOO: ICDCounter: 2124479668 - [1702437824.926955][2361:2363] CHIP:TOO: } - disabled: true - - - label: "Step 2b: TH reads from the DUT the RegisteredClients attribute." - PICS: ICDM.S.A0003 - verification: | - ./chip-tool icdmanagement read registered-clients 1 0 - - On TH(Chip-tool), Verify that the DUT response contains a list of 1 registered client of given CheckInNodeID, MonitoredSubject, and Key - - [1702437846.906320][2364:2366] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0046 Attribute 0x0000_0003 DataVersion: 2633987690 - [1702437846.906504][2364:2366] CHIP:TOO: RegisteredClients: 2 entries - [1702437846.906687][2364:2366] CHIP:TOO: [1]: { - [1702437846.906746][2364:2366] CHIP:TOO: CheckInNodeID: 112233 - [1702437846.906800][2364:2366] CHIP:TOO: MonitoredSubject: 112233 - [1702437846.906880][2364:2366] CHIP:TOO: FabricIndex: 1 - [1702437846.906934][2364:2366] CHIP:TOO: } - [1702437846.907003][2364:2366] CHIP:TOO: [2]: { - [1702437846.907059][2364:2366] CHIP:TOO: CheckInNodeID: 2 - [1702437846.907108][2364:2366] CHIP:TOO: MonitoredSubject: 2 - [1702437846.907160][2364:2366] CHIP:TOO: FabricIndex: 1 - [1702437846.907211][2364:2366] CHIP:TOO: } - disabled: true - - - label: - "Step 3: TH sends UnregisterClient command with the CheckInNodeID - (CheckInNodeID3)." - PICS: ICDM.S.C02.Rsp - verification: | - ./chip-tool icdmanagement unregister-client 3 1 0 - - [1702437560.584692][2341:2343] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0002 Status=0x8b - [1702437560.584811][2341:2343] CHIP:TOO: Error: IM Error 0x0000058B: General error: 0x8b (NOT_FOUND) - disabled: true - - - label: - "Step 4a: Setup the TH such that is has administrator privileges for - the ICDM cluster." - verification: | - chip-tool default has admin privilege - disabled: true - - - label: - "Step 4b: TH sends UnregisterClient command with the CheckInNodeID - (CheckInNodeID2)." - PICS: ICDM.S.C02.Rsp - verification: | - ./chip-tool icdmanagement unregister-client 2 1 0 - - [1702438116.143490][2387:2389] CHIP:DMG: InvokeResponseMessage = - [1702438116.143590][2387:2389] CHIP:DMG: { - [1702438116.143648][2387:2389] CHIP:DMG: suppressResponse = false, - [1702438116.143877][2387:2389] CHIP:DMG: InvokeResponseIBs = - [1702438116.144238][2387:2389] CHIP:DMG: [ - [1702438116.144308][2387:2389] CHIP:DMG: InvokeResponseIB = - [1702438116.144414][2387:2389] CHIP:DMG: { - [1702438116.144476][2387:2389] CHIP:DMG: CommandStatusIB = - [1702438116.144575][2387:2389] CHIP:DMG: { - [1702438116.144646][2387:2389] CHIP:DMG: CommandPathIB = - [1702438116.144723][2387:2389] CHIP:DMG: { - [1702438116.144825][2387:2389] CHIP:DMG: EndpointId = 0x0, - [1702438116.144911][2387:2389] CHIP:DMG: ClusterId = 0x46, - [1702438116.144993][2387:2389] CHIP:DMG: CommandId = 0x2, - [1702438116.145097][2387:2389] CHIP:DMG: }, - [1702438116.145186][2387:2389] CHIP:DMG: - [1702438116.145278][2387:2389] CHIP:DMG: StatusIB = - [1702438116.145357][2387:2389] CHIP:DMG: { - [1702438116.145457][2387:2389] CHIP:DMG: status = 0x00 (SUCCESS), - [1702438116.145538][2387:2389] CHIP:DMG: }, - [1702438116.145616][2387:2389] CHIP:DMG: - [1702438116.145683][2387:2389] CHIP:DMG: }, - [1702438116.145782][2387:2389] CHIP:DMG: - [1702438116.145846][2387:2389] CHIP:DMG: }, - [1702438116.145917][2387:2389] CHIP:DMG: - [1702438116.146004][2387:2389] CHIP:DMG: ], - [1702438116.146078][2387:2389] CHIP:DMG: - [1702438116.146155][2387:2389] CHIP:DMG: InteractionModelRevision = 11 - [1702438116.146213][2387:2389] CHIP:DMG: }, - [1702438116.146382][2387:2389] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0002 Status=0x0 - disabled: true - - - label: "Step 4c: TH reads from the DUT the RegisteredClients attribute." - PICS: ICDM.S.A0003 - verification: | - ./chip-tool icdmanagement read registered-clients 1 0 - - [1702438139.915311][2390:2392] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0046 Attribute 0x0000_0003 DataVersion: 2633987690 - [1702438139.915462][2390:2392] CHIP:TOO: RegisteredClients: 1 entries - [1702438139.915616][2390:2392] CHIP:TOO: [1]: { - [1702438139.915667][2390:2392] CHIP:TOO: CheckInNodeID: 112233 - [1702438139.915708][2390:2392] CHIP:TOO: MonitoredSubject: 112233 - [1702438139.915774][2390:2392] CHIP:TOO: FabricIndex: 1 - [1702438139.915818][2390:2392] CHIP:TOO: } - disabled: true - - - label: - "Step 4d: Clear the THs administrator privileges for the ICDM cluster." - verification: | - ./chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 4, "authMode": 2, "subjects": [112233], "targets": null } ]' 1 0 - disabled: true - - - label: - "Step 5a: TH sends RegisterClient command. - CheckInNodeID: - registering clients node ID (CheckInNodeID5) - MonitoredSubject: - monitored subject ID (MonitorSubID5) - Key: shared secret between the - client and the ICD (Key5) - VerificationKey: verification key - (VerificationKey5)" - PICS: ICDM.S.C00.Rsp - verification: | - ./chip-tool icdmanagement register-client 5 5 hex:5555567890abcdef5555567890abcdef 1 0 --VerificationKey hex:abcdef1234567890abcdef1234567890 - On TH(chip-tool) verify that DUT responds with status code as success - - [1702437824.926527][2361:2363] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0001 - [1702437824.926625][2361:2363] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0046 Command 0x0000_0001 - [1702437824.926835][2361:2363] CHIP:TOO: RegisterClientResponse: { - [1702437824.926901][2361:2363] CHIP:TOO: ICDCounter: 2124479668 - [1702437824.926955][2361:2363] CHIP:TOO: } - disabled: true - - - label: "Step 5b: TH reads from the DUT the RegisteredClients attribute." - PICS: ICDM.S.A0003 - verification: | - ./chip-tool icdmanagement read registered-clients 1 0 - - On TH(Chip-tool), Verify that the DUT response contains a list of 1 registered client of given CheckInNodeID, MonitoredSubject, and Key - - [1702438233.117193][2401:2403] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0046 Attribute 0x0000_0003 DataVersion: 2633987690 - [1702438233.117356][2401:2403] CHIP:TOO: RegisteredClients: 2 entries - [1702438233.117510][2401:2403] CHIP:TOO: [1]: { - [1702438233.117559][2401:2403] CHIP:TOO: CheckInNodeID: 112233 - [1702438233.117603][2401:2403] CHIP:TOO: MonitoredSubject: 112233 - [1702438233.117669][2401:2403] CHIP:TOO: FabricIndex: 1 - [1702438233.117713][2401:2403] CHIP:TOO: } - [1702438233.117772][2401:2403] CHIP:TOO: [2]: { - [1702438233.117816][2401:2403] CHIP:TOO: CheckInNodeID: 5 - [1702438233.117859][2401:2403] CHIP:TOO: MonitoredSubject: 5 - [1702438233.117902][2401:2403] CHIP:TOO: FabricIndex: 1 - [1702438233.117944][2401:2403] CHIP:TOO: } - disabled: true - - - label: - "Step 6: TH sends UnregisterClient command with the CheckInNodeID from - Step 5a and an invalid VerificationKey. - CheckInNodeID: registering - clients node ID (CheckInNodeID5) - VerificationKey: invalid - verification key (VerificationKey6)" - PICS: ICDM.S.C02.Rsp - verification: | - ./chip-tool icdmanagement unregister-client 5 1 0 --VerificationKey hex:abcdef1234567890 - - [1703268222.346310][2758:2760] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0002 Status=0x1 - [1703268222.346412][2758:2760] CHIP:TOO: Error: IM Error 0x00000501: General error: 0x01 (FAILURE) - disabled: true - - - label: - "Step 7: TH sends UnregisterClient command with the CheckInNodeID from - Step 5a and different VerificationKey. - CheckInNodeID: registering - clients node ID (CheckInNodeID5) - VerificationKey: valid verification - key (VerificationKey7)" - PICS: ICDM.S.C02.Rsp - verification: | - ./chip-tool icdmanagement unregister-client 5 1 0 --VerificationKey hex:abcdef1234567890abcdef1234500000 - - [1703268200.542869][2755:2757] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0002 Status=0x1 - [1703268200.543007][2755:2757] CHIP:TOO: Error: IM Error 0x00000501: General error: 0x01 (FAILURE) - disabled: true - - - label: - "Step 8: TH sends UnregisterClient command with the CheckInNodeID and - VerificationKey from Step 5a. - CheckInNodeID: registering clients - node ID (CheckInNodeID5) - VerificationKey: verification key - (VerificationKey5)" - PICS: ICDM.S.C02.Rsp - verification: | - ./chip-tool icdmanagement unregister-client 5 1 0 --VerificationKey hex:abcdef1234567890abcdef1234567890 - - [1702438116.143490][2387:2389] CHIP:DMG: InvokeResponseMessage = - [1702438116.143590][2387:2389] CHIP:DMG: { - [1702438116.143648][2387:2389] CHIP:DMG: suppressResponse = false, - [1702438116.143877][2387:2389] CHIP:DMG: InvokeResponseIBs = - [1702438116.144238][2387:2389] CHIP:DMG: [ - [1702438116.144308][2387:2389] CHIP:DMG: InvokeResponseIB = - [1702438116.144414][2387:2389] CHIP:DMG: { - [1702438116.144476][2387:2389] CHIP:DMG: CommandStatusIB = - [1702438116.144575][2387:2389] CHIP:DMG: { - [1702438116.144646][2387:2389] CHIP:DMG: CommandPathIB = - [1702438116.144723][2387:2389] CHIP:DMG: { - [1702438116.144825][2387:2389] CHIP:DMG: EndpointId = 0x0, - [1702438116.144911][2387:2389] CHIP:DMG: ClusterId = 0x46, - [1702438116.144993][2387:2389] CHIP:DMG: CommandId = 0x2, - [1702438116.145097][2387:2389] CHIP:DMG: }, - [1702438116.145186][2387:2389] CHIP:DMG: - [1702438116.145278][2387:2389] CHIP:DMG: StatusIB = - [1702438116.145357][2387:2389] CHIP:DMG: { - [1702438116.145457][2387:2389] CHIP:DMG: status = 0x00 (SUCCESS), - [1702438116.145538][2387:2389] CHIP:DMG: }, - [1702438116.145616][2387:2389] CHIP:DMG: - [1702438116.145683][2387:2389] CHIP:DMG: }, - [1702438116.145782][2387:2389] CHIP:DMG: - [1702438116.145846][2387:2389] CHIP:DMG: }, - [1702438116.145917][2387:2389] CHIP:DMG: - [1702438116.146004][2387:2389] CHIP:DMG: ], - [1702438116.146078][2387:2389] CHIP:DMG: - [1702438116.146155][2387:2389] CHIP:DMG: InteractionModelRevision = 11 - [1702438116.146213][2387:2389] CHIP:DMG: }, - [1702438116.146382][2387:2389] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0002 Status=0x0 - disabled: true diff --git a/src/app/tests/suites/manualTests.json b/src/app/tests/suites/manualTests.json index 7b99318fe6c9fd..bbb86f7092b715 100644 --- a/src/app/tests/suites/manualTests.json +++ b/src/app/tests/suites/manualTests.json @@ -119,7 +119,6 @@ "Identify": ["Test_TC_I_3_2"], "IcdManagement": [ "Test_TC_ICDM_3_2", - "Test_TC_ICDM_3_3", "Test_TC_ICDM_4_1", "Test_TC_ICDM_5_1" ], diff --git a/src/python_testing/TC_ICDM_3_3.py b/src/python_testing/TC_ICDM_3_3.py new file mode 100644 index 00000000000000..cb8d1bd7bcbbcd --- /dev/null +++ b/src/python_testing/TC_ICDM_3_3.py @@ -0,0 +1,380 @@ + +# +# Copyright (c) 2023 Project CHIP Authors +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments +# for details about the block below. +# +# === BEGIN CI TEST ARGUMENTS === +# test-runner-runs: run1 +# test-runner-run/run1/app: ${LIT_ICD_APP} +# test-runner-run/run1/factoryreset: True +# test-runner-run/run1/quiet: True +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json +# 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 +# === END CI TEST ARGUMENTS === + +import logging +from dataclasses import dataclass + +import chip.clusters as Clusters +from chip.interaction_model import InteractionModelError, Status +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from mobly import asserts + +logger = logging.getLogger(__name__) + +kRootEndpointId = 0 + +cluster = Clusters.Objects.IcdManagement +commands = cluster.Commands +ClientTypeEnum = cluster.Enums.ClientTypeEnum + + +@dataclass +class Client: + checkInNodeID: int + subjectId: int + key: bytes + clientType: ClientTypeEnum + + +# +# Test Input Data +# +kIncorrectKey = b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1a" +kInvalidKey = b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e1g" + +client1 = Client( + checkInNodeID=1, + subjectId=1, + key=b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + clientType=ClientTypeEnum.kEphemeral +) + +client2 = Client( + checkInNodeID=2, + subjectId=2, + key=b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + clientType=ClientTypeEnum.kEphemeral +) + +client3 = Client( + checkInNodeID=3, + subjectId=3, + key=b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + clientType=ClientTypeEnum.kEphemeral +) + +client4 = Client( + checkInNodeID=4, + subjectId=4, + key=b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + clientType=ClientTypeEnum.kEphemeral +) + +# Client 5 skipped in the Test Plan steps +client6 = Client( + checkInNodeID=6, + subjectId=6, + key=b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + clientType=ClientTypeEnum.kEphemeral +) + +# Client 7 skipped in the Test Plan steps +client8 = Client( + checkInNodeID=8, + subjectId=8, + key=b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + clientType=ClientTypeEnum.kEphemeral +) + + +class TC_ICDM_3_3(MatterBaseTest): + + # + # Class Helper functions + # + async def _read_icdm_attribute_expect_success(self, attribute): + return await self.read_single_attribute_check_success(endpoint=kRootEndpointId, cluster=cluster, attribute=attribute) + + async def _send_single_icdm_command(self, command): + return await self.send_single_cmd(command, endpoint=kRootEndpointId) + # + # Test Harness Helpers + # + + def desc_TC_ICDM_3_3(self) -> str: + """Returns a description of this test""" + return "[TC-ICDM-3.3] Register/Unregister Clients with DUT as Server" + + def steps_TC_ICDM_3_3(self) -> list[TestStep]: + steps = [ + TestStep(0, "Commissioning, already done", is_commissioning=True), + TestStep("1a", "TH reads from the DUT the RegisteredClients attribute."), + TestStep("1b", "TH sends UnregisterClient command with CheckInNodeID1, where CheckInNodeID1 can be any random node ID."), + TestStep("2a", "TH sends RegisterClient command."), + TestStep("2b", "TH reads from the DUT the RegisteredClients attribute."), + TestStep(3, "TH sends UnregisterClient command with the CheckInNodeID3."), + TestStep("4a", "TH sends UnregisterClient command with the CheckInNodeID2."), + TestStep("4b", "TH reads from the DUT the RegisteredClients attribute."), + TestStep("5a", "TH sends RegisterClient command."), + TestStep("5b", "TH reads from the DUT the RegisteredClients attribute."), + TestStep("5c", "TH sends UnregisterClient command with the CheckInNodeID4 as in Step 5a and an invalid VerificationKey5."), + TestStep("5d", "TH reads from the DUT the RegisteredClients attribute."), + TestStep("6a", "TH sends RegisterClient command."), + TestStep("6b", "TH reads from the DUT the RegisteredClients attribute."), + TestStep("6c", "TH sends UnregisterClient command with the CheckInNodeID6 as in Step 6a and a wrong VerificationKey7."), + TestStep("6d", "TH reads from the DUT the RegisteredClients attribute."), + TestStep(7, "Set the TH to Manage privilege for ICDM cluster."), + TestStep("8a", "TH sends RegisterClient command."), + TestStep("8b", "TH sends UnregisterClient command with the CheckInNodeID8 from Step 8a and an invalid VerificationKey9."), + TestStep("8c", "TH sends UnregisterClient command with the CheckInNodeID8 from Step 8a and a valid wrong VerificationKey10."), + TestStep("8d", "TH sends UnregisterClient command with the CheckInNodeID8 and VerificationKey8 from Step 8a."), + ] + return steps + + def pics_TC_ICDM_3_3(self) -> list[str]: + """ This function returns a list of PICS for this test case that must be True for the test to be run""" + pics = [ + "ICDM.S", + "ICDM.S.F00" + ] + return pics + + # + # ICDM 3.3 Test Body + # + + @async_test_body + async def test_TC_ICDM_3_3(self): + + cluster = Clusters.Objects.IcdManagement + attributes = cluster.Attributes + + # Pre-Condition: Commissioning + self.step(0) + + self.step("1a") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + + for client in registeredClients: + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client.checkInNodeID)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + # Try / Case for the Test Plan post condition + try: + self.step("1b") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client1.checkInNodeID)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.NotFound, "Unexpected error returned") + pass + + self.step("2a") + try: + await self._send_single_icdm_command(commands.RegisterClient(checkInNodeID=client2.checkInNodeID, monitoredSubject=client2.subjectId, key=client2.key, clientType=client2.clientType)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("2b") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + # Validate list size + asserts.assert_equal(len(registeredClients), 1, + "The expected length of RegisteredClients is 1. List has the wrong size.") + + # Validate entry values + asserts.assert_equal( + registeredClients[0].checkInNodeID, client2.checkInNodeID, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].monitoredSubject, client2.subjectId, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].clientType, client2.clientType, "The read attribute does not match the registered value.") + + self.step(3) + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client3.checkInNodeID)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.NotFound, "Unexpected error returned") + + self.step("4a") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client2.checkInNodeID)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("4b") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + asserts.assert_equal(len(registeredClients), 0, + "The RegisteredClients list must be empty. List has the wrong size.") + + self.step("5a") + try: + await self._send_single_icdm_command(commands.RegisterClient(checkInNodeID=client4.checkInNodeID, monitoredSubject=client4.subjectId, key=client4.key, clientType=client4.clientType)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("5b") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + # Validate list size + asserts.assert_equal(len(registeredClients), 1, + "The expected length of RegisteredClients is 1. List has the wrong size.") + + # Validate entry values + asserts.assert_equal( + registeredClients[0].checkInNodeID, client4.checkInNodeID, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].monitoredSubject, client4.subjectId, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].clientType, client4.clientType, "The read attribute does not match the registered value.") + + self.step("5c") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client4.checkInNodeID, verificationKey=kInvalidKey)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("5d") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + asserts.assert_equal(len(registeredClients), 0, + "The RegisteredClients list must be empty. List has the wrong size.") + + self.step("6a") + try: + await self._send_single_icdm_command(commands.RegisterClient(checkInNodeID=client6.checkInNodeID, monitoredSubject=client6.subjectId, key=client6.key, clientType=client6.clientType)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("6b") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + # Validate list size + asserts.assert_equal(len(registeredClients), 1, + "The expected length of RegisteredClients is 1. List has the wrong size.") + + # Validate entry values + asserts.assert_equal( + registeredClients[0].checkInNodeID, client6.checkInNodeID, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].monitoredSubject, client6.subjectId, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].clientType, client6.clientType, "The read attribute does not match the registered value.") + + self.step("6c") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client6.checkInNodeID, verificationKey=kIncorrectKey)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("6d") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + asserts.assert_equal(len(registeredClients), 0, + "The RegisteredClients list must be empty. List has the wrong size.") + self.step(7) + ac = Clusters.AccessControl + previousAcl = await self.read_single_attribute_check_success(cluster=ac, attribute=ac.Attributes.Acl) + newAcls = [] + + # Set Admin permissions on Access Control cluster + newAclEntry = ac.Structs.AccessControlEntryStruct(privilege=ac.Enums.AccessControlEntryPrivilegeEnum.kAdminister, + authMode=ac.Enums.AccessControlEntryAuthModeEnum.kCase, + subjects=previousAcl[0].subjects, targets=[ac.Structs.AccessControlTargetStruct( + cluster=Clusters.AccessControl.id)], fabricIndex=previousAcl[0].fabricIndex + ) + newAcls.append(newAclEntry) + + # Set Manage permissions on ICD Management cluster + newAclEntry = ac.Structs.AccessControlEntryStruct(privilege=ac.Enums.AccessControlEntryPrivilegeEnum.kManage, + authMode=ac.Enums.AccessControlEntryAuthModeEnum.kCase, + subjects=previousAcl[0].subjects, targets=[ac.Structs.AccessControlTargetStruct( + cluster=Clusters.IcdManagement.id)], fabricIndex=previousAcl[0].fabricIndex + ) + newAcls.append(newAclEntry) + + try: + await self.default_controller.WriteAttribute(nodeid=self.dut_node_id, attributes=[(0, ac.Attributes.Acl(newAcls))]) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("8a") + try: + await self._send_single_icdm_command(commands.RegisterClient(checkInNodeID=client8.checkInNodeID, monitoredSubject=client8.subjectId, key=client8.key, clientType=client8.clientType)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("8b") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client8.checkInNodeID, verificationKey=kInvalidKey)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Failure, "Unexpected error returned") + + self.step("8c") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client8.checkInNodeID, verificationKey=kIncorrectKey)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Failure, "Unexpected error returned") + self.step("8d") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client8.checkInNodeID, verificationKey=client8.key)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + # Post-Condition steps + finally: + # Reset ACLs + try: + await self.default_controller.WriteAttribute(nodeid=self.dut_node_id, attributes=[(0, ac.Attributes.Acl(previousAcl))]) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + # Clear all RegisteredClients + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + + for client in registeredClients: + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client.checkInNodeID)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + +if __name__ == "__main__": + default_matter_test_main() From 157aa4002e3ab98a13d8a083ba6d8e1d9f89e601 Mon Sep 17 00:00:00 2001 From: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com> Date: Sat, 3 Aug 2024 23:08:58 -0400 Subject: [PATCH 5/7] Update ICDM 3.1 Test Script (#34733) --- src/python_testing/TC_ICDM_3_1.py | 229 ++++++++++++++---------------- 1 file changed, 103 insertions(+), 126 deletions(-) diff --git a/src/python_testing/TC_ICDM_3_1.py b/src/python_testing/TC_ICDM_3_1.py index 938479a9147f5f..f20e2816723a28 100644 --- a/src/python_testing/TC_ICDM_3_1.py +++ b/src/python_testing/TC_ICDM_3_1.py @@ -72,32 +72,22 @@ def desc_TC_ICDM_3_1(self) -> str: def steps_TC_ICDM_3_1(self) -> list[TestStep]: steps = [ - TestStep("0a", "Commissioning, already done", + TestStep(0, "Commissioning, already done", is_commissioning=True), - TestStep( - "0b", "TH reads from the DUT the RegisteredClients attribute. RegisteredClients is empty."), - TestStep( - "1a", "TH reads from the DUT the ClientsSupportedPerFabric attribute."), - TestStep( - "1b", "TH reads from the DUT the ICDCounter attribute."), + TestStep("1a", "TH reads from the DUT the RegisteredClients attribute. RegisteredClients is empty."), + TestStep("1b", "TH reads from the DUT the ClientsSupportedPerFabric attribute."), + TestStep("1c", "TH reads from the DUT the ICDCounter attribute."), TestStep(2, "TH sends RegisterClient command."), TestStep(3, "TH reads from the DUT the RegisteredClients attribute."), - TestStep( - 4, "If len(RegisteredClients) is less than ClientsSupportedPerFabric, TH repeats RegisterClient command with different CheckInNodeID(s) until the number of entries in RegisteredClients equals ClientsSupportedPerFabric."), + TestStep(4, "If len(RegisteredClients) is less than ClientsSupportedPerFabric, TH repeats RegisterClient command with different CheckInNodeID(s) until the number of entries in RegisteredClients equals ClientsSupportedPerFabric."), TestStep(5, "TH reads from the DUT the RegisteredClients attribute."), - TestStep( - 6, "TH sends RegisterClient command with a different CheckInNodeID."), - TestStep( - 7, "TTH sends UnregisterClient command with the CheckInNodeID from Step 6."), - TestStep( - 8, "TH sends UnregisterClient command with the CheckInNodeID from Step 2."), - TestStep( - 9, "TH reads from the DUT the RegisteredClients attribute."), - TestStep( - 10, "Repeat Step 9 with the rest of CheckInNodeIDs from the list of RegisteredClients from Step 4, if any."), + TestStep(6, "TH sends RegisterClient command with a different CheckInNodeID."), + TestStep(7, "TTH sends UnregisterClient command with the CheckInNodeID from Step 6."), + TestStep(8, "TH sends UnregisterClient command with the CheckInNodeID from Step 2."), + TestStep(9, "TH reads from the DUT the RegisteredClients attribute."), + TestStep(10, "Repeat Step 9 with the rest of CheckInNodeIDs from the list of RegisteredClients from Step 4, if any."), TestStep(11, "TH reads from the DUT the RegisteredClients attribute."), - TestStep( - 12, "TH sends UnregisterClient command with the CheckInNodeID from Step 2."), + TestStep(12, "TH sends UnregisterClient command with the CheckInNodeID from Step 2."), ] return steps @@ -120,10 +110,10 @@ async def test_TC_ICDM_3_1(self): attributes = cluster.Attributes # Pre-Condition: Commissioning - self.step("0a") + self.step(0) - # Pre-Condition: Empty RegisteredClients attribute for all registrations - self.step("0b") + # Empty RegisteredClients attribute for all registrations + self.step("1a") registeredClients = await self._read_icdm_attribute_expect_success( attributes.RegisteredClients) @@ -135,56 +125,51 @@ async def test_TC_ICDM_3_1(self): e.status, Status.Success, "Unexpected error returned") pass - self.step("1a") - if self.pics_guard(self.check_pics("ICDM.S.A0005")): - clientsSupportedPerFabric = await self._read_icdm_attribute_expect_success( - attributes.ClientsSupportedPerFabric) - self.step("1b") - if self.pics_guard(self.check_pics("ICDM.S.A0005")): - icdCounter = await self._read_icdm_attribute_expect_success(attributes.ICDCounter) + clientsSupportedPerFabric = await self._read_icdm_attribute_expect_success( + attributes.ClientsSupportedPerFabric) + + self.step("1c") + icdCounter = await self._read_icdm_attribute_expect_success(attributes.ICDCounter) self.step(2) - if self.pics_guard(self.check_pics("ICDM.S.C00.Rsp")): - try: - response = await self._send_single_icdm_command(commands.RegisterClient(checkInNodeID=kStep2CheckInNodeId, monitoredSubject=kStep2MonitoredSubjectStep2, key=kStep2Key, clientType=clientTypeEnum.kEphemeral)) - except InteractionModelError as e: - asserts.assert_equal( - e.status, Status.Success, "Unexpected error returned") - pass + try: + response = await self._send_single_icdm_command(commands.RegisterClient(checkInNodeID=kStep2CheckInNodeId, monitoredSubject=kStep2MonitoredSubjectStep2, key=kStep2Key, clientType=clientTypeEnum.kEphemeral)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + pass - # Validate response contains the ICDCounter - asserts.assert_greater_equal(response.ICDCounter, icdCounter, - "The ICDCounter in the response does not match the read ICDCounter.") + # Validate response contains the ICDCounter + asserts.assert_greater_equal(response.ICDCounter, icdCounter, + "The ICDCounter in the response does not match the read ICDCounter.") self.step(3) - if self.pics_guard(self.check_pics("ICDM.S.A0003")): - registeredClients = await self._read_icdm_attribute_expect_success( - attributes.RegisteredClients) - # Validate list size - asserts.assert_equal(len(registeredClients), 1, - "The expected length of RegisteredClients is 1. List has the wrong size.") - - # Validate entry values - asserts.assert_equal( - registeredClients[0].checkInNodeID, kStep2CheckInNodeId, "The read attribute does not match the registered value.") - asserts.assert_equal( - registeredClients[0].monitoredSubject, kStep2MonitoredSubjectStep2, "The read attribute does not match the registered value.") - asserts.assert_equal( - registeredClients[0].clientType, clientTypeEnum.kEphemeral, "The read attribute does not match the registered value.") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + # Validate list size + asserts.assert_equal(len(registeredClients), 1, + "The expected length of RegisteredClients is 1. List has the wrong size.") + + # Validate entry values + asserts.assert_equal( + registeredClients[0].checkInNodeID, kStep2CheckInNodeId, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].monitoredSubject, kStep2MonitoredSubjectStep2, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].clientType, clientTypeEnum.kEphemeral, "The read attribute does not match the registered value.") self.step(4) - if self.pics_guard(self.check_pics("ICDM.S.C00.Rsp")): - if (len(registeredClients) < clientsSupportedPerFabric): - newClients = [] - # Generate new clients data - for i in range(clientsSupportedPerFabric - len(registeredClients)): - newClients.append({ - "checkInNodeID": i + 1, - "monitoredSubject": i + 1, - "key": os.urandom(16), - "clientType": clientTypeEnum.kPermanent - }) + if (len(registeredClients) < clientsSupportedPerFabric): + newClients = [] + # Generate new clients data + for i in range(clientsSupportedPerFabric - len(registeredClients)): + newClients.append({ + "checkInNodeID": i + 1, + "monitoredSubject": i + 1, + "key": os.urandom(16), + "clientType": clientTypeEnum.kPermanent + }) for client in newClients: try: @@ -199,84 +184,76 @@ async def test_TC_ICDM_3_1(self): "The ICDCounter in the response does not match the read ICDCounter.") self.step(5) - if self.pics_guard(self.check_pics("ICDM.S.A0003")): - registeredClients = await self._read_icdm_attribute_expect_success( - attributes.RegisteredClients) + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) - # Validate list size - asserts.assert_equal(len(registeredClients[1:]), len(newClients), - "The expected length of RegisteredClients is clientsSupportedPerFabric. List has the wrong size.") + # Validate list size + asserts.assert_equal(len(registeredClients[1:]), len(newClients), + "The expected length of RegisteredClients is clientsSupportedPerFabric. List has the wrong size.") - for client, expectedClient in zip(registeredClients[1:], newClients): - asserts.assert_equal( - client.checkInNodeID, expectedClient["checkInNodeID"], "The read attribute does not match the registered value.") - asserts.assert_equal( - client.monitoredSubject, expectedClient["monitoredSubject"], "The read attribute does not match the registered value.") - asserts.assert_equal( - client.clientType, expectedClient["clientType"], "The read attribute does not match the registered value.") + for client, expectedClient in zip(registeredClients[1:], newClients): + asserts.assert_equal( + client.checkInNodeID, expectedClient["checkInNodeID"], "The read attribute does not match the registered value.") + asserts.assert_equal( + client.monitoredSubject, expectedClient["monitoredSubject"], "The read attribute does not match the registered value.") + asserts.assert_equal( + client.clientType, expectedClient["clientType"], "The read attribute does not match the registered value.") self.step(6) - if self.pics_guard(self.check_pics("ICDM.S.C00.Rsp")): - try: - response = await self._send_single_icdm_command(commands.RegisterClient(checkInNodeID=0xFFFF, monitoredSubject=0xFFFF, key=os.urandom(16), clientType=clientTypeEnum.kPermanent)) - except InteractionModelError as e: - asserts.assert_equal( - e.status, Status.ResourceExhausted, "Unexpected error returned") - pass + try: + response = await self._send_single_icdm_command(commands.RegisterClient(checkInNodeID=0xFFFF, monitoredSubject=0xFFFF, key=os.urandom(16), clientType=clientTypeEnum.kPermanent)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.ResourceExhausted, "Unexpected error returned") + pass self.step(7) - if self.pics_guard(self.check_pics("ICDM.S.C02.Rsp")): - try: - await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=0xFFFF)) - except InteractionModelError as e: - asserts.assert_equal( - e.status, Status.NotFound, "Unexpected error returned") - pass + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=0xFFFF)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.NotFound, "Unexpected error returned") + pass self.step(8) - if self.pics_guard(self.check_pics("ICDM.S.C02.Rsp")): - try: - await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=kStep2CheckInNodeId)) - except InteractionModelError as e: - asserts.assert_equal( - e.status, Status.Success, "Unexpected error returned") - pass + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=kStep2CheckInNodeId)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + pass self.step(9) - if self.pics_guard(self.check_pics("ICDM.S.A0003")): - registeredClients = await self._read_icdm_attribute_expect_success( - attributes.RegisteredClients) + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) - for client in registeredClients: - asserts.assert_not_equal(client.checkInNodeID, kStep2CheckInNodeId, - "CheckInNodeID was unregistered. It should not be present in the attribute list.") + for client in registeredClients: + asserts.assert_not_equal(client.checkInNodeID, kStep2CheckInNodeId, + "CheckInNodeID was unregistered. It should not be present in the attribute list.") self.step(10) - if self.pics_guard(self.check_pics("ICDM.S.C02.Rsp")): - for client in newClients: - try: - await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client["checkInNodeID"])) - except InteractionModelError as e: - asserts.assert_equal( - e.status, Status.Success, "Unexpected error returned") - pass + for client in newClients: + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client["checkInNodeID"])) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + pass self.step(11) - if self.pics_guard(self.check_pics("ICDM.S.A0003")): - registeredClients = await self._read_icdm_attribute_expect_success( - attributes.RegisteredClients) + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) - asserts.assert_true( - not registeredClients, "This list should empty. An element did not get deleted.") + asserts.assert_true( + not registeredClients, "This list should empty. An element did not get deleted.") self.step(12) - if self.pics_guard(self.check_pics("ICDM.S.C02.Rsp")): - try: - await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=kStep2CheckInNodeId)) - except InteractionModelError as e: - asserts.assert_equal( - e.status, Status.NotFound, "Unexpected error returned") - pass + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=kStep2CheckInNodeId)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.NotFound, "Unexpected error returned") + pass if __name__ == "__main__": From 999c1dd734eb2d78688ee9883d2290eac48caa11 Mon Sep 17 00:00:00 2001 From: Anton Usmansky Date: Sun, 4 Aug 2024 13:32:03 +0300 Subject: [PATCH 6/7] OnOffServer: ignore StartUpOnOff value after reboot due to OTA (#34160) * feat: restore onOffValue after reboot during OTA applying * fix: style * fix: set onOffValueForStartUp in case of reserved values --- .../clusters/on-off-server/on-off-server.cpp | 74 ++++++++++++------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/src/app/clusters/on-off-server/on-off-server.cpp b/src/app/clusters/on-off-server/on-off-server.cpp index 98dfaf9da02c3e..d18aa09383a0d5 100644 --- a/src/app/clusters/on-off-server/on-off-server.cpp +++ b/src/app/clusters/on-off-server/on-off-server.cpp @@ -45,6 +45,7 @@ #endif // MATTER_DM_PLUGIN_MODE_BASE #include +#include #include using namespace chip; @@ -52,6 +53,8 @@ using namespace chip::app::Clusters; using namespace chip::app::Clusters::OnOff; using chip::Protocols::InteractionModel::Status; +using BootReasonType = GeneralDiagnostics::BootReasonEnum; + namespace { #ifdef MATTER_DM_PLUGIN_MODE_BASE @@ -95,6 +98,22 @@ bool IsKnownEnumValue(EnumType value) return (EnsureKnownEnumValue(value) != EnumType::kUnknownEnumValue); } +BootReasonType GetBootReason() +{ + BootReasonType bootReason = BootReasonType::kUnspecified; + + CHIP_ERROR error = DeviceLayer::GetDiagnosticDataProvider().GetBootReason(bootReason); + if (error != CHIP_NO_ERROR) + { + ChipLogError(Zcl, "Unable to retrieve boot reason: %" CHIP_ERROR_FORMAT, error.Format()); + bootReason = BootReasonType::kUnspecified; + } + + ChipLogProgress(Zcl, "Boot reason: %u", to_underlying(bootReason)); + + return bootReason; +} + } // namespace #ifdef MATTER_DM_PLUGIN_LEVEL_CONTROL @@ -537,35 +556,36 @@ Status OnOffServer::getOnOffValueForStartUp(chip::EndpointId endpoint, bool & on { app::DataModel::Nullable startUpOnOff; Status status = Attributes::StartUpOnOff::Get(endpoint, startUpOnOff); - if (status == Status::Success) + VerifyOrReturnError(status == Status::Success, status); + + bool currentOnOff = false; + status = Attributes::OnOff::Get(endpoint, ¤tOnOff); + VerifyOrReturnError(status == Status::Success, status); + + if (startUpOnOff.IsNull() || GetBootReason() == BootReasonType::kSoftwareUpdateCompleted) { - // Initialise updated value to 0 - bool updatedOnOff = false; - status = Attributes::OnOff::Get(endpoint, &updatedOnOff); - if (status == Status::Success) - { - if (!startUpOnOff.IsNull()) - { - switch (startUpOnOff.Value()) - { - case OnOff::StartUpOnOffEnum::kOff: - updatedOnOff = false; // Off - break; - case OnOff::StartUpOnOffEnum::kOn: - updatedOnOff = true; // On - break; - case OnOff::StartUpOnOffEnum::kToggle: - updatedOnOff = !updatedOnOff; - break; - default: - // All other values 0x03- 0xFE are reserved - no action. - break; - } - } - onOffValueForStartUp = updatedOnOff; - } + onOffValueForStartUp = currentOnOff; + return Status::Success; } - return status; + + switch (startUpOnOff.Value()) + { + case OnOff::StartUpOnOffEnum::kOff: + onOffValueForStartUp = false; // Off + break; + case OnOff::StartUpOnOffEnum::kOn: + onOffValueForStartUp = true; // On + break; + case OnOff::StartUpOnOffEnum::kToggle: + onOffValueForStartUp = !currentOnOff; + break; + default: + // All other values 0x03- 0xFE are reserved - no action. + onOffValueForStartUp = currentOnOff; + break; + } + + return Status::Success; } bool OnOffServer::offCommand(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath) From bbef51a418c17d5c2eaf667388cfec70383f524d Mon Sep 17 00:00:00 2001 From: lpbeliveau-silabs <112982107+lpbeliveau-silabs@users.noreply.github.com> Date: Sun, 4 Aug 2024 10:18:15 -0400 Subject: [PATCH 7/7] Fixed discrepancy between script and test plan for pics in step 9e (#34734) --- src/python_testing/TC_CC_10_1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_CC_10_1.py b/src/python_testing/TC_CC_10_1.py index 3f1e40278bb0c6..dee2dfad442485 100644 --- a/src/python_testing/TC_CC_10_1.py +++ b/src/python_testing/TC_CC_10_1.py @@ -502,7 +502,7 @@ async def test_TC_CC_10_1(self): asserts.assert_equal(ColorLoopDirection, 1, "ColorLoopDirection is not 1") self.step("9e") - if self.pics_guard(self.check_pics("CC.S.C44.Rsp")): + if self.pics_guard(self.check_pics("CC.S.F02")): ColorLoopTime = await self.read_single_attribute_check_success(cluster, attributes.ColorLoopTime) asserts.assert_equal(ColorLoopTime, 5, "ColorLoopTime is not 5")