Azim Khan | 1de892b | 2017-06-09 15:02:36 +0100 | [diff] [blame] | 1 | #line 2 "suites/main_test.function" |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 2 | /* |
| 3 | * *** THIS FILE HAS BEEN MACHINE GENERATED *** |
| 4 | * |
| 5 | * This file has been machine generated using the script: |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 6 | * $generator_script |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 7 | * |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 8 | * Test file : $test_file |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 9 | * |
| 10 | * The following files were used to create this file. |
| 11 | * |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 12 | * 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 Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 17 | * |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 18 | */ |
Paul Bakker | de56ca1 | 2013-09-15 17:05:21 +0200 | [diff] [blame] | 19 | |
Gilles Peskine | 31f88a2 | 2020-04-14 19:39:56 +0200 | [diff] [blame] | 20 | #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) |
| 21 | #if !defined(_POSIX_C_SOURCE) |
nia | 1c0c837 | 2020-06-11 12:03:45 +0100 | [diff] [blame] | 22 | #define _POSIX_C_SOURCE 200112L // for fileno() from <stdio.h> |
Gilles Peskine | 31f88a2 | 2020-04-14 19:39:56 +0200 | [diff] [blame] | 23 | #endif |
| 24 | #endif |
| 25 | |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 26 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 27 | #include <mbedtls/config.h> |
| 28 | #else |
| 29 | #include MBEDTLS_CONFIG_FILE |
| 30 | #endif |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 31 | |
Hanno Becker | 1cfc5dd | 2018-11-12 13:18:45 +0000 | [diff] [blame] | 32 | #if defined(MBEDTLS_USE_PSA_CRYPTO) |
| 33 | #include "psa/crypto.h" |
| 34 | #endif /* MBEDTLS_USE_PSA_CRYPTO */ |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 35 | |
Chris Jones | 808b7c8 | 2021-01-13 12:33:36 +0000 | [diff] [blame] | 36 | #if defined(MBEDTLS_TEST_HOOKS) |
Chris Jones | ef180af | 2021-01-26 17:50:48 +0000 | [diff] [blame] | 37 | #include "mbedtls/error.h" |
Chris Jones | 808b7c8 | 2021-01-13 12:33:36 +0000 | [diff] [blame] | 38 | #endif |
| 39 | |
Gilles Peskine | 2ff02c3 | 2019-11-29 12:17:21 +0100 | [diff] [blame] | 40 | /* Test code may use deprecated identifiers only if the preprocessor symbol |
| 41 | * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set |
| 42 | * MBEDTLS_TEST_DEPRECATED explicitly if MBEDTLS_DEPRECATED_WARNING is |
| 43 | * enabled but the corresponding warnings are not treated as errors. |
| 44 | */ |
Gilles Peskine | 841b14b | 2019-11-26 17:37:37 +0100 | [diff] [blame] | 45 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING) |
| 46 | #define MBEDTLS_TEST_DEPRECATED |
| 47 | #endif |
| 48 | |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 49 | /*----------------------------------------------------------------------------*/ |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 50 | /* Common helper code */ |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 51 | |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 52 | $test_common_helpers |
Paul Bakker | de56ca1 | 2013-09-15 17:05:21 +0200 | [diff] [blame] | 53 | |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 54 | #line $line_no "suites/main_test.function" |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 55 | |
| 56 | |
| 57 | /*----------------------------------------------------------------------------*/ |
| 58 | /* Test Suite Code */ |
| 59 | |
| 60 | |
| 61 | #define TEST_SUITE_ACTIVE |
| 62 | |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 63 | $functions_code |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 64 | |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 65 | #line $line_no "suites/main_test.function" |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 66 | |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 67 | |
| 68 | /*----------------------------------------------------------------------------*/ |
| 69 | /* Test dispatch code */ |
| 70 | |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 71 | |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 72 | /** |
| 73 | * \brief Evaluates an expression/macro into its literal integer value. |
| 74 | * For optimizing space for embedded targets each expression/macro |
| 75 | * is identified by a unique identifier instead of string literals. |
| 76 | * Identifiers and evaluation code is generated by script: |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 77 | * $generator_script |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 78 | * |
| 79 | * \param exp_id Expression identifier. |
| 80 | * \param out_value Pointer to int to hold the integer. |
| 81 | * |
| 82 | * \return 0 if exp_id is found. 1 otherwise. |
| 83 | */ |
| 84 | int get_expression( int32_t exp_id, int32_t * out_value ) |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 85 | { |
Azim Khan | b1c2d0f | 2017-07-07 17:14:02 +0100 | [diff] [blame] | 86 | int ret = KEY_VALUE_MAPPING_FOUND; |
| 87 | |
| 88 | (void) exp_id; |
| 89 | (void) out_value; |
| 90 | |
| 91 | switch( exp_id ) |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 92 | { |
| 93 | $expression_code |
| 94 | #line $line_no "suites/main_test.function" |
Azim Khan | b1c2d0f | 2017-07-07 17:14:02 +0100 | [diff] [blame] | 95 | default: |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 96 | { |
Azim Khan | b1c2d0f | 2017-07-07 17:14:02 +0100 | [diff] [blame] | 97 | ret = KEY_VALUE_MAPPING_NOT_FOUND; |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 98 | } |
Azim Khan | b1c2d0f | 2017-07-07 17:14:02 +0100 | [diff] [blame] | 99 | break; |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 100 | } |
Azim Khan | b1c2d0f | 2017-07-07 17:14:02 +0100 | [diff] [blame] | 101 | return( ret ); |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 102 | } |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 103 | |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 104 | |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 105 | /** |
| 106 | * \brief Checks if the dependency i.e. the compile flag is set. |
| 107 | * For optimizing space for embedded targets each dependency |
| 108 | * is identified by a unique identifier instead of string literals. |
| 109 | * Identifiers and check code is generated by script: |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 110 | * $generator_script |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 111 | * |
Gilles Peskine | 5a7702e | 2021-02-23 13:40:19 +0100 | [diff] [blame] | 112 | * \param dep_id Dependency identifier. |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 113 | * |
| 114 | * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED |
| 115 | */ |
| 116 | int dep_check( int dep_id ) |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 117 | { |
Azim Khan | b1c2d0f | 2017-07-07 17:14:02 +0100 | [diff] [blame] | 118 | int ret = DEPENDENCY_NOT_SUPPORTED; |
| 119 | |
| 120 | (void) dep_id; |
| 121 | |
| 122 | switch( dep_id ) |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 123 | { |
| 124 | $dep_check_code |
| 125 | #line $line_no "suites/main_test.function" |
Azim Khan | b1c2d0f | 2017-07-07 17:14:02 +0100 | [diff] [blame] | 126 | default: |
| 127 | break; |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 128 | } |
Azim Khan | b1c2d0f | 2017-07-07 17:14:02 +0100 | [diff] [blame] | 129 | return( ret ); |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 130 | } |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 131 | |
SimonB | 8ca7bc4 | 2016-04-17 23:24:50 +0100 | [diff] [blame] | 132 | |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 133 | /** |
| 134 | * \brief Function pointer type for test function wrappers. |
| 135 | * |
Gilles Peskine | 5a7702e | 2021-02-23 13:40:19 +0100 | [diff] [blame] | 136 | * A test function wrapper decodes the parameters and passes them to the |
| 137 | * underlying test function. Both the wrapper and the underlying function |
| 138 | * return void. Test wrappers assume that they are passed a suitable |
| 139 | * parameter array and do not perform any error detection. |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 140 | * |
Gilles Peskine | 5a7702e | 2021-02-23 13:40:19 +0100 | [diff] [blame] | 141 | * \param param_array The array of parameters. Each element is a `void *` |
| 142 | * which the wrapper casts to the correct type and |
| 143 | * dereferences. Each wrapper function hard-codes the |
| 144 | * number and types of the parameters. |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 145 | */ |
Gilles Peskine | 5a7702e | 2021-02-23 13:40:19 +0100 | [diff] [blame] | 146 | typedef void (*TestWrapper_t)( void **param_array ); |
Simon Butcher | 65b1fa6 | 2016-05-23 23:18:26 +0100 | [diff] [blame] | 147 | |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * \brief Table of test function wrappers. Used by dispatch_test(). |
| 151 | * This table is populated by script: |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 152 | * $generator_script |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 153 | * |
| 154 | */ |
| 155 | TestWrapper_t test_funcs[] = |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 156 | { |
| 157 | $dispatch_code |
| 158 | #line $line_no "suites/main_test.function" |
| 159 | }; |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 160 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 161 | /** |
| 162 | * \brief Execute the test function. |
| 163 | * |
| 164 | * This is a wrapper function around the test function execution |
| 165 | * to allow the setjmp() call used to catch any calls to the |
| 166 | * parameter failure callback, to be used. Calls to setjmp() |
| 167 | * can invalidate the state of any local auto variables. |
| 168 | * |
Gilles Peskine | 5a7702e | 2021-02-23 13:40:19 +0100 | [diff] [blame] | 169 | * \param fp Function pointer to the test function. |
| 170 | * \param params Parameters to pass to the #TestWrapper_t wrapper function. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 171 | * |
| 172 | */ |
| 173 | void execute_function_ptr(TestWrapper_t fp, void **params) |
| 174 | { |
Gilles Peskine | 76175ba | 2020-11-24 18:39:12 +0100 | [diff] [blame] | 175 | #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) |
| 176 | mbedtls_test_enable_insecure_external_rng( ); |
| 177 | #endif |
| 178 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 179 | #if defined(MBEDTLS_CHECK_PARAMS) |
Ronald Cron | 4e66587 | 2020-06-30 17:44:27 +0200 | [diff] [blame] | 180 | mbedtls_test_param_failed_location_record_t location_record; |
| 181 | |
Ronald Cron | 579fd28 | 2020-07-01 15:17:05 +0200 | [diff] [blame] | 182 | if ( setjmp( mbedtls_test_param_failed_get_state_buf( ) ) == 0 ) |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 183 | { |
| 184 | fp( params ); |
| 185 | } |
| 186 | else |
| 187 | { |
| 188 | /* Unexpected parameter validation error */ |
Ronald Cron | 4e66587 | 2020-06-30 17:44:27 +0200 | [diff] [blame] | 189 | mbedtls_test_param_failed_get_location_record( &location_record ); |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 190 | mbedtls_test_fail( location_record.failure_condition, |
| 191 | location_record.line, |
| 192 | location_record.file ); |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 193 | } |
| 194 | |
Ronald Cron | 579fd28 | 2020-07-01 15:17:05 +0200 | [diff] [blame] | 195 | mbedtls_test_param_failed_reset_state( ); |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 196 | #else |
| 197 | fp( params ); |
| 198 | #endif |
Gilles Peskine | 2a4c598 | 2021-01-29 21:18:09 +0100 | [diff] [blame] | 199 | |
| 200 | #if defined(MBEDTLS_TEST_MUTEX_USAGE) |
| 201 | mbedtls_test_mutex_usage_check( ); |
| 202 | #endif /* MBEDTLS_TEST_MUTEX_USAGE */ |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 203 | } |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 204 | |
| 205 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 206 | * \brief Dispatches test functions based on function index. |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 207 | * |
Gilles Peskine | 5a7702e | 2021-02-23 13:40:19 +0100 | [diff] [blame] | 208 | * \param func_idx Test function index. |
| 209 | * \param params The array of parameters to pass to the test function. |
| 210 | * It will be decoded by the #TestWrapper_t wrapper function. |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 211 | * |
| 212 | * \return DISPATCH_TEST_SUCCESS if found |
| 213 | * DISPATCH_TEST_FN_NOT_FOUND if not found |
| 214 | * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled. |
| 215 | */ |
k-stachowiak | 03954f2 | 2019-09-16 10:23:10 +0200 | [diff] [blame] | 216 | int dispatch_test( size_t func_idx, void ** params ) |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 217 | { |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 218 | int ret = DISPATCH_TEST_SUCCESS; |
| 219 | TestWrapper_t fp = NULL; |
| 220 | |
Mohammad Azim Khan | d2d0112 | 2018-07-18 17:48:37 +0100 | [diff] [blame] | 221 | if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) ) |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 222 | { |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 223 | fp = test_funcs[func_idx]; |
| 224 | if ( fp ) |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 225 | execute_function_ptr(fp, params); |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 226 | else |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 227 | ret = DISPATCH_UNSUPPORTED_SUITE; |
| 228 | } |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 229 | else |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 230 | { |
| 231 | ret = DISPATCH_TEST_FN_NOT_FOUND; |
| 232 | } |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 233 | |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 234 | return( ret ); |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 235 | } |
Paul Bakker | 1934318 | 2013-08-16 13:31:10 +0200 | [diff] [blame] | 236 | |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 237 | |
Azim Khan | 13c6bfb | 2017-06-15 14:45:56 +0100 | [diff] [blame] | 238 | /** |
Gilles Peskine | 5a7702e | 2021-02-23 13:40:19 +0100 | [diff] [blame] | 239 | * \brief Checks if test function is supported in this build-time |
| 240 | * configuration. |
Azim Khan | 13c6bfb | 2017-06-15 14:45:56 +0100 | [diff] [blame] | 241 | * |
Gilles Peskine | 5a7702e | 2021-02-23 13:40:19 +0100 | [diff] [blame] | 242 | * \param func_idx Test function index. |
Azim Khan | 13c6bfb | 2017-06-15 14:45:56 +0100 | [diff] [blame] | 243 | * |
| 244 | * \return DISPATCH_TEST_SUCCESS if found |
| 245 | * DISPATCH_TEST_FN_NOT_FOUND if not found |
| 246 | * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled. |
| 247 | */ |
k-stachowiak | 03954f2 | 2019-09-16 10:23:10 +0200 | [diff] [blame] | 248 | int check_test( size_t func_idx ) |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 249 | { |
Azim Khan | 13c6bfb | 2017-06-15 14:45:56 +0100 | [diff] [blame] | 250 | int ret = DISPATCH_TEST_SUCCESS; |
| 251 | TestWrapper_t fp = NULL; |
| 252 | |
| 253 | if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) ) |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 254 | { |
Azim Khan | 13c6bfb | 2017-06-15 14:45:56 +0100 | [diff] [blame] | 255 | fp = test_funcs[func_idx]; |
| 256 | if ( fp == NULL ) |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 257 | ret = DISPATCH_UNSUPPORTED_SUITE; |
| 258 | } |
Azim Khan | 13c6bfb | 2017-06-15 14:45:56 +0100 | [diff] [blame] | 259 | else |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 260 | { |
| 261 | ret = DISPATCH_TEST_FN_NOT_FOUND; |
| 262 | } |
Azim Khan | 13c6bfb | 2017-06-15 14:45:56 +0100 | [diff] [blame] | 263 | |
| 264 | return( ret ); |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 265 | } |
Azim Khan | 13c6bfb | 2017-06-15 14:45:56 +0100 | [diff] [blame] | 266 | |
| 267 | |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 268 | $platform_code |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 269 | |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 270 | #line $line_no "suites/main_test.function" |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 271 | |
SimonB | 152ea18 | 2016-02-15 23:27:28 +0000 | [diff] [blame] | 272 | /*----------------------------------------------------------------------------*/ |
| 273 | /* Main Test code */ |
| 274 | |
SimonB | 1594210 | 2016-04-25 21:34:49 +0100 | [diff] [blame] | 275 | |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 276 | /** |
| 277 | * \brief Program main. Invokes platform specific execute_tests(). |
Gilles Peskine | 964faeb | 2017-09-29 18:00:25 +0200 | [diff] [blame] | 278 | * |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 279 | * \param argc Command line arguments count. |
| 280 | * \param argv Array of command line arguments. |
| 281 | * |
| 282 | * \return Exit code. |
Gilles Peskine | 964faeb | 2017-09-29 18:00:25 +0200 | [diff] [blame] | 283 | */ |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 284 | int main( int argc, const char *argv[] ) |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 285 | { |
Chris Jones | 759e30b | 2021-02-09 15:30:54 +0000 | [diff] [blame^] | 286 | #if defined(MBEDTLS_TEST_HOOKS) && defined (MBEDTLS_ERROR_C) |
Chris Jones | 808b7c8 | 2021-01-13 12:33:36 +0000 | [diff] [blame] | 287 | mbedtls_set_err_add_hook( &mbedtls_test_err_add_check ); |
Chris Jones | 96ae73b | 2021-01-08 17:04:59 +0000 | [diff] [blame] | 288 | #endif |
| 289 | |
Ronald Cron | e9c09f1 | 2020-06-08 16:44:58 +0200 | [diff] [blame] | 290 | int ret = mbedtls_test_platform_setup(); |
Andrzej Kurek | f13ca95 | 2018-04-18 04:14:31 -0400 | [diff] [blame] | 291 | if( ret != 0 ) |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 292 | { |
Andrzej Kurek | f13ca95 | 2018-04-18 04:14:31 -0400 | [diff] [blame] | 293 | mbedtls_fprintf( stderr, |
| 294 | "FATAL: Failed to initialize platform - error %d\n", |
| 295 | ret ); |
| 296 | return( -1 ); |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 297 | } |
Hanno Becker | 1cfc5dd | 2018-11-12 13:18:45 +0000 | [diff] [blame] | 298 | |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 299 | ret = execute_tests( argc, argv ); |
Ronald Cron | e9c09f1 | 2020-06-08 16:44:58 +0200 | [diff] [blame] | 300 | mbedtls_test_platform_teardown(); |
Azim Khan | 191e904 | 2017-06-09 12:39:00 +0100 | [diff] [blame] | 301 | return( ret ); |
Mohammad Azim Khan | 5cb7017 | 2018-07-19 11:32:30 +0100 | [diff] [blame] | 302 | } |