* support/regression/fwk/lib/testfwk.c,
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 3 Mar 2006 19:32:46 +0000 (19:32 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 3 Mar 2006 19:32:46 +0000 (19:32 +0000)
  support/regression/fwk/include/testfwk.h: introduced function
  _prints(), nonrecursive _printn(), call _initEmu() from main()
* support/regression/ports/gbz80/support.asm,
  support/regression/ports/ucz80/support.asm,
  support/regression/ports/z80/support.asm,
  support/regression/ports/ds390/support.c,
  support/regression/ports/hc08/support.c,
  support/regression/ports/host/support.c,
  support/regression/ports/mcs51/support.c,
  support/regression/ports/xa51/support.c: added empty _initEmu() function
* support/regression/ports/pic16/gpsim.cmd,
  support/regression/ports/pic16/spec.mk,
  support/regression/ports/pic16/support.c,
  support/regression/Makefile.in: added pic16 regression test

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4049 4a8a32a2-be11-0410-ad9d-d568d2c75423

15 files changed:
ChangeLog
support/regression/Makefile.in
support/regression/fwk/include/testfwk.h
support/regression/fwk/lib/testfwk.c
support/regression/ports/ds390/support.c
support/regression/ports/gbz80/support.asm
support/regression/ports/hc08/support.c
support/regression/ports/host/support.c
support/regression/ports/mcs51/support.c
support/regression/ports/pic16/gpsim.cmd [new file with mode: 0755]
support/regression/ports/pic16/spec.mk [new file with mode: 0644]
support/regression/ports/pic16/support.c [new file with mode: 0644]
support/regression/ports/ucz80/support.asm
support/regression/ports/xa51/support.c
support/regression/ports/z80/support.asm

index 65c7c3ea7be5dfccec00d74903b72d7727ad18bc..e70abe4df289d48ef6bd5600f5891d359cb38af1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2006-03-02 Borut Razem <borut.razem AT siol.net>
+
+       * support/regression/fwk/lib/testfwk.c,
+         support/regression/fwk/include/testfwk.h: introduced function
+         _prints(), nonrecursive _printn(), call _initEmu() from main()
+       * support/regression/ports/gbz80/support.asm,
+         support/regression/ports/ucz80/support.asm,
+         support/regression/ports/z80/support.asm,
+         support/regression/ports/ds390/support.c,
+         support/regression/ports/hc08/support.c,
+         support/regression/ports/host/support.c,
+         support/regression/ports/mcs51/support.c,
+         support/regression/ports/xa51/support.c: added empty _initEmu()
+         function
+       * support/regression/ports/pic16/gpsim.cmd,
+         support/regression/ports/pic16/spec.mk,
+         support/regression/ports/pic16/support.c,
+         support/regression/Makefile.in: added pic16 regression test
+
 2006-03-01 Raphael Neider <rneider AT web.de>
 
        * src/pic16/gen.c (genPcall,pic16_derefPtr,genGenPointerGet,
index 6450e85b79350364a0f83f494ade29501cfdf76d..0c5e55dca3c50f16eaa9f620872b378508972fb5 100644 (file)
@@ -62,7 +62,7 @@ GENERATE_CASES = generate-cases.py
 # Each directory under ports/ is used as a port name.  Each port is tested.
 # Each port must have a spec.mk which describes how to build the object
 # files and how to run the emulator.
-ALL_PORTS = $(filter-out CVS xa51 ucz80 gbz80,$(notdir $(wildcard $(PORTS_DIR)/*)))
+ALL_PORTS = $(filter-out CVS xa51 ucz80 gbz80 pic16,$(notdir $(wildcard $(PORTS_DIR)/*)))
 
 # These  ports will be cleaned with 'make clean'
 CLEAN_PORTS = $(filter-out CVS,$(notdir $(wildcard $(PORTS_DIR)/*)))
index 07cfa31fade3859533774e4f01c30cbd8e15072f..2f8c3225dd907a7af607b377c278222bd9737a2a 100644 (file)
@@ -1,27 +1,25 @@
 #ifndef __TESTFWK_H
-#define __TESTFWK_H 1
+#define __TESTFWK_H   1
 
 extern int __numTests;
 
 void __fail(const char *szMsg, const char *szCond, const char *szFile, int line);
-void __printf(const char *szFormat, ...) REENTRANT;
+void __printf(const char *szFormat, ...);
 
-#define ASSERT(_a)     (__numTests++, (_a) ? (void)0 : __fail("Assertion failed", #_a, __FILE__, __LINE__))
-#define LOG(_a)                __printf _a
-#define FAIL()         FAILM("Failure")
-#define FAILM(_a)      __fail(_a, #_a, __FILE__, __LINE__)
+#define ASSERT(_a)  (__numTests++, (_a) ? (void)0 : __fail("Assertion failed", #_a, __FILE__, __LINE__))
+#define LOG(_a)     __printf _a
+#define FAIL()      FAILM("Failure")
+#define FAILM(_a)   __fail(_a, #_a, __FILE__, __LINE__)
 
 typedef void (*TESTFUNP)(void);
 
 // Provided by the suite
-TESTFUNP *
-suite(void);
+TESTFUNP *suite(void);
 
-const char *
-getSuiteName(void);
+const char *getSuiteName(void);
 
-#define NULL   0
+#define NULL  0
 
-#define UNUSED(_a)     if (_a) { }
+#define UNUSED(_a)  if (_a) { }
 
 #endif
index 4753dea39655ac3e1ff7df624d187004a3b9e265..7bad2a3ecaf9d20745ca6545e733c832790c156a 100644 (file)
@@ -7,12 +7,6 @@
 #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;
@@ -23,11 +17,13 @@ void T2_isr (void) interrupt 5;
 */
 //#define BROKEN_DIV_MOD               1
 
-void _putchar(char c);
-void _exitEmu(void);
+extern void _putchar(char c);
+extern void _initEmu(void);
+extern void _exitEmu(void);
 
 #if BROKEN_DIV_MOD
-int __div(int num, int denom)
+static int
+__div(int num, int denom)
 {
     int q = 0;
     while (num >= denom) {
@@ -37,7 +33,8 @@ int __div(int num, int denom)
     return q;
 }
 
-int __mod(int num, int denom)
+static int
+__mod(int num, int denom)
 {
     while (num >= denom) {
         num -= denom;
@@ -45,101 +42,120 @@ int __mod(int num, int denom)
     return num;
 }
 #else
-int __div(int num, int denom)
-{
-    return num/denom;
-}
+#define __div(num, denom) ((num) / (denom))
+#define __mod(num, denom) ((num) % (denom))
+#endif
 
-int __mod(int num, int denom)
+static void
+_prints(const char *s)
 {
-    return num%denom;
+  char c;
+
+  while ('\0' != (c = *s)) {
+    _putchar(c);
+    ++s;
+  }
 }
-#endif
 
-static void _printn(int n) _REENTRANT
+static void
+_printn(int n)
 {
-    int rem;
-
-    if (n < 0) {
-        _putchar('-');
-        n = -n;
+  if (0 == n) {
+    _putchar('0');
+  }
+  else {
+    char buf[6];
+    char *p = &buf[sizeof(buf) - 1];
+    char neg = 0;
+
+    buf[sizeof(buf) - 1] = '\0';
+
+    if (0 > n) {
+      n = -n;
+      neg = 1;
     }
-
-    rem = __mod(n, 10);
-    if (rem != n) {
-        _printn(__div(n, 10));
+  
+    while (0 != n) {
+      *--p = '0' + __mod(n, 10);
+      n = __div(n, 10);
     }
-    _putchar('0' + rem);
+
+    if (neg)
+      _putchar('-');
+
+    _prints(p);
+  }
 }
 
-void __printf(const char *szFormat, ...) REENTRANT
+void
+__printf(const char *szFormat, ...)
 {
-    va_list ap;
-    va_start(ap, szFormat);
-
-    while (*szFormat) {
-        if (*szFormat == '%') {
-            switch (*++szFormat) {
-            case 's': {
-                char *sz = va_arg(ap, char *);
-                while (*sz) {
-                    _putchar(*sz++);
-                }
-                break;
-            }
-            case 'u': {
-                int i = va_arg(ap, int);
-                _printn(i);
-                break;
-            }
-            case '%':
-                _putchar('%');
-                break;
-            default:
-                break;
-            }
-        }
-        else {
-            _putchar(*szFormat);
-        }
-        szFormat++;
+  va_list ap;
+  va_start(ap, szFormat);
+
+  while (*szFormat) {
+    if (*szFormat == '%') {
+      switch (*++szFormat) {
+      case 's': {
+        char *sz = va_arg(ap, char *);
+        _prints(sz);
+        break;
+      }
+      case 'u': {
+        int i = va_arg(ap, int);
+        _printn(i);
+        break;
+      }
+      case '%':
+        _putchar('%');
+        break;
+      default:
+        break;
+      }
+    }
+    else {
+      _putchar(*szFormat);
     }
-    va_end(ap);
+    szFormat++;
+  }
+  va_end(ap);
 }
 
-int __numTests;
-int __numFailures;
+int __numTests = 0;
+static int __numFailures = 0;
 
 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);
-    __numFailures++;
+  __printf("--- FAIL: \"%s\" on %s at %s:%u\n", szMsg, szCond, szFile, line);
+  __numFailures++;
 }
 
 int
 main(void)
 {
-    TESTFUNP *cases;
-    int numCases = 0;
+  TESTFUNP *cases;
+  int numCases = 0;
 
-    __printf("--- Running: %s\n", getSuiteName());
+  _initEmu();
 
-    cases = suite();
+  __printf("--- Running: %s\n", getSuiteName());
 
-    while (*cases) {
-        __printf("Running %u\n", numCases);
-        (*cases)();
-        cases++;
-        numCases++;
-    }
+  cases = suite();
+
+  while (*cases) {
+    __printf("Running %u\n", numCases);
+    (*cases)();
+    cases++;
+    numCases++;
+  }
 
-    __printf("--- Summary: %u/%u/%u: %u failed of %u tests in %u cases.\n",
-           __numFailures, __numTests, numCases,
-           __numFailures, __numTests, numCases
-           );
+  __printf("--- Summary: %u/%u/%u: %u failed of %u tests in %u cases.\n",
+     __numFailures, __numTests, numCases,
+     __numFailures, __numTests, numCases
+     );
 
-    _exitEmu();
+  _exitEmu();
 
-    return 0;
+  return 0;
 }
index 7ced42f70940028c52557e1c552c18a8cbc00f43..f582f22fbd224ef49b8dccf3e4f3430a1c4c2daa 100644 (file)
@@ -30,6 +30,11 @@ _putchar (char c)
   Serial0PutChar (c);
 }
 
+void
+_initEmu (void)
+{
+}
+
 void
 _exitEmu (void)
 {
index 01e0ef8b73cdd4953f84dff75780a9f2e6455f73..c16fa2ab3583365220c9b546c9c27d24bc0e1814 100644 (file)
@@ -5,5 +5,8 @@
 __putchar::
         jp      _putchar
 
+__initEmu::
+        ret
+
 __exitEmu::
         jp      _exit
index efb77ca640a3a697958178d02229d3673e7ecfab..69705c2a64a1ff20b929431227345ec18d32fb62 100644 (file)
@@ -8,6 +8,11 @@ _putchar(unsigned char c)
   _endasm;
 }
 
+void
+_initEmu(void)
+{
+}
+
 void
 _exitEmu(void)
 {
index 1077fb5b5eb767e9909816c460a81c21b38ff028..3921b47c65cbc7180b049e7936a39c6efca53eab 100644 (file)
@@ -3,12 +3,19 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-void _putchar(char c)
+void
+_putchar(char c)
 {
     putchar(c);
 }
 
-void _exitEmu(void)
+void
+_initEmu(void)
+{
+}
+
+void
+_exitEmu(void)
 {
     exit(0);
 }
index ddb75582bc5f9e2c2285aaad60c98998e9324e26..47ddf35bf636c0f83e261bc872a752ca38bb6f31 100644 (file)
@@ -27,6 +27,11 @@ _putchar (char c)
   TI = 0;
 }
 
+void
+_initEmu (void)
+{
+}
+
 void
 _exitEmu (void)
 {
diff --git a/support/regression/ports/pic16/gpsim.cmd b/support/regression/ports/pic16/gpsim.cmd
new file mode 100755 (executable)
index 0000000..58afc78
--- /dev/null
@@ -0,0 +1,2 @@
+run
+quit
diff --git a/support/regression/ports/pic16/spec.mk b/support/regression/ports/pic16/spec.mk
new file mode 100644 (file)
index 0000000..2716781
--- /dev/null
@@ -0,0 +1,43 @@
+# Port specification for the pic16 port running with uCsim
+
+# path to gpsim
+ifdef GPSIM_PATH
+  GPSIM := $(GPSIM_PATH)/gpsim
+else
+  GPSIM := gpsim
+endif
+
+SDCCFLAGS += -mpic16 -I$(SDCC_DIR)/device/include/pic16 --nostdinc --less-pedantic -Wl,-t255 -DREENTRANT=reentrant
+LINKFLAGS = --nostdlib
+LINKFLAGS += libsdcc.lib libc18f.lib
+LIBDIR = $(SDCC_DIR)/device/lib/build/pic16
+
+OBJEXT = .o
+EXEEXT = .cod
+
+EXTRAS = $(PORTS_DIR)/$(PORT)/testfwk$(OBJEXT) $(PORTS_DIR)/$(PORT)/support$(OBJEXT)
+
+# Rule to link into .ihx
+%$(EXEEXT): %$(OBJEXT) $(EXTRAS)
+       $(SDCC) $(SDCCFLAGS) $(LINKFLAGS) -L $(LIBDIR) $(EXTRAS) $< -o $@
+
+%$(OBJEXT): %.c
+       $(SDCC) $(SDCCFLAGS) -c $< -o $@
+
+$(PORTS_DIR)/$(PORT)/testfwk$(OBJEXT): fwk/lib/testfwk.c
+       $(SDCC) $(SDCCFLAGS) -c $< -o $@
+
+# run simulator with 25 seconds timeout
+%.out: %$(EXEEXT) fwk/lib/timeout
+       mkdir -p `dirname $@`
+       -fwk/lib/timeout 25 $(GPSIM) -i -s $< -c $(PORTS_DIR)/pic16/gpsim.cmd > $@ || \
+          echo -e --- FAIL: \"timeout, simulation killed\" in $(<:$(EXEEXT)=.c)"\n"--- Summary: 1/1/1: timeout >> $@
+       python get_ticks.py < $@ >> $@
+       -grep -n FAIL $@ /dev/null || true
+
+fwk/lib/timeout: fwk/lib/timeout.c
+
+_clean:
+       rm -f fwk/lib/timeout fwk/lib/timeout.exe $(PORTS_DIR)/$(PORT)/*.rel $(PORTS_DIR)/$(PORT)/*.rst \
+             $(PORTS_DIR)/$(PORT)/*.lst $(PORTS_DIR)/$(PORT)/*.sym $(PORTS_DIR)/$(PORT)/*.asm \
+             $(PORTS_DIR)/$(PORT)/*.lnk $(PORTS_DIR)/$(PORT)/*.map $(PORTS_DIR)/$(PORT)/*.mem
diff --git a/support/regression/ports/pic16/support.c b/support/regression/ports/pic16/support.c
new file mode 100644 (file)
index 0000000..281ebb1
--- /dev/null
@@ -0,0 +1,102 @@
+/*-------------------------------------------------------------------------
+  support.c - startup for PIC16 regression tests with gpsim
+  
+  Copyright (c) 2006 Borut Razem
+    
+  This program is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License as published by the
+  Free Software Foundation; either version 2, or (at your option) any
+  later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+   
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+  In other words, you are welcome to use, share and improve this program.
+  You are forbidden to forbid anyone else to use, share and improve
+  what you give them.   Help stamp out software-hoarding!
+-------------------------------------------------------------------------*/
+
+#pragma preproc_asm -
+#include <pic18f452.h>
+
+
+void
+_putchar(char c)
+{
+  while (!PIR1bits.TXIF)
+    ;
+  TXREG = c;
+}
+
+
+void
+_initEmu(void)
+{
+  /* load and configure the libgpsim_usart_con module */
+  _asm
+    ;; Set frequency to 20MHz
+    .direct "e", ".frequency=20e6"
+    
+    ;; Load the USART library and module
+    .direct "e", "module library libgpsim_usart_con"
+    .direct "e", "module load usart_con U1"
+
+    ;; Define a node
+    .direct "e", "node PIC_tx"
+
+    ;; Tie the USART module to the PIC
+    .direct "e", "attach PIC_tx portc6 U1.RXPIN"
+
+    ;; Set the USART module's Baud Rate
+    .direct "e", "U1.rxbaud = 9600"
+  _endasm;
+
+  /* USART initialization */
+  PORTCbits.TX = 1;     // Set TX pin to 1
+  TRISCbits.TRISC6 = 0; // TX pin is output
+
+  TXSTA = 0;            // Reset USART registers to POR state
+  RCSTA = 0;
+
+  //1. Initialize the SPBRG register for the appropriate
+  //   baud rate. If a high speed baud rate is desired,
+  //   set bit BRGH (Section 16.1).
+  TXSTAbits.BRGH = 1;
+  SPBRG = 129;
+
+  //2. Enable the asynchronous serial port by clearing
+  //   bit SYNC and setting bit SPEN.
+  RCSTAbits.SPEN = 1;
+
+  //3. If interrupts are desired, set enable bit TXIE.
+  //4. If 9-bit transmission is desired, set transmit bit
+  //   TX9. Can be used as address/data bit.
+  //5. Enable the transmission by setting bit TXEN,
+  //   which will also set bit TXIF.
+  TXSTAbits.TXEN = 1;
+
+  //6. If 9-bit transmission is selected, the ninth bit
+  //   should be loaded in bit TX9D.
+  //7. Load data to the TXREG register (starts
+  //   transmission).
+}
+
+
+void
+_exitEmu(void)
+{
+  /* wait until the transmit buffer is empty */
+  while (!TXSTAbits.TRMT)
+    ;
+
+  /* set the breakpoint */
+  _asm
+   .direct "a", "\"\""
+  _endasm;
+}
index 01e0ef8b73cdd4953f84dff75780a9f2e6455f73..c16fa2ab3583365220c9b546c9c27d24bc0e1814 100644 (file)
@@ -5,5 +5,8 @@
 __putchar::
         jp      _putchar
 
+__initEmu::
+        ret
+
 __exitEmu::
         jp      _exit
index 8b0919175f2a10777a2ce695f34702ddec64a819..85c986762089ab186b00549de727eb48dfc74331 100755 (executable)
@@ -36,6 +36,11 @@ _putchar (char c)
   _endasm;
 }
 
+void
+_initEmu (void)
+{
+}
+
 void
 _exitEmu (void)
 {
index 01e0ef8b73cdd4953f84dff75780a9f2e6455f73..c16fa2ab3583365220c9b546c9c27d24bc0e1814 100644 (file)
@@ -5,5 +5,8 @@
 __putchar::
         jp      _putchar
 
+__initEmu::
+        ret
+
 __exitEmu::
         jp      _exit