amiro-os / os / core / inc / aos_unittest.h @ e545e620
History | View | Annotate | Download (3.071 KB)
1 | e545e620 | Thomas Schöpping | /*
|
---|---|---|---|
2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | Copyright (C) 2016..2018 Thomas Schöpping et al.
|
||
4 | |||
5 | This program is free software: you can redistribute it and/or modify
|
||
6 | it under the terms of the GNU General Public License as published by
|
||
7 | the Free Software Foundation, either version 3 of the License, or
|
||
8 | (at your option) any later version.
|
||
9 | |||
10 | This program is distributed in the hope that it will be useful,
|
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | GNU General Public License for more details.
|
||
14 | |||
15 | You should have received a copy of the GNU General Public License
|
||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
17 | */
|
||
18 | |||
19 | #ifndef _AMIROOS_UNITTEST_H_
|
||
20 | #define _AMIROOS_UNITTEST_H_
|
||
21 | |||
22 | #include <aosconf.h> |
||
23 | #include <hal.h> |
||
24 | #include <aos_shell.h> |
||
25 | |||
26 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
27 | |||
28 | /*
|
||
29 | * Forward declarations.
|
||
30 | */
|
||
31 | typedef struct aos_unittest aos_unittest_t; |
||
32 | typedef struct aos_utresult aos_utresult_t; |
||
33 | |||
34 | /**
|
||
35 | * @brief Unit test interface function definition.
|
||
36 | *
|
||
37 | * @param[in] stream The stream to use for printing messages.
|
||
38 | * @param[in] ut The object to run the test on.
|
||
39 | *
|
||
40 | * @return A result containing the number of passed and failed tests.
|
||
41 | */
|
||
42 | typedef aos_utresult_t (*aos_utfunction_t)(BaseSequentialStream* stream, aos_unittest_t* ut);
|
||
43 | |||
44 | /**
|
||
45 | * @brief Unit test result struct.
|
||
46 | */
|
||
47 | struct aos_utresult {
|
||
48 | /**
|
||
49 | * @brief Number of passed tests.
|
||
50 | */
|
||
51 | uint32_t passed; |
||
52 | |||
53 | /**
|
||
54 | * @brief Number of failed tests.
|
||
55 | */
|
||
56 | uint32_t failed; |
||
57 | }; |
||
58 | |||
59 | /**
|
||
60 | * @brief Unit test definition struct.
|
||
61 | */
|
||
62 | struct aos_unittest {
|
||
63 | /**
|
||
64 | * @brief Name of the unit test.
|
||
65 | */
|
||
66 | const char* name; |
||
67 | |||
68 | /**
|
||
69 | * @brief Further information about the test.
|
||
70 | */
|
||
71 | const char* info; |
||
72 | |||
73 | /**
|
||
74 | * @brief Callback function to run that executes the unit test.
|
||
75 | */
|
||
76 | aos_utfunction_t testfunc; |
||
77 | |||
78 | /**
|
||
79 | * @brief Shell command to add to an shell command list.
|
||
80 | */
|
||
81 | aos_shellcommand_t shellcmd; |
||
82 | |||
83 | /**
|
||
84 | * @brief Further test specific data.
|
||
85 | */
|
||
86 | void* data;
|
||
87 | }; |
||
88 | |||
89 | #ifdef __cplusplus
|
||
90 | extern "C" { |
||
91 | #endif
|
||
92 | uint32_t aosUtResultTotal(aos_utresult_t* result); |
||
93 | float aosUtResultRatio(aos_utresult_t* result);
|
||
94 | void aosUtResultPrintSummary(BaseSequentialStream* stream, aos_utresult_t* result, char* heading); |
||
95 | void aosUtObjectInit(aos_unittest_t* ut, char* name, char* info, aos_utfunction_t func, void* data, char* shellname, aos_shellcmdcb_t shellcb); |
||
96 | aos_utresult_t aosUtRun(BaseSequentialStream* stream, aos_unittest_t* ut, char* note);
|
||
97 | void aosUtPassed(BaseSequentialStream* stream, aos_utresult_t* result);
|
||
98 | void aosUtPassedMsg(BaseSequentialStream* stream, aos_utresult_t* result, const char* fmt, ...); |
||
99 | void aosUtFailed(BaseSequentialStream* stream, aos_utresult_t* result);
|
||
100 | void aosUtFailedMsg(BaseSequentialStream* stream, aos_utresult_t* result, const char* fmt, ...); |
||
101 | void aosUtInfoMsg(BaseSequentialStream* stream, const char* fmt, ...); |
||
102 | #ifdef __cplusplus
|
||
103 | } |
||
104 | #endif
|
||
105 | |||
106 | #endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
||
107 | |||
108 | #endif /* _AMIROOS_UNITTEST_H_ */ |