test.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* wolfcrypt/test/test.h
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifndef WOLFCRYPT_TEST_H
  22. #define WOLFCRYPT_TEST_H
  23. #include <wolfssl/wolfcrypt/types.h>
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #ifdef WC_TEST_RET_CUSTOM_TYPE
  28. typedef WC_TEST_RET_CUSTOM_TYPE wc_test_ret_t;
  29. #else
  30. typedef sword32 wc_test_ret_t;
  31. #endif
  32. #include <wolfssl/wolfcrypt/settings.h>
  33. #include <wolfssl/wolfcrypt/error-crypt.h>
  34. #ifdef HAVE_STACK_SIZE
  35. THREAD_RETURN WOLFSSL_THREAD wolfcrypt_test(void* args);
  36. #else
  37. wc_test_ret_t wolfcrypt_test(void* args);
  38. #endif
  39. #ifndef NO_MAIN_DRIVER
  40. wc_test_ret_t wolfcrypt_test_main(int argc, char** argv);
  41. #endif
  42. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  43. int wolf_test_task(void);
  44. #endif
  45. #ifndef WC_TEST_RET_HAVE_CUSTOM_MACROS
  46. #define WC_TEST_RET_TAG_NC 0L
  47. #define WC_TEST_RET_TAG_EC 1L
  48. #define WC_TEST_RET_TAG_ERRNO 2L
  49. #define WC_TEST_RET_TAG_I 3L
  50. wc_static_assert(-(long)MIN_CODE_E < 0x7ffL);
  51. #define WC_TEST_RET_ENC(line, i, tag) \
  52. ((wc_test_ret_t)(-((wc_test_ret_t)(line) + ((wc_test_ret_t)((word32)(i) & 0x7ffL) * 100000L) + ((wc_test_ret_t)(tag) << 29L))))
  53. #ifndef WC_TEST_RET_LN
  54. #define WC_TEST_RET_LN __LINE__
  55. #endif
  56. /* encode no code */
  57. #define WC_TEST_RET_ENC_NC WC_TEST_RET_ENC(WC_TEST_RET_LN, 0, WC_TEST_RET_TAG_NC)
  58. /* encode positive integer */
  59. #define WC_TEST_RET_ENC_I(i) WC_TEST_RET_ENC(WC_TEST_RET_LN, i, WC_TEST_RET_TAG_I)
  60. /* encode error code (negative integer) */
  61. #define WC_TEST_RET_ENC_EC(ec) WC_TEST_RET_ENC(WC_TEST_RET_LN, -(ec), WC_TEST_RET_TAG_EC)
  62. /* encode system/libc error code */
  63. #if defined(HAVE_ERRNO_H) && !defined(NO_FILESYSTEM) && \
  64. !defined(NO_STDIO_FILESYSTEM) && !defined(WOLFSSL_USER_IO)
  65. #include <errno.h>
  66. #define WC_TEST_RET_ENC_ERRNO WC_TEST_RET_ENC(WC_TEST_RET_LN, errno, WC_TEST_RET_TAG_ERRNO)
  67. #else
  68. #define WC_TEST_RET_ENC_ERRNO WC_TEST_RET_ENC_NC
  69. #endif
  70. #define WC_TEST_RET_DEC_TAG(x) ((-(x)) >> 29L)
  71. /* decode line number */
  72. #define WC_TEST_RET_DEC_LN(x) ((int)(((-(x)) & ~(3L << 29L)) % 100000L))
  73. /* decode integer or errno */
  74. #define WC_TEST_RET_DEC_I(x) ((int)((((-(x)) & ~(3L << 29L)) / 100000L)))
  75. /* decode error code */
  76. #define WC_TEST_RET_DEC_EC(x) ((int)(-WC_TEST_RET_DEC_I(x)))
  77. #endif /* !WC_TEST_RET_HAVE_CUSTOM_MACROS */
  78. #ifdef __cplusplus
  79. } /* extern "C" */
  80. #endif
  81. #endif /* WOLFCRYPT_TEST_H */