-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathDV_Report.c
347 lines (299 loc) · 10.3 KB
/
DV_Report.c
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/*
* Copyright (c) 2015-2021 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* -----------------------------------------------------------------------------
*
* Project: CMSIS-Driver Validation
* Title: Report statistics and layout implementation
*
* -----------------------------------------------------------------------------
*/
#include "DV_Report.h"
/* Local macros */
#define PRINT(x) MsgPrint x
#define FLUSH() MsgFlush()
/* Local functions */
static void tr_Init (void);
static void tr_Uninit (void);
static void tg_Init (const char *title, const char *date, const char *time, const char *fn);
static void tg_Info (const char *info);
static void tg_InfoDone(void);
static void tg_Uninit (void);
static void tc_Init (uint32_t num, const char *fn);
static void tc_Detail (const char *module, uint32_t line, const char *message);
static void tc_Uninit (void);
static void as_Result (TC_RES res);
static void MsgPrint (const char *msg, ...);
static void MsgFlush (void);
/* Global variables */
REPORT_ITF ritf = { /* Structure for report interface */
tr_Init,
tr_Uninit,
tg_Init,
tg_Info,
tg_InfoDone,
tg_Uninit,
tc_Init,
tc_Detail,
tc_Uninit,
as_Result,
};
/* Local variables */
static TEST_GROUP_RESULTS test_group_result; /* Test group results */
static uint32_t as_passed = 0U; /* Assertions passed */
static uint32_t as_failed = 0U; /* Assertions failed */
static uint32_t as_detail = 0U; /* Assertions details available */
static const char Passed[] = "PASSED";
static const char Failed[] = "FAILED";
static const char NotExe[] = "NOT EXECUTED";
/*-----------------------------------------------------------------------------
* No path - helper function
*----------------------------------------------------------------------------*/
static const char *no_path (const char *fn) {
const char *cp;
#if defined(__CC_ARM)
cp = strrchr(fn, (int32_t)'\\');
#else
cp = strrchr(fn, (int32_t)'/');
#endif
if (cp != NULL) {
cp = &cp[1];
} else {
cp = fn;
}
return (cp);
}
/*-----------------------------------------------------------------------------
* Init test report
*----------------------------------------------------------------------------*/
static void tr_Init (void) {
test_group_result.idx = 0;
#if (PRINT_XML_REPORT==1)
PRINT(("<?xml version=\"1.0\"?>\n"));
PRINT(("<?xml-stylesheet href=\"TR_Style.xsl\" type=\"text/xsl\" ?>\n"));
PRINT(("<report>\n"));
#else
PRINT((" \n\n"));
#endif
}
/*-----------------------------------------------------------------------------
* Uninit test report
*----------------------------------------------------------------------------*/
static void tr_Uninit (void) {
#if (PRINT_XML_REPORT==1)
PRINT(("</report>\n"));
#endif
}
/*-----------------------------------------------------------------------------
* Init test group
*----------------------------------------------------------------------------*/
static void tg_Init (const char *title, const char *date, const char *time, const char *fn) {
test_group_result.idx++;
test_group_result.tests = 0U;
test_group_result.passed = 0U;
test_group_result.failed = 0U;
#if (PRINT_XML_REPORT==1)
PRINT(("<test>\n"));
PRINT(("<title>%s</title>\n", title));
PRINT(("<date>%s</date>\n", date));
PRINT(("<time>%s</time>\n", time));
PRINT(("<file>%s</file>\n", fn));
PRINT(("<group>%i</group>\n", test_group_result.idx));
PRINT(("<info>\n"));
#else
(void) fn;
PRINT(("%s %s %s \n\n", title, date, time));
#endif
}
/*-----------------------------------------------------------------------------
* Write test group info
*----------------------------------------------------------------------------*/
static void tg_Info (const char *info) {
PRINT(("%s", info));
PRINT(("\n"));
#if (PRINT_XML_REPORT==0)
PRINT(("\n"));
#endif
}
/*-----------------------------------------------------------------------------
* Test group info done
*----------------------------------------------------------------------------*/
static void tg_InfoDone (void) {
#if (PRINT_XML_REPORT==1)
PRINT(("</info>\n"));
PRINT(("<test_cases>\n"));
#endif
}
/*-----------------------------------------------------------------------------
* Uninit test group
*----------------------------------------------------------------------------*/
static void tg_Uninit (void) {
const char *tres;
if (test_group_result.failed > 0U) { /* If any test failed => Failed */
tres = Failed;
} else if (test_group_result.passed > 0U) { /* If 1 passed => Passed */
tres = Passed;
} else { /* If no tests exec => Not-executed */
tres = NotExe;
}
#if (PRINT_XML_REPORT==1)
PRINT(("</test_cases>\n"));
PRINT(("<summary>\n"));
PRINT(("<tcnt>%d</tcnt>\n", test_group_result.tests));
PRINT(("<pass>%d</pass>\n", test_group_result.passed));
PRINT(("<fail>%d</fail>\n", test_group_result.failed));
PRINT(("<tres>%s</tres>\n", tres));
PRINT(("</summary>\n"));
PRINT(("</test>\n"));
#else
PRINT(("\nTest Summary: %d Tests, %d Passed, %d Failed.\n",
test_group_result.tests,
test_group_result.passed,
test_group_result.failed));
PRINT(("Test Result: %s\n\n\n", tres));
#endif
FLUSH();
}
/*-----------------------------------------------------------------------------
* Init test
*----------------------------------------------------------------------------*/
static void tc_Init (uint32_t num, const char *fn) {
as_passed = 0U;
as_failed = 0U;
as_detail = 0U;
#if (PRINT_XML_REPORT==1)
PRINT(("<tc>\n"));
PRINT(("<no>%d</no>\n", num));
PRINT(("<func>%s</func>\n", fn));
PRINT(("<dbgi>\n"));
#else
PRINT(("TEST %02d: %-32s ", num, fn));
#endif
}
/*-----------------------------------------------------------------------------
* Write test detail
*----------------------------------------------------------------------------*/
static void tc_Detail (const char *module, uint32_t line, const char *message) {
const char *module_no_path;
module_no_path = no_path (module);
as_detail = 1U;
#if (PRINT_XML_REPORT==1)
PRINT(("<detail>\n"));
PRINT(("<module>%s</module>\n", module_no_path));
PRINT(("<line>%d</line>\n", line));
if (message != NULL) {
PRINT(("<message>%s</message>\n", message));
}
PRINT(("</detail>\n"));
#else
PRINT(("\n %s (%d)", module_no_path, line));
if (message != NULL) {
PRINT((": %s", message));
}
#endif
}
/*-----------------------------------------------------------------------------
* Uninit test
*----------------------------------------------------------------------------*/
static void tc_Uninit (void) {
const char *res;
test_group_result.tests++;
if (as_failed > 0U) { /* If any assertion failed => Failed */
test_group_result.failed++;
res = Failed;
} else if (as_passed > 0U) { /* If 1 assertion passed => Passed */
test_group_result.passed++;
res = Passed;
} else { /* If no assertions => Not-executed */
res = NotExe;
}
#if (PRINT_XML_REPORT==1)
PRINT(("</dbgi>\n"));
PRINT(("<res>%s</res>\n", res));
PRINT(("</tc>\n"));
(void)as_detail;
#else
if (as_detail != 0U) {
PRINT(("\n "));
}
PRINT(("%s\n", res));
#endif
}
/*-----------------------------------------------------------------------------
* Assertion result registering
*----------------------------------------------------------------------------*/
static void as_Result (TC_RES res) {
if (res == PASSED) {
as_passed++;
} else if (res == FAILED) {
as_failed++;
} else {
// Do nothing
}
}
/*-----------------------------------------------------------------------------
* Add info line to group info
*----------------------------------------------------------------------------*/
void __tg_info (const char *info) {
if (info != NULL) {
tg_Info(info);
}
}
/*-----------------------------------------------------------------------------
* Set result
*----------------------------------------------------------------------------*/
void __set_result (const char *module, uint32_t line, const char *message, TC_RES res) {
// Set debug info
if (message != NULL) {
tc_Detail(module, line, message);
}
// Set result
as_Result(res);
}
/*-----------------------------------------------------------------------------
* Set message
*----------------------------------------------------------------------------*/
void __set_message (const char *module, uint32_t line, const char *message) {
if (message != NULL) {
tc_Detail(module, line, message);
}
}
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
/*-----------------------------------------------------------------------------
* MsgPrint: Print a message to the standard output
*----------------------------------------------------------------------------*/
static void MsgPrint (const char *msg, ...) {
va_list args;
va_start(args, msg);
(void)vprintf(msg, args);
va_end(args);
}
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#pragma clang diagnostic pop
#endif
/*-----------------------------------------------------------------------------
* SER_MsgFlush: Flush the standard output
*----------------------------------------------------------------------------*/
static void MsgFlush(void) {
(void)fflush(stdout);
}
/*-----------------------------------------------------------------------------
* End of file
*----------------------------------------------------------------------------*/