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")
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);
#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);
_printn(i);
break;
}
+ case '%':
+ _putchar('%');
+ break;
default:
break;
}
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++;
}
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
);
# 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 $<
# 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
+
type: signed char, int, long
storage: static,
- attr: volatile,
+ attr: volatile
*/
#include <testfwk.h>
/** 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);
}