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 pathlib
18import Lib.test
19
20
21def generate(params, args):
22    """ Generate data for a number of tests and optionally create corresponding code to run the test"""
23
24    # Filter out params from suite to pass on to each test
25    def is_common(key):
26        return key not in ["tests"]
27
28    common_test_params = {key: val for key, val in params.items() if is_common(key)}
29
30    # Create fpaths related to the test suite
31    # NOTE: All paths are relative to the 'cmsis-nn/Tests/UnitTest/' folder
32    fpaths = {}
33    fpaths["json_template_folder"] = pathlib.Path("RefactoredTestGen") / "JsonTemplates"
34
35    # Generate data for each test
36    tests = []
37    for test_params in params["tests"]:
38        if (test_params["name"] in args.tests) or (args.tests == []):
39            print()
40            print(f"- {test_params['name']}")
41
42            # Test params overrides common params
43            test_params = common_test_params | test_params
44
45            test = Lib.test.generate(test_params, args, fpaths)
46            tests.append(test)
47
48    return tests
49