1 /** Test framework support functions.
9 #include <tinibios.h> /* main() must see the ISR declarations */
13 /* until changed, isr's must have a prototype in the module containing main */
14 void T2_isr (void) __interrupt (5);
15 #define MEMSPACE_BUF __idata
20 /** Define this if the port's div or mod functions are broken.
21 A slow loop based method will be substituded.
23 //#define BROKEN_DIV_MOD 1
25 extern void _putchar(char c
);
26 extern void _initEmu(void);
27 extern void _exitEmu(void);
30 static int __numFailures
= 0;
32 #if BROKEN_DIV_MOD && !defined(TARGET_VERY_LOW_MEMORY)
34 __div(int num
, int denom
)
46 __mod (int num
, int denom
)
55 #define __div(num, denom) ((num) / (denom))
56 #define __mod(num, denom) ((num) % (denom))
60 __prints (const char *s
)
64 while ('\0' != (c
= *s
))
71 #ifdef TARGET_VERY_LOW_MEMORY
73 __printNibble (unsigned char c
)
86 #define SWAP_BYTE(x) ((x) >> 4 | (x) << 4)
95 // This seems to be the most efficient way to do it for PDK (both in RAM & ROM)
103 chr
= SWAP_BYTE(chr
);
105 chr
= SWAP_BYTE(chr
);
118 static char MEMSPACE_BUF buf
[6];
119 char MEMSPACE_BUF
*p
= &buf
[sizeof (buf
) - 1];
122 buf
[sizeof(buf
) - 1] = '\0';
132 *--p
= '0' + __mod (n
, 10);
144 __printu (unsigned int n
)
152 static char MEMSPACE_BUF buf
[6];
153 char MEMSPACE_BUF
*p
= &buf
[sizeof (buf
) - 1];
155 buf
[sizeof(buf
) - 1] = '\0';
159 *--p
= '0' + __mod (n
, 10);
170 __printf (const char *szFormat
, ...)
173 va_start (ap
, szFormat
);
177 if (*szFormat
== '%')
183 char *sz
= va_arg (ap
, char *);
190 int i
= va_arg (ap
, int);
197 unsigned int i
= va_arg (ap
, unsigned int);
212 _putchar (*szFormat
);
220 __fail (__code
const char *szMsg
, __code
const char *szCond
, __code
const char *szFile
, int line
)
222 __printf("--- FAIL: \"%s\" on %s at %s:%u\n", szMsg
, szCond
, szFile
, line
);
231 __printf("--- Running: %s\n", __getSuiteName());
235 __printf("--- Summary: %u/%u/%u: %u failed of %u tests in %u cases.\n",
236 __numFailures
, __numTests
, __numCases
,
237 __numFailures
, __numTests
, __numCases
246 __fail (__code
const char *szMsg
, __code
const char *szCond
, __code
const char *szFile
, int line
)
248 __prints("--- FAIL: \"");
266 __prints("--- Running: ");
267 __prints(__getSuiteName());
272 __prints("--- Summary: ");
273 __printd(__numFailures
);
275 __printd(__numTests
);
277 __printd(__numCases
);
279 #ifndef TARGET_VERY_LOW_MEMORY
281 __printd(__numFailures
);
282 __prints(" failed of ");
283 __printd(__numTests
);
284 __prints(" tests in ");
285 __printd(__numCases
);
286 __prints(" cases.\n");