blob: 1574556d5b21c79426db3ef3a38a4ce6fe4d3d99 [file] [log] [blame]
Azim Khan1de892b2017-06-09 15:02:36 +01001#line 2 "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +01002/*
3 * *** THIS FILE HAS BEEN MACHINE GENERATED ***
4 *
5 * This file has been machine generated using the script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +01006 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +01007 *
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +01008 * Test file : $test_file
Azim Khan191e9042017-06-09 12:39:00 +01009 *
10 * The following files were used to create this file.
11 *
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010012 * Main code file : $test_main_file
13 * Platform code file : $test_platform_file
14 * Helper file : $test_common_helper_file
15 * Test suite file : $test_case_file
16 * Test suite data : $test_case_data_file
Azim Khan191e9042017-06-09 12:39:00 +010017 *
18 *
Mohammad Azim Khand2d01122018-07-18 17:48:37 +010019 * This file is part of Mbed TLS (https://tls.mbed.org)
Azim Khan191e9042017-06-09 12:39:00 +010020 */
Paul Bakkerde56ca12013-09-15 17:05:21 +020021
Azim Khan191e9042017-06-09 12:39:00 +010022#if !defined(MBEDTLS_CONFIG_FILE)
23#include <mbedtls/config.h>
24#else
25#include MBEDTLS_CONFIG_FILE
26#endif
Paul Bakker19343182013-08-16 13:31:10 +020027
Hanno Becker1cfc5dd2018-11-12 13:18:45 +000028#if defined(MBEDTLS_USE_PSA_CRYPTO)
29#include "psa/crypto.h"
30#endif /* MBEDTLS_USE_PSA_CRYPTO */
SimonB152ea182016-02-15 23:27:28 +000031
32/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010033/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000034
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010035$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020036
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010037#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010038
39
40/*----------------------------------------------------------------------------*/
41/* Test Suite Code */
42
43
44#define TEST_SUITE_ACTIVE
45
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010046$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010047
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010048#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010049
SimonB152ea182016-02-15 23:27:28 +000050
51/*----------------------------------------------------------------------------*/
52/* Test dispatch code */
53
Paul Bakker19343182013-08-16 13:31:10 +020054
Azim Khan191e9042017-06-09 12:39:00 +010055/**
56 * \brief Evaluates an expression/macro into its literal integer value.
57 * For optimizing space for embedded targets each expression/macro
58 * is identified by a unique identifier instead of string literals.
59 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010060 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010061 *
62 * \param exp_id Expression identifier.
63 * \param out_value Pointer to int to hold the integer.
64 *
65 * \return 0 if exp_id is found. 1 otherwise.
66 */
67int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010068{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010069 int ret = KEY_VALUE_MAPPING_FOUND;
70
71 (void) exp_id;
72 (void) out_value;
73
74 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010075 {
76$expression_code
77#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010078 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010079 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010080 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010081 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010082 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010083 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010084 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010085}
Paul Bakker19343182013-08-16 13:31:10 +020086
Paul Bakker19343182013-08-16 13:31:10 +020087
Azim Khan191e9042017-06-09 12:39:00 +010088/**
89 * \brief Checks if the dependency i.e. the compile flag is set.
90 * For optimizing space for embedded targets each dependency
91 * is identified by a unique identifier instead of string literals.
92 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010093 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010094 *
95 * \param exp_id Dependency identifier.
96 *
97 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
98 */
99int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100100{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100101 int ret = DEPENDENCY_NOT_SUPPORTED;
102
103 (void) dep_id;
104
105 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100106 {
107$dep_check_code
108#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100109 default:
110 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100111 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100112 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100113}
Paul Bakker19343182013-08-16 13:31:10 +0200114
SimonB8ca7bc42016-04-17 23:24:50 +0100115
Azim Khan191e9042017-06-09 12:39:00 +0100116/**
117 * \brief Function pointer type for test function wrappers.
118 *
119 *
120 * \param void ** Pointer to void pointers. Represents an array of test
121 * function parameters.
122 *
123 * \return void
124 */
125typedef void (*TestWrapper_t)( void ** );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100126
Azim Khan191e9042017-06-09 12:39:00 +0100127
128/**
129 * \brief Table of test function wrappers. Used by dispatch_test().
130 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100131 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100132 *
133 */
134TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100135{
136$dispatch_code
137#line $line_no "suites/main_test.function"
138};
Azim Khan191e9042017-06-09 12:39:00 +0100139
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500140/**
141 * \brief Execute the test function.
142 *
143 * This is a wrapper function around the test function execution
144 * to allow the setjmp() call used to catch any calls to the
145 * parameter failure callback, to be used. Calls to setjmp()
146 * can invalidate the state of any local auto variables.
147 *
148 * \param fp Function pointer to the test function
149 * \param params Parameters to pass
150 *
151 */
152void execute_function_ptr(TestWrapper_t fp, void **params)
153{
154#if defined(MBEDTLS_CHECK_PARAMS)
155 if ( setjmp( param_fail_jmp ) == 0 )
156 {
157 fp( params );
158 }
159 else
160 {
161 /* Unexpected parameter validation error */
162 test_info.failed = 1;
163 }
164
165 memset( param_fail_jmp, 0, sizeof(jmp_buf) );
166#else
167 fp( params );
168#endif
169}
Azim Khan191e9042017-06-09 12:39:00 +0100170
171/**
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500172 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100173 *
174 * \param exp_id Test function index.
175 *
176 * \return DISPATCH_TEST_SUCCESS if found
177 * DISPATCH_TEST_FN_NOT_FOUND if not found
178 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
179 */
180int dispatch_test( int func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100181{
Azim Khan191e9042017-06-09 12:39:00 +0100182 int ret = DISPATCH_TEST_SUCCESS;
183 TestWrapper_t fp = NULL;
184
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100185 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100186 {
Azim Khan191e9042017-06-09 12:39:00 +0100187 fp = test_funcs[func_idx];
188 if ( fp )
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500189 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100190 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100191 ret = DISPATCH_UNSUPPORTED_SUITE;
192 }
Azim Khan191e9042017-06-09 12:39:00 +0100193 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100194 {
195 ret = DISPATCH_TEST_FN_NOT_FOUND;
196 }
Azim Khan191e9042017-06-09 12:39:00 +0100197
Paul Bakker19343182013-08-16 13:31:10 +0200198 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100199}
Paul Bakker19343182013-08-16 13:31:10 +0200200
SimonB152ea182016-02-15 23:27:28 +0000201
Azim Khan13c6bfb2017-06-15 14:45:56 +0100202/**
203 * \brief Checks if test function is supported
204 *
205 * \param exp_id Test function index.
206 *
207 * \return DISPATCH_TEST_SUCCESS if found
208 * DISPATCH_TEST_FN_NOT_FOUND if not found
209 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
210 */
211int check_test( int func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100212{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100213 int ret = DISPATCH_TEST_SUCCESS;
214 TestWrapper_t fp = NULL;
215
216 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100217 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100218 fp = test_funcs[func_idx];
219 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100220 ret = DISPATCH_UNSUPPORTED_SUITE;
221 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100222 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100223 {
224 ret = DISPATCH_TEST_FN_NOT_FOUND;
225 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100226
227 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100228}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100229
230
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100231$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100232
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100233#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100234
SimonB152ea182016-02-15 23:27:28 +0000235/*----------------------------------------------------------------------------*/
236/* Main Test code */
237
SimonB15942102016-04-25 21:34:49 +0100238
Azim Khan191e9042017-06-09 12:39:00 +0100239/**
240 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200241 *
Azim Khan191e9042017-06-09 12:39:00 +0100242 * \param argc Command line arguments count.
243 * \param argv Array of command line arguments.
244 *
245 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200246 */
Azim Khan191e9042017-06-09 12:39:00 +0100247int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100248{
Azim Khan191e9042017-06-09 12:39:00 +0100249 int ret = platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400250 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100251 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400252 mbedtls_fprintf( stderr,
253 "FATAL: Failed to initialize platform - error %d\n",
254 ret );
255 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100256 }
Hanno Becker1cfc5dd2018-11-12 13:18:45 +0000257
Azim Khan191e9042017-06-09 12:39:00 +0100258 ret = execute_tests( argc, argv );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400259 platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100260 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100261}