blob: 52b586eaad5bcc3a854bb7bc139d101e156bbb6f [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
Bence Szépkútic662b362021-05-27 11:25:03 +020026#include "mbedtls/build_info.h"
Paul Bakker19343182013-08-16 13:31:10 +020027
Gilles Peskine2ff02c32019-11-29 12:17:21 +010028/* Test code may use deprecated identifiers only if the preprocessor symbol
29 * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set
30 * MBEDTLS_TEST_DEPRECATED explicitly if MBEDTLS_DEPRECATED_WARNING is
31 * enabled but the corresponding warnings are not treated as errors.
32 */
Gilles Peskine841b14b2019-11-26 17:37:37 +010033#if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING)
34#define MBEDTLS_TEST_DEPRECATED
35#endif
36
SimonB152ea182016-02-15 23:27:28 +000037/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010038/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000039
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010040$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020041
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010042#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010043
44
45/*----------------------------------------------------------------------------*/
46/* Test Suite Code */
47
48
49#define TEST_SUITE_ACTIVE
50
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010051$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010052
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010053#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010054
SimonB152ea182016-02-15 23:27:28 +000055
56/*----------------------------------------------------------------------------*/
57/* Test dispatch code */
58
Paul Bakker19343182013-08-16 13:31:10 +020059
Azim Khan191e9042017-06-09 12:39:00 +010060/**
61 * \brief Evaluates an expression/macro into its literal integer value.
62 * For optimizing space for embedded targets each expression/macro
63 * is identified by a unique identifier instead of string literals.
64 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010065 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010066 *
67 * \param exp_id Expression identifier.
68 * \param out_value Pointer to int to hold the integer.
69 *
70 * \return 0 if exp_id is found. 1 otherwise.
71 */
72int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010073{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010074 int ret = KEY_VALUE_MAPPING_FOUND;
75
76 (void) exp_id;
77 (void) out_value;
78
79 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010080 {
81$expression_code
82#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010083 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010084 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010085 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010086 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010087 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010088 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010089 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010090}
Paul Bakker19343182013-08-16 13:31:10 +020091
Paul Bakker19343182013-08-16 13:31:10 +020092
Azim Khan191e9042017-06-09 12:39:00 +010093/**
94 * \brief Checks if the dependency i.e. the compile flag is set.
95 * For optimizing space for embedded targets each dependency
96 * is identified by a unique identifier instead of string literals.
97 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010098 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010099 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100100 * \param dep_id Dependency identifier.
Azim Khan191e9042017-06-09 12:39:00 +0100101 *
102 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
103 */
104int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100105{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100106 int ret = DEPENDENCY_NOT_SUPPORTED;
107
108 (void) dep_id;
109
110 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100111 {
112$dep_check_code
113#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100114 default:
115 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100116 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100117 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100118}
Paul Bakker19343182013-08-16 13:31:10 +0200119
SimonB8ca7bc42016-04-17 23:24:50 +0100120
Azim Khan191e9042017-06-09 12:39:00 +0100121/**
122 * \brief Function pointer type for test function wrappers.
123 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100124 * A test function wrapper decodes the parameters and passes them to the
125 * underlying test function. Both the wrapper and the underlying function
126 * return void. Test wrappers assume that they are passed a suitable
127 * parameter array and do not perform any error detection.
Azim Khan191e9042017-06-09 12:39:00 +0100128 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100129 * \param param_array The array of parameters. Each element is a `void *`
130 * which the wrapper casts to the correct type and
131 * dereferences. Each wrapper function hard-codes the
132 * number and types of the parameters.
Azim Khan191e9042017-06-09 12:39:00 +0100133 */
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100134typedef void (*TestWrapper_t)( void **param_array );
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/**
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500150 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100151 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100152 * \param func_idx Test function index.
153 * \param params The array of parameters to pass to the test function.
154 * It will be decoded by the #TestWrapper_t wrapper function.
Azim Khan191e9042017-06-09 12:39:00 +0100155 *
156 * \return DISPATCH_TEST_SUCCESS if found
157 * DISPATCH_TEST_FN_NOT_FOUND if not found
158 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
159 */
k-stachowiak03954f22019-09-16 10:23:10 +0200160int dispatch_test( size_t func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100161{
Azim Khan191e9042017-06-09 12:39:00 +0100162 int ret = DISPATCH_TEST_SUCCESS;
163 TestWrapper_t fp = NULL;
164
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100165 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100166 {
Azim Khan191e9042017-06-09 12:39:00 +0100167 fp = test_funcs[func_idx];
168 if ( fp )
TRodziewicz2d0769d2021-05-27 15:24:33 +0200169 {
170 #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
171 mbedtls_test_enable_insecure_external_rng( );
172 #endif
173
174 fp( params );
175
176 #if defined(MBEDTLS_TEST_MUTEX_USAGE)
177 mbedtls_test_mutex_usage_check( );
178 #endif /* MBEDTLS_TEST_MUTEX_USAGE */
179 }
Azim Khan191e9042017-06-09 12:39:00 +0100180 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100181 ret = DISPATCH_UNSUPPORTED_SUITE;
182 }
Azim Khan191e9042017-06-09 12:39:00 +0100183 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100184 {
185 ret = DISPATCH_TEST_FN_NOT_FOUND;
186 }
Azim Khan191e9042017-06-09 12:39:00 +0100187
Paul Bakker19343182013-08-16 13:31:10 +0200188 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100189}
Paul Bakker19343182013-08-16 13:31:10 +0200190
SimonB152ea182016-02-15 23:27:28 +0000191
Azim Khan13c6bfb2017-06-15 14:45:56 +0100192/**
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100193 * \brief Checks if test function is supported in this build-time
194 * configuration.
Azim Khan13c6bfb2017-06-15 14:45:56 +0100195 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100196 * \param func_idx Test function index.
Azim Khan13c6bfb2017-06-15 14:45:56 +0100197 *
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 check_test( size_t func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100203{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100204 int ret = DISPATCH_TEST_SUCCESS;
205 TestWrapper_t fp = NULL;
206
207 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100208 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100209 fp = test_funcs[func_idx];
210 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100211 ret = DISPATCH_UNSUPPORTED_SUITE;
212 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100213 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100214 {
215 ret = DISPATCH_TEST_FN_NOT_FOUND;
216 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100217
218 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100219}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100220
221
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100222$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100223
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100224#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100225
SimonB152ea182016-02-15 23:27:28 +0000226/*----------------------------------------------------------------------------*/
227/* Main Test code */
228
SimonB15942102016-04-25 21:34:49 +0100229
Azim Khan191e9042017-06-09 12:39:00 +0100230/**
231 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200232 *
Azim Khan191e9042017-06-09 12:39:00 +0100233 * \param argc Command line arguments count.
234 * \param argv Array of command line arguments.
235 *
236 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200237 */
Azim Khan191e9042017-06-09 12:39:00 +0100238int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100239{
Chris Jones759e30b2021-02-09 15:30:54 +0000240#if defined(MBEDTLS_TEST_HOOKS) && defined (MBEDTLS_ERROR_C)
Chris Jones74392092021-04-01 16:00:01 +0100241 mbedtls_test_hook_error_add = &mbedtls_test_err_add_check;
Chris Jones96ae73b2021-01-08 17:04:59 +0000242#endif
243
Ronald Crone9c09f12020-06-08 16:44:58 +0200244 int ret = mbedtls_test_platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400245 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100246 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400247 mbedtls_fprintf( stderr,
248 "FATAL: Failed to initialize platform - error %d\n",
249 ret );
250 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100251 }
Hanno Becker1cfc5dd2018-11-12 13:18:45 +0000252
Azim Khan191e9042017-06-09 12:39:00 +0100253 ret = execute_tests( argc, argv );
Ronald Crone9c09f12020-06-08 16:44:58 +0200254 mbedtls_test_platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100255 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100256}