blob: 28c7aa8fb179f6835f2d27745f15f8859a69950c [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 Peskine31f88a22020-04-14 19:39:56 +020022#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
23#if !defined(_POSIX_C_SOURCE)
nia1c0c8372020-06-11 12:03:45 +010024#define _POSIX_C_SOURCE 200112L // for fileno() from <stdio.h>
Gilles Peskine31f88a22020-04-14 19:39:56 +020025#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
Hanno Becker1cfc5dd2018-11-12 13:18:45 +000034#if defined(MBEDTLS_USE_PSA_CRYPTO)
35#include "psa/crypto.h"
36#endif /* MBEDTLS_USE_PSA_CRYPTO */
SimonB152ea182016-02-15 23:27:28 +000037
Gilles Peskine2ff02c32019-11-29 12:17:21 +010038/* Test code may use deprecated identifiers only if the preprocessor symbol
39 * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set
40 * MBEDTLS_TEST_DEPRECATED explicitly if MBEDTLS_DEPRECATED_WARNING is
41 * enabled but the corresponding warnings are not treated as errors.
42 */
Gilles Peskine841b14b2019-11-26 17:37:37 +010043#if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING)
44#define MBEDTLS_TEST_DEPRECATED
45#endif
46
SimonB152ea182016-02-15 23:27:28 +000047/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010048/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000049
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010050$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020051
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010052#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010053
54
55/*----------------------------------------------------------------------------*/
56/* Test Suite Code */
57
58
59#define TEST_SUITE_ACTIVE
60
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010061$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010062
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010063#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010064
SimonB152ea182016-02-15 23:27:28 +000065
66/*----------------------------------------------------------------------------*/
67/* Test dispatch code */
68
Paul Bakker19343182013-08-16 13:31:10 +020069
Azim Khan191e9042017-06-09 12:39:00 +010070/**
71 * \brief Evaluates an expression/macro into its literal integer value.
72 * For optimizing space for embedded targets each expression/macro
73 * is identified by a unique identifier instead of string literals.
74 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010075 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010076 *
77 * \param exp_id Expression identifier.
78 * \param out_value Pointer to int to hold the integer.
79 *
80 * \return 0 if exp_id is found. 1 otherwise.
81 */
82int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010083{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010084 int ret = KEY_VALUE_MAPPING_FOUND;
85
86 (void) exp_id;
87 (void) out_value;
88
89 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010090 {
91$expression_code
92#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010093 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010094 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010095 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010096 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010097 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010098 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010099 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100100}
Paul Bakker19343182013-08-16 13:31:10 +0200101
Paul Bakker19343182013-08-16 13:31:10 +0200102
Azim Khan191e9042017-06-09 12:39:00 +0100103/**
104 * \brief Checks if the dependency i.e. the compile flag is set.
105 * For optimizing space for embedded targets each dependency
106 * is identified by a unique identifier instead of string literals.
107 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100108 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100109 *
110 * \param exp_id Dependency identifier.
111 *
112 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
113 */
114int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100115{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100116 int ret = DEPENDENCY_NOT_SUPPORTED;
117
118 (void) dep_id;
119
120 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100121 {
122$dep_check_code
123#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100124 default:
125 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100126 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100127 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100128}
Paul Bakker19343182013-08-16 13:31:10 +0200129
SimonB8ca7bc42016-04-17 23:24:50 +0100130
Azim Khan191e9042017-06-09 12:39:00 +0100131/**
132 * \brief Function pointer type for test function wrappers.
133 *
134 *
135 * \param void ** Pointer to void pointers. Represents an array of test
136 * function parameters.
137 *
138 * \return void
139 */
140typedef void (*TestWrapper_t)( void ** );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100141
Azim Khan191e9042017-06-09 12:39:00 +0100142
143/**
144 * \brief Table of test function wrappers. Used by dispatch_test().
145 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100146 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100147 *
148 */
149TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100150{
151$dispatch_code
152#line $line_no "suites/main_test.function"
153};
Azim Khan191e9042017-06-09 12:39:00 +0100154
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500155/**
156 * \brief Execute the test function.
157 *
158 * This is a wrapper function around the test function execution
159 * to allow the setjmp() call used to catch any calls to the
160 * parameter failure callback, to be used. Calls to setjmp()
161 * can invalidate the state of any local auto variables.
162 *
163 * \param fp Function pointer to the test function
164 * \param params Parameters to pass
165 *
166 */
167void execute_function_ptr(TestWrapper_t fp, void **params)
168{
169#if defined(MBEDTLS_CHECK_PARAMS)
Ronald Cron4e665872020-06-30 17:44:27 +0200170 mbedtls_test_param_failed_location_record_t location_record;
171
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500172 if ( setjmp( param_fail_jmp ) == 0 )
173 {
174 fp( params );
175 }
176 else
177 {
178 /* Unexpected parameter validation error */
Ronald Cron4e665872020-06-30 17:44:27 +0200179 mbedtls_test_param_failed_get_location_record( &location_record );
180 test_fail( location_record.failure_condition,
181 location_record.line,
182 location_record.file );
Hanno Beckere69d0152019-07-05 13:31:30 +0100183 test_info.result = TEST_RESULT_FAILED;
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500184 }
185
186 memset( param_fail_jmp, 0, sizeof(jmp_buf) );
187#else
188 fp( params );
189#endif
190}
Azim Khan191e9042017-06-09 12:39:00 +0100191
192/**
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500193 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100194 *
195 * \param exp_id Test function index.
196 *
197 * \return DISPATCH_TEST_SUCCESS if found
198 * DISPATCH_TEST_FN_NOT_FOUND if not found
199 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
200 */
k-stachowiak03954f22019-09-16 10:23:10 +0200201int dispatch_test( size_t func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100202{
Azim Khan191e9042017-06-09 12:39:00 +0100203 int ret = DISPATCH_TEST_SUCCESS;
204 TestWrapper_t fp = NULL;
205
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100206 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100207 {
Azim Khan191e9042017-06-09 12:39:00 +0100208 fp = test_funcs[func_idx];
209 if ( fp )
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500210 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100211 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100212 ret = DISPATCH_UNSUPPORTED_SUITE;
213 }
Azim Khan191e9042017-06-09 12:39:00 +0100214 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100215 {
216 ret = DISPATCH_TEST_FN_NOT_FOUND;
217 }
Azim Khan191e9042017-06-09 12:39:00 +0100218
Paul Bakker19343182013-08-16 13:31:10 +0200219 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100220}
Paul Bakker19343182013-08-16 13:31:10 +0200221
SimonB152ea182016-02-15 23:27:28 +0000222
Azim Khan13c6bfb2017-06-15 14:45:56 +0100223/**
224 * \brief Checks if test function is supported
225 *
226 * \param exp_id Test function index.
227 *
228 * \return DISPATCH_TEST_SUCCESS if found
229 * DISPATCH_TEST_FN_NOT_FOUND if not found
230 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
231 */
k-stachowiak03954f22019-09-16 10:23:10 +0200232int check_test( size_t func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100233{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100234 int ret = DISPATCH_TEST_SUCCESS;
235 TestWrapper_t fp = NULL;
236
237 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100238 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100239 fp = test_funcs[func_idx];
240 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100241 ret = DISPATCH_UNSUPPORTED_SUITE;
242 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100243 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100244 {
245 ret = DISPATCH_TEST_FN_NOT_FOUND;
246 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100247
248 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100249}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100250
251
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100252$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100253
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100254#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100255
SimonB152ea182016-02-15 23:27:28 +0000256/*----------------------------------------------------------------------------*/
257/* Main Test code */
258
SimonB15942102016-04-25 21:34:49 +0100259
Azim Khan191e9042017-06-09 12:39:00 +0100260/**
261 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200262 *
Azim Khan191e9042017-06-09 12:39:00 +0100263 * \param argc Command line arguments count.
264 * \param argv Array of command line arguments.
265 *
266 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200267 */
Azim Khan191e9042017-06-09 12:39:00 +0100268int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100269{
Ronald Crone9c09f12020-06-08 16:44:58 +0200270 int ret = mbedtls_test_platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400271 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100272 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400273 mbedtls_fprintf( stderr,
274 "FATAL: Failed to initialize platform - error %d\n",
275 ret );
276 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100277 }
Hanno Becker1cfc5dd2018-11-12 13:18:45 +0000278
Azim Khan191e9042017-06-09 12:39:00 +0100279 ret = execute_tests( argc, argv );
Ronald Crone9c09f12020-06-08 16:44:58 +0200280 mbedtls_test_platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100281 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100282}