1# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <open-source-office@arm.com> 2# 3# SPDX-License-Identifier: Apache-2.0 4# 5# Licensed under the Apache License, Version 2.0 (the License); you may 6# not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# 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, WITHOUT 13# 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# 17import json 18import Lib.test_suite 19import sys 20 21 22def generate(args): 23 """Generate a number of test suites defined by a json-file test plan""" 24 25 test_plan = args.test_plan.read_text() 26 test_suite_params_list = json.loads(test_plan) 27 28 # List available tests for convenience 29 if args.list: 30 for suite in test_suite_params_list: 31 print(f"{suite['suite_name']}") 32 for test in suite["tests"]: 33 print(f"- {test['name']}") 34 35 sys.exit() 36 37 test_suites = [] 38 for s in args.test_suites: 39 test_suites.append(list(filter(None, str.split(s, '/')))[-1]) 40 41 print(f"\nGenerating tests from {args.test_plan}") 42 for test_suite_params in test_suite_params_list: 43 if (test_suite_params["suite_name"] in test_suites) or (test_suites == []): 44 test_names = [test["name"] for test in test_suite_params["tests"] if test["name"] in args.tests] 45 if (len(test_names) > 0) or (args.tests == []): 46 print(f"{test_suite_params['suite_name']}") 47 Lib.test_suite.generate(test_suite_params, args) 48