blob: 8944fd9128f214f1722154c50e3a680fc4b53fc3 [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
Azim Khan191e9042017-06-09 12:39:00 +010028#if !defined(MBEDTLS_CONFIG_FILE)
29#include <mbedtls/config.h>
30#else
31#include MBEDTLS_CONFIG_FILE
32#endif
Paul Bakker19343182013-08-16 13:31:10 +020033
SimonB152ea182016-02-15 23:27:28 +000034
35/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010036/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000037
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010038$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020039
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010040#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010041
42
43/*----------------------------------------------------------------------------*/
44/* Test Suite Code */
45
46
47#define TEST_SUITE_ACTIVE
48
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010049$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010050
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010051#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010052
SimonB152ea182016-02-15 23:27:28 +000053
54/*----------------------------------------------------------------------------*/
55/* Test dispatch code */
56
Paul Bakker19343182013-08-16 13:31:10 +020057
Azim Khan191e9042017-06-09 12:39:00 +010058/**
59 * \brief Evaluates an expression/macro into its literal integer value.
60 * For optimizing space for embedded targets each expression/macro
61 * is identified by a unique identifier instead of string literals.
62 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010063 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010064 *
65 * \param exp_id Expression identifier.
66 * \param out_value Pointer to int to hold the integer.
67 *
68 * \return 0 if exp_id is found. 1 otherwise.
69 */
70int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010071{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010072 int ret = KEY_VALUE_MAPPING_FOUND;
73
74 (void) exp_id;
75 (void) out_value;
76
77 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010078 {
79$expression_code
80#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010081 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010082 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010083 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010084 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010085 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010086 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010087 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010088}
Paul Bakker19343182013-08-16 13:31:10 +020089
Paul Bakker19343182013-08-16 13:31:10 +020090
Azim Khan191e9042017-06-09 12:39:00 +010091/**
92 * \brief Checks if the dependency i.e. the compile flag is set.
93 * For optimizing space for embedded targets each dependency
94 * is identified by a unique identifier instead of string literals.
95 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010096 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010097 *
98 * \param exp_id Dependency identifier.
99 *
100 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
101 */
102int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100103{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100104 int ret = DEPENDENCY_NOT_SUPPORTED;
105
106 (void) dep_id;
107
108 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100109 {
110$dep_check_code
111#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100112 default:
113 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100114 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100115 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100116}
Paul Bakker19343182013-08-16 13:31:10 +0200117
SimonB8ca7bc42016-04-17 23:24:50 +0100118
Azim Khan191e9042017-06-09 12:39:00 +0100119/**
120 * \brief Function pointer type for test function wrappers.
121 *
122 *
123 * \param void ** Pointer to void pointers. Represents an array of test
124 * function parameters.
125 *
126 * \return void
127 */
128typedef void (*TestWrapper_t)( void ** );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100129
Azim Khan191e9042017-06-09 12:39:00 +0100130
131/**
132 * \brief Table of test function wrappers. Used by dispatch_test().
133 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100134 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100135 *
136 */
137TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100138{
139$dispatch_code
140#line $line_no "suites/main_test.function"
141};
Azim Khan191e9042017-06-09 12:39:00 +0100142
Simon Butcher6542f6c2018-12-09 22:09:59 +0000143/**
144 * \brief Execute the test function.
145 *
146 * This is a wrapper function around the test function execution
147 * to allow the setjmp() call used to catch any calls to the
148 * parameter failure callback, to be used. Calls to setjmp()
149 * can invalidate the state of any local auto variables.
150 *
151 * \param fp Function pointer to the test function
152 * \param params Parameters to pass
153 *
154 */
155void execute_function_ptr(TestWrapper_t fp, void **params)
156{
157#if defined(MBEDTLS_CHECK_PARAMS)
158 if ( setjmp( param_fail_jmp ) == 0 )
159 {
160 fp( params );
161 }
162 else
163 {
164 /* Unexpected parameter validation error */
Hanno Beckerd3369f62019-07-05 13:31:30 +0100165 test_info.result = TEST_RESULT_FAILED;
Simon Butcher6542f6c2018-12-09 22:09:59 +0000166 }
167
168 memset( param_fail_jmp, 0, sizeof(jmp_buf) );
169#else
170 fp( params );
171#endif
172}
Azim Khan191e9042017-06-09 12:39:00 +0100173
174/**
Simon Butcher6542f6c2018-12-09 22:09:59 +0000175 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100176 *
177 * \param exp_id Test function index.
178 *
179 * \return DISPATCH_TEST_SUCCESS if found
180 * DISPATCH_TEST_FN_NOT_FOUND if not found
181 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
182 */
k-stachowiak531b00b2019-09-16 10:23:10 +0200183int dispatch_test( size_t func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100184{
Azim Khan191e9042017-06-09 12:39:00 +0100185 int ret = DISPATCH_TEST_SUCCESS;
186 TestWrapper_t fp = NULL;
187
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100188 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100189 {
Azim Khan191e9042017-06-09 12:39:00 +0100190 fp = test_funcs[func_idx];
191 if ( fp )
Simon Butcher6542f6c2018-12-09 22:09:59 +0000192 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100193 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100194 ret = DISPATCH_UNSUPPORTED_SUITE;
195 }
Azim Khan191e9042017-06-09 12:39:00 +0100196 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100197 {
198 ret = DISPATCH_TEST_FN_NOT_FOUND;
199 }
Azim Khan191e9042017-06-09 12:39:00 +0100200
Paul Bakker19343182013-08-16 13:31:10 +0200201 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100202}
Paul Bakker19343182013-08-16 13:31:10 +0200203
SimonB152ea182016-02-15 23:27:28 +0000204
Azim Khan13c6bfb2017-06-15 14:45:56 +0100205/**
206 * \brief Checks if test function is supported
207 *
208 * \param exp_id Test function index.
209 *
210 * \return DISPATCH_TEST_SUCCESS if found
211 * DISPATCH_TEST_FN_NOT_FOUND if not found
212 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
213 */
k-stachowiak531b00b2019-09-16 10:23:10 +0200214int check_test( size_t func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100215{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100216 int ret = DISPATCH_TEST_SUCCESS;
217 TestWrapper_t fp = NULL;
218
219 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100220 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100221 fp = test_funcs[func_idx];
222 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100223 ret = DISPATCH_UNSUPPORTED_SUITE;
224 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100225 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100226 {
227 ret = DISPATCH_TEST_FN_NOT_FOUND;
228 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100229
230 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100231}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100232
233
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100234$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100235
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100236#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100237
SimonB152ea182016-02-15 23:27:28 +0000238/*----------------------------------------------------------------------------*/
239/* Main Test code */
240
SimonB15942102016-04-25 21:34:49 +0100241
Azim Khan191e9042017-06-09 12:39:00 +0100242/**
243 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200244 *
Azim Khan191e9042017-06-09 12:39:00 +0100245 * \param argc Command line arguments count.
246 * \param argv Array of command line arguments.
247 *
248 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200249 */
Azim Khan191e9042017-06-09 12:39:00 +0100250int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100251{
Azim Khan191e9042017-06-09 12:39:00 +0100252 int ret = platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400253 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100254 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400255 mbedtls_fprintf( stderr,
256 "FATAL: Failed to initialize platform - error %d\n",
257 ret );
258 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100259 }
Azim Khan191e9042017-06-09 12:39:00 +0100260 ret = execute_tests( argc, argv );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400261 platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100262 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100263}
Azim Khan191e9042017-06-09 12:39:00 +0100264