1#line 2 "suites/main_test.function" 2/* 3 * *** THIS FILE HAS BEEN MACHINE GENERATED *** 4 * 5 * This file has been machine generated using the script: 6 * $generator_script 7 * 8 * Test file : $test_file 9 * 10 * The following files were used to create this file. 11 * 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 17 * 18 */ 19 20#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) 21#if !defined(_POSIX_C_SOURCE) 22#define _POSIX_C_SOURCE 200112L // for fileno() from <stdio.h> 23#endif 24#endif 25 26#include "mbedtls/build_info.h" 27 28/* 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 */ 33#if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING) 34#define MBEDTLS_TEST_DEPRECATED 35#endif 36 37/*----------------------------------------------------------------------------*/ 38/* Common helper code */ 39 40$test_common_helpers 41 42#line $line_no "suites/main_test.function" 43 44 45/*----------------------------------------------------------------------------*/ 46/* Test Suite Code */ 47 48 49#define TEST_SUITE_ACTIVE 50 51$functions_code 52 53#line $line_no "suites/main_test.function" 54 55 56/*----------------------------------------------------------------------------*/ 57/* Test dispatch code */ 58 59 60/** 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: 65 * $generator_script 66 * 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 ) 73{ 74 int ret = KEY_VALUE_MAPPING_FOUND; 75 76 (void) exp_id; 77 (void) out_value; 78 79 switch( exp_id ) 80 { 81$expression_code 82#line $line_no "suites/main_test.function" 83 default: 84 { 85 ret = KEY_VALUE_MAPPING_NOT_FOUND; 86 } 87 break; 88 } 89 return( ret ); 90} 91 92 93/** 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: 98 * $generator_script 99 * 100 * \param dep_id Dependency identifier. 101 * 102 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED 103 */ 104int dep_check( int dep_id ) 105{ 106 int ret = DEPENDENCY_NOT_SUPPORTED; 107 108 (void) dep_id; 109 110 switch( dep_id ) 111 { 112$dep_check_code 113#line $line_no "suites/main_test.function" 114 default: 115 break; 116 } 117 return( ret ); 118} 119 120 121/** 122 * \brief Function pointer type for test function wrappers. 123 * 124 * 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. 128 * 129 * \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. 133 */ 134typedef void (*TestWrapper_t)( void **param_array ); 135 136 137/** 138 * \brief Table of test function wrappers. Used by dispatch_test(). 139 * This table is populated by script: 140 * $generator_script 141 * 142 */ 143TestWrapper_t test_funcs[] = 144{ 145$dispatch_code 146#line $line_no "suites/main_test.function" 147}; 148 149/** 150 * \brief Dispatches test functions based on function index. 151 * 152 * \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. 155 * 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 */ 160int dispatch_test( size_t func_idx, void ** params ) 161{ 162 int ret = DISPATCH_TEST_SUCCESS; 163 TestWrapper_t fp = NULL; 164 165 if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) ) 166 { 167 fp = test_funcs[func_idx]; 168 if ( fp ) 169 { 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 } 180 else 181 ret = DISPATCH_UNSUPPORTED_SUITE; 182 } 183 else 184 { 185 ret = DISPATCH_TEST_FN_NOT_FOUND; 186 } 187 188 return( ret ); 189} 190 191 192/** 193 * \brief Checks if test function is supported in this build-time 194 * configuration. 195 * 196 * \param func_idx Test function index. 197 * 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 */ 202int check_test( size_t func_idx ) 203{ 204 int ret = DISPATCH_TEST_SUCCESS; 205 TestWrapper_t fp = NULL; 206 207 if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) ) 208 { 209 fp = test_funcs[func_idx]; 210 if ( fp == NULL ) 211 ret = DISPATCH_UNSUPPORTED_SUITE; 212 } 213 else 214 { 215 ret = DISPATCH_TEST_FN_NOT_FOUND; 216 } 217 218 return( ret ); 219} 220 221 222$platform_code 223 224#line $line_no "suites/main_test.function" 225 226/*----------------------------------------------------------------------------*/ 227/* Main Test code */ 228 229 230/** 231 * \brief Program main. Invokes platform specific execute_tests(). 232 * 233 * \param argc Command line arguments count. 234 * \param argv Array of command line arguments. 235 * 236 * \return Exit code. 237 */ 238int main( int argc, const char *argv[] ) 239{ 240#if defined(MBEDTLS_TEST_HOOKS) 241 extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const char * file ); 242 mbedtls_test_hook_test_fail = &mbedtls_test_fail; 243#if defined(MBEDTLS_ERROR_C) 244 mbedtls_test_hook_error_add = &mbedtls_test_err_add_check; 245#endif 246#endif 247 248 int ret = mbedtls_test_platform_setup(); 249 if( ret != 0 ) 250 { 251 mbedtls_fprintf( stderr, 252 "FATAL: Failed to initialize platform - error %d\n", 253 ret ); 254 return( -1 ); 255 } 256 257 ret = execute_tests( argc, argv ); 258 mbedtls_test_platform_teardown(); 259 return( ret ); 260} 261