|
| 1 | +# |
| 2 | +# Copyright (c) 2023 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: |
| 23 | +# run1: |
| 24 | +# app: ${ALL_CLUSTERS_APP} |
| 25 | +# app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json |
| 26 | +# script-args: > |
| 27 | +# --storage-path admin_storage.json |
| 28 | +# --manual-code 10054912339 |
| 29 | +# --PICS src/app/tests/suites/certification/ci-pics-values |
| 30 | +# --trace-to json:${TRACE_TEST_JSON}.json |
| 31 | +# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto |
| 32 | +# --endpoint 1 |
| 33 | +# factory-reset: true |
| 34 | +# quiet: true |
| 35 | +# run2: |
| 36 | +# app: ${ALL_CLUSTERS_APP} |
| 37 | +# app-args: --discriminator 1234 --passcode 20202021 --KVS kvs1 |
| 38 | +# script-args: > |
| 39 | +# --storage-path admin_storage.json |
| 40 | +# --discriminator 1234 |
| 41 | +# --passcode 20202021 |
| 42 | +# --endpoint 1 |
| 43 | +# --commissioning-method on-network |
| 44 | +# factory-reset: true |
| 45 | +# quiet: true |
| 46 | +# run3: |
| 47 | +# app: ${ALL_CLUSTERS_APP} |
| 48 | +# app-args: --discriminator 1234 --KVS kvs1 |
| 49 | +# script-args: > |
| 50 | +# --storage-path admin_storage.json |
| 51 | +# --endpoint 1 |
| 52 | +# --discriminator 1234 |
| 53 | +# --passcode 20202021 |
| 54 | +# factory-reset: false |
| 55 | +# quiet: true |
| 56 | +# === END CI TEST ARGUMENTS === |
| 57 | + |
| 58 | +# Run 1: Tests PASE connection using manual code |
| 59 | +# Run 2: Tests CASE connection using manual discriminator and passcode |
| 60 | +# Run 3: Tests without factory reset |
| 61 | + |
| 62 | +import asyncio |
| 63 | + |
| 64 | +import chip.clusters as Clusters |
| 65 | +from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main |
| 66 | +from mobly import asserts |
| 67 | + |
| 68 | + |
| 69 | +class TC_TestAttrAvail(MatterBaseTest): |
| 70 | + # Using get_code and a modified version of setup_class_helper functions from chip.testing.basic_composition module |
| 71 | + def get_code(self, dev_ctrl): |
| 72 | + created_codes = [] |
| 73 | + for idx, discriminator in enumerate(self.matter_test_config.discriminators): |
| 74 | + created_codes.append(dev_ctrl.CreateManualCode(discriminator, self.matter_test_config.setup_passcodes[idx])) |
| 75 | + |
| 76 | + setup_codes = self.matter_test_config.qr_code_content + self.matter_test_config.manual_code + created_codes |
| 77 | + if not setup_codes: |
| 78 | + return None |
| 79 | + asserts.assert_equal(len(setup_codes), 1, |
| 80 | + "Require exactly one of either --qr-code, --manual-code or (--discriminator and --passcode).") |
| 81 | + return setup_codes[0] |
| 82 | + |
| 83 | + async def setup_class_helper(self, allow_pase: bool = True): |
| 84 | + dev_ctrl = self.default_controller |
| 85 | + self.problems = [] |
| 86 | + |
| 87 | + node_id = self.dut_node_id |
| 88 | + |
| 89 | + task_list = [] |
| 90 | + if allow_pase and self.get_code(dev_ctrl): |
| 91 | + setup_code = self.get_code(dev_ctrl) |
| 92 | + pase_future = dev_ctrl.EstablishPASESession(setup_code, self.dut_node_id) |
| 93 | + task_list.append(asyncio.create_task(pase_future)) |
| 94 | + |
| 95 | + case_future = dev_ctrl.GetConnectedDevice(nodeid=node_id, allowPASE=False) |
| 96 | + task_list.append(asyncio.create_task(case_future)) |
| 97 | + |
| 98 | + for task in task_list: |
| 99 | + asyncio.ensure_future(task) |
| 100 | + |
| 101 | + done, pending = await asyncio.wait(task_list, return_when=asyncio.FIRST_COMPLETED) |
| 102 | + |
| 103 | + for task in pending: |
| 104 | + try: |
| 105 | + task.cancel() |
| 106 | + await task |
| 107 | + except asyncio.CancelledError: |
| 108 | + pass |
| 109 | + |
| 110 | + wildcard_read = (await dev_ctrl.Read(node_id, [()])) |
| 111 | + |
| 112 | + # ======= State kept for use by all tests ======= |
| 113 | + # All endpoints in "full object" indexing format |
| 114 | + self.endpoints = wildcard_read.attributes |
| 115 | + |
| 116 | + def steps_TC_TestAttrAvail(self) -> list[TestStep]: |
| 117 | + return [ |
| 118 | + TestStep(1, "Commissioning, already done", is_commissioning=True), |
| 119 | + TestStep(2, "Checking OperationalState attribute is available on endpoint"), |
| 120 | + TestStep(3, "Checking Operational Resume command is available on endpoint"), |
| 121 | + TestStep(4, "Checking Timezone feature is available on endpoint"), |
| 122 | + ] |
| 123 | + |
| 124 | + def TC_TestAttrAvail(self) -> list[str]: |
| 125 | + return ["RVCOPSTATE.S"] |
| 126 | + |
| 127 | + @async_test_body |
| 128 | + async def setup_class(self): |
| 129 | + super().setup_class() |
| 130 | + await self.setup_class_helper() |
| 131 | + |
| 132 | + # ======= START OF ACTUAL TESTS ======= |
| 133 | + @async_test_body |
| 134 | + async def test_TC_TestAttrAvail(self): |
| 135 | + self.step(1) |
| 136 | + |
| 137 | + if self.matter_test_config.endpoint is None or self.matter_test_config.endpoint == 0: |
| 138 | + asserts.fail("--endpoint must be set and not set to 0 for this test to run correctly.") |
| 139 | + self.endpoint = self.get_endpoint() |
| 140 | + asserts.assert_false(self.endpoint is None, "--endpoint <endpoint> must be included on the command line in.") |
| 141 | + |
| 142 | + cluster = Clusters.RvcOperationalState |
| 143 | + attributes = cluster.Attributes |
| 144 | + commands = cluster.Commands |
| 145 | + self.th1 = self.default_controller |
| 146 | + |
| 147 | + self.step(2) |
| 148 | + attr_should_be_there = await self.attribute_guard(endpoint=self.endpoint, attribute=attributes.OperationalState) |
| 149 | + asserts.assert_true(attr_should_be_there, True) |
| 150 | + self.print_step("Operational State Attr", attr_should_be_there) |
| 151 | + |
| 152 | + self.step(3) |
| 153 | + cmd_should_be_there = await self.command_guard(endpoint=self.endpoint, command=commands.Resume) |
| 154 | + asserts.assert_true(cmd_should_be_there, True) |
| 155 | + self.print_step("Operational Resume Command available ", cmd_should_be_there) |
| 156 | + |
| 157 | + self.step(4) |
| 158 | + feat_should_be_there = await self.feature_guard(endpoint=self.endpoint, cluster=Clusters.BooleanStateConfiguration, feature_int=Clusters.BooleanStateConfiguration.Bitmaps.Feature.kAudible) |
| 159 | + asserts.assert_true(feat_should_be_there, True) |
| 160 | + self.print_step("Boolean State Config Audio Feature available ", feat_should_be_there) |
| 161 | + |
| 162 | + |
| 163 | +if __name__ == "__main__": |
| 164 | + default_matter_test_main() |
0 commit comments