Statistics
| Branch: | Tag: | Revision:

amiro-os / core / inc / aos_test.h @ a7e54ea4

History | View | Annotate | Download (6.401 KB)

1 e545e620 Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3 96621a83 Thomas Schöpping
Copyright (C) 2016..2020  Thomas Schöpping et al.
4 e545e620 Thomas Schöpping

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 53710ca3 Marc Rothmann
/**
20 4c72a54c Thomas Schöpping
 * @file    aos_test.h
21
 * @brief   Test structures and interfaces.
22 53710ca3 Marc Rothmann
 *
23
 * @addtogroup aos_unittests
24
 * @{
25
 */
26
27 4c72a54c Thomas Schöpping
#ifndef AMIROOS_TEST_H
28
#define AMIROOS_TEST_H
29 e545e620 Thomas Schöpping
30 3940ba8a Thomas Schöpping
#include <amiroos.h>
31
32 bc5cdb79 Thomas Schöpping
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
33 3940ba8a Thomas Schöpping
34 f3ac1c96 Thomas Schöpping
/******************************************************************************/
35
/* CONSTANTS                                                                  */
36
/******************************************************************************/
37
38
/******************************************************************************/
39
/* SETTINGS                                                                   */
40
/******************************************************************************/
41
42
/******************************************************************************/
43
/* CHECKS                                                                     */
44
/******************************************************************************/
45
46
/******************************************************************************/
47
/* DATA STRUCTURES AND TYPES                                                  */
48
/******************************************************************************/
49 e545e620 Thomas Schöpping
50
/*
51 f3ac1c96 Thomas Schöpping
 * forward declarations
52 e545e620 Thomas Schöpping
 */
53 4c72a54c Thomas Schöpping
typedef struct aos_testresult aos_testresult_t;
54
typedef struct aos_test aos_test_t;
55 e545e620 Thomas Schöpping
56
/**
57 4c72a54c Thomas Schöpping
 * @brief   Test interface function definition.
58 e545e620 Thomas Schöpping
 *
59
 * @param[in] stream  The stream to use for printing messages.
60
 * @param[in] ut      The object to run the test on.
61
 *
62 4c72a54c Thomas Schöpping
 * @return    Result containing the number of passed and failed tests.
63 e545e620 Thomas Schöpping
 */
64 4c72a54c Thomas Schöpping
typedef aos_testresult_t (*aos_testfunction_t)(BaseSequentialStream* stream, const aos_test_t* test);
65 e545e620 Thomas Schöpping
66
/**
67 4c72a54c Thomas Schöpping
 * @brief   Wrapper interface definition to allow programmatical shell-like call
68
 *          of the test.
69
 * @details While the first three arguments (stream, argc and argv) as well as
70
 *          the return value are identical to a shell command, the additional
71
 *          optional argument (result) is set by the function.
72
 *
73
 * @param[in]   stream  Stream to print to.
74
 * @param[in]   argc    Number of arguments given.
75
 * @param[in]   argv    List of arguments.
76
 * @param[out]  result  Result of the test (optional).
77
 *
78
 * @return    Execution status of the function, which can be passed on to a
79
 *            shell callback.
80 e545e620 Thomas Schöpping
 */
81 4c72a54c Thomas Schöpping
typedef int (*aos_testshellcallback_t)(BaseSequentialStream* stream, int argc, char* argv[], aos_testresult_t* result);
82
83
/**
84
 * @brief   Test result struct.
85
 */
86
struct aos_testresult {
87 e545e620 Thomas Schöpping
  /**
88
   * @brief   Number of passed tests.
89
   */
90
  uint32_t passed;
91
92
  /**
93
   * @brief   Number of failed tests.
94
   */
95
  uint32_t failed;
96
};
97
98
/**
99 4c72a54c Thomas Schöpping
 * @brief   Test definition struct.
100 e545e620 Thomas Schöpping
 */
