blob: 27010780ffa9b16d519914e644329c691f5e7870 [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
Gilles Peskine5ac97932020-04-14 19:39:56 +020022#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
23#if !defined(_POSIX_C_SOURCE)
24#define _POSIX_C_SOURCE 1 // for fileno() from <stdio.h>
25#endif
26#endif
27
gufe4487d79362020-08-17 15:04:06 +020028/*
29 * for arc4random_buf() from <stdlib.h>
30 */
31#if defined(__NetBSD__)
32#define _NETBSD_SOURCE 1
33#elif defined(__OpenBSD__)
34#define _BSD_SOURCE 1
35#endif
36
Azim Khan191e9042017-06-09 12:39:00 +010037#if !defined(MBEDTLS_CONFIG_FILE)
38#include <mbedtls/config.h>
39#else
40#include MBEDTLS_CONFIG_FILE
41#endif
Paul Bakker19343182013-08-16 13:31:10 +020042
SimonB152ea182016-02-15 23:27:28 +000043
44/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010045/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000046
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010047$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020048
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010049#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010050
51
52/*----------------------------------------------------------------------------*/
53/* Test Suite Code */
54
55
56#define TEST_SUITE_ACTIVE
57
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010058$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010059
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010060#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010061
SimonB152ea182016-02-15 23:27:28 +000062
63/*----------------------------------------------------------------------------*/
64/* Test dispatch code */
65
Paul Bakker19343182013-08-16 13:31:10 +020066
Azim Khan191e9042017-06-09 12:39:00 +010067/**
68 * \brief Evaluates an expression/macro into its literal integer value.
69 * For optimizing space for embedded targets each expression/macro
70 * is identified by a unique identifier instead of string literals.
71 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010072 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010073 *
74 * \param exp_id Expression identifier.
75 * \param out_value Pointer to int to hold the integer.
76 *
77 * \return 0 if exp_id is found. 1 otherwise.
78 */
79int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010080{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010081 int ret = KEY_VALUE_MAPPING_FOUND;
82
83 (void) exp_id;
84 (void) out_value;
85
86 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010087 {
88$expression_code
89#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010090 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010091 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010092 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010093 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010094 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010095 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010096 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010097}
Paul Bakker19343182013-08-16 13:31:10 +020098
Paul Bakker19343182013-08-16 13:31:10 +020099
Azim Khan191e9042017-06-09 12:39:00 +0100100/**
101 * \brief Checks if the dependency i.e. the compile flag is set.
102 * For optimizing space for embedded targets each dependency
103 * is identified by a unique identifier instead of string literals.
104 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100105 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100106 *
107 * \param exp_id Dependency identifier.
108 *
109 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
110 */
111int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100112{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100113 int ret = DEPENDENCY_NOT_SUPPORTED;
114
115 (void) dep_id;
116
117 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100118 {
119$dep_check_code
120#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100121 default:
122 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100123 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100124 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100125}
Paul Bakker19343182013-08-16 13:31:10 +0200126
SimonB8ca7bc42016-04-17 23:24:50 +0100127
Azim Khan191e9042017-06-09 12:39:00 +0100128/**
129 * \brief Function pointer type for test function wrappers.
130 *
131 *
132 * \param void ** Pointer to void pointers. Represents an array of test
133 * function parameters.
134 *
135 * \return void
136 */
137typedef void (*TestWrapper_t)( void ** );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100138
Azim Khan191e9042017-06-09 12:39:00 +0100139
140/**
141 * \brief Table of test function wrappers. Used by dispatch_test().
142 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100143 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100144 *
145 */
146TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100147{
148$dispatch_code
149#line $line_no "suites/main_test.function"
150};
Azim Khan191e9042017-06-09 12:39:00 +0100151
Simon Butcher6542f6c2018-12-09 22:09:59 +0000152/**
153 * \brief Execute the test function.
154 *
155 * This is a wrapper function around the test function execution
156 * to allow the setjmp() call used to catch any calls to the
157 * parameter failure callback, to be used. Calls to setjmp()
158 * can invalidate the state of any local auto variables.
159 *
160 * \param fp Function pointer to the test function
161 * \param params Parameters to pass
162 *
163 */
164void execute_function_ptr(TestWrapper_t fp, void **params)
165{
166#if defined(MBEDTLS_CHECK_PARAMS)
167 if ( setjmp( param_fail_jmp ) == 0 )
168 {
169 fp( params );
170 }
171 else
172 {
173 /* Unexpected parameter validation error */
Hanno Beckerd3369f62019-07-05 13:31:30 +0100174 test_info.result = TEST_RESULT_FAILED;
Simon Butcher6542f6c2018-12-09 22:09:59 +0000175 }
176
177 memset( param_fail_jmp, 0, sizeof(jmp_buf) );
178#else
179 fp( params );
180#endif
181}
Azim Khan191e9042017-06-09 12:39:00 +0100182
183/**
Simon Butcher6542f6c2018-12-09 22:09:59 +0000184 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100185 *
186 * \param exp_id Test function index.
187 *
188 * \return DISPATCH_TEST_SUCCESS if found
189 * DISPATCH_TEST_FN_NOT_FOUND if not found
190 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
191 */
k-stachowiak531b00b2019-09-16 10:23:10 +0200192int dispatch_test( size_t func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100193{
Azim Khan191e9042017-06-09 12:39:00 +0100194 int ret = DISPATCH_TEST_SUCCESS;
195 TestWrapper_t fp = NULL;
196
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100197 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100198 {
Azim Khan191e9042017-06-09 12:39:00 +0100199 fp = test_funcs[func_idx];
200 if ( fp )
Simon Butcher6542f6c2018-12-09 22:09:59 +0000201 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100202 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100203 ret = DISPATCH_UNSUPPORTED_SUITE;
204 }
Azim Khan191e9042017-06-09 12:39:00 +0100205 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100206 {
207 ret = DISPATCH_TEST_FN_NOT_FOUND;
208 }
Azim Khan191e9042017-06-09 12:39:00 +0100209
Paul Bakker19343182013-08-16 13:31:10 +0200210 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100211}
Paul Bakker19343182013-08-16 13:31:10 +0200212
SimonB152ea182016-02-15 23:27:28 +0000213
Azim Khan13c6bfb2017-06-15 14:45:56 +0100214/**
215 * \brief Checks if test function is supported
216 *
217 * \param exp_id Test function index.
218 *
219 * \return DISPATCH_TEST_SUCCESS if found
220 * DISPATCH_TEST_FN_NOT_FOUND if not found
221 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
222 */
k-stachowiak531b00b2019-09-16 10:23:10 +0200223int check_test( size_t func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100224{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100225 int ret = DISPATCH_TEST_SUCCESS;
226 TestWrapper_t fp = NULL;
227
228 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100229 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100230 fp = test_funcs[func_idx];
231 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100232 ret = DISPATCH_UNSUPPORTED_SUITE;
233 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100234 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100235 {
236 ret = DISPATCH_TEST_FN_NOT_FOUND;
237 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100238
239 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100240}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100241
242
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100243$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100244
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100245#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100246
SimonB152ea182016-02-15 23:27:28 +0000247/*----------------------------------------------------------------------------*/
248/* Main Test code */
249
SimonB15942102016-04-25 21:34:49 +0100250
Azim Khan191e9042017-06-09 12:39:00 +0100251/**
252 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200253 *
Azim Khan191e9042017-06-09 12:39:00 +0100254 * \param argc Command line arguments count.
255 * \param argv Array of command line arguments.
256 *
257 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200258 */
Azim Khan191e9042017-06-09 12:39:00 +0100259int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100260{
Azim Khan191e9042017-06-09 12:39:00 +0100261 int ret = platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400262 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100263 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400264 mbedtls_fprintf( stderr,
265 "FATAL: Failed to initialize platform - error %d\n",
266 ret );
267 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100268 }
Azim Khan191e9042017-06-09 12:39:00 +0100269 ret = execute_tests( argc, argv );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400270 platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100271 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100272}
Azim Khan191e9042017-06-09 12:39:00 +0100273