test.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef _PICO_TEST_H
  7. #define _PICO_TEST_H
  8. #include "pico.h"
  9. /* Various macros to help with test harnesses
  10. Note: really need to change the returns to exit()
  11. but not sure that is implemented yet.
  12. */
  13. #define PICOTEST_MODULE_NAME(n,d) const char *picotest_module=n; const char *picotest_description=d; int picotest_error_code;
  14. #define PICOTEST_START() printf("Starting Picotest for %s\n", picotest_description);
  15. #define PICOTEST_START_SECTION(NAME) if (1) {const char *picotest_section_name=NAME; picotest_error_code = 0;
  16. #define PICOTEST_END_SECTION() if (picotest_error_code != 0) { \
  17. printf("Module %s: Section %s : Failed test\n", picotest_module, picotest_section_name);\
  18. return -1; \
  19. } else \
  20. printf("Module %s: Section %s : Passed\n", picotest_module, picotest_section_name); \
  21. }
  22. #define PICOTEST_CHECK(COND, MESSAGE) if (!(COND)) { \
  23. printf("Module %s: %s\n", picotest_module, MESSAGE); \
  24. picotest_error_code = -1; \
  25. }
  26. #define PICOTEST_CHECK_CHANNEL(CHANNEL, COND, MESSAGE) if (!(COND)) { \
  27. printf("Module %s, channel %d: %s\n", picotest_module, CHANNEL, MESSAGE); \
  28. picotest_error_code = -1; \
  29. }
  30. #define PICOTEST_CHECK_AND_ABORT(COND, MESSAGE) if (!(COND)) { \
  31. printf("Module %s: %s\n", picotest_module, MESSAGE); \
  32. return -1; \
  33. }
  34. #define PICOTEST_CHECK_CHANNEL_AND_ABORT(CHANNEL, COND, MESSAGE) if (!(COND)) { \
  35. printf("Module %s, channel %d: %s\n", picotest_module, CHANNEL, MESSAGE); \
  36. return -1; \
  37. }
  38. #define PICOTEST_ABORT_IF_FAILED() if (picotest_error_code != 0) { \
  39. printf("Module %s: Aborting\n", picotest_module); \
  40. return -1; \
  41. }
  42. #define PICOTEST_END_TEST() if (picotest_error_code != 0) \
  43. {printf("%s: Failed\n", picotest_description); return -1;} \
  44. else \
  45. {printf("%s: Success\n", picotest_description); return 0;}
  46. #endif