blob: 01baad1d638d63352a62c19591297fbff17c7810 [file] [log] [blame]
Minos Galanakis2c824b42025-03-20 09:28:45 +00001#!/usr/bin/env python3
2"""Generate wrapper functions for PSA function calls.
3"""
4
5# Copyright The Mbed TLS Contributors
6# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7
8import argparse
9from mbedtls_framework.code_wrapper.psa_test_wrapper import PSATestWrapper, PSALoggingTestWrapper
10from mbedtls_framework import build_tree
11
12def main() -> None:
13 default_c_output_file_name = 'tests/src/psa_test_wrappers.c'
14 default_h_output_file_name = 'tests/include/test/psa_test_wrappers.h'
15
16 project_root = build_tree.guess_project_root()
17 if build_tree.looks_like_mbedtls_root(project_root) and \
18 not build_tree.is_mbedtls_3_6():
19 default_c_output_file_name = 'tf-psa-crypto/' + default_c_output_file_name
20 default_h_output_file_name = 'tf-psa-crypto/' + default_h_output_file_name
21
22 parser = argparse.ArgumentParser(description=globals()['__doc__'])
23 parser.add_argument('--log',
24 help='Stream to log to (default: no logging code)')
25 parser.add_argument('--output-c',
26 metavar='FILENAME',
27 default=default_c_output_file_name,
28 help=('Output .c file path (default: {}; skip .c output if empty)'
29 .format(default_c_output_file_name)))
30 parser.add_argument('--output-h',
31 metavar='FILENAME',
32 default=default_h_output_file_name,
33 help=('Output .h file path (default: {}; skip .h output if empty)'
34 .format(default_h_output_file_name)))
35 options = parser.parse_args()
36
37 if options.log:
38 generator = PSALoggingTestWrapper(default_h_output_file_name,
39 default_c_output_file_name,
40 options.log) #type: PSATestWrapper
41 else:
42 generator = PSATestWrapper(default_h_output_file_name,
43 default_c_output_file_name)
44
45 if options.output_h:
46 generator.write_h_file(options.output_h)
47 if options.output_c:
48 generator.write_c_file(options.output_c)
49
50if __name__ == '__main__':
51 main()