1 /*-----------------------------------------------------------------------------
3 * Purpose: Report statistics and layout implementation
4 *-----------------------------------------------------------------------------
5 * Copyright(c) KEIL - An ARM Company
6 *----------------------------------------------------------------------------*/
12 #define PRINT(x) MsgPrint x
13 #define FLUSH() MsgFlush()
15 /* Global functions */
16 void __set_result (const char *module, uint32_t line, const char *message, TC_RES res);
17 void __set_message (const char *module, uint32_t line, const char *message);
20 static void tr_Init (void);
21 static void tr_Uninit(void);
22 static void tg_Init (const char *title, const char *date, const char *time, const char *file);
23 static void tg_Uninit(void);
24 static void tc_Init (uint32_t num, const char *fn);
25 static void tc_Uninit(void);
26 static void tc_Detail(const char *module, uint32_t line, const char *message);
27 static void as_Result(TC_RES res);
29 static void MsgPrint (const char *msg, ...);
30 static void MsgFlush (void);
32 /* Global variables */
33 REPORT_ITF ritf = { /* Structure for report interface */
45 static TEST_GROUP_RESULTS test_group_result; /* Test group results */
47 static uint32_t as_passed = 0; /* Assertions passed */
48 static uint32_t as_failed = 0; /* Assertions failed */
49 static uint32_t as_detail = 0; /* Assertions details available */
50 static const char Passed[] = "PASSED";
51 static const char Failed[] = "FAILED";
52 static const char NotExe[] = "NOT EXECUTED";
55 /*-----------------------------------------------------------------------------
56 * No path - helper function
57 *----------------------------------------------------------------------------*/
58 static const char *no_path (const char *fn) {
61 cp = strrchr(fn, '\\');
63 cp = strrchr(fn, '/');
65 if (cp) return (cp + 1);
69 /*-----------------------------------------------------------------------------
71 *----------------------------------------------------------------------------*/
72 static void tr_Init (void) {
74 test_group_result.idx = 0;
76 #if (PRINT_XML_REPORT==1)
77 PRINT(("<?xml version=\"1.0\"?>\n"));
78 PRINT(("<?xml-stylesheet href=\"TR_Style.xsl\" type=\"text/xsl\" ?>\n"));
79 PRINT(("<report>\n"));
85 /*-----------------------------------------------------------------------------
87 *----------------------------------------------------------------------------*/
88 static void tr_Uninit (void) {
89 #if (PRINT_XML_REPORT==1)
90 PRINT(("</report>\n"));
94 /*-----------------------------------------------------------------------------
96 *----------------------------------------------------------------------------*/
97 static void tg_Init (const char *title, const char *date, const char *time, const char *fn) {
99 test_group_result.idx++;
100 test_group_result.tests = 0;
101 test_group_result.passed = 0;
102 test_group_result.failed = 0;
104 #if (PRINT_XML_REPORT==1)
106 PRINT(("<title>%s</title>\n", title));
107 PRINT(("<date>%s</date>\n", date));
108 PRINT(("<time>%s</time>\n", time));
109 PRINT(("<file>%s</file>\n", fn));
110 PRINT(("<group>%i</group>\n", test_group_result.idx));
111 PRINT(("<test_cases>\n"));
114 PRINT(("%s %s %s \n\n", title, date, time));
118 /*-----------------------------------------------------------------------------
120 *----------------------------------------------------------------------------*/
121 static void tg_Uninit (void) {
124 if (test_group_result.failed > 0) { /* If any test failed => Failed */
126 } else if (test_group_result.passed > 0) { /* If 1 passed => Passed */
128 } else { /* If no tests exec => Not-executed */
132 #if (PRINT_XML_REPORT==1)
133 PRINT(("</test_cases>\n"));
134 PRINT(("<summary>\n"));
135 PRINT(("<tcnt>%d</tcnt>\n", test_group_result.tests));
136 PRINT(("<pass>%d</pass>\n", test_group_result.passed));
137 PRINT(("<fail>%d</fail>\n", test_group_result.failed));
138 PRINT(("<tres>%s</tres>\n", tres));
139 PRINT(("</summary>\n"));
140 PRINT(("</test>\n"));
142 PRINT(("\nTest Summary: %d Tests, %d Passed, %d Failed.\n",
143 test_group_result.tests,
144 test_group_result.passed,
145 test_group_result.failed));
146 PRINT(("Test Result: %s\n\n\n", tres));
151 /*-----------------------------------------------------------------------------
153 *----------------------------------------------------------------------------*/
154 static void tc_Init (uint32_t num, const char *fn) {
160 #if (PRINT_XML_REPORT==1)
162 PRINT(("<no>%d</no>\n", num));
163 PRINT(("<func>%s</func>\n", fn));
166 PRINT(("TEST %02d: %-32s ", num, fn));
170 /*-----------------------------------------------------------------------------
172 *----------------------------------------------------------------------------*/
173 static void tc_Uninit (void) {
176 test_group_result.tests++;
178 if (as_failed > 0) { /* If any assertion failed => Failed */
179 test_group_result.failed++;
181 } else if (as_passed > 0) { /* If 1 assertion passed => Passed */
182 test_group_result.passed++;
184 } else { /* If no assertions => Not-executed */
188 #if (PRINT_XML_REPORT==1)
189 PRINT(("</dbgi>\n"));
190 PRINT(("<res>%s</res>\n", res));
194 if (as_detail != 0) {
197 PRINT(("%s\n", res));
201 /*-----------------------------------------------------------------------------
202 * Write test case detail
203 *----------------------------------------------------------------------------*/
204 static void tc_Detail (const char *module, uint32_t line, const char *message) {
206 module = no_path (module);
210 #if (PRINT_XML_REPORT==1)
211 PRINT(("<detail>\n"));
212 PRINT(("<module>%s</module>\n", module));
213 PRINT(("<line>%d</line>\n", line));
214 if (message != NULL) {
215 PRINT(("<message>%s</message>\n", message));
217 PRINT(("</detail>\n"));
219 PRINT(("\n %s (%d)", module, line));
220 if (message != NULL) {
221 PRINT((": %s", message));
226 /*-----------------------------------------------------------------------------
227 * Assertion result registering
228 *----------------------------------------------------------------------------*/
229 static void as_Result (TC_RES res) {
233 } else if (res == FAILED) {
238 /*-----------------------------------------------------------------------------
240 *----------------------------------------------------------------------------*/
241 void __set_result (const char *module, uint32_t line, const char *message, TC_RES res) {
244 if (message != NULL) {
245 tc_Detail(module, line, message);
252 /*-----------------------------------------------------------------------------
254 *----------------------------------------------------------------------------*/
255 void __set_message (const char *module, uint32_t line, const char *message) {
256 if (message != NULL) {
257 tc_Detail(module, line, message);
262 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
263 #pragma clang diagnostic push
264 #pragma clang diagnostic ignored "-Wformat-nonliteral"
266 /*-----------------------------------------------------------------------------
267 * MsgPrint: Print a message to the standard output
268 *----------------------------------------------------------------------------*/
269 void MsgPrint (const char *msg, ...) {
275 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
276 #pragma clang diagnostic pop
279 /*-----------------------------------------------------------------------------
280 * SER_MsgFlush: Flush the standard output
281 *----------------------------------------------------------------------------*/
282 void MsgFlush(void) {
286 /*-----------------------------------------------------------------------------
288 *----------------------------------------------------------------------------*/