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 * __MBEDTLS_TEST_TEMPLATE__GENERATOR_SCRIPT 7 * 8 * Test file : __MBEDTLS_TEST_TEMPLATE__TEST_FILE 9 * 10 * The following files were used to create this file. 11 * 12 * Main code file : __MBEDTLS_TEST_TEMPLATE__TEST_MAIN_FILE 13 * Platform code file : __MBEDTLS_TEST_TEMPLATE__TEST_PLATFORM_FILE 14 * Helper file : __MBEDTLS_TEST_TEMPLATE__TEST_COMMON_HELPER_FILE 15 * Test suite file : __MBEDTLS_TEST_TEMPLATE__TEST_CASE_FILE 16 * Test suite data : __MBEDTLS_TEST_TEMPLATE__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#if !defined(MBEDTLS_CONFIG_FILE) 27#include <mbedtls/config.h> 28#else 29#include MBEDTLS_CONFIG_FILE 30#endif 31 32#if defined(MBEDTLS_USE_PSA_CRYPTO) 33#include "psa/crypto.h" 34#endif /* MBEDTLS_USE_PSA_CRYPTO */ 35 36#if defined(MBEDTLS_TEST_HOOKS) 37#include "mbedtls/error.h" 38#endif 39 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 */ 45#if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING) 46#define MBEDTLS_TEST_DEPRECATED 47#endif 48 49/*----------------------------------------------------------------------------*/ 50/* Common helper code */ 51 52__MBEDTLS_TEST_TEMPLATE__TEST_COMMON_HELPERS 53 54#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function" 55 56 57/*----------------------------------------------------------------------------*/ 58/* Test Suite Code */ 59 60 61#define TEST_SUITE_ACTIVE 62 63__MBEDTLS_TEST_TEMPLATE__FUNCTIONS_CODE 64 65#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function" 66 67 68/*----------------------------------------------------------------------------*/ 69/* Test dispatch code */ 70 71 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: 77 * __MBEDTLS_TEST_TEMPLATE__GENERATOR_SCRIPT 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 */ 84int get_expression(int32_t exp_id, intmax_t *out_value) 85{ 86 int ret = KEY_VALUE_MAPPING_FOUND; 87 88 (void) exp_id; 89 (void) out_value; 90 91 switch (exp_id) { 92 __MBEDTLS_TEST_TEMPLATE__EXPRESSION_CODE 93#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function" 94 default: 95 { 96 ret = KEY_VALUE_MAPPING_NOT_FOUND; 97 } 98 break; 99 } 100 return ret; 101} 102 103 104/** 105 * \brief Checks if the dependency i.e. the compile flag is set. 106 * For optimizing space for embedded targets each dependency 107 * is identified by a unique identifier instead of string literals. 108 * Identifiers and check code is generated by script: 109 * __MBEDTLS_TEST_TEMPLATE__GENERATOR_SCRIPT 110 * 111 * \param dep_id Dependency identifier. 112 * 113 * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED 114 */ 115int dep_check(int dep_id) 116{ 117 int ret = DEPENDENCY_NOT_SUPPORTED; 118 119 (void) dep_id; 120 121 switch (dep_id) { 122 __MBEDTLS_TEST_TEMPLATE__DEP_CHECK_CODE 123#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function" 124 default: 125 break; 126 } 127 return ret; 128} 129 130 131/** 132 * \brief Function pointer type for test function wrappers. 133 * 134 * A test function wrapper decodes the parameters and passes them to the 135 * underlying test function. Both the wrapper and the underlying function 136 * return void. Test wrappers assume that they are passed a suitable 137 * parameter array and do not perform any error detection. 138 * 139 * \param param_array The array of parameters. Each element is a `void *` 140 * which the wrapper casts to the correct type and 141 * dereferences. Each wrapper function hard-codes the 142 * number and types of the parameters. 143 */ 144typedef void (*TestWrapper_t)(void **param_array); 145 146 147/** 148 * \brief Table of test function wrappers. Used by dispatch_test(). 149 * This table is populated by script: 150 * __MBEDTLS_TEST_TEMPLATE__GENERATOR_SCRIPT 151 * 152 */ 153TestWrapper_t test_funcs[] = 154{ 155 __MBEDTLS_TEST_TEMPLATE__DISPATCH_CODE 156#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function" 157}; 158 159/** 160 * \brief Execute the test function. 161 * 162 * This is a wrapper function around the test function execution 163 * to allow the setjmp() call used to catch any calls to the 164 * parameter failure callback, to be used. Calls to setjmp() 165 * can invalidate the state of any local auto variables. 166 * 167 * \param fp Function pointer to the test function. 168 * \param params Parameters to pass to the #TestWrapper_t wrapper function. 169 * 170 */ 171void execute_function_ptr(TestWrapper_t fp, void **params) 172{ 173#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) 174 mbedtls_test_enable_insecure_external_rng(); 175#endif 176 177#if defined(MBEDTLS_CHECK_PARAMS) 178 mbedtls_test_param_failed_location_record_t location_record; 179 180 if (setjmp(mbedtls_test_param_failed_get_state_buf()) == 0) { 181 fp(params); 182 } else { 183 /* Unexpected parameter validation error */ 184 mbedtls_test_param_failed_get_location_record(&location_record); 185 mbedtls_test_fail(location_record.failure_condition, 186 location_record.line, 187 location_record.file); 188 } 189 190 mbedtls_test_param_failed_reset_state(); 191#else 192 fp(params); 193#endif 194 195#if defined(MBEDTLS_TEST_MUTEX_USAGE) 196 mbedtls_test_mutex_usage_check(); 197#endif /* MBEDTLS_TEST_MUTEX_USAGE */ 198} 199 200/** 201 * \brief Dispatches test functions based on function index. 202 * 203 * \param func_idx Test function index. 204 * \param params The array of parameters to pass to the test function. 205 * It will be decoded by the #TestWrapper_t wrapper function. 206 * 207 * \return DISPATCH_TEST_SUCCESS if found 208 * DISPATCH_TEST_FN_NOT_FOUND if not found 209 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled. 210 */ 211int dispatch_test(size_t func_idx, void **params) 212{ 213 int ret = DISPATCH_TEST_SUCCESS; 214 TestWrapper_t fp = NULL; 215 216 if (func_idx < (int) (sizeof(test_funcs) / sizeof(TestWrapper_t))) { 217 fp = test_funcs[func_idx]; 218 if (fp) { 219 execute_function_ptr(fp, params); 220 } else { 221 ret = DISPATCH_UNSUPPORTED_SUITE; 222 } 223 } else { 224 ret = DISPATCH_TEST_FN_NOT_FOUND; 225 } 226 227 return ret; 228} 229 230 231/** 232 * \brief Checks if test function is supported in this build-time 233 * configuration. 234 * 235 * \param func_idx Test function index. 236 * 237 * \return DISPATCH_TEST_SUCCESS if found 238 * DISPATCH_TEST_FN_NOT_FOUND if not found 239 * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled. 240 */ 241int check_test(size_t func_idx) 242{ 243 int ret = DISPATCH_TEST_SUCCESS; 244 TestWrapper_t fp = NULL; 245 246 if (func_idx < (int) (sizeof(test_funcs)/sizeof(TestWrapper_t))) { 247 fp = test_funcs[func_idx]; 248 if (fp == NULL) { 249 ret = DISPATCH_UNSUPPORTED_SUITE; 250 } 251 } else { 252 ret = DISPATCH_TEST_FN_NOT_FOUND; 253 } 254 255 return ret; 256} 257 258 259__MBEDTLS_TEST_TEMPLATE__PLATFORM_CODE 260 261#line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function" 262 263/*----------------------------------------------------------------------------*/ 264/* Main Test code */ 265 266 267/** 268 * \brief Program main. Invokes platform specific execute_tests(). 269 * 270 * \param argc Command line arguments count. 271 * \param argv Array of command line arguments. 272 * 273 * \return Exit code. 274 */ 275int main(int argc, const char *argv[]) 276{ 277#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_ERROR_C) 278 mbedtls_test_hook_error_add = &mbedtls_test_err_add_check; 279#endif 280 281 int ret = mbedtls_test_platform_setup(); 282 if (ret != 0) { 283 mbedtls_fprintf(stderr, 284 "FATAL: Failed to initialize platform - error %d\n", 285 ret); 286 return -1; 287 } 288 289 ret = execute_tests(argc, argv); 290 mbedtls_test_platform_teardown(); 291 return ret; 292} 293