|
| 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 | +import argparse |
| 19 | +import os |
| 20 | +import sys |
| 21 | + |
| 22 | +from rich.console import Console |
| 23 | + |
| 24 | +# Add the path to python_testing folder, in order to be able to import from matter_testing_support |
| 25 | +sys.path.append(os.path.abspath(sys.path[0] + "/../../python_testing")) |
| 26 | +from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main # noqa: E402 |
| 27 | +from spec_parsing_support import build_xml_clusters # noqa: E402 |
| 28 | + |
| 29 | +console = None |
| 30 | +xml_clusters = None |
| 31 | + |
| 32 | +parser = argparse.ArgumentParser() |
| 33 | +parser.add_argument('--pics-template', required=True) |
| 34 | +args, unknown = parser.parse_known_args() |
| 35 | + |
| 36 | +xmlTemplatePathStr = args.pics_template |
| 37 | +if not xmlTemplatePathStr.endswith('/'): |
| 38 | + xmlTemplatePathStr += '/' |
| 39 | + |
| 40 | +# Load PICS XML templates |
| 41 | +print("Capture list of PICS XML templates") |
| 42 | +xmlFileList = os.listdir(xmlTemplatePathStr) |
| 43 | +for PICSXmlFile in xmlFileList: |
| 44 | + print(f"{xmlTemplatePathStr}/{PICSXmlFile}") |
| 45 | + |
| 46 | + |
| 47 | +class XMLPICSValidator(MatterBaseTest): |
| 48 | + @async_test_body |
| 49 | + async def test_xml_pics_validator(self): |
| 50 | + |
| 51 | + # Create console to print |
| 52 | + global console |
| 53 | + console = Console() |
| 54 | + |
| 55 | + global xml_clusters |
| 56 | + xml_clusters, problems = build_xml_clusters() |
| 57 | + |
| 58 | + for cluster in xml_clusters: |
| 59 | + |
| 60 | + fileName = "" |
| 61 | + clusterName = xml_clusters[cluster].name |
| 62 | + |
| 63 | + if "ICDManagement" == clusterName: |
| 64 | + picsFileName = "ICD Management" |
| 65 | + |
| 66 | + elif "OTA Software Update Provider" in clusterName or \ |
| 67 | + "OTA Software Update Requestor" in clusterName: |
| 68 | + picsFileName = "OTA Software Update" |
| 69 | + |
| 70 | + elif "On/Off" == clusterName: |
| 71 | + picsFileName = clusterName.replace("/", "-") |
| 72 | + |
| 73 | + elif "GroupKeyManagement" == clusterName: |
| 74 | + picsFileName = "Group Communication" |
| 75 | + |
| 76 | + elif "Wake on LAN" == clusterName or \ |
| 77 | + "Low Power" == clusterName or \ |
| 78 | + "Keypad Input" == clusterName or \ |
| 79 | + "Audio Output" == clusterName or \ |
| 80 | + "Media Input" == clusterName or \ |
| 81 | + "Target Navigator" == clusterName or \ |
| 82 | + "Content Control" == clusterName or \ |
| 83 | + "Channel" == clusterName or \ |
| 84 | + "Media Playback" == clusterName or \ |
| 85 | + "Account Login" == clusterName or \ |
| 86 | + "Application Basic" == clusterName or \ |
| 87 | + "Content Launcher" == clusterName or \ |
| 88 | + "Content App Observer" == clusterName or \ |
| 89 | + "Application Launcher" == clusterName: |
| 90 | + |
| 91 | + picsFileName = "Media Cluster" |
| 92 | + |
| 93 | + elif "Operational Credentials" == clusterName: |
| 94 | + picsFileName = "Node Operational Credentials" |
| 95 | + |
| 96 | + # Workaround for naming colisions with current logic |
| 97 | + elif "Thermostat" == clusterName: |
| 98 | + picsFileName = "Thermostat Cluster" |
| 99 | + |
| 100 | + elif "Boolean State" == clusterName: |
| 101 | + picsFileName = "Boolean State Cluster" |
| 102 | + |
| 103 | + elif "AccessControl" in clusterName: |
| 104 | + picsFileName = "Access Control Cluster" |
| 105 | + |
| 106 | + else: |
| 107 | + picsFileName = clusterName |
| 108 | + |
| 109 | + for file in xmlFileList: |
| 110 | + if file.lower().startswith(picsFileName.lower()): |
| 111 | + fileName = file |
| 112 | + break |
| 113 | + |
| 114 | + if fileName: |
| 115 | + console.print(f"[blue]\"{clusterName}\" - \"{fileName}\" ✅") |
| 116 | + else: |
| 117 | + console.print(f"[red]Could not find matching file for \"{clusterName}\" ❌") |
| 118 | + continue |
| 119 | + |
| 120 | + |
| 121 | +if __name__ == "__main__": |
| 122 | + default_matter_test_main() |
0 commit comments