From: michaelh Date: Sun, 13 May 2001 17:15:54 +0000 (+0000) Subject: Added log methods, added mod test X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=81d1bf22460fdc85ca5b000820079c3d055cb864;p=fw%2Fsdcc Added log methods, added mod test git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@809 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/support/regression/Makefile b/support/regression/Makefile index 5d596da4..5ad6aad3 100644 --- a/support/regression/Makefile +++ b/support/regression/Makefile @@ -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") diff --git a/support/regression/fwk/include/testfwk.h b/support/regression/fwk/include/testfwk.h index 2e3a721f..54f559c9 100644 --- a/support/regression/fwk/include/testfwk.h +++ b/support/regression/fwk/include/testfwk.h @@ -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); diff --git a/support/regression/fwk/lib/testfwk.c b/support/regression/fwk/lib/testfwk.c index 4ebace85..0bfcbc0b 100644 --- a/support/regression/fwk/lib/testfwk.c +++ b/support/regression/fwk/lib/testfwk.c @@ -3,16 +3,60 @@ #include #include -//#include +/** 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 ); diff --git a/support/regression/ports/z80/spec.mk b/support/regression/ports/z80/spec.mk index 4dfbcc98..55c73c43 100644 --- a/support/regression/ports/z80/spec.mk +++ b/support/regression/ports/z80/spec.mk @@ -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 + diff --git a/support/regression/tests/increment.c b/support/regression/tests/increment.c index 8807a65c..bfbb22a0 100644 --- a/support/regression/tests/increment.c +++ b/support/regression/tests/increment.c @@ -2,7 +2,7 @@ type: signed char, int, long storage: static, - attr: volatile, + attr: volatile */ #include diff --git a/support/regression/tests/muldiv.c b/support/regression/tests/muldiv.c index ad3bdfc5..3757d04c 100644 --- a/support/regression/tests/muldiv.c +++ b/support/regression/tests/muldiv.c @@ -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 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); }