blob: f516d2caa12db19f8017b0145086e148bcddc767 [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 *
Azim Khan191e9042017-06-09 12:39:00 +010018 */
Paul Bakkerde56ca12013-09-15 17:05:21 +020019
Gilles Peskine5ac97932020-04-14 19:39:56 +020020#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
21#if !defined(_POSIX_C_SOURCE)
22#define _POSIX_C_SOURCE 1 // for fileno() from <stdio.h>
23#endif
24#endif
25
Azim Khan191e9042017-06-09 12:39:00 +010026#if !defined(MBEDTLS_CONFIG_FILE)
27#include <mbedtls/config.h>
28#else
29#include MBEDTLS_CONFIG_FILE
30#endif
Paul Bakker19343182013-08-16 13:31:10 +020031
SimonB152ea182016-02-15 23:27:28 +000032
33/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010034/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000035
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010036$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020037
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010038#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010039
40
41/*----------------------------------------------------------------------------*/
42/* Test Suite Code */
43
44
45#define TEST_SUITE_ACTIVE
46
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010047$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010048
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010049#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010050
SimonB152ea182016-02-15 23:27:28 +000051
52/*----------------------------------------------------------------------------*/
53/* Test dispatch code */
54
Paul Bakker19343182013-08-16 13:31:10 +020055
Azim Khan191e9042017-06-09 12:39:00 +010056/**
57 * \brief Evaluates an expression/macro into its literal integer value.
58 * For optimizing space for embedded targets each expression/macro
59 * is identified by a unique identifier instead of string literals.
60 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010061 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010062 *
63 * \param exp_id Expression identifier.
64 * \param out_value Pointer to int to hold the integer.
65 *
66 * \return 0 if exp_id is found. 1 otherwise.
67 */
68int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010069{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010070 int ret = KEY_VALUE_MAPPING_FOUND;
71
72 (void) exp_id;
73 (void) out_value;
74
75 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010076 {
77$expression_code
78#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010079 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010080 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010081 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010082 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010083 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010084 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010085 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010086}
Paul Bakker19343182013-08-16 13:31:10 +020087
Paul Bakker19343182013-08-16 13:31:10 +020088
Azim Khan191e9042017-06-09 12:39:00 +010089/**
90 * \brief Checks if the dependency i.e. the compile flag is set.
91 * For optimizing space for embedded targets each dependency
92 * is identified by a unique identifier instead of string literals.
93 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010094 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010095 *
96 * \param exp_id Dependency identifier.
97 *
98 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
99 */
100int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100101{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100102 int ret = DEPENDENCY_NOT_SUPPORTED;
103
104 (void) dep_id;
105
106 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100107 {
108$dep_check_code
109#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100110 default:
111 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100112 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100113 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100114}
Paul Bakker19343182013-08-16 13:31:10 +0200115
SimonB8ca7bc42016-04-17 23:24:50 +0100116
Azim Khan191e9042017-06-09 12:39:00 +0100117/**
118 * \brief Function pointer type for test function wrappers.
119 *
120 *
121 * \param void ** Pointer to void pointers. Represents an array of test
122 * function parameters.
123 *
124 * \return void
125 */
126typedef void (*TestWrapper_t)( void ** );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100127
Azim Khan191e9042017-06-09 12:39:00 +0100128
129/**
130 * \brief Table of test function wrappers. Used by dispatch_test().
131 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100132 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100133 *
134 */
135TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100136{
137$dispatch_code
138#line $line_no "suites/main_test.function"
139};
Azim Khan191e9042017-06-09 12:39:00 +0100140
Simon Butcher6542f6c2018-12-09 22:09:59 +0000141/**
142 * \brief Execute the test function.
143 *
144 * This is a wrapper function around the test function execution
145 * to allow the setjmp() call used to catch any calls to the
146 * parameter failure callback, to be used. Calls to setjmp()
147 * can invalidate the state of any local auto variables.
148 *
149 * \param fp Function pointer to the test function
150 * \param params Parameters to pass
151 *
152 */
153void execute_function_ptr(TestWrapper_t fp, void **params)
154{
155#if defined(MBEDTLS_CHECK_PARAMS)
156 if ( setjmp( param_fail_jmp ) == 0 )
157 {
158 fp( params );
159 }
160 else
161 {
162 /* Unexpected parameter validation error */
Hanno Beckerd3369f62019-07-05 13:31:30 +0100163 test_info.result = TEST_RESULT_FAILED;
Simon Butcher6542f6c2018-12-09 22:09:59 +0000164 }
165
166 memset( param_fail_jmp, 0, sizeof(jmp_buf) );
167#else
168 fp( params );
169#endif
170}
Azim Khan191e9042017-06-09 12:39:00 +0100171
172/**
Simon Butcher6542f6c2018-12-09 22:09:59 +0000173 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100174 *
175 * \param exp_id Test function index.
176 *
177 * \return DISPATCH_TEST_SUCCESS if found
178 * DISPATCH_TEST_FN_NOT_FOUND if not found
179 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
180 */
k-stachowiak531b00b2019-09-16 10:23:10 +0200181int dispatch_test( size_t func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100182{
Azim Khan191e9042017-06-09 12:39:00 +0100183 int ret = DISPATCH_TEST_SUCCESS;
184 TestWrapper_t fp = NULL;
185
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100186 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100187 {
Azim Khan191e9042017-06-09 12:39:00 +0100188 fp = test_funcs[func_idx];
189 if ( fp )
Simon Butcher6542f6c2018-12-09 22:09:59 +0000190 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100191 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100192 ret = DISPATCH_UNSUPPORTED_SUITE;
193 }
Azim Khan191e9042017-06-09 12:39:00 +0100194 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100195 {
196 ret = DISPATCH_TEST_FN_NOT_FOUND;
197 }
Azim Khan191e9042017-06-09 12:39:00 +0100198
Paul Bakker19343182013-08-16 13:31:10 +0200199 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100200}
Paul Bakker19343182013-08-16 13:31:10 +0200201
SimonB152ea182016-02-15 23:27:28 +0000202
Azim Khan13c6bfb2017-06-15 14:45:56 +0100203/**
204 * \brief Checks if test function is supported
205 *
206 * \param exp_id Test function index.
207 *
208 * \return DISPATCH_TEST_SUCCESS if found
209 * DISPATCH_TEST_FN_NOT_FOUND if not found
210 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
211 */
k-stachowiak531b00b2019-09-16 10:23:10 +0200212int check_test( size_t func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100213{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100214 int ret = DISPATCH_TEST_SUCCESS;
215 TestWrapper_t fp = NULL;
216
217 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100218 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100219 fp = test_funcs[func_idx];
220 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100221 ret = DISPATCH_UNSUPPORTED_SUITE;
222 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100223 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100224 {
225 ret = DISPATCH_TEST_FN_NOT_FOUND;
226 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100227
228 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100229}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100230
231
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100232$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100233
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100234#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100235
SimonB152ea182016-02-15 23:27:28 +0000236/*----------------------------------------------------------------------------*/
237/* Main Test code */
238
SimonB15942102016-04-25 21:34:49 +0100239
Azim Khan191e9042017-06-09 12:39:00 +0100240/**
241 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200242 *
Azim Khan191e9042017-06-09 12:39:00 +0100243 * \param argc Command line arguments count.
244 * \param argv Array of command line arguments.
245 *
246 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200247 */
Azim Khan191e9042017-06-09 12:39:00 +0100248int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100249{
Azim Khan191e9042017-06-09 12:39:00 +0100250 int ret = platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400251 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100252 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400253 mbedtls_fprintf( stderr,
254 "FATAL: Failed to initialize platform - error %d\n",
255 ret );
256 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100257 }
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}
Azim Khan191e9042017-06-09 12:39:00 +0100262