Tests.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2024-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. /*
  14. * This header and its implementation in Tests.cpp contain assertion tests,
  15. * self-tests, cryptographic tests, and fuzzing for the ZeroTier core.
  16. *
  17. * To build these ensure that ZT_ENABLE_TESTS is defined during build time.
  18. * Otherwise they are omitted.
  19. *
  20. * These symbols are defined extern "C" so tests can be called from regular
  21. * C code, which is important for use via CGo or in plain C projects.
  22. *
  23. * The ZT_T_PRINTF macro defaults to printf() but if it's defined at compile
  24. * time (also must be set while building Tests.cpp) it can specify another
  25. * function to use for output. Defining it to a no-op can be used to disable
  26. * output.
  27. *
  28. * Each test function returns NULL if the tests succeeds or an error message
  29. * on test failure.
  30. *
  31. * Only the fuzzing test functions are thread-safe. Other test functions
  32. * should not be called concurrently. It's okay to call different tests from
  33. * different threads, but not the same test.
  34. */
  35. #ifndef ZT_TESTS_HPP
  36. #define ZT_TESTS_HPP
  37. #ifdef ZT_ENABLE_TESTS
  38. #ifdef __cplusplus
  39. #include <cstdint>
  40. #include <cstdio>
  41. extern "C" {
  42. #else
  43. #include <stdint.h>
  44. #include <stdio.h>
  45. #endif
  46. #ifndef ZT_T_PRINTF
  47. #define ZT_T_PRINTF(fmt,...) printf((fmt),##__VA_ARGS__),fflush(stdout)
  48. #endif
  49. // Basic self-tests ---------------------------------------------------------------------------------------------------
  50. const char *ZTT_general();
  51. const char *ZTT_crypto();
  52. // Benchmarks ---------------------------------------------------------------------------------------------------------
  53. const char *ZTT_benchmarkCrypto();
  54. // Fuzzing ------------------------------------------------------------------------------------------------------------
  55. // --------------------------------------------------------------------------------------------------------------------
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif // ZT_ENABLE_TESTS
  60. #endif