main_test.function 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
  20. #if !defined(_POSIX_C_SOURCE)
  21. #define _POSIX_C_SOURCE 200112L // for fileno() from <stdio.h>
  22. #endif
  23. #endif
  24. #if !defined(MBEDTLS_CONFIG_FILE)
  25. #include <mbedtls/config.h>
  26. #else
  27. #include MBEDTLS_CONFIG_FILE
  28. #endif
  29. #if defined(MBEDTLS_USE_PSA_CRYPTO)
  30. #include "psa/crypto.h"
  31. #endif /* MBEDTLS_USE_PSA_CRYPTO */
  32. #if defined(MBEDTLS_TEST_HOOKS)
  33. #include "mbedtls/error.h"
  34. #endif
  35. /* Test code may use deprecated identifiers only if the preprocessor symbol
  36. * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set
  37. * MBEDTLS_TEST_DEPRECATED explicitly if MBEDTLS_DEPRECATED_WARNING is
  38. * enabled but the corresponding warnings are not treated as errors.
  39. */
  40. #if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING)
  41. #define MBEDTLS_TEST_DEPRECATED
  42. #endif
  43. /*----------------------------------------------------------------------------*/
  44. /* Common helper code */
  45. $test_common_helpers
  46. #line $line_no "suites/main_test.function"
  47. /*----------------------------------------------------------------------------*/
  48. /* Test Suite Code */
  49. #define TEST_SUITE_ACTIVE
  50. $functions_code
  51. #line $line_no "suites/main_test.function"
  52. /*----------------------------------------------------------------------------*/
  53. /* Test dispatch code */
  54. /**
  55. * \brief Evaluates an expression/macro into its literal integer value.
  56. * For optimizing space for embedded targets each expression/macro
  57. * is identified by a unique identifier instead of string literals.
  58. * Identifiers and evaluation code is generated by script:
  59. * $generator_script
  60. *
  61. * \param exp_id Expression identifier.
  62. * \param out_value Pointer to int to hold the integer.
  63. *
  64. * \return 0 if exp_id is found. 1 otherwise.
  65. */
  66. int get_expression( int32_t exp_id, int32_t * out_value )
  67. {
  68. int ret = KEY_VALUE_MAPPING_FOUND;
  69. (void) exp_id;
  70. (void) out_value;
  71. switch( exp_id )
  72. {
  73. $expression_code
  74. #line $line_no "suites/main_test.function"
  75. default:
  76. {
  77. ret = KEY_VALUE_MAPPING_NOT_FOUND;
  78. }
  79. break;
  80. }
  81. return( ret );
  82. }
  83. /**
  84. * \brief Checks if the dependency i.e. the compile flag is set.
  85. * For optimizing space for embedded targets each dependency
  86. * is identified by a unique identifier instead of string literals.
  87. * Identifiers and check code is generated by script:
  88. * $generator_script
  89. *
  90. * \param dep_id Dependency identifier.
  91. *
  92. * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
  93. */
  94. int dep_check( int dep_id )
  95. {
  96. int ret = DEPENDENCY_NOT_SUPPORTED;
  97. (void) dep_id;
  98. switch( dep_id )
  99. {
  100. $dep_check_code
  101. #line $line_no "suites/main_test.function"
  102. default:
  103. break;
  104. }
  105. return( ret );
  106. }
  107. /**
  108. * \brief Function pointer type for test function wrappers.
  109. *
  110. * A test function wrapper decodes the parameters and passes them to the
  111. * underlying test function. Both the wrapper and the underlying function
  112. * return void. Test wrappers assume that they are passed a suitable
  113. * parameter array and do not perform any error detection.
  114. *
  115. * \param param_array The array of parameters. Each element is a `void *`
  116. * which the wrapper casts to the correct type and
  117. * dereferences. Each wrapper function hard-codes the
  118. * number and types of the parameters.
  119. */
  120. typedef void (*TestWrapper_t)( void **param_array );
  121. /**
  122. * \brief Table of test function wrappers. Used by dispatch_test().
  123. * This table is populated by script:
  124. * $generator_script
  125. *
  126. */
  127. TestWrapper_t test_funcs[] =
  128. {
  129. $dispatch_code
  130. #line $line_no "suites/main_test.function"
  131. };
  132. /**
  133. * \brief Execute the test function.
  134. *
  135. * This is a wrapper function around the test function execution
  136. * to allow the setjmp() call used to catch any calls to the
  137. * parameter failure callback, to be used. Calls to setjmp()
  138. * can invalidate the state of any local auto variables.
  139. *
  140. * \param fp Function pointer to the test function.
  141. * \param params Parameters to pass to the #TestWrapper_t wrapper function.
  142. *
  143. */
  144. void execute_function_ptr(TestWrapper_t fp, void **params)
  145. {
  146. #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
  147. mbedtls_test_enable_insecure_external_rng( );
  148. #endif
  149. #if defined(MBEDTLS_CHECK_PARAMS)
  150. mbedtls_test_param_failed_location_record_t location_record;
  151. if ( setjmp( mbedtls_test_param_failed_get_state_buf( ) ) == 0 )
  152. {
  153. fp( params );
  154. }
  155. else
  156. {
  157. /* Unexpected parameter validation error */
  158. mbedtls_test_param_failed_get_location_record( &location_record );
  159. mbedtls_test_fail( location_record.failure_condition,
  160. location_record.line,
  161. location_record.file );
  162. }
  163. mbedtls_test_param_failed_reset_state( );
  164. #else
  165. fp( params );
  166. #endif
  167. #if defined(MBEDTLS_TEST_MUTEX_USAGE)
  168. mbedtls_test_mutex_usage_check( );
  169. #endif /* MBEDTLS_TEST_MUTEX_USAGE */
  170. }
  171. /**
  172. * \brief Dispatches test functions based on function index.
  173. *
  174. * \param func_idx Test function index.
  175. * \param params The array of parameters to pass to the test function.
  176. * It will be decoded by the #TestWrapper_t wrapper function.
  177. *
  178. * \return DISPATCH_TEST_SUCCESS if found
  179. * DISPATCH_TEST_FN_NOT_FOUND if not found
  180. * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
  181. */
  182. int dispatch_test( size_t func_idx, void ** params )
  183. {
  184. int ret = DISPATCH_TEST_SUCCESS;
  185. TestWrapper_t fp = NULL;
  186. if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
  187. {
  188. fp = test_funcs[func_idx];
  189. if ( fp )
  190. execute_function_ptr(fp, params);
  191. else
  192. ret = DISPATCH_UNSUPPORTED_SUITE;
  193. }
  194. else
  195. {
  196. ret = DISPATCH_TEST_FN_NOT_FOUND;
  197. }
  198. return( ret );
  199. }
  200. /**
  201. * \brief Checks if test function is supported in this build-time
  202. * configuration.
  203. *
  204. * \param func_idx Test function index.
  205. *
  206. * \return DISPATCH_TEST_SUCCESS if found
  207. * DISPATCH_TEST_FN_NOT_FOUND if not found
  208. * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
  209. */
  210. int check_test( size_t func_idx )
  211. {
  212. int ret = DISPATCH_TEST_SUCCESS;
  213. TestWrapper_t fp = NULL;
  214. if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
  215. {
  216. fp = test_funcs[func_idx];
  217. if ( fp == NULL )
  218. ret = DISPATCH_UNSUPPORTED_SUITE;
  219. }
  220. else
  221. {
  222. ret = DISPATCH_TEST_FN_NOT_FOUND;
  223. }
  224. return( ret );
  225. }
  226. $platform_code
  227. #line $line_no "suites/main_test.function"
  228. /*----------------------------------------------------------------------------*/
  229. /* Main Test code */
  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. */
  238. int main( int argc, const char *argv[] )
  239. {
  240. #if defined(MBEDTLS_TEST_HOOKS) && defined (MBEDTLS_ERROR_C)
  241. mbedtls_test_hook_error_add = &mbedtls_test_err_add_check;
  242. #endif
  243. int ret = mbedtls_test_platform_setup();
  244. if( ret != 0 )
  245. {
  246. mbedtls_fprintf( stderr,
  247. "FATAL: Failed to initialize platform - error %d\n",
  248. ret );
  249. return( -1 );
  250. }
  251. ret = execute_tests( argc, argv );
  252. mbedtls_test_platform_teardown();
  253. return( ret );
  254. }