101 4c72a54c Thomas Schöpping
struct aos_test {
102 e545e620 Thomas Schöpping
  /**
103 4c72a54c Thomas Schöpping
   * @brief   Name of the test.
104 e545e620 Thomas Schöpping
   */
105
  const char* name;
106
107
  /**
108
   * @brief   Further information about the test.
109
   */
110
  const char* info;
111
112
  /**
113 4c72a54c Thomas Schöpping
   * @brief   Callback function to serve as wrapper between shell and test.
114
   *
115
   * @details The purpose of this wrapper is to be able to execute tests
116
   *          programatically exactly like a shell command from the CLI. It
117
   *          should handle any required setup depending on given arguments and
118
   *          eventually execute the test.
119 e545e620 Thomas Schöpping
   */
120 4c72a54c Thomas Schöpping
  aos_testshellcallback_t shellcb;
121 e545e620 Thomas Schöpping
122
  /**
123 4c72a54c Thomas Schöpping
   * @brief   Callback function to run that executes the test.
124 e545e620 Thomas Schöpping
   */
125 4c72a54c Thomas Schöpping
  aos_testfunction_t testfunc;
126 e545e620 Thomas Schöpping
127
  /**
128
   * @brief   Further test specific data.
129
   */
130
  void* data;
131
};
132
133 f3ac1c96 Thomas Schöpping
134
/******************************************************************************/
135
/* MACROS                                                                     */
136
/******************************************************************************/
137
138 4c72a54c Thomas Schöpping
#define AOS_TEST(var, name, info, shellcb, testfunc, data) aos_test_t var = { \
139
  /* name     */ name,                                                        \
140
  /* info     */ info,                                                        \
141
  /* shellcb  */ shellcb,                                                     \
142
  /* testfunc */ testfunc,                                                    \
143
  /* data     */ data,                                                        \
144
}
145
146 f3ac1c96 Thomas Schöpping
/******************************************************************************/
147
/* EXTERN DECLARATIONS                                                        */
148
/******************************************************************************/
149
150 7de0cc90 Thomas Schöpping
#if defined(__cplusplus)
151 e545e620 Thomas Schöpping
extern "C" {
152 7de0cc90 Thomas Schöpping
#endif /* defined(__cplusplus) */
153 ce12e797 Thomas Schöpping
  void aosTestResultInit(aos_testresult_t* result);
154 4c72a54c Thomas Schöpping
  aos_testresult_t aosTestResultAdd(aos_testresult_t a, aos_testresult_t b);
155
  uint32_t aosTestResultTotal(const aos_testresult_t* result);
156
  float aosTestResultRatio(const aos_testresult_t* result);
157
  void aosTestResultPrintSummary(BaseSequentialStream* stream, const aos_testresult_t* result, const char* heading);
158
  aos_testresult_t aosTestRun(BaseSequentialStream* stream, const aos_test_t* test, const char* note);
159
  void aosTestPassed(BaseSequentialStream* stream, aos_testresult_t* result);
160
  void aosTestPassedMsg(BaseSequentialStream* stream, aos_testresult_t* result, const char* fmt, ...);
161
  void aosTestFailed(BaseSequentialStream* stream, aos_testresult_t* result);
162
  void aosTestFailedMsg(BaseSequentialStream* stream, aos_testresult_t* result, const char* fmt, ...);
163
  void aosTestInfoMsg(BaseSequentialStream* stream, const char* fmt, ...);
164 7de0cc90 Thomas Schöpping
#if defined(__cplusplus)
165 e545e620 Thomas Schöpping
}
166 7de0cc90 Thomas Schöpping
#endif /* defined(__cplusplus) */
167 e545e620 Thomas Schöpping
168 f3ac1c96 Thomas Schöpping
/******************************************************************************/
169
/* INLINE FUNCTIONS                                                           */
170
/******************************************************************************/
171
172 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
173 e545e620 Thomas Schöpping
174 4c72a54c Thomas Schöpping
#endif /* AMIROOS_TEST_H */
175 53710ca3 Marc Rothmann
176
/** @} */