]> git.gag.com Git - fw/sdcc/blobdiff - support/regression/fwk/lib/testfwk.c
* .version: bumped version to 2.4.7
[fw/sdcc] / support / regression / fwk / lib / testfwk.c
index 4ebace855c5eeedb5a3b7ed28fa93bcade93f117..4753dea39655ac3e1ff7df624d187004a3b9e265 100644 (file)
@@ -3,16 +3,76 @@
 #include <testfwk.h>
 #include <stdarg.h>
 
-//#include <stdio.h>
+#ifdef __ds390
+#include <tinibios.h> /* main() must see the ISR declarations */
+#endif
+
+#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80)
+#define _REENTRANT
+#else
+#define _REENTRANT reentrant
+#endif
+
+#if defined(SDCC_mcs51)
+/* until changed, isr's must have a prototype in the module containing main */
+void T2_isr (void) interrupt 5;
+#endif
+
+/** Define this if the port's div or mod functions are broken.
+    A slow loop based method will be substituded.
+*/
+//#define BROKEN_DIV_MOD               1
 
 void _putchar(char c);
+void _exitEmu(void);
+
+#if BROKEN_DIV_MOD
+int __div(int num, int denom)
+{
+    int q = 0;
+    while (num >= denom) {
+        q++;
+        num -= denom;
+    }
+    return q;
+}
+
+int __mod(int num, int denom)
+{
+    while (num >= denom) {
+        num -= denom;
+    }
+    return num;
+}
+#else
+int __div(int num, int denom)
+{
+    return num/denom;
+}
+
+int __mod(int num, int denom)
+{
+    return num%denom;
+}
+#endif
+
+static void _printn(int n) _REENTRANT
+{
+    int rem;
 
-static void _printn(int n) {
-    // PENDING
-    _putchar('0' + n);
+    if (n < 0) {
+        _putchar('-');
+        n = -n;
+    }
+
+    rem = __mod(n, 10);
+    if (rem != n) {
+        _printn(__div(n, 10));
+    }
+    _putchar('0' + rem);
 }
 
-static void _printf(const char *szFormat, ...)
+void __printf(const char *szFormat, ...) REENTRANT
 {
     va_list ap;
     va_start(ap, szFormat);
@@ -21,7 +81,7 @@ static void _printf(const char *szFormat, ...)
         if (*szFormat == '%') {
             switch (*++szFormat) {
             case 's': {
-                const char *sz = va_arg(ap, const char *);
+                char *sz = va_arg(ap, char *);
                 while (*sz) {
                     _putchar(*sz++);
                 }
@@ -32,6 +92,9 @@ static void _printf(const char *szFormat, ...)
                 _printn(i);
                 break;
             }
+            case '%':
+                _putchar('%');
+                break;
             default:
                 break;
             }
@@ -47,34 +110,36 @@ static void _printf(const char *szFormat, ...)
 int __numTests;
 int __numFailures;
 
-void 
+void
 __fail(const char *szMsg, const char *szCond, const char *szFile, int line)
 {
-    _printf("--- FAIL: \"%s\" on %s at %s:%u\n", szMsg, szCond, szFile, line);
+    __printf("--- FAIL: \"%s\" on %s at %s:%u\n", szMsg, szCond, szFile, line);
     __numFailures++;
 }
 
-int 
+int
 main(void)
 {
-    TESTFUN **cases;
+    TESTFUN*cases;
     int numCases = 0;
 
-    _printf("--- Running: %s\n", getSuiteName());
+    __printf("--- Running: %s\n", getSuiteName());
 
-    cases = (TESTFUN **)suite();
+    cases = suite();
 
     while (*cases) {
-        _printf("Running %u\n", numCases);
+        __printf("Running %u\n", numCases);
         (*cases)();
         cases++;
         numCases++;
     }
-    
-    _printf("--- Summary: %u/%u/%u: %u failed of %u tests in %u cases.\n", 
+
+    __printf("--- Summary: %u/%u/%u: %u failed of %u tests in %u cases.\n",
            __numFailures, __numTests, numCases,
            __numFailures, __numTests, numCases
            );
 
-    return __numFailures;
+    _exitEmu();
+
+    return 0;
 }