|
| 1 | +#!/usr/bin/env -S python3 -B |
| 2 | +# |
| 3 | +# Copyright (c) 2024 Project CHIP Authors |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | + |
| 19 | +import os |
| 20 | +import sys |
| 21 | + |
| 22 | +import chip.clusters as Clusters |
| 23 | +from chip.clusters import Attribute |
| 24 | + |
| 25 | +try: |
| 26 | + from pics_support import parse_pics_xml |
| 27 | +except ImportError: |
| 28 | + sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) |
| 29 | + from pics_support import parse_pics_xml |
| 30 | + |
| 31 | +from MockTestRunner import MockTestRunner |
| 32 | + |
| 33 | +# Reachable attribute is off in the pics file |
| 34 | +# MaxPathsPerInvoke is not include in the pics file |
| 35 | +# Vendor ID is included on ON in the PICS file |
| 36 | + |
| 37 | + |
| 38 | +def create_read(include_reachable: bool = False, include_max_paths: bool = False, include_vendor_id: bool = True) -> Attribute.AsyncReadTransaction.ReadResponse: |
| 39 | + # Attribute read here is set to match the example_pics_xml_basic_info.xml in this directory |
| 40 | + bi = Clusters.BasicInformation.Attributes |
| 41 | + attrs = {bi.DataModelRevision: 1, |
| 42 | + bi.VendorName: 'testVendor', |
| 43 | + bi.ProductName: 'testProduct', |
| 44 | + bi.ProductID: 0x8000, |
| 45 | + bi.NodeLabel: 'label', |
| 46 | + bi.Location: 'XX', |
| 47 | + bi.HardwareVersion: 1, |
| 48 | + bi.HardwareVersionString: 'one', |
| 49 | + bi.SoftwareVersion: 2, |
| 50 | + bi.SoftwareVersionString: 'two', |
| 51 | + bi.ManufacturingDate: 'today', |
| 52 | + bi.PartNumber: 'three', |
| 53 | + bi.ProductURL: 'example.com', |
| 54 | + bi.ProductLabel: 'myProduct', |
| 55 | + bi.SerialNumber: 'ABCD1234', |
| 56 | + bi.LocalConfigDisabled: False, |
| 57 | + bi.UniqueID: 'Hashy-McHashface'} |
| 58 | + if include_reachable: |
| 59 | + attrs[bi.Reachable] = True |
| 60 | + if include_max_paths: |
| 61 | + attrs[bi.MaxPathsPerInvoke] = 2 |
| 62 | + if include_vendor_id: |
| 63 | + attrs[bi.VendorID] = 0xFFF1 |
| 64 | + |
| 65 | + attrs[bi.AttributeList] = [a.attribute_id for a in attrs.keys()] |
| 66 | + attrs[bi.AcceptedCommandList] = [] |
| 67 | + attrs[bi.GeneratedCommandList] = [] |
| 68 | + attrs[bi.FeatureMap] = 0 |
| 69 | + |
| 70 | + resp = Attribute.AsyncReadTransaction.ReadResponse({}, [], {}) |
| 71 | + resp.attributes = {0: {Clusters.BasicInformation: attrs}} |
| 72 | + |
| 73 | + tlv_attrs = {a.attribute_id: value for a, value in attrs.items()} |
| 74 | + resp.tlvAttributes = {0: {Clusters.BasicInformation.id: tlv_attrs}} |
| 75 | + |
| 76 | + return resp |
| 77 | + |
| 78 | + |
| 79 | +def main(): |
| 80 | + # TODO: add the same test for commands and features |
| 81 | + script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 82 | + with open(f'{script_dir}/example_pics_xml_basic_info.xml') as f: |
| 83 | + pics = parse_pics_xml(f.read()) |
| 84 | + test_runner = MockTestRunner('TC_pics_checker.py', 'TC_PICS_Checker', 'test_TC_IDM_10_4', 0, pics) |
| 85 | + failures = [] |
| 86 | + |
| 87 | + # Success, include vendor ID, which IS in the pics file, and neither of the incorrect ones |
| 88 | + resp = create_read() |
| 89 | + print(resp) |
| 90 | + if not test_runner.run_test_with_mock_read(resp): |
| 91 | + failures.append("Test case failure: Vendor ID included - expected pass") |
| 92 | + |
| 93 | + # Failure because Vendor ID is not included in the read, but included in the PICS |
| 94 | + resp = create_read(include_vendor_id=False) |
| 95 | + if test_runner.run_test_with_mock_read(resp): |
| 96 | + failures.append("Test case failure: Vendor ID not included - expected failure") |
| 97 | + |
| 98 | + # Failure because Reachable is included in the read, but not in the PICS |
| 99 | + resp = create_read(include_reachable=True) |
| 100 | + if test_runner.run_test_with_mock_read(resp): |
| 101 | + failures.append("Test case failure: Reachable included but not in PICS- expected failure") |
| 102 | + |
| 103 | + # Failure because MaxPathsPerInvoke is included in the read, but not in the PICS |
| 104 | + resp = create_read(include_max_paths=True) |
| 105 | + if test_runner.run_test_with_mock_read(resp): |
| 106 | + failures.append("Test case failure: MaxPathsPerInvoke included but not in PICS- expected failure") |
| 107 | + |
| 108 | + pics['PICS_SDK_CI_ONLY'] = True |
| 109 | + test_runner.config.pics = pics |
| 110 | + # This is a success case for the attributes (as seen above), but the test should fail because the CI PICS is added |
| 111 | + resp = create_read() |
| 112 | + if test_runner.run_test_with_mock_read(resp): |
| 113 | + failures.append("Test case failure: SDK CI PICS is included - expected failure") |
| 114 | + |
| 115 | + test_runner.Shutdown() |
| 116 | + |
| 117 | + print( |
| 118 | + f"Test of tests: PICS - test response incorrect: {len(failures)}") |
| 119 | + for f in failures: |
| 120 | + print(f) |
| 121 | + |
| 122 | + return 1 if failures else 0 |
| 123 | + |
| 124 | + |
| 125 | +if __name__ == "__main__": |
| 126 | + sys.exit(main()) |
0 commit comments