|
| 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 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto |
| 28 | +# === END CI TEST ARGUMENTS === |
| 29 | +# |
| 30 | + |
| 31 | +import chip.clusters as Clusters |
| 32 | +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main |
| 33 | +from mobly import asserts |
| 34 | + |
| 35 | + |
| 36 | +class TC_DGSW_2_1(MatterBaseTest): |
| 37 | + |
| 38 | + @staticmethod |
| 39 | + def is_valid_uint64_value(value): |
| 40 | + return isinstance(value, int) and 0 <= value <= 0xFFFFFFFFFFFFFFFF |
| 41 | + |
| 42 | + @staticmethod |
| 43 | + def is_valid_uint32_value(value): |
| 44 | + return isinstance(value, int) and 0 <= value <= 0xFFFFFFFF |
| 45 | + |
| 46 | + async def read_dgsw_attribute_expect_success(self, endpoint, attribute): |
| 47 | + cluster = Clusters.Objects.SoftwareDiagnostics |
| 48 | + return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute) |
| 49 | + |
| 50 | + def desc_TC_DGSW_2_1(self) -> str: |
| 51 | + """Returns a description of this test""" |
| 52 | + return "[TC-DGSW-2.1] Attributes with Server as DUT" |
| 53 | + |
| 54 | + def pics_TC_DGSW_2_1(self) -> list[str]: |
| 55 | + return ["DGSW.S"] |
| 56 | + |
| 57 | + def steps_TC_DGSW_2_1(self) -> list[TestStep]: |
| 58 | + steps = [ |
| 59 | + TestStep(1, "Commissioning, already done", is_commissioning=True), |
| 60 | + TestStep(2, "Read the ThreadMetrics attribute"), |
| 61 | + TestStep(3, "Read the CurrentHeapFree attribute"), |
| 62 | + TestStep(4, "Read the CurrentHeapUsed attribute"), |
| 63 | + TestStep(5, "Read the CurrentHeapHighWatermark attribute"), |
| 64 | + ] |
| 65 | + return steps |
| 66 | + |
| 67 | + @async_test_body |
| 68 | + async def test_TC_DGSW_2_1(self): |
| 69 | + |
| 70 | + endpoint = self.user_params.get("endpoint", 0) |
| 71 | + |
| 72 | + # STEP 1: Commission DUT (already done) |
| 73 | + self.step(1) |
| 74 | + |
| 75 | + attributes = Clusters.SoftwareDiagnostics.Attributes |
| 76 | + attribute_list = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.AttributeList) |
| 77 | + |
| 78 | + # STEP 2: TH reads from the DUT the ThreadMetrics attribute |
| 79 | + self.step(2) |
| 80 | + if self.pics_guard(Clusters.SoftwareDiagnostics.Attributes.ThreadMetrics.attribute_id in attribute_list): |
| 81 | + thread_metrics_list = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.ThreadMetrics) |
| 82 | + # the Id field is mandatory |
| 83 | + asserts.assert_true(self.is_valid_uint64_value(thread_metrics_list[0].id), "Id field should be a uint64 type") |
| 84 | + if thread_metrics_list[0].name is not None: |
| 85 | + asserts.assert_true(thread_metrics_list[0].name, str, "Name field should be a string type") |
| 86 | + if thread_metrics_list[0].stackFreeCurrent is not None: |
| 87 | + asserts.assert_true(self.is_valid_uint32_value( |
| 88 | + thread_metrics_list[0].stackFreeCurrent), "StackFreeCurrent field should be a uint32 type") |
| 89 | + if thread_metrics_list[0].stackFreeMinimum is not None: |
| 90 | + asserts.assert_true(self.is_valid_uint32_value( |
| 91 | + thread_metrics_list[0].stackFreeMinimum), "StackFreeMinimum field should be a uint32 type") |
| 92 | + if thread_metrics_list[0].stackSize is not None: |
| 93 | + asserts.assert_true(self.is_valid_uint32_value( |
| 94 | + thread_metrics_list[0].stackSize), "StackSize field should be a uint32s type") |
| 95 | + |
| 96 | + # STEP 3: TH reads from the DUT the CurrentHeapFree attribute |
| 97 | + self.step(3) |
| 98 | + if self.pics_guard(Clusters.SoftwareDiagnostics.Attributes.CurrentHeapFree.attribute_id in attribute_list): |
| 99 | + current_heap_free_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapFree) |
| 100 | + asserts.assert_true(self.is_valid_uint64_value(current_heap_free_attr), "CurrentHeapFree field should be a uint64 type") |
| 101 | + |
| 102 | + # STEP 4: TH reads from the DUT the CurrentHeapUsed attribute |
| 103 | + self.step(4) |
| 104 | + if self.pics_guard(Clusters.SoftwareDiagnostics.Attributes.CurrentHeapUsed.attribute_id in attribute_list): |
| 105 | + current_heap_used_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapUsed) |
| 106 | + asserts.assert_true(self.is_valid_uint64_value(current_heap_used_attr), "CurrentHeapUsed field should be a uint64 type") |
| 107 | + |
| 108 | + # STEP 5: TH reads from the DUT the CurrentHeapHighWatermark attribute |
| 109 | + self.step(5) |
| 110 | + if self.pics_guard(Clusters.SoftwareDiagnostics.Attributes.CurrentHeapHighWatermark.attribute_id in attribute_list): |
| 111 | + current_heap_high_watermark_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapHighWatermark) |
| 112 | + asserts.assert_true(self.is_valid_uint64_value(current_heap_high_watermark_attr), |
| 113 | + "CurrentHeapHighWatermark field should be a uint64 type") |
| 114 | + |
| 115 | + |
| 116 | +if __name__ == "__main__": |
| 117 | + default_matter_test_main() |
0 commit comments