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