main_test.function 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 1 // for fileno() from <stdio.h>
  22. #endif
  23. #endif
  24. /*
  25. * for arc4random_buf() from <stdlib.h>
  26. */
  27. #if defined(__NetBSD__)
  28. #define _NETBSD_SOURCE 1
  29. #elif defined(__OpenBSD__)
  30. #define _BSD_SOURCE 1
  31. #endif
  32. #if !defined(MBEDTLS_CONFIG_FILE)
  33. #include <mbedtls/config.h>
  34. #else
  35. #include MBEDTLS_CONFIG_FILE
  36. #endif
  37. /*----------------------------------------------------------------------------*/
  38. /* Common helper code */
  39. $test_common_helpers
  40. #line $line_no "suites/main_test.function"
  41. /*----------------------------------------------------------------------------*/
  42. /* Test Suite Code */
  43. #define TEST_SUITE_ACTIVE
  44. $functions_code
  45. #line $line_no "suites/main_test.function"
  46. /*----------------------------------------------------------------------------*/
  47. /* Test dispatch code */
  48. /**
  49. * \brief Evaluates an expression/macro into its literal integer value.
  50. * For optimizing space for embedded targets each expression/macro
  51. * is identified by a unique identifier instead of string literals.
  52. * Identifiers and evaluation code is generated by script:
  53. * $generator_script
  54. *
  55. * \param exp_id Expression identifier.
  56. * \param out_value Pointer to int to hold the integer.
  57. *
  58. * \return 0 if exp_id is found. 1 otherwise.
  59. */
  60. int get_expression( int32_t exp_id, int32_t * out_value )
  61. {
  62. int ret = KEY_VALUE_MAPPING_FOUND;
  63. (void) exp_id;
  64. (void) out_value;
  65. switch( exp_id )
  66. {
  67. $expression_code
  68. #line $line_no "suites/main_test.function"
  69. default:
  70. {
  71. ret = KEY_VALUE_MAPPING_NOT_FOUND;
  72. }
  73. break;
  74. }
  75. return( ret );
  76. }
  77. /**
  78. * \brief Checks if the dependency i.e. the compile flag is set.
  79. * For optimizing space for embedded targets each dependency
  80. * is identified by a unique identifier instead of string literals.
  81. * Identifiers and check code is generated by script:
  82. * $generator_script
  83. *
  84. * \param exp_id Dependency identifier.
  85. *
  86. * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
  87. */
  88. int dep_check( int dep_id )
  89. {
  90. int ret = DEPENDENCY_NOT_SUPPORTED;
  91. (void) dep_id;
  92. switch( dep_id )
  93. {
  94. $dep_check_code
  95. #line $line_no "suites/main_test.function"
  96. default:
  97. break;
  98. }
  99. return( ret );
  100. }
  101. /**
  102. * \brief Function pointer type for test function wrappers.
  103. *
  104. *
  105. * \param void ** Pointer to void pointers. Represents an array of test
  106. * function parameters.
  107. *
  108. * \return void
  109. */
  110. typedef void (*TestWrapper_t)( void ** );
  111. /**
  112. * \brief Table of test function wrappers. Used by dispatch_test().
  113. * This table is populated by script:
  114. * $generator_script
  115. *
  116. */
  117. TestWrapper_t test_funcs[] =
  118. {
  119. $dispatch_code
  120. #line $line_no "suites/main_test.function"
  121. };
  122. /**
  123. * \brief Execute the test function.
  124. *
  125. * This is a wrapper function around the test function execution
  126. * to allow the setjmp() call used to catch any calls to the
  127. * parameter failure callback, to be used. Calls to setjmp()
  128. * can invalidate the state of any local auto variables.
  129. *
  130. * \param fp Function pointer to the test function
  131. * \param params Parameters to pass
  132. *
  133. */
  134. void execute_function_ptr(TestWrapper_t fp, void **params)
  135. {
  136. #if defined(MBEDTLS_CHECK_PARAMS)
  137. if ( setjmp( param_fail_jmp ) == 0 )
  138. {
  139. fp( params );
  140. }
  141. else
  142. {
  143. /* Unexpected parameter validation error */
  144. test_info.result = TEST_RESULT_FAILED;
  145. }
  146. memset( param_fail_jmp, 0, sizeof(jmp_buf) );
  147. #else
  148. fp( params );
  149. #endif
  150. #if defined(MBEDTLS_TEST_MUTEX_USAGE)
  151. mbedtls_test_mutex_usage_check( );
  152. #endif /* MBEDTLS_TEST_MUTEX_USAGE */
  153. }
  154. /**
  155. * \brief Dispatches test functions based on function index.
  156. *
  157. * \param exp_id Test function index.
  158. *
  159. * \return DISPATCH_TEST_SUCCESS if found
  160. * DISPATCH_TEST_FN_NOT_FOUND if not found
  161. * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
  162. */
  163. int dispatch_test( size_t func_idx, void ** params )
  164. {
  165. int ret = DISPATCH_TEST_SUCCESS;
  166. TestWrapper_t fp = NULL;
  167. if ( func_idx < (int)( sizeof( test_funcs ) / sizeof( TestWrapper_t ) ) )
  168. {
  169. fp = test_funcs[func_idx];
  170. if ( fp )
  171. execute_function_ptr(fp, params);
  172. else
  173. ret = DISPATCH_UNSUPPORTED_SUITE;
  174. }
  175. else
  176. {
  177. ret = DISPATCH_TEST_FN_NOT_FOUND;
  178. }
  179. return( ret );
  180. }
  181. /**
  182. * \brief Checks if test function is supported
  183. *
  184. * \param exp_id Test function index.
  185. *
  186. * \return DISPATCH_TEST_SUCCESS if found
  187. * DISPATCH_TEST_FN_NOT_FOUND if not found
  188. * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
  189. */
  190. int check_test( size_t func_idx )
  191. {
  192. int ret = DISPATCH_TEST_SUCCESS;
  193. TestWrapper_t fp = NULL;
  194. if ( func_idx < (int)( sizeof(test_funcs)/sizeof( TestWrapper_t ) ) )
  195. {
  196. fp = test_funcs[func_idx];
  197. if ( fp == NULL )
  198. ret = DISPATCH_UNSUPPORTED_SUITE;
  199. }
  200. else
  201. {
  202. ret = DISPATCH_TEST_FN_NOT_FOUND;
  203. }
  204. return( ret );
  205. }
  206. $platform_code
  207. #line $line_no "suites/main_test.function"
  208. /*----------------------------------------------------------------------------*/
  209. /* Main Test code */
  210. /**
  211. * \brief Program main. Invokes platform specific execute_tests().
  212. *
  213. * \param argc Command line arguments count.
  214. * \param argv Array of command line arguments.
  215. *
  216. * \return Exit code.
  217. */
  218. int main( int argc, const char *argv[] )
  219. {
  220. int ret = platform_setup();
  221. if( ret != 0 )
  222. {
  223. mbedtls_fprintf( stderr,
  224. "FATAL: Failed to initialize platform - error %d\n",
  225. ret );
  226. return( -1 );
  227. }
  228. ret = execute_tests( argc, argv );
  229. platform_teardown();
  230. return( ret );
  231. }