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