-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IDM-10.4: check that CI PICS is not on for cert (#33817)
* IDM-10.1: check that CI PICS is not on for cert Also adding a test of the test to prove that this works. Added attribute tests as well. * Restyled by autopep8 * Restyled by isort * linter * missed one * whoopsie-doodles, changed the wrong one * add to tests.yaml --------- Co-authored-by: Restyled.io <[email protected]>
- Loading branch information
1 parent
94d5100
commit 9306418
Showing
6 changed files
with
158 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#!/usr/bin/env -S python3 -B | ||
# | ||
# Copyright (c) 2024 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. | ||
# | ||
|
||
import os | ||
import sys | ||
|
||
import chip.clusters as Clusters | ||
from chip.clusters import Attribute | ||
|
||
try: | ||
from pics_support import parse_pics_xml | ||
except ImportError: | ||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
from pics_support import parse_pics_xml | ||
|
||
from MockTestRunner import MockTestRunner | ||
|
||
# Reachable attribute is off in the pics file | ||
# MaxPathsPerInvoke is not include in the pics file | ||
# Vendor ID is included on ON in the PICS file | ||
|
||
|
||
def create_read(include_reachable: bool = False, include_max_paths: bool = False, include_vendor_id: bool = True) -> Attribute.AsyncReadTransaction.ReadResponse: | ||
# Attribute read here is set to match the example_pics_xml_basic_info.xml in this directory | ||
bi = Clusters.BasicInformation.Attributes | ||
attrs = {bi.DataModelRevision: 1, | ||
bi.VendorName: 'testVendor', | ||
bi.ProductName: 'testProduct', | ||
bi.ProductID: 0x8000, | ||
bi.NodeLabel: 'label', | ||
bi.Location: 'XX', | ||
bi.HardwareVersion: 1, | ||
bi.HardwareVersionString: 'one', | ||
bi.SoftwareVersion: 2, | ||
bi.SoftwareVersionString: 'two', | ||
bi.ManufacturingDate: 'today', | ||
bi.PartNumber: 'three', | ||
bi.ProductURL: 'example.com', | ||
bi.ProductLabel: 'myProduct', | ||
bi.SerialNumber: 'ABCD1234', | ||
bi.LocalConfigDisabled: False, | ||
bi.UniqueID: 'Hashy-McHashface'} | ||
if include_reachable: | ||
attrs[bi.Reachable] = True | ||
if include_max_paths: | ||
attrs[bi.MaxPathsPerInvoke] = 2 | ||
if include_vendor_id: | ||
attrs[bi.VendorID] = 0xFFF1 | ||
|
||
attrs[bi.AttributeList] = [a.attribute_id for a in attrs.keys()] | ||
attrs[bi.AcceptedCommandList] = [] | ||
attrs[bi.GeneratedCommandList] = [] | ||
attrs[bi.FeatureMap] = 0 | ||
|
||
resp = Attribute.AsyncReadTransaction.ReadResponse({}, [], {}) | ||
resp.attributes = {0: {Clusters.BasicInformation: attrs}} | ||
|
||
tlv_attrs = {a.attribute_id: value for a, value in attrs.items()} | ||
resp.tlvAttributes = {0: {Clusters.BasicInformation.id: tlv_attrs}} | ||
|
||
return resp | ||
|
||
|
||
def main(): | ||
# TODO: add the same test for commands and features | ||
script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
with open(f'{script_dir}/example_pics_xml_basic_info.xml') as f: | ||
pics = parse_pics_xml(f.read()) | ||
test_runner = MockTestRunner('TC_pics_checker.py', 'TC_PICS_Checker', 'test_TC_IDM_10_4', 0, pics) | ||
failures = [] | ||
|
||
# Success, include vendor ID, which IS in the pics file, and neither of the incorrect ones | ||
resp = create_read() | ||
print(resp) | ||
if not test_runner.run_test_with_mock_read(resp): | ||
failures.append("Test case failure: Vendor ID included - expected pass") | ||
|
||
# Failure because Vendor ID is not included in the read, but included in the PICS | ||
resp = create_read(include_vendor_id=False) | ||
if test_runner.run_test_with_mock_read(resp): | ||
failures.append("Test case failure: Vendor ID not included - expected failure") | ||
|
||
# Failure because Reachable is included in the read, but not in the PICS | ||
resp = create_read(include_reachable=True) | ||
if test_runner.run_test_with_mock_read(resp): | ||
failures.append("Test case failure: Reachable included but not in PICS- expected failure") | ||
|
||
# Failure because MaxPathsPerInvoke is included in the read, but not in the PICS | ||
resp = create_read(include_max_paths=True) | ||
if test_runner.run_test_with_mock_read(resp): | ||
failures.append("Test case failure: MaxPathsPerInvoke included but not in PICS- expected failure") | ||
|
||
pics['PICS_SDK_CI_ONLY'] = True | ||
test_runner.config.pics = pics | ||
# This is a success case for the attributes (as seen above), but the test should fail because the CI PICS is added | ||
resp = create_read() | ||
if test_runner.run_test_with_mock_read(resp): | ||
failures.append("Test case failure: SDK CI PICS is included - expected failure") | ||
|
||
test_runner.Shutdown() | ||
|
||
print( | ||
f"Test of tests: PICS - test response incorrect: {len(failures)}") | ||
for f in failures: | ||
print(f) | ||
|
||
return 1 if failures else 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |