main_test.function 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. #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. #include "mbedtls/build_info.h"
  25. /* Test code may use deprecated identifiers only if the preprocessor symbol
  26. * MBEDTLS_TEST_DEPRECATED is defined. When building tests, set
  27. * MBEDTLS_TEST_DEPRECATED explicitly if MBEDTLS_DEPRECATED_WARNING is
  28. * enabled but the corresponding warnings are not treated as errors.
  29. */
  30. #if !defined(MBEDTLS_DEPRECATED_REMOVED) && !defined(MBEDTLS_DEPRECATED_WARNING)
  31. #define MBEDTLS_TEST_DEPRECATED
  32. #endif
  33. /*----------------------------------------------------------------------------*/
  34. /* Common helper code */
  35. __MBEDTLS_TEST_TEMPLATE__TEST_COMMON_HELPERS
  36. #line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
  37. /*----------------------------------------------------------------------------*/
  38. /* Test Suite Code */
  39. #define TEST_SUITE_ACTIVE
  40. __MBEDTLS_TEST_TEMPLATE__FUNCTIONS_CODE
  41. #line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
  42. /*----------------------------------------------------------------------------*/
  43. /* Test dispatch code */
  44. /**
  45. * \brief Evaluates an expression/macro into its literal integer value.
  46. * For optimizing space for embedded targets each expression/macro
  47. * is identified by a unique identifier instead of string literals.
  48. * Identifiers and evaluation code is generated by script:
  49. * __MBEDTLS_TEST_TEMPLATE__GENERATOR_SCRIPT
  50. *
  51. * \param exp_id Expression identifier.
  52. * \param out_value Pointer to int to hold the integer.
  53. *
  54. * \return 0 if exp_id is found. 1 otherwise.
  55. */
  56. int get_expression(int32_t exp_id, int32_t *out_value)
  57. {
  58. int ret = KEY_VALUE_MAPPING_FOUND;
  59. (void) exp_id;
  60. (void) out_value;
  61. switch (exp_id) {
  62. __MBEDTLS_TEST_TEMPLATE__EXPRESSION_CODE
  63. #line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
  64. default:
  65. {
  66. ret = KEY_VALUE_MAPPING_NOT_FOUND;
  67. }
  68. break;
  69. }
  70. return ret;
  71. }
  72. /**
  73. * \brief Checks if the dependency i.e. the compile flag is set.
  74. * For optimizing space for embedded targets each dependency
  75. * is identified by a unique identifier instead of string literals.
  76. * Identifiers and check code is generated by script:
  77. * __MBEDTLS_TEST_TEMPLATE__GENERATOR_SCRIPT
  78. *
  79. * \param dep_id Dependency identifier.
  80. *
  81. * \return DEPENDENCY_SUPPORTED if set else DEPENDENCY_NOT_SUPPORTED
  82. */
  83. int dep_check(int dep_id)
  84. {
  85. int ret = DEPENDENCY_NOT_SUPPORTED;
  86. (void) dep_id;
  87. switch (dep_id) {
  88. __MBEDTLS_TEST_TEMPLATE__DEP_CHECK_CODE
  89. #line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
  90. default:
  91. break;
  92. }
  93. return ret;
  94. }
  95. /**
  96. * \brief Function pointer type for test function wrappers.
  97. *
  98. * A test function wrapper decodes the parameters and passes them to the
  99. * underlying test function. Both the wrapper and the underlying function
  100. * return void. Test wrappers assume that they are passed a suitable
  101. * parameter array and do not perform any error detection.
  102. *
  103. * \param param_array The array of parameters. Each element is a `void *`
  104. * which the wrapper casts to the correct type and
  105. * dereferences. Each wrapper function hard-codes the
  106. * number and types of the parameters.
  107. */
  108. typedef void (*TestWrapper_t)(void **param_array);
  109. /**
  110. * \brief Table of test function wrappers. Used by dispatch_test().
  111. * This table is populated by script:
  112. * __MBEDTLS_TEST_TEMPLATE__GENERATOR_SCRIPT
  113. *
  114. */
  115. TestWrapper_t test_funcs[] =
  116. {
  117. __MBEDTLS_TEST_TEMPLATE__DISPATCH_CODE
  118. #line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
  119. };
  120. /**
  121. * \brief Dispatches test functions based on function index.
  122. *
  123. * \param func_idx Test function index.
  124. * \param params The array of parameters to pass to the test function.
  125. * It will be decoded by the #TestWrapper_t wrapper function.
  126. *
  127. * \return DISPATCH_TEST_SUCCESS if found
  128. * DISPATCH_TEST_FN_NOT_FOUND if not found
  129. * DISPATCH_UNSUPPORTED_SUITE if not compile time enabled.
  130. */
  131. int dispatch_test(size_t func_idx, void **params)
  132. {
  133. int ret = DISPATCH_TEST_SUCCESS;
  134. TestWrapper_t fp = NULL;
  135. if (func_idx < (int) (sizeof(test_funcs) / sizeof(TestWrapper_t))) {
  136. fp = test_funcs[func_idx];
  137. if (fp) {
  138. #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
  139. mbedtls_test_enable_insecure_external_rng();
  140. #endif
  141. fp(params);
  142. #if defined(MBEDTLS_TEST_MUTEX_USAGE)
  143. mbedtls_test_mutex_usage_check();
  144. #endif /* MBEDTLS_TEST_MUTEX_USAGE */
  145. } else {
  146. ret = DISPATCH_UNSUPPORTED_SUITE;
  147. }
  148. } else {
  149. ret = DISPATCH_TEST_FN_NOT_FOUND;
  150. }
  151. return ret;
  152. }
  153. /**
  154. * \brief Checks if test function is supported in this build-time
  155. * configuration.
  156. *
  157. * \param func_idx 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 check_test(size_t func_idx)
  164. {
  165. int ret = DISPATCH_TEST_SUCCESS;
  166. TestWrapper_t fp = NULL;
  167. if (func_idx < (int) (sizeof(test_funcs)/sizeof(TestWrapper_t))) {
  168. fp = test_funcs[func_idx];
  169. if (fp == NULL) {
  170. ret = DISPATCH_UNSUPPORTED_SUITE;
  171. }
  172. } else {
  173. ret = DISPATCH_TEST_FN_NOT_FOUND;
  174. }
  175. return ret;
  176. }
  177. __MBEDTLS_TEST_TEMPLATE__PLATFORM_CODE
  178. #line __MBEDTLS_TEST_TEMPLATE__LINE_NO "suites/main_test.function"
  179. /*----------------------------------------------------------------------------*/
  180. /* Main Test code */
  181. /**
  182. * \brief Program main. Invokes platform specific execute_tests().
  183. *
  184. * \param argc Command line arguments count.
  185. * \param argv Array of command line arguments.
  186. *
  187. * \return Exit code.
  188. */
  189. int main(int argc, const char *argv[])
  190. {
  191. #if defined(MBEDTLS_TEST_HOOKS)
  192. extern void (*mbedtls_test_hook_test_fail)(const char *test, int line, const char *file);
  193. mbedtls_test_hook_test_fail = &mbedtls_test_fail;
  194. #if defined(MBEDTLS_ERROR_C)
  195. mbedtls_test_hook_error_add = &mbedtls_test_err_add_check;
  196. #endif
  197. #endif
  198. int ret = mbedtls_test_platform_setup();
  199. if (ret != 0) {
  200. mbedtls_fprintf(stderr,
  201. "FATAL: Failed to initialize platform - error %d\n",
  202. ret);
  203. return -1;
  204. }
  205. ret = execute_tests(argc, argv);
  206. mbedtls_test_platform_teardown();
  207. return ret;
  208. }