blob: a1ba6105851a7bdd66f35652f704227f47c31240 [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
Hanno Becker1cfc5dd2018-11-12 13:18:45 +000028#if defined(MBEDTLS_USE_PSA_CRYPTO)
29#include "psa/crypto.h"
30#endif /* MBEDTLS_USE_PSA_CRYPTO */
SimonB152ea182016-02-15 23:27:28 +000031
Gilles Peskine2ff02c32019-11-29 12:17:21 +010032/* Test code may use deprecated identifiers only if the preprocessor symbol
33 * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set
34 * MBEDTLS_TEST_DEPRECATED explicitly if MBEDTLS_DEPRECATED_WARNING is
35 * enabled but the corresponding warnings are not treated as errors.
36 */
Gilles Peskine841b14b2019-11-26 17:37:37 +010037#if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING)
38#define MBEDTLS_TEST_DEPRECATED
39#endif
40
SimonB152ea182016-02-15 23:27:28 +000041/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010042/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000043
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010044$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020045
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010046#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010047
48
49/*----------------------------------------------------------------------------*/
50/* Test Suite Code */
51
52
53#define TEST_SUITE_ACTIVE
54
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010055$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010056
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010057#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010058
SimonB152ea182016-02-15 23:27:28 +000059
60/*----------------------------------------------------------------------------*/
61/* Test dispatch code */
62
Paul Bakker19343182013-08-16 13:31:10 +020063
Azim Khan191e9042017-06-09 12:39:00 +010064/**
65 * \brief Evaluates an expression/macro into its literal integer value.
66 * For optimizing space for embedded targets each expression/macro
67 * is identified by a unique identifier instead of string literals.
68 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010069 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010070 *
71 * \param exp_id Expression identifier.
72 * \param out_value Pointer to int to hold the integer.
73 *
74 * \return 0 if exp_id is found. 1 otherwise.
75 */
76int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010077{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010078 int ret = KEY_VALUE_MAPPING_FOUND;
79
80 (void) exp_id;
81 (void) out_value;
82
83 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010084 {
85$expression_code
86#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010087 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010088 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010089 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010090 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010091 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010092 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010093 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010094}
Paul Bakker19343182013-08-16 13:31:10 +020095
Paul Bakker19343182013-08-16 13:31:10 +020096
Azim Khan191e9042017-06-09 12:39:00 +010097/**
98 * \brief Checks if the dependency i.e. the compile flag is set.
99 * For optimizing space for embedded targets each dependency
100 * is identified by a unique identifier instead of string literals.
101 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100102 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100103 *
104 * \param exp_id Dependency identifier.
105 *
106 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
107 */
108int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100109{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100110 int ret = DEPENDENCY_NOT_SUPPORTED;
111
112 (void) dep_id;
113
114 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100115 {
116$dep_check_code
117#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100118 default:
119 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100120 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100121 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100122}
Paul Bakker19343182013-08-16 13:31:10 +0200123
SimonB8ca7bc42016-04-17 23:24:50 +0100124
Azim Khan191e9042017-06-09 12:39:00 +0100125/**
126 * \brief Function pointer type for test function wrappers.
127 *
128 *
129 * \param void ** Pointer to void pointers. Represents an array of test
130 * function parameters.
131 *
132 * \return void
133 */
134typedef void (*TestWrapper_t)( void ** );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100135
Azim Khan191e9042017-06-09 12:39:00 +0100136
137/**
138 * \brief Table of test function wrappers. Used by dispatch_test().
139 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100140 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100141 *
142 */
143TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100144{
145$dispatch_code
146#line $line_no "suites/main_test.function"
147};
Azim Khan191e9042017-06-09 12:39:00 +0100148
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500149/**
150 * \brief Execute the test function.
151 *
152 * This is a wrapper function around the test function execution
153 * to allow the setjmp() call used to catch any calls to the
154 * parameter failure callback, to be used. Calls to setjmp()
155 * can invalidate the state of any local auto variables.
156 *
157 * \param fp Function pointer to the test function
158 * \param params Parameters to pass
159 *
160 */
161void execute_function_ptr(TestWrapper_t fp, void **params)
162{
163#if defined(MBEDTLS_CHECK_PARAMS)
164 if ( setjmp( param_fail_jmp ) == 0 )
165 {
166 fp( params );
167 }
168 else
169 {
170 /* Unexpected parameter validation error */
Hanno Beckere69d0152019-07-05 13:31:30 +0100171 test_info.result = TEST_RESULT_FAILED;
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500172 }
173
174 memset( param_fail_jmp, 0, sizeof(jmp_buf) );
175#else
176 fp( params );
177#endif
178}
Azim Khan191e9042017-06-09 12:39:00 +0100179
180/**
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500181 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100182 *
183 * \param exp_id Test function index.
184 *
185 * \return DISPATCH_TEST_SUCCESS if found
186 * DISPATCH_TEST_FN_NOT_FOUND if not found
187 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
188 */
189int dispatch_test( int func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100190{
Azim Khan191e9042017-06-09 12:39:00 +0100191 int ret = DISPATCH_TEST_SUCCESS;
192 TestWrapper_t fp = NULL;
193
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100194 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100195 {
Azim Khan191e9042017-06-09 12:39:00 +0100196 fp = test_funcs[func_idx];
197 if ( fp )
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500198 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100199 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100200 ret = DISPATCH_UNSUPPORTED_SUITE;
201 }
Azim Khan191e9042017-06-09 12:39:00 +0100202 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100203 {
204 ret = DISPATCH_TEST_FN_NOT_FOUND;
205 }
Azim Khan191e9042017-06-09 12:39:00 +0100206
Paul Bakker19343182013-08-16 13:31:10 +0200207 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100208}
Paul Bakker19343182013-08-16 13:31:10 +0200209
SimonB152ea182016-02-15 23:27:28 +0000210
Azim Khan13c6bfb2017-06-15 14:45:56 +0100211/**
212 * \brief Checks if test function is supported
213 *
214 * \param exp_id Test function index.
215 *
216 * \return DISPATCH_TEST_SUCCESS if found
217 * DISPATCH_TEST_FN_NOT_FOUND if not found
218 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
219 */
220int check_test( int func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100221{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100222 int ret = DISPATCH_TEST_SUCCESS;
223 TestWrapper_t fp = NULL;
224
225 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100226 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100227 fp = test_funcs[func_idx];
228 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100229 ret = DISPATCH_UNSUPPORTED_SUITE;
230 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100231 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100232 {
233 ret = DISPATCH_TEST_FN_NOT_FOUND;
234 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100235
236 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100237}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100238
239
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100240$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100241
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100242#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100243
SimonB152ea182016-02-15 23:27:28 +0000244/*----------------------------------------------------------------------------*/
245/* Main Test code */
246
SimonB15942102016-04-25 21:34:49 +0100247
Azim Khan191e9042017-06-09 12:39:00 +0100248/**
249 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200250 *
Azim Khan191e9042017-06-09 12:39:00 +0100251 * \param argc Command line arguments count.
252 * \param argv Array of command line arguments.
253 *
254 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200255 */
Azim Khan191e9042017-06-09 12:39:00 +0100256int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100257{
Azim Khan191e9042017-06-09 12:39:00 +0100258 int ret = platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400259 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100260 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400261 mbedtls_fprintf( stderr,
262 "FATAL: Failed to initialize platform - error %d\n",
263 ret );
264 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100265 }
Hanno Becker1cfc5dd2018-11-12 13:18:45 +0000266
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}