]> begriffs open source - cmsis-driver-validation/blob - Source/DV_Report.c
Updated WiFi test example for STMicroelectonics B-L475E-IOT01A1 board (added test...
[cmsis-driver-validation] / Source / DV_Report.c
1 /*-----------------------------------------------------------------------------
2  *      Name:         DV_Report.c 
3  *      Purpose:      Report statistics and layout implementation
4  *-----------------------------------------------------------------------------
5  *      Copyright(c) KEIL - An ARM Company
6  *----------------------------------------------------------------------------*/
7
8 #include "DV_Report.h"
9
10
11 /* Local macros */
12 #define PRINT(x) MsgPrint x
13 #define FLUSH()  MsgFlush()
14
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);
18
19 /* Local functions */
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);
28
29 static void MsgPrint (const char *msg, ...);
30 static void MsgFlush (void);
31
32 /* Global variables */
33 REPORT_ITF ritf = {                     /* Structure for report interface     */
34   tr_Init,
35   tr_Uninit,
36   tg_Init,
37   tg_Uninit,
38   tc_Init,
39   tc_Uninit,
40   tc_Detail,
41   as_Result
42 };
43
44 /* Local variables */
45 static TEST_GROUP_RESULTS test_group_result;    /* Test group results         */
46
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";
53
54
55 /*-----------------------------------------------------------------------------
56  * No path - helper function
57  *----------------------------------------------------------------------------*/
58 static const char *no_path (const char *fn) {
59   const char *cp;
60 #if defined(__CC_ARM)
61   cp = strrchr(fn, '\\');
62 #else
63   cp = strrchr(fn, '/');
64 #endif
65   if (cp) return (cp + 1);
66   return (fn);
67 }
68
69 /*-----------------------------------------------------------------------------
70  * Init test report
71  *----------------------------------------------------------------------------*/
72 static void tr_Init (void) {
73
74   test_group_result.idx = 0;
75
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"));
80 #else
81   PRINT(("                                \n\n"));
82 #endif  
83 }
84
85 /*-----------------------------------------------------------------------------
86  * Uninit test report
87  *----------------------------------------------------------------------------*/
88 static void tr_Uninit (void) {
89 #if (PRINT_XML_REPORT==1)
90   PRINT(("</report>\n"));
91 #endif
92 }
93
94 /*-----------------------------------------------------------------------------
95  * Init test group
96  *----------------------------------------------------------------------------*/
97 static void tg_Init (const char *title, const char *date, const char *time, const char *fn) {
98
99   test_group_result.idx++;
100   test_group_result.tests  = 0;
101   test_group_result.passed = 0;
102   test_group_result.failed = 0;
103
104 #if (PRINT_XML_REPORT==1)
105   PRINT(("<test>\n"));
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"));
112 #else
113   (void) fn;
114   PRINT(("%s   %s   %s \n\n", title, date, time));
115 #endif  
116 }
117
118 /*-----------------------------------------------------------------------------
119  * Uninit test group
120  *----------------------------------------------------------------------------*/
121 static void tg_Uninit (void) {
122   const char *tres;
123
124   if (test_group_result.failed > 0) {   /* If any test failed => Failed       */
125     tres = Failed;
126   } else if (test_group_result.passed > 0) {    /* If 1 passed => Passed      */
127     tres = Passed;
128   } else {                              /* If no tests exec => Not-executed   */
129     tres = NotExe;
130   }
131
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"));
141 #else
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));
147 #endif 
148   FLUSH();
149 }
150
151 /*-----------------------------------------------------------------------------
152  * Init test case
153  *----------------------------------------------------------------------------*/
154 static void tc_Init (uint32_t num, const char *fn) {
155
156   as_passed = 0;
157   as_failed = 0;
158   as_detail = 0;
159
160 #if (PRINT_XML_REPORT==1)   
161   PRINT(("<tc>\n"));
162   PRINT(("<no>%d</no>\n",     num));
163   PRINT(("<func>%s</func>\n", fn));
164   PRINT(("<dbgi>\n"));
165 #else
166   PRINT(("TEST %02d: %-32s ", num, fn));
167 #endif 
168 }
169
170 /*-----------------------------------------------------------------------------
171  * Uninit test case
172  *----------------------------------------------------------------------------*/
173 static void tc_Uninit (void) {
174   const char *res;
175
176   test_group_result.tests++;
177
178   if (as_failed > 0) {                  /* If any assertion failed => Failed  */
179     test_group_result.failed++;
180     res = Failed;
181   } else if (as_passed > 0) {           /* If 1 assertion passed => Passed    */
182     test_group_result.passed++;
183     res = Passed;
184   } else {                              /* If no assertions => Not-executed   */
185     res = NotExe;
186   }
187
188 #if (PRINT_XML_REPORT==1) 
189   PRINT(("</dbgi>\n"));
190   PRINT(("<res>%s</res>\n", res));
191   PRINT(("</tc>\n"));
192   (void)as_detail;
193 #else
194   if (as_detail != 0) {
195     PRINT(("\n                                          "));
196   }
197   PRINT(("%s\n", res));
198 #endif 
199 }
200
201 /*-----------------------------------------------------------------------------
202  * Write test case detail
203  *----------------------------------------------------------------------------*/
204 static void tc_Detail (const char *module, uint32_t line, const char *message) {
205
206   module = no_path (module);
207
208   as_detail = 1;
209
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));
216   }
217   PRINT(("</detail>\n"));
218 #else
219   PRINT(("\n  %s (%d)", module, line));
220   if (message != NULL) {
221     PRINT((": %s", message));
222   }
223 #endif
224 }
225
226 /*-----------------------------------------------------------------------------
227  * Assertion result registering
228  *----------------------------------------------------------------------------*/
229 static void as_Result (TC_RES res) {
230
231   if (res == PASSED) {
232     as_passed++;
233   } else if (res == FAILED) {
234     as_failed++;
235   }
236 }
237
238 /*-----------------------------------------------------------------------------
239  * Set result
240  *----------------------------------------------------------------------------*/
241 void __set_result (const char *module, uint32_t line, const char *message, TC_RES res) {
242
243   // Set debug info
244   if (message != NULL) {
245     tc_Detail(module, line, message);
246   }
247
248   // Set result
249   as_Result(res);
250 }
251
252 /*-----------------------------------------------------------------------------
253  * Set message
254  *----------------------------------------------------------------------------*/
255 void __set_message (const char *module, uint32_t line, const char *message) {
256   if (message != NULL) {
257     tc_Detail(module, line, message);
258   }
259 }
260
261
262 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
263 #pragma clang diagnostic push
264 #pragma clang diagnostic ignored "-Wformat-nonliteral"
265 #endif
266 /*-----------------------------------------------------------------------------
267  *       MsgPrint:  Print a message to the standard output
268  *----------------------------------------------------------------------------*/
269 void MsgPrint (const char *msg, ...) {
270   va_list args;
271   va_start(args, msg);
272   vprintf(msg, args);
273   va_end(args);
274 }
275 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
276 #pragma clang diagnostic pop
277 #endif
278
279 /*-----------------------------------------------------------------------------
280  *       SER_MsgFlush:  Flush the standard output
281  *----------------------------------------------------------------------------*/
282 void MsgFlush(void) {
283   fflush(stdout);
284 }
285
286 /*-----------------------------------------------------------------------------
287  * End of file
288  *----------------------------------------------------------------------------*/