blob: 9f366907bb2f1bb935eb0dd380922d11e9dda1bd [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
gufe4487d79362020-08-17 15:04:06 +020026/*
27 * for arc4random_buf() from <stdlib.h>
28 */
29#if defined(__NetBSD__)
30#define _NETBSD_SOURCE 1
31#elif defined(__OpenBSD__)
32#define _BSD_SOURCE 1
33#endif
34
Azim Khan191e9042017-06-09 12:39:00 +010035#if !defined(MBEDTLS_CONFIG_FILE)
36#include <mbedtls/config.h>
37#else
38#include MBEDTLS_CONFIG_FILE
39#endif
Paul Bakker19343182013-08-16 13:31:10 +020040
SimonB152ea182016-02-15 23:27:28 +000041
42/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010043/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000044
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010045$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020046
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010047#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010048
49
50/*----------------------------------------------------------------------------*/
51/* Test Suite Code */
52
53
54#define TEST_SUITE_ACTIVE
55
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010056$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010057
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010058#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010059
SimonB152ea182016-02-15 23:27:28 +000060
61/*----------------------------------------------------------------------------*/
62/* Test dispatch code */
63
Paul Bakker19343182013-08-16 13:31:10 +020064
Azim Khan191e9042017-06-09 12:39:00 +010065/**
66 * \brief Evaluates an expression/macro into its literal integer value.
67 * For optimizing space for embedded targets each expression/macro
68 * is identified by a unique identifier instead of string literals.
69 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010070 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010071 *
72 * \param exp_id Expression identifier.
73 * \param out_value Pointer to int to hold the integer.
74 *
75 * \return 0 if exp_id is found. 1 otherwise.
76 */
77int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010078{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010079 int ret = KEY_VALUE_MAPPING_FOUND;
80
81 (void) exp_id;
82 (void) out_value;
83
84 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010085 {
86$expression_code
87#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010088 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010089 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010090 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010091 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010092 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010093 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010094 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010095}
Paul Bakker19343182013-08-16 13:31:10 +020096
Paul Bakker19343182013-08-16 13:31:10 +020097
Azim Khan191e9042017-06-09 12:39:00 +010098/**
99 * \brief Checks if the dependency i.e. the compile flag is set.
100 * For optimizing space for embedded targets each dependency
101 * is identified by a unique identifier instead of string literals.
102 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100103 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100104 *
105 * \param exp_id Dependency identifier.
106 *
107 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
108 */
109int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100110{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100111 int ret = DEPENDENCY_NOT_SUPPORTED;
112
113 (void) dep_id;
114
115 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100116 {
117$dep_check_code
118#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100119 default:
120 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100121 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100122 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100123}
Paul Bakker19343182013-08-16 13:31:10 +0200124
SimonB8ca7bc42016-04-17 23:24:50 +0100125
Azim Khan191e9042017-06-09 12:39:00 +0100126/**
127 * \brief Function pointer type for test function wrappers.
128 *
129 *
130 * \param void ** Pointer to void pointers. Represents an array of test
131 * function parameters.
132 *
133 * \return void
134 */
135typedef void (*TestWrapper_t)( void ** );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100136
Azim Khan191e9042017-06-09 12:39:00 +0100137
138/**
139 * \brief Table of test function wrappers. Used by dispatch_test().
140 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100141 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100142 *
143 */
144TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100145{
146$dispatch_code
147#line $line_no "suites/main_test.function"
148};
Azim Khan191e9042017-06-09 12:39:00 +0100149
Simon Butcher6542f6c2018-12-09 22:09:59 +0000150/**
151 * \brief Execute the test function.
152 *
153 * This is a wrapper function around the test function execution
154 * to allow the setjmp() call used to catch any calls to the
155 * parameter failure callback, to be used. Calls to setjmp()
156 * can invalidate the state of any local auto variables.
157 *
158 * \param fp Function pointer to the test function
159 * \param params Parameters to pass
160 *
161 */
162void execute_function_ptr(TestWrapper_t fp, void **params)
163{
164#if defined(MBEDTLS_CHECK_PARAMS)
165 if ( setjmp( param_fail_jmp ) == 0 )
166 {
167 fp( params );
168 }
169 else
170 {
171 /* Unexpected parameter validation error */
Hanno Beckerd3369f62019-07-05 13:31:30 +0100172 test_info.result = TEST_RESULT_FAILED;
Simon Butcher6542f6c2018-12-09 22:09:59 +0000173 }
174
175 memset( param_fail_jmp, 0, sizeof(jmp_buf) );
176#else
177 fp( params );
178#endif
179}
Azim Khan191e9042017-06-09 12:39:00 +0100180
181/**
Simon Butcher6542f6c2018-12-09 22:09:59 +0000182 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100183 *
184 * \param exp_id Test function index.
185 *
186 * \return DISPATCH_TEST_SUCCESS if found
187 * DISPATCH_TEST_FN_NOT_FOUND if not found
188 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
189 */
k-stachowiak531b00b2019-09-16 10:23:10 +0200190int dispatch_test( size_t func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100191{
Azim Khan191e9042017-06-09 12:39:00 +0100192 int ret = DISPATCH_TEST_SUCCESS;
193 TestWrapper_t fp = NULL;
194
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100195 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100196 {
Azim Khan191e9042017-06-09 12:39:00 +0100197 fp = test_funcs[func_idx];
198 if ( fp )
Simon Butcher6542f6c2018-12-09 22:09:59 +0000199 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100200 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100201 ret = DISPATCH_UNSUPPORTED_SUITE;
202 }
Azim Khan191e9042017-06-09 12:39:00 +0100203 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100204 {
205 ret = DISPATCH_TEST_FN_NOT_FOUND;
206 }
Azim Khan191e9042017-06-09 12:39:00 +0100207
Paul Bakker19343182013-08-16 13:31:10 +0200208 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100209}
Paul Bakker19343182013-08-16 13:31:10 +0200210
SimonB152ea182016-02-15 23:27:28 +0000211
Azim Khan13c6bfb2017-06-15 14:45:56 +0100212/**
213 * \brief Checks if test function is supported
214 *
215 * \param exp_id Test function index.
216 *
217 * \return DISPATCH_TEST_SUCCESS if found
218 * DISPATCH_TEST_FN_NOT_FOUND if not found
219 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
220 */
k-stachowiak531b00b2019-09-16 10:23:10 +0200221int check_test( size_t func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100222{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100223 int ret = DISPATCH_TEST_SUCCESS;
224 TestWrapper_t fp = NULL;
225
226 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100227 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100228 fp = test_funcs[func_idx];
229 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100230 ret = DISPATCH_UNSUPPORTED_SUITE;
231 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100232 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100233 {
234 ret = DISPATCH_TEST_FN_NOT_FOUND;
235 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100236
237 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100238}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100239
240
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100241$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100242
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100243#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100244
SimonB152ea182016-02-15 23:27:28 +0000245/*----------------------------------------------------------------------------*/
246/* Main Test code */
247
SimonB15942102016-04-25 21:34:49 +0100248
Azim Khan191e9042017-06-09 12:39:00 +0100249/**
250 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200251 *
Azim Khan191e9042017-06-09 12:39:00 +0100252 * \param argc Command line arguments count.
253 * \param argv Array of command line arguments.
254 *
255 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200256 */
Azim Khan191e9042017-06-09 12:39:00 +0100257int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100258{
Azim Khan191e9042017-06-09 12:39:00 +0100259 int ret = platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400260 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100261 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400262 mbedtls_fprintf( stderr,
263 "FATAL: Failed to initialize platform - error %d\n",
264 ret );
265 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100266 }
Azim Khan191e9042017-06-09 12:39:00 +0100267 ret = execute_tests( argc, argv );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400268 platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100269 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100270}
Azim Khan191e9042017-06-09 12:39:00 +0100271