2 * Copyright (c) 2015-2021 Arm Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * -----------------------------------------------------------------------------
20 * Project: CMSIS-Driver Validation
21 * Title: Report statistics and layout implementation
23 * -----------------------------------------------------------------------------
27 #include "DV_Report.h"
31 #define PRINT(x) MsgPrint x
32 #define FLUSH() MsgFlush()
35 static void tr_Init (void);
36 static void tr_Uninit (void);
37 static void tg_Init (const char *title, const char *date, const char *time, const char *fn);
38 static void tg_Info (const char *info);
39 static void tg_InfoDone(void);
40 static void tg_Uninit (void);
41 static void tc_Init (uint32_t num, const char *fn);
42 static void tc_Detail (const char *module, uint32_t line, const char *message);
43 static void tc_Uninit (void);
44 static void as_Result (TC_RES res);
46 static void MsgPrint (const char *msg, ...);
47 static void MsgFlush (void);
49 /* Global variables */
50 REPORT_ITF ritf = { /* Structure for report interface */
64 static TEST_GROUP_RESULTS test_group_result; /* Test group results */
66 static uint32_t as_passed = 0U; /* Assertions passed */
67 static uint32_t as_failed = 0U; /* Assertions failed */
68 static uint32_t as_detail = 0U; /* Assertions details available */
69 static const char Passed[] = "PASSED";
70 static const char Failed[] = "FAILED";
71 static const char NotExe[] = "NOT EXECUTED";
74 /*-----------------------------------------------------------------------------
75 * No path - helper function
76 *----------------------------------------------------------------------------*/
77 static const char *no_path (const char *fn) {
80 cp = strrchr(fn, (int32_t)'\\');
82 cp = strrchr(fn, (int32_t)'/');
92 /*-----------------------------------------------------------------------------
94 *----------------------------------------------------------------------------*/
95 static void tr_Init (void) {
97 test_group_result.idx = 0;
99 #if (PRINT_XML_REPORT==1)
100 PRINT(("<?xml version=\"1.0\"?>\n"));
101 PRINT(("<?xml-stylesheet href=\"TR_Style.xsl\" type=\"text/xsl\" ?>\n"));
102 PRINT(("<report>\n"));
108 /*-----------------------------------------------------------------------------
110 *----------------------------------------------------------------------------*/
111 static void tr_Uninit (void) {
112 #if (PRINT_XML_REPORT==1)
113 PRINT(("</report>\n"));
117 /*-----------------------------------------------------------------------------
119 *----------------------------------------------------------------------------*/
120 static void tg_Init (const char *title, const char *date, const char *time, const char *fn) {
122 test_group_result.idx++;
123 test_group_result.tests = 0U;
124 test_group_result.passed = 0U;
125 test_group_result.failed = 0U;
127 #if (PRINT_XML_REPORT==1)
129 PRINT(("<title>%s</title>\n", title));
130 PRINT(("<date>%s</date>\n", date));
131 PRINT(("<time>%s</time>\n", time));
132 PRINT(("<file>%s</file>\n", fn));
133 PRINT(("<group>%i</group>\n", test_group_result.idx));
137 PRINT(("%s %s %s \n\n", title, date, time));
141 /*-----------------------------------------------------------------------------
142 * Write test group info
143 *----------------------------------------------------------------------------*/
144 static void tg_Info (const char *info) {
148 #if (PRINT_XML_REPORT==0)
153 /*-----------------------------------------------------------------------------
154 * Test group info done
155 *----------------------------------------------------------------------------*/
156 static void tg_InfoDone (void) {
158 #if (PRINT_XML_REPORT==1)
159 PRINT(("</info>\n"));
160 PRINT(("<test_cases>\n"));
164 /*-----------------------------------------------------------------------------
166 *----------------------------------------------------------------------------*/
167 static void tg_Uninit (void) {
170 if (test_group_result.failed > 0U) { /* If any test failed => Failed */
172 } else if (test_group_result.passed > 0U) { /* If 1 passed => Passed */
174 } else { /* If no tests exec => Not-executed */
178 #if (PRINT_XML_REPORT==1)
179 PRINT(("</test_cases>\n"));
180 PRINT(("<summary>\n"));
181 PRINT(("<tcnt>%d</tcnt>\n", test_group_result.tests));
182 PRINT(("<pass>%d</pass>\n", test_group_result.passed));
183 PRINT(("<fail>%d</fail>\n", test_group_result.failed));
184 PRINT(("<tres>%s</tres>\n", tres));
185 PRINT(("</summary>\n"));
186 PRINT(("</test>\n"));
188 PRINT(("\nTest Summary: %d Tests, %d Passed, %d Failed.\n",
189 test_group_result.tests,
190 test_group_result.passed,
191 test_group_result.failed));
192 PRINT(("Test Result: %s\n\n\n", tres));
197 /*-----------------------------------------------------------------------------
199 *----------------------------------------------------------------------------*/
200 static void tc_Init (uint32_t num, const char *fn) {
206 #if (PRINT_XML_REPORT==1)
208 PRINT(("<no>%d</no>\n", num));
209 PRINT(("<func>%s</func>\n", fn));
212 PRINT(("TEST %02d: %-32s ", num, fn));
216 /*-----------------------------------------------------------------------------
218 *----------------------------------------------------------------------------*/
219 static void tc_Detail (const char *module, uint32_t line, const char *message) {
220 const char *module_no_path;
222 module_no_path = no_path (module);
226 #if (PRINT_XML_REPORT==1)
227 PRINT(("<detail>\n"));
228 PRINT(("<module>%s</module>\n", module_no_path));
229 PRINT(("<line>%d</line>\n", line));
230 if (message != NULL) {
231 PRINT(("<message>%s</message>\n", message));
233 PRINT(("</detail>\n"));
235 PRINT(("\n %s (%d)", module_no_path, line));
236 if (message != NULL) {
237 PRINT((": %s", message));
242 /*-----------------------------------------------------------------------------
244 *----------------------------------------------------------------------------*/
245 static void tc_Uninit (void) {
248 test_group_result.tests++;
250 if (as_failed > 0U) { /* If any assertion failed => Failed */
251 test_group_result.failed++;
253 } else if (as_passed > 0U) { /* If 1 assertion passed => Passed */
254 test_group_result.passed++;
256 } else { /* If no assertions => Not-executed */
260 #if (PRINT_XML_REPORT==1)
261 PRINT(("</dbgi>\n"));
262 PRINT(("<res>%s</res>\n", res));
266 if (as_detail != 0U) {
269 PRINT(("%s\n", res));
273 /*-----------------------------------------------------------------------------
274 * Assertion result registering
275 *----------------------------------------------------------------------------*/
276 static void as_Result (TC_RES res) {
280 } else if (res == FAILED) {
287 /*-----------------------------------------------------------------------------
288 * Add info line to group info
289 *----------------------------------------------------------------------------*/
290 void __tg_info (const char *info) {
297 /*-----------------------------------------------------------------------------
299 *----------------------------------------------------------------------------*/
300 void __set_result (const char *module, uint32_t line, const char *message, TC_RES res) {
303 if (message != NULL) {
304 tc_Detail(module, line, message);
311 /*-----------------------------------------------------------------------------
313 *----------------------------------------------------------------------------*/
314 void __set_message (const char *module, uint32_t line, const char *message) {
315 if (message != NULL) {
316 tc_Detail(module, line, message);
321 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
322 #pragma clang diagnostic push
323 #pragma clang diagnostic ignored "-Wformat-nonliteral"
325 /*-----------------------------------------------------------------------------
326 * MsgPrint: Print a message to the standard output
327 *----------------------------------------------------------------------------*/
328 static void MsgPrint (const char *msg, ...) {
331 (void)vprintf(msg, args);
334 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
335 #pragma clang diagnostic pop
338 /*-----------------------------------------------------------------------------
339 * SER_MsgFlush: Flush the standard output
340 *----------------------------------------------------------------------------*/
341 static void MsgFlush(void) {
342 (void)fflush(stdout);
345 /*-----------------------------------------------------------------------------
347 *----------------------------------------------------------------------------*/