blob: 6a87e809940f84717f7132d47342628f0b104dee [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"
TRodziewicz12c77412021-07-15 16:12:54 +020027#include "common.h"
Paul Bakker19343182013-08-16 13:31:10 +020028
Gilles Peskine2ff02c32019-11-29 12:17:21 +010029/* Test code may use deprecated identifiers only if the preprocessor symbol
30 * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set
31 * MBEDTLS_TEST_DEPRECATED explicitly if MBEDTLS_DEPRECATED_WARNING is
32 * enabled but the corresponding warnings are not treated as errors.
33 */
Gilles Peskine841b14b2019-11-26 17:37:37 +010034#if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING)
35#define MBEDTLS_TEST_DEPRECATED
36#endif
37
SimonB152ea182016-02-15 23:27:28 +000038/*----------------------------------------------------------------------------*/
Azim Khan191e9042017-06-09 12:39:00 +010039/* Common helper code */
SimonB152ea182016-02-15 23:27:28 +000040
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010041$test_common_helpers
Paul Bakkerde56ca12013-09-15 17:05:21 +020042
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010043#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +010044
45
46/*----------------------------------------------------------------------------*/
47/* Test Suite Code */
48
49
50#define TEST_SUITE_ACTIVE
51
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010052$functions_code
Azim Khan191e9042017-06-09 12:39:00 +010053
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010054#line $line_no "suites/main_test.function"
SimonB15942102016-04-25 21:34:49 +010055
SimonB152ea182016-02-15 23:27:28 +000056
57/*----------------------------------------------------------------------------*/
58/* Test dispatch code */
59
Paul Bakker19343182013-08-16 13:31:10 +020060
Azim Khan191e9042017-06-09 12:39:00 +010061/**
62 * \brief Evaluates an expression/macro into its literal integer value.
63 * For optimizing space for embedded targets each expression/macro
64 * is identified by a unique identifier instead of string literals.
65 * Identifiers and evaluation code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010066 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +010067 *
68 * \param exp_id Expression identifier.
69 * \param out_value Pointer to int to hold the integer.
70 *
71 * \return 0 if exp_id is found. 1 otherwise.
72 */
73int get_expression( int32_t exp_id, int32_t * out_value )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010074{
Azim Khanb1c2d0f2017-07-07 17:14:02 +010075 int ret = KEY_VALUE_MAPPING_FOUND;
76
77 (void) exp_id;
78 (void) out_value;
79
80 switch( exp_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010081 {
82$expression_code
83#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +010084 default:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010085 {
Azim Khanb1c2d0f2017-07-07 17:14:02 +010086 ret = KEY_VALUE_MAPPING_NOT_FOUND;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010087 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010088 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010089 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +010090 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010091}
Paul Bakker19343182013-08-16 13:31:10 +020092
Paul Bakker19343182013-08-16 13:31:10 +020093
Azim Khan191e9042017-06-09 12:39:00 +010094/**
95 * \brief Checks if the dependency i.e. the compile flag is set.
96 * For optimizing space for embedded targets each dependency
97 * is identified by a unique identifier instead of string literals.
98 * Identifiers and check code is generated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +010099 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100100 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100101 * \param dep_id Dependency identifier.
Azim Khan191e9042017-06-09 12:39:00 +0100102 *
103 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
104 */
105int dep_check( int dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100106{
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100107 int ret = DEPENDENCY_NOT_SUPPORTED;
108
109 (void) dep_id;
110
111 switch( dep_id )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100112 {
113$dep_check_code
114#line $line_no "suites/main_test.function"
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100115 default:
116 break;
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100117 }
Azim Khanb1c2d0f2017-07-07 17:14:02 +0100118 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100119}
Paul Bakker19343182013-08-16 13:31:10 +0200120
SimonB8ca7bc42016-04-17 23:24:50 +0100121
Azim Khan191e9042017-06-09 12:39:00 +0100122/**
123 * \brief Function pointer type for test function wrappers.
124 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100125 * A test function wrapper decodes the parameters and passes them to the
126 * underlying test function. Both the wrapper and the underlying function
127 * return void. Test wrappers assume that they are passed a suitable
128 * parameter array and do not perform any error detection.
Azim Khan191e9042017-06-09 12:39:00 +0100129 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100130 * \param param_array The array of parameters. Each element is a `void *`
131 * which the wrapper casts to the correct type and
132 * dereferences. Each wrapper function hard-codes the
133 * number and types of the parameters.
Azim Khan191e9042017-06-09 12:39:00 +0100134 */
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100135typedef void (*TestWrapper_t)( void **param_array );
Simon Butcher65b1fa62016-05-23 23:18:26 +0100136
Azim Khan191e9042017-06-09 12:39:00 +0100137
138/**
139 * \brief Table of test function wrappers. Used by dispatch_test().
140 * This table is populated by script:
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100141 * $generator_script
Azim Khan191e9042017-06-09 12:39:00 +0100142 *
143 */
144TestWrapper_t test_funcs[] =
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100145{
146$dispatch_code
147#line $line_no "suites/main_test.function"
148};
Azim Khan191e9042017-06-09 12:39:00 +0100149
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500150/**
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500151 * \brief Dispatches test functions based on function index.
Azim Khan191e9042017-06-09 12:39:00 +0100152 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100153 * \param func_idx Test function index.
154 * \param params The array of parameters to pass to the test function.
155 * It will be decoded by the #TestWrapper_t wrapper function.
Azim Khan191e9042017-06-09 12:39:00 +0100156 *
157 * \return DISPATCH_TEST_SUCCESS if found
158 * DISPATCH_TEST_FN_NOT_FOUND if not found
159 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
160 */
k-stachowiak03954f22019-09-16 10:23:10 +0200161int dispatch_test( size_t func_idx, void ** params )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100162{
Azim Khan191e9042017-06-09 12:39:00 +0100163 int ret = DISPATCH_TEST_SUCCESS;
164 TestWrapper_t fp = NULL;
165
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100166 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100167 {
Azim Khan191e9042017-06-09 12:39:00 +0100168 fp = test_funcs[func_idx];
169 if ( fp )
TRodziewicz2d0769d2021-05-27 15:24:33 +0200170 {
171 #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
172 mbedtls_test_enable_insecure_external_rng( );
173 #endif
174
175 fp( params );
176
177 #if defined(MBEDTLS_TEST_MUTEX_USAGE)
178 mbedtls_test_mutex_usage_check( );
179 #endif /* MBEDTLS_TEST_MUTEX_USAGE */
180 }
Azim Khan191e9042017-06-09 12:39:00 +0100181 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100182 ret = DISPATCH_UNSUPPORTED_SUITE;
183 }
Azim Khan191e9042017-06-09 12:39:00 +0100184 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100185 {
186 ret = DISPATCH_TEST_FN_NOT_FOUND;
187 }
Azim Khan191e9042017-06-09 12:39:00 +0100188
Paul Bakker19343182013-08-16 13:31:10 +0200189 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100190}
Paul Bakker19343182013-08-16 13:31:10 +0200191
SimonB152ea182016-02-15 23:27:28 +0000192
Azim Khan13c6bfb2017-06-15 14:45:56 +0100193/**
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100194 * \brief Checks if test function is supported in this build-time
195 * configuration.
Azim Khan13c6bfb2017-06-15 14:45:56 +0100196 *
Gilles Peskine5a7702e2021-02-23 13:40:19 +0100197 * \param func_idx Test function index.
Azim Khan13c6bfb2017-06-15 14:45:56 +0100198 *
199 * \return DISPATCH_TEST_SUCCESS if found
200 * DISPATCH_TEST_FN_NOT_FOUND if not found
201 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
202 */
k-stachowiak03954f22019-09-16 10:23:10 +0200203int check_test( size_t func_idx )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100204{
Azim Khan13c6bfb2017-06-15 14:45:56 +0100205 int ret = DISPATCH_TEST_SUCCESS;
206 TestWrapper_t fp = NULL;
207
208 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100209 {
Azim Khan13c6bfb2017-06-15 14:45:56 +0100210 fp = test_funcs[func_idx];
211 if ( fp == NULL )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100212 ret = DISPATCH_UNSUPPORTED_SUITE;
213 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100214 else
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100215 {
216 ret = DISPATCH_TEST_FN_NOT_FOUND;
217 }
Azim Khan13c6bfb2017-06-15 14:45:56 +0100218
219 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100220}
Azim Khan13c6bfb2017-06-15 14:45:56 +0100221
222
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100223$platform_code
Azim Khan191e9042017-06-09 12:39:00 +0100224
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100225#line $line_no "suites/main_test.function"
Azim Khan191e9042017-06-09 12:39:00 +0100226
SimonB152ea182016-02-15 23:27:28 +0000227/*----------------------------------------------------------------------------*/
228/* Main Test code */
229
SimonB15942102016-04-25 21:34:49 +0100230
Azim Khan191e9042017-06-09 12:39:00 +0100231/**
232 * \brief Program main. Invokes platform specific execute_tests().
Gilles Peskine964faeb2017-09-29 18:00:25 +0200233 *
Azim Khan191e9042017-06-09 12:39:00 +0100234 * \param argc Command line arguments count.
235 * \param argv Array of command line arguments.
236 *
237 * \return Exit code.
Gilles Peskine964faeb2017-09-29 18:00:25 +0200238 */
Azim Khan191e9042017-06-09 12:39:00 +0100239int main( int argc, const char *argv[] )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100240{
TRodziewiczd9be6522021-07-05 15:16:00 +0200241#if defined(MBEDTLS_TEST_HOOKS)
TRodziewicz7871c2e2021-07-07 17:29:43 +0200242 mbedtls_test_hook_test_fail = &mbedtls_test_fail;
TRodziewicz829fe702021-07-13 12:23:12 +0200243#if defined(MBEDTLS_ERROR_C)
244 mbedtls_test_hook_error_add = &mbedtls_test_err_add_check;
245#endif
TRodziewiczd9be6522021-07-05 15:16:00 +0200246#endif
247
Ronald Crone9c09f12020-06-08 16:44:58 +0200248 int ret = mbedtls_test_platform_setup();
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400249 if( ret != 0 )
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100250 {
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400251 mbedtls_fprintf( stderr,
252 "FATAL: Failed to initialize platform - error %d\n",
253 ret );
254 return( -1 );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100255 }
Hanno Becker1cfc5dd2018-11-12 13:18:45 +0000256
Azim Khan191e9042017-06-09 12:39:00 +0100257 ret = execute_tests( argc, argv );
Ronald Crone9c09f12020-06-08 16:44:58 +0200258 mbedtls_test_platform_teardown();
Azim Khan191e9042017-06-09 12:39:00 +0100259 return( ret );
Mohammad Azim Khan5cb70172018-07-19 11:32:30 +0100260}