blob: 2aecf8142f85a131e1d3ed6eb7c015dcc9c5e92f [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
Gilles Peskinecd2e2482021-01-29 21:18:09 +0100179
180#if defined(MBEDTLS_TEST_MUTEX_USAGE)
181 mbedtls_test_mutex_usage_check( );
182#endif /* MBEDTLS_TEST_MUTEX_USAGE */
Simon Butcher6542f6c2018-12-09 22:09:59 +0000183}
Azim Khan191e9042017-06-09 12:39:00 +0100184
185/**
Simon Butcher6542f6c2018-12-09 22:09:59 +0000186 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100187 *
188 * \param exp_id Test function index.
189 *
190 * \return DISPATCH_TEST_SUCCESS if found
191 * DISPATCH_TEST_FN_NOT_FOUND if not found
192 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
193 */
k-stachowiak531b00b2019-09-16 10:23:10 +0200194int dispatch_test( size_t func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100195{
Azim Khan191e9042017-06-09 12:39:00 +0100196 int ret = DISPATCH_TEST_SUCCESS;
197 TestWrapper_t fp = NULL;
198
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100199 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100200 {
Azim Khan191e9042017-06-09 12:39:00 +0100201 fp = test_funcs[func_idx];
202 if ( fp )
Simon Butcher6542f6c2018-12-09 22:09:59 +0000203 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100204 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100205 ret = DISPATCH_UNSUPPORTED_SUITE;
206 }
Azim Khan191e9042017-06-09 12:39:00 +0100207 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100208 {
209 ret = DISPATCH_TEST_FN_NOT_FOUND;
210 }
Azim Khan191e9042017-06-09 12:39:00 +0100211
Paul Bakker19343182013-08-16 13:31:10 +0200212 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100213}
Paul Bakker19343182013-08-16 13:31:10 +0200214
SimonB152ea182016-02-15 23:27:28 +0000215
Azim Khan13c6bfb2017-06-15 14:45:56 +0100216/**
217 * \brief Checks if test function is supported
218 *
219 * \param exp_id Test function index.
220 *
221 * \return DISPATCH_TEST_SUCCESS if found
222 * DISPATCH_TEST_FN_NOT_FOUND if not found
223 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
224 */
k-stachowiak531b00b2019-09-16 10:23:10 +0200225int check_test( size_t func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100226{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100227 int ret = DISPATCH_TEST_SUCCESS;
228 TestWrapper_t fp = NULL;
229
230 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100231 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100232 fp = test_funcs[func_idx];
233 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100234 ret = DISPATCH_UNSUPPORTED_SUITE;
235 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100236 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100237 {
238 ret = DISPATCH_TEST_FN_NOT_FOUND;
239 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100240
241 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100242}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100243
244
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100245$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100246
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100247#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100248
SimonB152ea182016-02-15 23:27:28 +0000249/*----------------------------------------------------------------------------*/
250/* Main Test code */
251
SimonB15942102016-04-25 21:34:49 +0100252
Azim Khan191e9042017-06-09 12:39:00 +0100253/**
254 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200255 *
Azim Khan191e9042017-06-09 12:39:00 +0100256 * \param argc Command line arguments count.
257 * \param argv Array of command line arguments.
258 *
259 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200260 */
Azim Khan191e9042017-06-09 12:39:00 +0100261int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100262{
Azim Khan191e9042017-06-09 12:39:00 +0100263 int ret = platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400264 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100265 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400266 mbedtls_fprintf( stderr,
267 "FATAL: Failed to initialize platform - error %d\n",
268 ret );
269 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100270 }
Azim Khan191e9042017-06-09 12:39:00 +0100271 ret = execute_tests( argc, argv );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400272 platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100273 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100274}
Azim Khan191e9042017-06-09 12:39:00 +0100275