From: borutr Date: Sat, 12 Aug 2006 20:13:39 +0000 (+0000) Subject: * support/regression/fwk/include/testfwk.h, X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=527df2cf2950118c1406a65102bf15d909747e08;p=fw%2Fsdcc * support/regression/fwk/include/testfwk.h, support/regression/fwk/lib/testfwk.c, support/regression/generate-cases.py, support/regression/Makefile.in: regression test framework does not depend on function pointers and variable arguments git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4334 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 957ffeed..2ac9557f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-08-12 Borut Razem + + * support/regression/fwk/include/testfwk.h, + support/regression/fwk/lib/testfwk.c, + support/regression/generate-cases.py, + support/regression/Makefile.in: + regression test framework does not depend on function pointers and + variable arguments + 2006-08-09 Maarten Brock * device/include/stddef.h: c temporary hack to fix bug 1518273 diff --git a/support/regression/Makefile.in b/support/regression/Makefile.in index 3378a7b0..384a549e 100644 --- a/support/regression/Makefile.in +++ b/support/regression/Makefile.in @@ -41,7 +41,7 @@ .SILENT: CC = @CC@ -CPPFLAGS = @CPPFLAGS@ +CPPFLAGS = @CPPFLAGS@ -DNO_VARARGS # support VPATH: VPATH = @srcdir@ @@ -150,7 +150,7 @@ INC_DIR = $(top_srcdir)/device/include # Path to SDCC SDCC = $(top_builddir)bin/sdcc # Base flags. -SDCCFLAGS += +SDCCFLAGS += -DNO_VARARGS # Extension of object intermediate files OBJEXT = .o # Extension of files that can be run in the emulator diff --git a/support/regression/fwk/include/testfwk.h b/support/regression/fwk/include/testfwk.h index 85c780eb..bfe3d34e 100644 --- a/support/regression/fwk/include/testfwk.h +++ b/support/regression/fwk/include/testfwk.h @@ -2,22 +2,25 @@ #define __TESTFWK_H 1 extern int __numTests; +extern const int __numCases; -void __fail(const char *szMsg, const char *szCond, const char *szFile, int line); +#ifndef NO_VARARGS void __printf(const char *szFormat, ...); +#define LOG(_a) __printf _a +#else +#define LOG(_a) /* hollow log */ +#endif + +void __fail(const char *szMsg, const char *szCond, const char *szFile, int line); +void __prints(const char *s); +void __printn(int n); +const char *__getSuiteName(void); +void __runSuite(void); #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); - -const char *getSuiteName(void); - #define NULL 0 #define UNUSED(_a) if (_a) { } diff --git a/support/regression/fwk/lib/testfwk.c b/support/regression/fwk/lib/testfwk.c index 092d1653..8c162c88 100644 --- a/support/regression/fwk/lib/testfwk.c +++ b/support/regression/fwk/lib/testfwk.c @@ -1,7 +1,9 @@ /** Test framework support functions. */ #include +#ifndef NO_VARARGS #include +#endif #ifdef SDCC_ds390 #include /* main() must see the ISR declarations */ @@ -21,6 +23,9 @@ extern void _putchar(char c); extern void _initEmu(void); extern void _exitEmu(void); +int __numTests = 0; +static int __numFailures = 0; + #if BROKEN_DIV_MOD static int __div(int num, int denom) @@ -46,8 +51,8 @@ __mod(int num, int denom) #define __mod(num, denom) ((num) % (denom)) #endif -static void -_prints(const char *s) +void +__prints(const char *s) { char c; @@ -57,8 +62,8 @@ _prints(const char *s) } } -static void -_printn(int n) +void +__printn(int n) { if (0 == n) { _putchar('0'); @@ -83,10 +88,11 @@ _printn(int n) if (neg) _putchar('-'); - _prints(p); + __prints(p); } } +#ifndef NO_VARARGS void __printf(const char *szFormat, ...) { @@ -98,12 +104,12 @@ __printf(const char *szFormat, ...) switch (*++szFormat) { case 's': { char *sz = va_arg(ap, char *); - _prints(sz); + __prints(sz); break; } case 'u': { int i = va_arg(ap, int); - _printn(i); + __printn(i); break; } case '%': @@ -121,9 +127,6 @@ __printf(const char *szFormat, ...) va_end(ap); } -int __numTests = 0; -static int __numFailures = 0; - void __fail(const char *szMsg, const char *szCond, const char *szFile, int line) { @@ -134,28 +137,65 @@ __fail(const char *szMsg, const char *szCond, const char *szFile, int line) int main(void) { - TESTFUNP *cases; - int numCases = 0; - _initEmu(); - __printf("--- Running: %s\n", getSuiteName()); + __printf("--- Running: %s\n", __getSuiteName()); - cases = suite(); - - while (*cases) { - __printf("Running %u\n", numCases); - (*cases)(); - cases++; - numCases++; - } + __runSuite(); __printf("--- Summary: %u/%u/%u: %u failed of %u tests in %u cases.\n", - __numFailures, __numTests, numCases, - __numFailures, __numTests, numCases + __numFailures, __numTests, __numCases, + __numFailures, __numTests, __numCases ); _exitEmu(); return 0; } +#else +void +__fail(const char *szMsg, const char *szCond, const char *szFile, int line) +{ + __prints("--- FAIL: \""); + __prints(szMsg); + __prints("\" on "); + __prints(szCond); + __prints(" at "); + __prints(szFile); + _putchar(':'); + __printn(line); + _putchar('\n'); + + __numFailures++; +} + +int +main(void) +{ + _initEmu(); + + __prints("--- Running: "); + __prints(__getSuiteName()); + _putchar('\n'); + + __runSuite(); + + __prints("--- Summary: "); + __printn(__numFailures); + _putchar('/'); + __printn(__numTests); + _putchar('/'); + __printn(__numCases); + __prints(": "); + __printn(__numFailures); + __prints(" failed of "); + __printn(__numTests); + __prints(" tests in "); + __printn(__numCases); + __prints(" cases.\n"); + + _exitEmu(); + + return 0; +} +#endif diff --git a/support/regression/generate-cases.py b/support/regression/generate-cases.py index 9c9bb045..9ad7a5bb 100644 --- a/support/regression/generate-cases.py +++ b/support/regression/generate-cases.py @@ -9,27 +9,21 @@ outdir = sys.argv[2] # Start of the test function table definition testfuntableheader = """ -static TESTFUNP _tests[] = { +void +__runSuite(void) +{ """ - # End of the test function table definition -testfuntablefooter = """\tNULL -}; +testfuntablefooter = """} """ # Code to generate the suite function testfunsuite = """ -TESTFUNP * -suite(void) -{ - return _tests; -} - const char * -getSuiteName(void) +__getSuiteName(void) { - return "{testcase}"; + return "{testcase}"; } """ @@ -111,12 +105,16 @@ class InstanceGenerator: # Emmit the suite table fout.write(testfuntableheader) + n = 0; for fun in self.functions: # Turn the function definition into a pointer fun = re.sub(r'\(\w+\)', '', fun) - fout.write("\t" + fun + ",\n") + fout.write(" __prints(\"Running " + fun + "\\n\");\n"); + fout.write(' ' + fun + "();\n") + n += 1; fout.write(testfuntablefooter) + fout.write("\nconst int __numCases = " + str(n) + ";\n") fout.write(testfunsuite); fout.close() @@ -189,4 +187,3 @@ def main(): if __name__ == '__main__': main() -