* support/regression/fwk/include/testfwk.h,
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 12 Aug 2006 20:13:39 +0000 (20:13 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 12 Aug 2006 20:13:39 +0000 (20:13 +0000)
  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

ChangeLog
support/regression/Makefile.in
support/regression/fwk/include/testfwk.h
support/regression/fwk/lib/testfwk.c
support/regression/generate-cases.py

index 957ffeed4956f9210cc7ccc3bbd4eb861ca16580..2ac9557f4cbecb71cebe2d1debb315deb4610a68 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-08-12 Borut Razem <borut.razem AT siol.net>
+
+       * 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 <sourceforge.brock AT dse.nl>
 
        * device/include/stddef.h: c temporary hack to fix bug 1518273
index 3378a7b0cb174e5c49897a22ec357fb9e715ab1a..384a549ec241547f1c9ce55881cf063d1181a5ca 100644 (file)
@@ -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
index 85c780eb622f419e2654b18d0cb62a2883f861f5..bfe3d34e89a20fb11aac62575d03b8ee33ae814c 100644 (file)
@@ -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) { }
index 092d16535155cc5fe61f8dfcf58060300e35ea1b..8c162c8877ea971f08e2a787b5bb08b3ded72cb7 100644 (file)
@@ -1,7 +1,9 @@
 /** Test framework support functions.
  */
 #include <testfwk.h>
+#ifndef NO_VARARGS
 #include <stdarg.h>
+#endif
 
 #ifdef SDCC_ds390
 #include <tinibios.h> /* 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
index 9c9bb04585ce5dc122a0f9aff0970e74531bf45f..9ad7a5bb54048968e91e370b4bb3a57406ea2e12 100644 (file)
@@ -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()
-