blob: 6ddfc5927a6d522b798b91c6e912d137e8624907 [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 Peskine841b14b2019-11-26 17:37:37 +010032#if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING)
33#define MBEDTLS_TEST_DEPRECATED
34#endif
35
SimonB152ea182016-02-15 23:27:28 +000036/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010037/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000038
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010039$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020040
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010041#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010042
43
44/*----------------------------------------------------------------------------*/
45/* Test Suite Code */
46
47
48#define TEST_SUITE_ACTIVE
49
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010050$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010051
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010052#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010053
SimonB152ea182016-02-15 23:27:28 +000054
55/*----------------------------------------------------------------------------*/
56/* Test dispatch code */
57
Paul Bakker19343182013-08-16 13:31:10 +020058
Azim Khan191e9042017-06-09 12:39:00 +010059/**
60 * \brief Evaluates an expression/macro into its literal integer value.
61 * For optimizing space for embedded targets each expression/macro
62 * is identified by a unique identifier instead of string literals.
63 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010064 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010065 *
66 * \param exp_id Expression identifier.
67 * \param out_value Pointer to int to hold the integer.
68 *
69 * \return 0 if exp_id is found. 1 otherwise.
70 */
71int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010072{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010073 int ret = KEY_VALUE_MAPPING_FOUND;
74
75 (void) exp_id;
76 (void) out_value;
77
78 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010079 {
80$expression_code
81#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010082 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010083 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010084 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010085 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010086 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010087 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010088 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010089}
Paul Bakker19343182013-08-16 13:31:10 +020090
Paul Bakker19343182013-08-16 13:31:10 +020091
Azim Khan191e9042017-06-09 12:39:00 +010092/**
93 * \brief Checks if the dependency i.e. the compile flag is set.
94 * For optimizing space for embedded targets each dependency
95 * is identified by a unique identifier instead of string literals.
96 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010097 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010098 *
99 * \param exp_id Dependency identifier.
100 *
101 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
102 */
103int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100104{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100105 int ret = DEPENDENCY_NOT_SUPPORTED;
106
107 (void) dep_id;
108
109 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100110 {
111$dep_check_code
112#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100113 default:
114 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100115 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100116 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100117}
Paul Bakker19343182013-08-16 13:31:10 +0200118
SimonB8ca7bc42016-04-17 23:24:50 +0100119
Azim Khan191e9042017-06-09 12:39:00 +0100120/**
121 * \brief Function pointer type for test function wrappers.
122 *
123 *
124 * \param void ** Pointer to void pointers. Represents an array of test
125 * function parameters.
126 *
127 * \return void
128 */
129typedef void (*TestWrapper_t)( void ** );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100130
Azim Khan191e9042017-06-09 12:39:00 +0100131
132/**
133 * \brief Table of test function wrappers. Used by dispatch_test().
134 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100135 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100136 *
137 */
138TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100139{
140$dispatch_code
141#line $line_no "suites/main_test.function"
142};
Azim Khan191e9042017-06-09 12:39:00 +0100143
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500144/**
145 * \brief Execute the test function.
146 *
147 * This is a wrapper function around the test function execution
148 * to allow the setjmp() call used to catch any calls to the
149 * parameter failure callback, to be used. Calls to setjmp()
150 * can invalidate the state of any local auto variables.
151 *
152 * \param fp Function pointer to the test function
153 * \param params Parameters to pass
154 *
155 */
156void execute_function_ptr(TestWrapper_t fp, void **params)
157{
158#if defined(MBEDTLS_CHECK_PARAMS)
159 if ( setjmp( param_fail_jmp ) == 0 )
160 {
161 fp( params );
162 }
163 else
164 {
165 /* Unexpected parameter validation error */
Hanno Beckere69d0152019-07-05 13:31:30 +0100166 test_info.result = TEST_RESULT_FAILED;
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500167 }
168
169 memset( param_fail_jmp, 0, sizeof(jmp_buf) );
170#else
171 fp( params );
172#endif
173}
Azim Khan191e9042017-06-09 12:39:00 +0100174
175/**
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500176 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100177 *
178 * \param exp_id Test function index.
179 *
180 * \return DISPATCH_TEST_SUCCESS if found
181 * DISPATCH_TEST_FN_NOT_FOUND if not found
182 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
183 */
184int dispatch_test( int func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100185{
Azim Khan191e9042017-06-09 12:39:00 +0100186 int ret = DISPATCH_TEST_SUCCESS;
187 TestWrapper_t fp = NULL;
188
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100189 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100190 {
Azim Khan191e9042017-06-09 12:39:00 +0100191 fp = test_funcs[func_idx];
192 if ( fp )
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500193 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100194 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100195 ret = DISPATCH_UNSUPPORTED_SUITE;
196 }
Azim Khan191e9042017-06-09 12:39:00 +0100197 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100198 {
199 ret = DISPATCH_TEST_FN_NOT_FOUND;
200 }
Azim Khan191e9042017-06-09 12:39:00 +0100201
Paul Bakker19343182013-08-16 13:31:10 +0200202 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100203}
Paul Bakker19343182013-08-16 13:31:10 +0200204
SimonB152ea182016-02-15 23:27:28 +0000205
Azim Khan13c6bfb2017-06-15 14:45:56 +0100206/**
207 * \brief Checks if test function is supported
208 *
209 * \param exp_id Test function index.
210 *
211 * \return DISPATCH_TEST_SUCCESS if found
212 * DISPATCH_TEST_FN_NOT_FOUND if not found
213 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
214 */
215int check_test( int func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100216{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100217 int ret = DISPATCH_TEST_SUCCESS;
218 TestWrapper_t fp = NULL;
219
220 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100221 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100222 fp = test_funcs[func_idx];
223 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100224 ret = DISPATCH_UNSUPPORTED_SUITE;
225 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100226 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100227 {
228 ret = DISPATCH_TEST_FN_NOT_FOUND;
229 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100230
231 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100232}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100233
234
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100235$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100236
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100237#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100238
SimonB152ea182016-02-15 23:27:28 +0000239/*----------------------------------------------------------------------------*/
240/* Main Test code */
241
SimonB15942102016-04-25 21:34:49 +0100242
Azim Khan191e9042017-06-09 12:39:00 +0100243/**
244 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200245 *
Azim Khan191e9042017-06-09 12:39:00 +0100246 * \param argc Command line arguments count.
247 * \param argv Array of command line arguments.
248 *
249 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200250 */
Azim Khan191e9042017-06-09 12:39:00 +0100251int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100252{
Azim Khan191e9042017-06-09 12:39:00 +0100253 int ret = platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400254 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100255 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400256 mbedtls_fprintf( stderr,
257 "FATAL: Failed to initialize platform - error %d\n",
258 ret );
259 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100260 }
Hanno Becker1cfc5dd2018-11-12 13:18:45 +0000261
Azim Khan191e9042017-06-09 12:39:00 +0100262 ret = execute_tests( argc, argv );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400263 platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100264 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100265}