File: test.h

package info (click to toggle)
pico-sdk 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 26,552 kB
  • sloc: ansic: 146,841; asm: 13,423; python: 2,417; cpp: 2,171; yacc: 381; lex: 270; makefile: 32; sh: 13; javascript: 13
file content (61 lines) | stat: -rw-r--r-- 3,374 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef _PICO_TEST_H
#define _PICO_TEST_H

#include "pico.h"

/* Various macros to help with test harnesses

Note: really need to change the returns to exit()
but not sure that is implemented yet.
*/

#define PICOTEST_MODULE_NAME(n,d) const char *picotest_module=n; const char *picotest_description=d; int picotest_error_code;

#define PICOTEST_START() printf("Starting Picotest for %s\n", picotest_description);

#define PICOTEST_START_SECTION(NAME) if (1) {const char *picotest_section_name=NAME; picotest_error_code = 0;

#define PICOTEST_END_SECTION() if (picotest_error_code != 0) {                                      \
                                    printf("Module %s: Section %s : Failed test\n", picotest_module, picotest_section_name);\
                                    return -1;                                                      \
                                    } else                                                          \
                                    printf("Module %s: Section %s : Passed\n", picotest_module, picotest_section_name); \
                               }

#define PICOTEST_CHECK(COND, MESSAGE) if (!(COND)) {                                               \
                                        printf("Module %s: %s\n", picotest_module, MESSAGE);       \
                                        picotest_error_code = -1;                                   \
                                    }
#define PICOTEST_CHECK_CHANNEL(CHANNEL, COND, MESSAGE) if (!(COND)) {                              \
                                        printf("Module %s, channel %d: %s\n", picotest_module, CHANNEL, MESSAGE);  \
                                        picotest_error_code = -1;                                   \
                                    }

#define PICOTEST_CHECK_AND_ABORT(COND, MESSAGE) if (!(COND)) {                                     \
                                        printf("Module %s: %s\n", picotest_module, MESSAGE);       \
                                        return -1;                                                  \
                                    }

#define PICOTEST_CHECK_CHANNEL_AND_ABORT(CHANNEL, COND, MESSAGE) if (!(COND)) {                    \
                                        printf("Module %s, channel %d: %s\n", picotest_module, CHANNEL, MESSAGE);  \
                                        return -1;                                                  \
                                    }

#define PICOTEST_ABORT_IF_FAILED()  if (picotest_error_code != 0) {                                 \
                                        printf("Module %s: Aborting\n", picotest_module);           \
                                        return -1;                                                  \
                                    }

#define PICOTEST_END_TEST()       if (picotest_error_code != 0)                                     \
                                      {printf("%s: Failed\n", picotest_description); return -1;}  \
                                  else                                                              \
                                      {printf("%s: Success\n", picotest_description); return 0;}


#endif