Statistics
| Branch: | Tag: | Revision:

amiro-os / core / inc / aos_test.h @ 4e8e8462

History | View | Annotate | Download (6.401 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  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
/**
20
 * @file    aos_test.h
21
 * @brief   Test structures and interfaces.
22
 *
23
 * @addtogroup aos_unittests
24
 * @{
25
 */
26

    
27
#ifndef AMIROOS_TEST_H
28
#define AMIROOS_TEST_H
29

    
30
#include <amiroos.h>
31

    
32
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
33

    
34
/******************************************************************************/
35
/* CONSTANTS                                                                  */
36
/******************************************************************************/
37

    
38
/******************************************************************************/
39
/* SETTINGS                                                                   */
40
/******************************************************************************/
41

    
42
/******************************************************************************/
43
/* CHECKS                                                                     */
44
/******************************************************************************/
45

    
46
/******************************************************************************/
47
/* DATA STRUCTURES AND TYPES                                                  */
48
/******************************************************************************/
49

    
50
/*
51
 * forward declarations
52
 */
53
typedef struct aos_testresult aos_testresult_t;
54
typedef struct aos_test aos_test_t;
55

    
56
/**
57
 * @brief   Test interface function definition.
58
 *
59
 * @param[in] stream  The stream to use for printing messages.
60
 * @param[in] ut      The object to run the test on.
61
 *
62
 * @return    Result containing the number of passed and failed tests.
63
 */
64
typedef aos_testresult_t (*aos_testfunction_t)(BaseSequentialStream* stream, const aos_test_t* test);
65

    
66
/**
67
 * @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
 */
81
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
  /**
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
 * @brief   Test definition struct.
100
 */
101
struct aos_test {
102
  /**
103
   * @brief   Name of the test.
104
   */
105
  const char* name;
106

    
107
  /**
108
   * @brief   Further information about the test.
109
   */
110
  const char* info;
111

    
112
  /**
113
   * @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
   */
120
  aos_testshellcallback_t shellcb;
121

    
122
  /**
123
   * @brief   Callback function to run that executes the test.
124
   */
125
  aos_testfunction_t testfunc;
126

    
127
  /**
128
   * @brief   Further test specific data.
129
   */
130
  void* data;
131
};
132

    
133

    
134
/******************************************************************************/
135
/* MACROS                                                                     */
136
/******************************************************************************/
137

    
138
#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
/******************************************************************************/
147
/* EXTERN DECLARATIONS                                                        */
148
/******************************************************************************/
149

    
150
#if defined(__cplusplus)
151
extern "C" {
152
#endif /* defined(__cplusplus) */
153
  void aosTestResultInit(aos_testresult_t* result);
154
  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
#if defined(__cplusplus)
165
}
166
#endif /* defined(__cplusplus) */
167

    
168
/******************************************************************************/
169
/* INLINE FUNCTIONS                                                           */
170
/******************************************************************************/
171

    
172
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
173

    
174
#endif /* AMIROOS_TEST_H */
175

    
176
/** @} */