1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2024 Antmicro
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# SPDX-License-Identifier: Apache-2.0
19
20from argparse import ArgumentParser
21import json
22import subprocess
23import os
24
25def main():
26    parser = ArgumentParser()
27    parser.add_argument('json', type=str, help='JSON file with test info')
28    args = parser.parse_args()
29
30    with open(args.json, 'r') as json_file:
31        test_desc = json.loads(json_file.read())
32
33    for test in test_desc:
34        output = test["file"]
35        dir = os.path.dirname(output)
36        if not os.path.exists(dir):
37            print(f"Creating the `{dir}` directory")
38            os.makedirs(dir)
39        print(f'Generating `{output}`...')
40        subprocess.run(test['peakrdl'])
41
42    print('Done!')
43
44
45if __name__ == '__main__':
46    main()
47