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
+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,
# 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)/*)))
#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
#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;
*/
//#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) {
return q;
}
-int __mod(int num, int denom)
+static int
+__mod(int num, int denom)
{
while (num >= denom) {
num -= 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;
}
Serial0PutChar (c);
}
+void
+_initEmu (void)
+{
+}
+
void
_exitEmu (void)
{
__putchar::
jp _putchar
+__initEmu::
+ ret
+
__exitEmu::
jp _exit
_endasm;
}
+void
+_initEmu(void)
+{
+}
+
void
_exitEmu(void)
{
#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);
}
TI = 0;
}
+void
+_initEmu (void)
+{
+}
+
void
_exitEmu (void)
{
--- /dev/null
+# 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
--- /dev/null
+/*-------------------------------------------------------------------------
+ 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;
+}
__putchar::
jp _putchar
+__initEmu::
+ ret
+
__exitEmu::
jp _exit
_endasm;
}
+void
+_initEmu (void)
+{
+}
+
void
_exitEmu (void)
{
__putchar::
jp _putchar
+__initEmu::
+ ret
+
__exitEmu::
jp _exit