blob: 36a7d231e3927f2972d432b4935916fdd7eacfb2 [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 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100108 * \param dep_id Dependency identifier.
Azim Khan191e9042017-06-09 12:39:00 +0100109 *
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 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100132 * A test function wrapper decodes the parameters and passes them to the
133 * underlying test function. Both the wrapper and the underlying function
134 * return void. Test wrappers assume that they are passed a suitable
135 * parameter array and do not perform any error detection.
Azim Khan191e9042017-06-09 12:39:00 +0100136 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100137 * \param param_array The array of parameters. Each element is a `void *`
138 * which the wrapper casts to the correct type and
139 * dereferences. Each wrapper function hard-codes the
140 * number and types of the parameters.
Azim Khan191e9042017-06-09 12:39:00 +0100141 */
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100142typedef void (*TestWrapper_t)( void **param_array );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100143
Azim Khan191e9042017-06-09 12:39:00 +0100144
145/**
146 * \brief Table of test function wrappers. Used by dispatch_test().
147 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100148 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100149 *
150 */
151TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100152{
153$dispatch_code
154#line $line_no "suites/main_test.function"
155};
Azim Khan191e9042017-06-09 12:39:00 +0100156
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500157/**
158 * \brief Execute the test function.
159 *
160 * This is a wrapper function around the test function execution
161 * to allow the setjmp() call used to catch any calls to the
162 * parameter failure callback, to be used. Calls to setjmp()
163 * can invalidate the state of any local auto variables.
164 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100165 * \param fp Function pointer to the test function.
166 * \param params Parameters to pass to the #TestWrapper_t wrapper function.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500167 *
168 */
169void execute_function_ptr(TestWrapper_t fp, void **params)
170{
Gilles Peskine76175ba2020-11-24 18:39:12 +0100171#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
172 mbedtls_test_enable_insecure_external_rng( );
173#endif
174
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500175#if defined(MBEDTLS_CHECK_PARAMS)
Ronald Cron4e665872020-06-30 17:44:27 +0200176 mbedtls_test_param_failed_location_record_t location_record;
177
Ronald Cron579fd282020-07-01 15:17:05 +0200178 if ( setjmp( mbedtls_test_param_failed_get_state_buf( ) ) == 0 )
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500179 {
180 fp( params );
181 }
182 else
183 {
184 /* Unexpected parameter validation error */
Ronald Cron4e665872020-06-30 17:44:27 +0200185 mbedtls_test_param_failed_get_location_record( &location_record );
Chris Jones9634bb12021-01-20 15:56:42 +0000186 mbedtls_test_fail( location_record.failure_condition,
187 location_record.line,
188 location_record.file );
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500189 }
190
Ronald Cron579fd282020-07-01 15:17:05 +0200191 mbedtls_test_param_failed_reset_state( );
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500192#else
193 fp( params );
194#endif
Gilles Peskine2a4c5982021-01-29 21:18:09 +0100195
196#if defined(MBEDTLS_TEST_MUTEX_USAGE)
197 mbedtls_test_mutex_usage_check( );
198#endif /* MBEDTLS_TEST_MUTEX_USAGE */
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500199}
Azim Khan191e9042017-06-09 12:39:00 +0100200
201/**
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500202 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100203 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100204 * \param func_idx Test function index.
205 * \param params The array of parameters to pass to the test function.
206 * It will be decoded by the #TestWrapper_t wrapper function.
Azim Khan191e9042017-06-09 12:39:00 +0100207 *
208 * \return DISPATCH_TEST_SUCCESS if found
209 * DISPATCH_TEST_FN_NOT_FOUND if not found
210 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
211 */
k-stachowiak03954f22019-09-16 10:23:10 +0200212int dispatch_test( size_t func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100213{
Azim Khan191e9042017-06-09 12:39:00 +0100214 int ret = DISPATCH_TEST_SUCCESS;
215 TestWrapper_t fp = NULL;
216
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100217 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100218 {
Azim Khan191e9042017-06-09 12:39:00 +0100219 fp = test_funcs[func_idx];
220 if ( fp )
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500221 execute_function_ptr(fp, params);
Azim Khan191e9042017-06-09 12:39:00 +0100222 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100223 ret = DISPATCH_UNSUPPORTED_SUITE;
224 }
Azim Khan191e9042017-06-09 12:39:00 +0100225 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100226 {
227 ret = DISPATCH_TEST_FN_NOT_FOUND;
228 }
Azim Khan191e9042017-06-09 12:39:00 +0100229
Paul Bakker19343182013-08-16 13:31:10 +0200230 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100231}
Paul Bakker19343182013-08-16 13:31:10 +0200232
SimonB152ea182016-02-15 23:27:28 +0000233
Azim Khan13c6bfb2017-06-15 14:45:56 +0100234/**
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100235 * \brief Checks if test function is supported in this build-time
236 * configuration.
Azim Khan13c6bfb2017-06-15 14:45:56 +0100237 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100238 * \param func_idx Test function index.
Azim Khan13c6bfb2017-06-15 14:45:56 +0100239 *
240 * \return DISPATCH_TEST_SUCCESS if found
241 * DISPATCH_TEST_FN_NOT_FOUND if not found
242 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
243 */
k-stachowiak03954f22019-09-16 10:23:10 +0200244int check_test( size_t func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100245{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100246 int ret = DISPATCH_TEST_SUCCESS;
247 TestWrapper_t fp = NULL;
248
249 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100250 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100251 fp = test_funcs[func_idx];
252 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100253 ret = DISPATCH_UNSUPPORTED_SUITE;
254 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100255 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100256 {
257 ret = DISPATCH_TEST_FN_NOT_FOUND;
258 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100259
260 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100261}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100262
263
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100264$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100265
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100266#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100267
SimonB152ea182016-02-15 23:27:28 +0000268/*----------------------------------------------------------------------------*/
269/* Main Test code */
270
SimonB15942102016-04-25 21:34:49 +0100271
Azim Khan191e9042017-06-09 12:39:00 +0100272/**
273 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200274 *
Azim Khan191e9042017-06-09 12:39:00 +0100275 * \param argc Command line arguments count.
276 * \param argv Array of command line arguments.
277 *
278 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200279 */
Azim Khan191e9042017-06-09 12:39:00 +0100280int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100281{
Ronald Crone9c09f12020-06-08 16:44:58 +0200282 int ret = mbedtls_test_platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400283 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100284 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400285 mbedtls_fprintf( stderr,
286 "FATAL: Failed to initialize platform - error %d\n",
287 ret );
288 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100289 }
Hanno Becker1cfc5dd2018-11-12 13:18:45 +0000290
Azim Khan191e9042017-06-09 12:39:00 +0100291 ret = execute_tests( argc, argv );
Ronald Crone9c09f12020-06-08 16:44:58 +0200292 mbedtls_test_platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100293 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100294}