blob: 57395aebb36da5ed5e49b400372436867f5299f6 [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 Peskine31f88a22020-04-14 19:39:56 +020020#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
21#if !defined(_POSIX_C_SOURCE)
nia1c0c8372020-06-11 12:03:45 +010022#define _POSIX_C_SOURCE 200112L // for fileno() from <stdio.h>
Gilles Peskine31f88a22020-04-14 19:39:56 +020023#endif
24#endif
25
Azim Khan191e9042017-06-09 12:39:00 +010026#if !defined(MBEDTLS_CONFIG_FILE)
27#include <mbedtls/config.h>
28#else
29#include MBEDTLS_CONFIG_FILE
30#endif
Paul Bakker19343182013-08-16 13:31:10 +020031
Hanno Becker1cfc5dd2018-11-12 13:18:45 +000032#if defined(MBEDTLS_USE_PSA_CRYPTO)
33#include "psa/crypto.h"
34#endif /* MBEDTLS_USE_PSA_CRYPTO */
SimonB152ea182016-02-15 23:27:28 +000035
Gilles Peskine2ff02c32019-11-29 12:17:21 +010036/* Test code may use deprecated identifiers only if the preprocessor symbol
37 * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set
38 * MBEDTLS_TEST_DEPRECATED explicitly if MBEDTLS_DEPRECATED_WARNING is
39 * enabled but the corresponding warnings are not treated as errors.
40 */
Gilles Peskine841b14b2019-11-26 17:37:37 +010041#if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING)
42#define MBEDTLS_TEST_DEPRECATED
43#endif
44
SimonB152ea182016-02-15 23:27:28 +000045/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010046/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000047
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010048$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020049
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010050#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010051
52
53/*----------------------------------------------------------------------------*/
54/* Test Suite Code */
55
56
57#define TEST_SUITE_ACTIVE
58
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010059$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010060
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010061#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010062
SimonB152ea182016-02-15 23:27:28 +000063
64/*----------------------------------------------------------------------------*/
65/* Test dispatch code */
66
Paul Bakker19343182013-08-16 13:31:10 +020067
Azim Khan191e9042017-06-09 12:39:00 +010068/**
69 * \brief Evaluates an expression/macro into its literal integer value.
70 * For optimizing space for embedded targets each expression/macro
71 * is identified by a unique identifier instead of string literals.
72 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010073 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010074 *
75 * \param exp_id Expression identifier.
76 * \param out_value Pointer to int to hold the integer.
77 *
78 * \return 0 if exp_id is found. 1 otherwise.
79 */
80int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010081{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010082 int ret = KEY_VALUE_MAPPING_FOUND;
83
84 (void) exp_id;
85 (void) out_value;
86
87 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010088 {
89$expression_code
90#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010091 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010092 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010093 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010094 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010095 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010096 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010097 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010098}
Paul Bakker19343182013-08-16 13:31:10 +020099
Paul Bakker19343182013-08-16 13:31:10 +0200100
Azim Khan191e9042017-06-09 12:39:00 +0100101/**
102 * \brief Checks if the dependency i.e. the compile flag is set.
103 * For optimizing space for embedded targets each dependency
104 * is identified by a unique identifier instead of string literals.
105 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100106 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100107 *
108 * \param exp_id Dependency identifier.
109 *
110 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
111 */
112int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100113{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100114 int ret = DEPENDENCY_NOT_SUPPORTED;
115
116 (void) dep_id;
117
118 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100119 {
120$dep_check_code
121#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100122 default:
123 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100124 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100125 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100126}
Paul Bakker19343182013-08-16 13:31:10 +0200127
SimonB8ca7bc42016-04-17 23:24:50 +0100128
Azim Khan191e9042017-06-09 12:39:00 +0100129/**
130 * \brief Function pointer type for test function wrappers.
131 *
132 *
133 * \param void ** Pointer to void pointers. Represents an array of test
134 * function parameters.
135 *
136 * \return void
137 */
138typedef void (*TestWrapper_t)( void ** );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100139
Azim Khan191e9042017-06-09 12:39:00 +0100140
141/**
142 * \brief Table of test function wrappers. Used by dispatch_test().
143 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100144 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100145 *
146 */
147TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100148{
149$dispatch_code
150#line $line_no "suites/main_test.function"
151};
Azim Khan191e9042017-06-09 12:39:00 +0100152
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500153/**
154 * \brief Execute the test function.
155 *
156 * This is a wrapper function around the test function execution
157 * to allow the setjmp() call used to catch any calls to the
158 * parameter failure callback, to be used. Calls to setjmp()
159 * can invalidate the state of any local auto variables.
160 *
161 * \param fp Function pointer to the test function
162 * \param params Parameters to pass
163 *
164 */
165void execute_function_ptr(TestWrapper_t fp, void **params)
166{
Gilles Peskine76175ba2020-11-24 18:39:12 +0100167#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
168 mbedtls_test_enable_insecure_external_rng( );
169#endif
170
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500171#if defined(MBEDTLS_CHECK_PARAMS)
Ronald Cron4e665872020-06-30 17:44:27 +0200172 mbedtls_test_param_failed_location_record_t location_record;
173
Ronald Cron579fd282020-07-01 15:17:05 +0200174 if ( setjmp( mbedtls_test_param_failed_get_state_buf( ) ) == 0 )
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500175 {
176 fp( params );
177 }
178 else
179 {
180 /* Unexpected parameter validation error */
Ronald Cron4e665872020-06-30 17:44:27 +0200181 mbedtls_test_param_failed_get_location_record( &location_record );
Chris Jones9634bb12021-01-20 15:56:42 +0000182 mbedtls_test_fail( location_record.failure_condition,
183 location_record.line,
184 location_record.file );
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500185 }
186
Ronald Cron579fd282020-07-01 15:17:05 +0200187 mbedtls_test_param_failed_reset_state( );
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500188#else
189 fp( params );
190#endif
191}
Azim Khan191e9042017-06-09 12:39:00 +0100192
193/**
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500194 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100195 *
196 * \param exp_id Test function index.
197 *
198 * \return DISPATCH_TEST_SUCCESS if found
199 * DISPATCH_TEST_FN_NOT_FOUND if not found
200 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
201 */
k-stachowiak03954f22019-09-16 10:23:10 +0200202int dispatch_test( size_t func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100203{
Azim Khan191e9042017-06-09 12:39:00 +0100204 int ret = DISPATCH_TEST_SUCCESS;
205 TestWrapper_t fp = NULL;
206
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100207 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100208 {
Azim Khan191e9042017-06-09 12:39:00 +0100209 fp = test_funcs[func_idx];
210 if ( fp )
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500211 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100212 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100213 ret = DISPATCH_UNSUPPORTED_SUITE;
214 }
Azim Khan191e9042017-06-09 12:39:00 +0100215 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100216 {
217 ret = DISPATCH_TEST_FN_NOT_FOUND;
218 }
Azim Khan191e9042017-06-09 12:39:00 +0100219
Paul Bakker19343182013-08-16 13:31:10 +0200220 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100221}
Paul Bakker19343182013-08-16 13:31:10 +0200222
SimonB152ea182016-02-15 23:27:28 +0000223
Azim Khan13c6bfb2017-06-15 14:45:56 +0100224/**
225 * \brief Checks if test function is supported
226 *
227 * \param exp_id Test function index.
228 *
229 * \return DISPATCH_TEST_SUCCESS if found
230 * DISPATCH_TEST_FN_NOT_FOUND if not found
231 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
232 */
k-stachowiak03954f22019-09-16 10:23:10 +0200233int check_test( size_t func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100234{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100235 int ret = DISPATCH_TEST_SUCCESS;
236 TestWrapper_t fp = NULL;
237
238 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100239 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100240 fp = test_funcs[func_idx];
241 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100242 ret = DISPATCH_UNSUPPORTED_SUITE;
243 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100244 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100245 {
246 ret = DISPATCH_TEST_FN_NOT_FOUND;
247 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100248
249 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100250}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100251
252
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100253$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100254
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100255#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100256
SimonB152ea182016-02-15 23:27:28 +0000257/*----------------------------------------------------------------------------*/
258/* Main Test code */
259
SimonB15942102016-04-25 21:34:49 +0100260
Azim Khan191e9042017-06-09 12:39:00 +0100261/**
262 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200263 *
Azim Khan191e9042017-06-09 12:39:00 +0100264 * \param argc Command line arguments count.
265 * \param argv Array of command line arguments.
266 *
267 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200268 */
Azim Khan191e9042017-06-09 12:39:00 +0100269int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100270{
Ronald Crone9c09f12020-06-08 16:44:58 +0200271 int ret = mbedtls_test_platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400272 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100273 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400274 mbedtls_fprintf( stderr,
275 "FATAL: Failed to initialize platform - error %d\n",
276 ret );
277 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100278 }
Hanno Becker1cfc5dd2018-11-12 13:18:45 +0000279
Azim Khan191e9042017-06-09 12:39:00 +0100280 ret = execute_tests( argc, argv );
Ronald Crone9c09f12020-06-08 16:44:58 +0200281 mbedtls_test_platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100282 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100283}