Added log methods, added mod test
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 13 May 2001 17:15:54 +0000 (17:15 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 13 May 2001 17:15:54 +0000 (17:15 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@809 4a8a32a2-be11-0410-ad9d-d568d2c75423

support/regression/Makefile
support/regression/fwk/include/testfwk.h
support/regression/fwk/lib/testfwk.c
support/regression/ports/z80/spec.mk
support/regression/tests/increment.c
support/regression/tests/muldiv.c

index 5d596da459177266290ac218c150ddc74a145091..5ad6aad332fbab1687c13aec01df916785111e4d 100644 (file)
@@ -65,6 +65,11 @@ ALL_PORTS = $(filter-out CVS,$(notdir $(wildcard $(PORTS_DIR)/*)))
 test-ports:
        for i in $(ALL_PORTS); do $(MAKE) inter-port-clean test-port PORT=$$i; done
 
+# Helper rule for testing the z80 port only
+test-z80:
+       $(MAKE) inter-port-clean clean test-port PORT=z80
+
+test-z80:
 # Begin per-port rules
 # List of all of the known source test suites.
 ALL_TESTS = $(shell find $(TESTS_DIR) -name "*.c")
index 2e3a721fe2f39d175efbd70d6a3063e9eb937db1..54f559c9056326ea4268e9aa0d7f856b3f04d851 100644 (file)
@@ -4,8 +4,10 @@
 extern int __numTests;
 
 void __fail(const char *szMsg, const char *szCond, const char *szFile, int line);
+void __printf(const char *szFormat, ...);
 
-#define ASSERT(_a) (__numTests++, (_a) ? (void)0 : __fail("Assertion failed", #_a, __FILE__, __LINE__))
+#define ASSERT(_a)     (__numTests++, (_a) ? (void)0 : __fail("Assertion failed", #_a, __FILE__, __LINE__))
+#define LOG(_a)                __printf _a
 
 typedef void TESTFUN(void);
 
index 4ebace855c5eeedb5a3b7ed28fa93bcade93f117..0bfcbc0b679dec996ea8932dde8c75bfa5fdc37b 100644 (file)
@@ -3,16 +3,60 @@
 #include <testfwk.h>
 #include <stdarg.h>
 
-//#include <stdio.h>
+/** 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);
 
-static void _printn(int n) {
-    // PENDING
-    _putchar('0' + n);
+#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;
 }
 
-static void _printf(const char *szFormat, ...)
+int __mod(int num, int denom)
+{
+    return num%denom;
+}
+#endif
+
+static void _printn(int n) 
+{
+    int rem;
+
+    if (n < 0) {
+        _putchar('-');
+        n = -n;
+    }
+
+    rem = __mod(n, 10);
+    if (rem != n) {
+        _printn(__div(n, 10));
+    }
+    _putchar('0' + rem);
+}
+
+void __printf(const char *szFormat, ...)
 {
     va_list ap;
     va_start(ap, szFormat);
@@ -32,6 +76,9 @@ static void _printf(const char *szFormat, ...)
                 _printn(i);
                 break;
             }
+            case '%':
+                _putchar('%');
+                break;
             default:
                 break;
             }
@@ -50,7 +97,7 @@ int __numFailures;
 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++;
 }
 
@@ -60,18 +107,18 @@ main(void)
     TESTFUN **cases;
     int numCases = 0;
 
-    _printf("--- Running: %s\n", getSuiteName());
+    __printf("--- Running: %s\n", getSuiteName());
 
     cases = (TESTFUN **)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
            );
index 4dfbcc981d28a67eda75a5389b0f632698e2fa17..55c73c43e3f16d2555c42d94ef73b8c2d2b2edf7 100644 (file)
@@ -20,7 +20,7 @@ EXTRAS = fwk/lib/testfwk$(OBJEXT) ports/$(PORT)/support$(OBJEXT) \
 
 # Rule to link into .ihx
 %.ihx: %$(OBJEXT) $(EXTRAS)
-       ../../bin/link-z80 -n -- -b_CODE=0x200 -b_DATA=0x8000 -i $@ $< $(EXTRAS)
+       ../../bin/link-z80 -n -- -b_CODE=0x200 -b_DATA=0x8000 -j -i $@ $< $(EXTRAS)
 
 %$(OBJEXT): %.c fwk/include/*.h
        $(SDCC) $(SDCCFLAGS) -c $<
@@ -34,5 +34,6 @@ EXTRAS = fwk/lib/testfwk$(OBJEXT) ports/$(PORT)/support$(OBJEXT) \
 # PENDING: Path to sdcc-extra
 %.out: %$(EXEEXT)
        mkdir -p `dirname $@`
-       $(RRZ80) $< > $@
-       if grep -q FAIL $@; then echo FAILURES in $@; fi
+       $(RRZ80) --maxruntime=3 --mapfile=$(<:.bin=.sym) $< > $@
+       -grep -n FAIL $@ /dev/null || true
+
index 8807a65c9bdcbe0e7bfa5192dd99f0ba301f189c..bfbb22a0550b61aa573e24dc67f7cdc811dd6ca3 100644 (file)
@@ -2,7 +2,7 @@
 
     type: signed char, int, long
     storage: static, 
-    attr: volatile,
+    attr: volatile
 */
 #include <testfwk.h>
 
index ad3bdfc5560104cda06e0af63f9718c0f248b983..3757d04ccbb9edfef1c3b01e80b45062193ef8c0 100644 (file)
@@ -1,42 +1,66 @@
 /** Simple test for the mul/div/mod operations.
 
-    type: int
-    storage: , static
+    type: int, signed char, short
+    storage: static,
+    attr: volatile,
 */
 #include <testfwk.h>
 
 static void
 testMul(void)
 {
-#if SDCC
-    // Disabled as the z80 port is broken
-#else
-    volatile {storage} {type} i;
+    {attr} {storage} {type} i;
+    {type} result;
 
     i = 5;
-    ASSERT(i*5 == 25);
+
+    LOG(("i*5 == 25 = %u\n", (int)i*5));
+    result = i*5;
+    ASSERT(result == 25);
+    LOG(("i*-4 == -20 = %u\n", (int)i*-4));
     ASSERT(i*-4 == -20);
 
     i = -10;
+    LOG(("i*12 == -120 = %u\n", (int)i*12));
     ASSERT(i*12 == -120);
+    LOG(("i*-3 == 30 = %u\n", (int)i*-3));
     ASSERT(i*-3 == 30);
-#endif
+
+    LOG(("30 == %u\n", (int)i*-3));
 }
 
 static void
 testDiv(void)
 {
-#if SDCC
-    // Disabled as the z80 port is broken
-#else
-    volatile {storage} {type} i;
+    {attr} {storage} {type} i;
 
     i = 100;
+    LOG(("i/5 == 20 = %u\n", (int)i/5));
     ASSERT(i/5 == 20);
+    LOG(("i/-4 == -25 = %u\n", (int)i/-4));
     ASSERT(i/-4 == -25);
 
     i = -50;
+    LOG(("i/25 == -2 = %u\n", (int)i/25));
     ASSERT(i/25 == -2);
+    LOG(("i/-12 == 4 = %u\n", (int)i/-12));
     ASSERT(i/-12 == 4);
-#endif
+}
+
+static void
+disabled_testMod(void)
+{
+    {attr} {storage} {type} i;
+
+    i = 100;
+    LOG(("i%%17 == 15 = %u\n", (int)(i%9)));
+    ASSERT(i%17 == 15);
+    LOG(("i%%-7 == 2 = %u\n", (int)i%-7));
+    ASSERT(i%-7 == 2);
+
+    i = -49;
+    LOG(("i%%3 == -1 = %u\n", (int)i%3));
+    ASSERT(i%3 == -1);
+    LOG(("i%%-5 == -4 = %u\n", (int)i%-5));
+    ASSERT(i%-5 == -4);
 }