blob: ca4783dcf7ba0d2015af8254964c6d9069c07538 [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
SimonB152ea182016-02-15 23:27:28 +000028
29/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010030/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000031
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010032$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020033
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010034#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010035
36
37/*----------------------------------------------------------------------------*/
38/* Test Suite Code */
39
40
41#define TEST_SUITE_ACTIVE
42
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010043$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010044
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010045#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010046
SimonB152ea182016-02-15 23:27:28 +000047
48/*----------------------------------------------------------------------------*/
49/* Test dispatch code */
50
Paul Bakker19343182013-08-16 13:31:10 +020051
Azim Khan191e9042017-06-09 12:39:00 +010052/**
53 * \brief Evaluates an expression/macro into its literal integer value.
54 * For optimizing space for embedded targets each expression/macro
55 * is identified by a unique identifier instead of string literals.
56 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010057 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010058 *
59 * \param exp_id Expression identifier.
60 * \param out_value Pointer to int to hold the integer.
61 *
62 * \return 0 if exp_id is found. 1 otherwise.
63 */
64int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010065{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010066 int ret = KEY_VALUE_MAPPING_FOUND;
67
68 (void) exp_id;
69 (void) out_value;
70
71 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010072 {
73$expression_code
74#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010075 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010076 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010077 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010078 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010079 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010080 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010081 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010082}
Paul Bakker19343182013-08-16 13:31:10 +020083
Paul Bakker19343182013-08-16 13:31:10 +020084
Azim Khan191e9042017-06-09 12:39:00 +010085/**
86 * \brief Checks if the dependency i.e. the compile flag is set.
87 * For optimizing space for embedded targets each dependency
88 * is identified by a unique identifier instead of string literals.
89 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010090 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010091 *
92 * \param exp_id Dependency identifier.
93 *
94 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
95 */
96int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010097{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010098 int ret = DEPENDENCY_NOT_SUPPORTED;
99
100 (void) dep_id;
101
102 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100103 {
104$dep_check_code
105#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100106 default:
107 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100108 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100109 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100110}
Paul Bakker19343182013-08-16 13:31:10 +0200111
SimonB8ca7bc42016-04-17 23:24:50 +0100112
Azim Khan191e9042017-06-09 12:39:00 +0100113/**
114 * \brief Function pointer type for test function wrappers.
115 *
116 *
117 * \param void ** Pointer to void pointers. Represents an array of test
118 * function parameters.
119 *
120 * \return void
121 */
122typedef void (*TestWrapper_t)( void ** );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100123
Azim Khan191e9042017-06-09 12:39:00 +0100124
125/**
126 * \brief Table of test function wrappers. Used by dispatch_test().
127 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100128 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100129 *
130 */
131TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100132{
133$dispatch_code
134#line $line_no "suites/main_test.function"
135};
Azim Khan191e9042017-06-09 12:39:00 +0100136
Simon Butcher6542f6c2018-12-09 22:09:59 +0000137/**
138 * \brief Execute the test function.
139 *
140 * This is a wrapper function around the test function execution
141 * to allow the setjmp() call used to catch any calls to the
142 * parameter failure callback, to be used. Calls to setjmp()
143 * can invalidate the state of any local auto variables.
144 *
145 * \param fp Function pointer to the test function
146 * \param params Parameters to pass
147 *
148 */
149void execute_function_ptr(TestWrapper_t fp, void **params)
150{
151#if defined(MBEDTLS_CHECK_PARAMS)
152 if ( setjmp( param_fail_jmp ) == 0 )
153 {
154 fp( params );
155 }
156 else
157 {
158 /* Unexpected parameter validation error */
159 test_info.failed = 1;
160 }
161
162 memset( param_fail_jmp, 0, sizeof(jmp_buf) );
163#else
164 fp( params );
165#endif
166}
Azim Khan191e9042017-06-09 12:39:00 +0100167
168/**
Simon Butcher6542f6c2018-12-09 22:09:59 +0000169 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100170 *
171 * \param exp_id Test function index.
172 *
173 * \return DISPATCH_TEST_SUCCESS if found
174 * DISPATCH_TEST_FN_NOT_FOUND if not found
175 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
176 */
177int dispatch_test( int func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100178{
Azim Khan191e9042017-06-09 12:39:00 +0100179 int ret = DISPATCH_TEST_SUCCESS;
180 TestWrapper_t fp = NULL;
181
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100182 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100183 {
Azim Khan191e9042017-06-09 12:39:00 +0100184 fp = test_funcs[func_idx];
185 if ( fp )
Simon Butcher6542f6c2018-12-09 22:09:59 +0000186 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100187 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100188 ret = DISPATCH_UNSUPPORTED_SUITE;
189 }
Azim Khan191e9042017-06-09 12:39:00 +0100190 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100191 {
192 ret = DISPATCH_TEST_FN_NOT_FOUND;
193 }
Azim Khan191e9042017-06-09 12:39:00 +0100194
Paul Bakker19343182013-08-16 13:31:10 +0200195 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100196}
Paul Bakker19343182013-08-16 13:31:10 +0200197
SimonB152ea182016-02-15 23:27:28 +0000198
Azim Khan13c6bfb2017-06-15 14:45:56 +0100199/**
200 * \brief Checks if test function is supported
201 *
202 * \param exp_id Test function index.
203 *
204 * \return DISPATCH_TEST_SUCCESS if found
205 * DISPATCH_TEST_FN_NOT_FOUND if not found
206 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
207 */
208int check_test( int func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100209{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100210 int ret = DISPATCH_TEST_SUCCESS;
211 TestWrapper_t fp = NULL;
212
213 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100214 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100215 fp = test_funcs[func_idx];
216 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100217 ret = DISPATCH_UNSUPPORTED_SUITE;
218 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100219 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100220 {
221 ret = DISPATCH_TEST_FN_NOT_FOUND;
222 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100223
224 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100225}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100226
227
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100228$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100229
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100230#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100231
SimonB152ea182016-02-15 23:27:28 +0000232/*----------------------------------------------------------------------------*/
233/* Main Test code */
234
SimonB15942102016-04-25 21:34:49 +0100235
Azim Khan191e9042017-06-09 12:39:00 +0100236/**
237 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200238 *
Azim Khan191e9042017-06-09 12:39:00 +0100239 * \param argc Command line arguments count.
240 * \param argv Array of command line arguments.
241 *
242 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200243 */
Azim Khan191e9042017-06-09 12:39:00 +0100244int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100245{
Azim Khan191e9042017-06-09 12:39:00 +0100246 int ret = platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400247 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100248 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400249 mbedtls_fprintf( stderr,
250 "FATAL: Failed to initialize platform - error %d\n",
251 ret );
252 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100253 }
Azim Khan191e9042017-06-09 12:39:00 +0100254 ret = execute_tests( argc, argv );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400255 platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100256 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100257}
Azim Khan191e9042017-06-09 12:39:00 +0100258