2 * Copyright (c) 2015-2020 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_Uninit(void);
39 static void tc_Init (uint32_t num, const char *fn);
40 static void tc_Uninit(void);
41 static void tc_Detail(const char *module, uint32_t line, const char *message);
42 static void as_Result(TC_RES res);
44 static void MsgPrint (const char *msg, ...);
45 static void MsgFlush (void);
47 /* Global variables */
48 REPORT_ITF ritf = { /* Structure for report interface */
60 static TEST_GROUP_RESULTS test_group_result; /* Test group results */
62 static uint32_t as_passed = 0U; /* Assertions passed */
63 static uint32_t as_failed = 0U; /* Assertions failed */
64 static uint32_t as_detail = 0U; /* Assertions details available */
65 static const char Passed[] = "PASSED";
66 static const char Failed[] = "FAILED";
67 static const char NotExe[] = "NOT EXECUTED";
70 /*-----------------------------------------------------------------------------
71 * No path - helper function
72 *----------------------------------------------------------------------------*/
73 static const char *no_path (const char *fn) {
76 cp = strrchr(fn, (int32_t)'\\');
78 cp = strrchr(fn, (int32_t)'/');
88 /*-----------------------------------------------------------------------------
90 *----------------------------------------------------------------------------*/
91 static void tr_Init (void) {
93 test_group_result.idx = 0;
95 #if (PRINT_XML_REPORT==1)
96 PRINT(("<?xml version=\"1.0\"?>\n"));
97 PRINT(("<?xml-stylesheet href=\"TR_Style.xsl\" type=\"text/xsl\" ?>\n"));
98 PRINT(("<report>\n"));
104 /*-----------------------------------------------------------------------------
106 *----------------------------------------------------------------------------*/
107 static void tr_Uninit (void) {
108 #if (PRINT_XML_REPORT==1)
109 PRINT(("</report>\n"));
113 /*-----------------------------------------------------------------------------
115 *----------------------------------------------------------------------------*/
116 static void tg_Init (const char *title, const char *date, const char *time, const char *fn) {
118 test_group_result.idx++;
119 test_group_result.tests = 0U;
120 test_group_result.passed = 0U;
121 test_group_result.failed = 0U;
123 #if (PRINT_XML_REPORT==1)
125 PRINT(("<title>%s</title>\n", title));
126 PRINT(("<date>%s</date>\n", date));
127 PRINT(("<time>%s</time>\n", time));
128 PRINT(("<file>%s</file>\n", fn));
129 PRINT(("<group>%i</group>\n", test_group_result.idx));
130 PRINT(("<test_cases>\n"));
133 PRINT(("%s %s %s \n\n", title, date, time));
137 /*-----------------------------------------------------------------------------
139 *----------------------------------------------------------------------------*/
140 static void tg_Uninit (void) {
143 if (test_group_result.failed > 0U) { /* If any test failed => Failed */
145 } else if (test_group_result.passed > 0U) { /* If 1 passed => Passed */
147 } else { /* If no tests exec => Not-executed */
151 #if (PRINT_XML_REPORT==1)
152 PRINT(("</test_cases>\n"));
153 PRINT(("<summary>\n"));
154 PRINT(("<tcnt>%d</tcnt>\n", test_group_result.tests));
155 PRINT(("<pass>%d</pass>\n", test_group_result.passed));
156 PRINT(("<fail>%d</fail>\n", test_group_result.failed));
157 PRINT(("<tres>%s</tres>\n", tres));
158 PRINT(("</summary>\n"));
159 PRINT(("</test>\n"));
161 PRINT(("\nTest Summary: %d Tests, %d Passed, %d Failed.\n",
162 test_group_result.tests,
163 test_group_result.passed,
164 test_group_result.failed));
165 PRINT(("Test Result: %s\n\n\n", tres));
170 /*-----------------------------------------------------------------------------
172 *----------------------------------------------------------------------------*/
173 static void tc_Init (uint32_t num, const char *fn) {
179 #if (PRINT_XML_REPORT==1)
181 PRINT(("<no>%d</no>\n", num));
182 PRINT(("<func>%s</func>\n", fn));
185 PRINT(("TEST %02d: %-32s ", num, fn));
189 /*-----------------------------------------------------------------------------
191 *----------------------------------------------------------------------------*/
192 static void tc_Uninit (void) {
195 test_group_result.tests++;
197 if (as_failed > 0U) { /* If any assertion failed => Failed */
198 test_group_result.failed++;
200 } else if (as_passed > 0U) { /* If 1 assertion passed => Passed */
201 test_group_result.passed++;
203 } else { /* If no assertions => Not-executed */
207 #if (PRINT_XML_REPORT==1)
208 PRINT(("</dbgi>\n"));
209 PRINT(("<res>%s</res>\n", res));
213 if (as_detail != 0U) {
216 PRINT(("%s\n", res));
220 /*-----------------------------------------------------------------------------
222 *----------------------------------------------------------------------------*/
223 static void tc_Detail (const char *module, uint32_t line, const char *message) {
224 const char *module_no_path;
226 module_no_path = no_path (module);
230 #if (PRINT_XML_REPORT==1)
231 PRINT(("<detail>\n"));
232 PRINT(("<module>%s</module>\n", module_no_path));
233 PRINT(("<line>%d</line>\n", line));
234 if (message != NULL) {
235 PRINT(("<message>%s</message>\n", message));
237 PRINT(("</detail>\n"));
239 PRINT(("\n %s (%d)", module_no_path, line));
240 if (message != NULL) {
241 PRINT((": %s", message));
246 /*-----------------------------------------------------------------------------
247 * Assertion result registering
248 *----------------------------------------------------------------------------*/
249 static void as_Result (TC_RES res) {
253 } else if (res == FAILED) {
260 /*-----------------------------------------------------------------------------
262 *----------------------------------------------------------------------------*/
263 void __set_result (const char *module, uint32_t line, const char *message, TC_RES res) {
266 if (message != NULL) {
267 tc_Detail(module, line, message);
274 /*-----------------------------------------------------------------------------
276 *----------------------------------------------------------------------------*/
277 void __set_message (const char *module, uint32_t line, const char *message) {
278 if (message != NULL) {
279 tc_Detail(module, line, message);
284 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
285 #pragma clang diagnostic push
286 #pragma clang diagnostic ignored "-Wformat-nonliteral"
288 /*-----------------------------------------------------------------------------
289 * MsgPrint: Print a message to the standard output
290 *----------------------------------------------------------------------------*/
291 static void MsgPrint (const char *msg, ...) {
294 (void)vprintf(msg, args);
297 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
298 #pragma clang diagnostic pop
301 /*-----------------------------------------------------------------------------
302 * SER_MsgFlush: Flush the standard output
303 *----------------------------------------------------------------------------*/
304 static void MsgFlush(void) {
305 (void)fflush(stdout);
308 /*-----------------------------------------------------------------------------
310 *----------------------------------------------------------------------------*/