1#!/usr/bin/env python3
2#
3# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
4#
5# SPDX-License-Identifier: Apache-2.0
6#
7# Licensed under the Apache License, Version 2.0 (the License); you may
8# not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an AS IS BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19import os
20
21os.environ["TF_USE_LEGACY_KERAS"] = "1"  # See https://github.com/tensorflow/tensorflow/releases/tag/v2.16.1
22os.environ['TF_CPP_MIN_LOG_LEVEL'] = "2"  # See https://github.com/tensorflow/tensorflow/issues/59779
23import json
24import argparse
25import pathlib
26import sys
27
28import Lib.test_plan
29
30
31def main():
32    parser = argparse.ArgumentParser(
33        prog="generate_test_data",
34        description="Generates reference data and test code for CMSIS-NN kernels. Tensorflow, Tflite or TFLM may be "
35        "used for reference."
36    )
37
38    parser.add_argument("-p",
39                        "--test_plan",
40                        type=pathlib.Path,
41                        default="./RefactoredTestGen/test_plan.json",
42                        help="Path to a json test-plan")
43    parser.add_argument("-s",
44                        "--test_suites",
45                        nargs='+',
46                        default=[],
47                        help="Generate specific test suites, defaults to all test suites")
48    parser.add_argument("-t",
49                        "--tests",
50                        action="append",
51                        default=[],
52                        help="Generate specific tests, defaults to all tests")
53
54    parser.add_argument("--schema",
55                        type=pathlib.Path,
56                        default="../../../tflite_micro/tensorflow/lite/schema/schema.fbs",
57                        help="Path to the schema-file needed for generating tflite-files with flatc")
58    parser.add_argument("--list", action="store_true", help="Only list tests in test plan")
59
60    args = parser.parse_args()
61
62    Lib.test_plan.generate(args)
63
64
65if __name__ == '__main__':
66    sys.exit(main())
67