More tests
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 14 May 2001 01:24:23 +0000 (01:24 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 14 May 2001 01:24:23 +0000 (01:24 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@811 4a8a32a2-be11-0410-ad9d-d568d2c75423

support/Util/SDCCerr.c
support/Util/SDCCerr.h
support/cpp/cpplib.c
support/regression/COVERAGE [new file with mode: 0644]
support/regression/FAILURES [new file with mode: 0644]
support/regression/Makefile
support/regression/ports/host/spec.mk
support/regression/ports/z80/spec.mk
support/regression/tests/muldiv.c
support/regression/tests/shifts.c [new file with mode: 0644]
support/regression/tests/storage.c [new file with mode: 0644]

index d949a6ff831f376b4c2e30251872dca4bdf3f27e..59aef76aca0ce1261cfdba1909a6fd92c6423316 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "SDCCerr.h"
 
+
 #define USE_STDOUT_FOR_ERRORS          0
 
 #if USE_STDOUT_FOR_ERRORS
 #define DEFAULT_ERROR_OUT      stderr
 #endif
 
-static FILE *ErrorOut ;
+static struct {
+    ERROR_LOG_LEVEL logLevel;
+    FILE *out;
+} _SDCCERRG;
+
+enum {
+    PEDANTIC,
+    WARNING,
+    ERROR
+};
 
-#define ERROR          0
-#define WARNING                1
 
 extern char *filename ;
 extern int lineno ;
@@ -123,7 +131,7 @@ struct  {
 { WARNING,"warning *** pointer being cast to incompatible type \n"                        },
 { WARNING,"warning *** 'while' loop with 'zero' constant.loop eliminated\n"          },
 { WARNING,"warning *** %s expression has NO side effects.expr eliminated\n"          },
-{ WARNING,"warning *** constant value '%s', out of range.\n"                 },
+{ PEDANTIC,"warning *** constant value '%s', out of range.\n"                },
 { WARNING,"warning *** comparison will either, ALWAYs succeed or ALWAYs fail\n"   },
 { ERROR  ,"error *** Compiler Terminating , contact author with source\n"            },
 { WARNING,"warning *** 'auto' variable '%s' may be used before initialization at %s(%d)\n"      },
@@ -152,13 +160,13 @@ struct  {
 { ERROR  ,"error *** switch value not an integer\n"},
 { ERROR  ,"error *** case label not an integer\n"},
 { WARNING,"warning *** function '%s' too large for global optimization\n"},
-{ WARNING,"warning *** conditional flow changed by optimizer '%s(%d)':so said EVELYN the modified DOG\n"},
+{ PEDANTIC,"warning *** conditional flow changed by optimizer '%s(%d)':so said EVELYN the modified DOG\n"},
 { WARNING,"warning *** invalid type specifier for pointer type specifier ignored\n"},
 { WARNING,"warning *** function '%s' implicit declaration\n"},
 { WARNING,"warning *** %s"},
 { WARNING,"info *** %s extended by %d bytes for compiler temp(s) :in function  '%s': %s \n"},
 { WARNING,"warning *** unknown or unsupported #pragma directive '%s'\n"},
-{ WARNING,"warning *** %s shifting more than size of object changed to zero\n"},
+{ PEDANTIC, "warning *** %s shifting more than size of object changed to zero\n"},
 { WARNING,"warning *** unknown compiler option '%s' ignored\n"},
 { WARNING,"warning *** option '%s' no longer supported  '%s' \n"},
 { WARNING,"warning *** don't know what to do with file '%s'. file extension unsupported\n"},
@@ -168,7 +176,7 @@ struct  {
 { ERROR  ,"error *** function cannot return 'bit'\n"},
 { ERROR  ,"error *** casting from to type 'void' is illegal\n"},
 { WARNING,"warning *** constant is out of range %s\n" },
-{ WARNING,"warning *** unreachable code %s(%d)\n"},
+{ PEDANTIC,"warning *** unreachable code %s(%d)\n"},
 { WARNING,"warning *** non-pointer type cast to _generic pointer\n"},
 { WARNING,"warning *** possible code generation error at line %d,\n send source to sandeep.dutta@usa.net\n"},
 { WARNING,"warning *** pointer types incompatible \n" },
@@ -190,10 +198,17 @@ SetErrorOut - Set the error output file
 FILE *SetErrorOut(FILE *NewErrorOut)
 
 {
-ErrorOut = NewErrorOut ;
+    _SDCCERRG.out = NewErrorOut ;
 
 return NewErrorOut ;
 }
+
+void
+setErrorLogLevel (ERROR_LOG_LEVEL level)
+{
+    _SDCCERRG.logLevel = level;
+}
+
 /*
 -------------------------------------------------------------------------------
 vwerror - Output a standard eror message with variable number of arguements
@@ -203,19 +218,25 @@ vwerror - Output a standard eror message with variable number of arguements
 
 void vwerror (int errNum, va_list marker)
 {
-  if (!ErrorOut)
-    ErrorOut = DEFAULT_ERROR_OUT ;
-  
-  if ( ErrTab[errNum].errType == ERROR )
-    fatalError++ ;
-  
-  if ( filename && lineno ) {
-    fprintf(ErrorOut, "%s(%d):",filename,lineno);
-  } else if (lineno) {
-    fprintf(ErrorOut, "at %d:", lineno);
-  }
+    if (_SDCCERRG.out == NULL) {
+        _SDCCERRG.out = DEFAULT_ERROR_OUT;
+    }
+
+    if (ErrTab[errNum].errType >= _SDCCERRG.logLevel) {
+        if ( ErrTab[errNum].errType == ERROR )
+            fatalError++ ;
   
-  vfprintf(ErrorOut, ErrTab[errNum].errText,marker);
+        if ( filename && lineno ) {
+            fprintf(_SDCCERRG.out, "%s(%d):",filename,lineno);
+        } else if (lineno) {
+            fprintf(_SDCCERRG.out, "at %d:", lineno);
+        }
+    
+        vfprintf(_SDCCERRG.out, ErrTab[errNum].errText,marker);
+    }
+    else {
+        // Below the logging level, drop.
+    }
 }
 /*
 -------------------------------------------------------------------------------
@@ -225,11 +246,10 @@ werror - Output a standard eror message with variable number of arguements
 */
 
 void werror (int errNum, ... )
-
 {
-va_list        marker;
-va_start(marker,errNum);
-vwerror(errNum, marker);
-va_end( marker );
+    va_list    marker;
+    va_start(marker,errNum);
+    vwerror(errNum, marker);
+    va_end( marker );
 }
 
index 9c4e0d8798d98738913e2359317b314828487888..ee134615e3460f1a2d62609491a543b0d9372a4f 100644 (file)
@@ -13,7 +13,7 @@ SDCCERR - SDCC Standard error handler
 #include <stdio.h>
 #include <stdarg.h>
 
-/* ERROR MEssage Definition */
+/* ERROR Message Definition */
 
 #define  E_DUPLICATE       0         /* Duplicate variable   */
 #define  E_SYNTAX_ERROR    1         /* Syntax Error         */
@@ -153,6 +153,29 @@ SDCCERR - SDCC Standard error handler
 #define         W_BANKED_WITH_STATIC 135       /* banked and static mixed */
 #define  W_INT_TO_GEN_PTR_CAST 136     /* Converting integer type to generic pointer. */
 
+/** Describes the maximum error level that will be logged.  Any level
+    includes all of the levels listed after it.
+ */
+enum _ERROR_LOG_LEVEL {
+    /** Everything.  Currently the same as PEDANTIC. */
+    ERROR_LEVEL_ALL,
+    /** All warnings, including those considered 'reasonable to use,
+        on occasion, in clean programs' (man 3 gcc). */
+    ERROR_LEVEL_PEDANTIC,
+    /** Most warnings. */
+    ERROR_LEVEL_WARNINGS,
+    /** Errors only. */
+    ERROR_LEVEL_ERRORS
+};
+
+typedef enum _ERROR_LOG_LEVEL ERROR_LOG_LEVEL;
+
+/** Sets the maximum error level to log.
+    See MAX_ERROR_LEVEL.  The default is ERROR_LEVEL_ALL.
+*/
+void
+setErrorLogLevel (ERROR_LOG_LEVEL level);
+
 /*
 -------------------------------------------------------------------------------
 SetErrorOut - Set the error output file
index acf8d69d8848182724988e48d34eca7e524c127a..4f71d82b1adbdc3155b890449a05b35e8e0f34bb 100644 (file)
@@ -87,6 +87,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 #include <stdlib.h>
 #endif
 
+// PENDING: Straighten this out into configure
 #ifdef __MINGW32__
 #include <time.h>
 #else
@@ -96,6 +97,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 #ifndef VMS
 #ifndef USG
 #if !defined(_MSC_VER)
+// PENDING
+#include <time.h>
 #include <sys/time.h>   /* for __DATE__ and __TIME__ */
 #include <sys/resource.h>
 #else
diff --git a/support/regression/COVERAGE b/support/regression/COVERAGE
new file mode 100644 (file)
index 0000000..e06e497
--- /dev/null
@@ -0,0 +1,180 @@
+Primary goal: good coverage of the backend code generators.  The
+following list was derived from the token list in SDCC.lex
+
+Follows is a list of tokens and the test case that covers them.  If no
+case is listed then the token is not yet covered.  Special cases are
+listed under the token.  If the token is listed as covered then the
+special cases are also covered.
+
+The cases generally assume that on stack local variables and
+parameters are accessed using the same methods and hence doesn't test
+stack based parameters.
+
+Todo
+Operations:
+        Shifts:
+                Common cases:
+                        For byte multiples (8, 16...)
+                        For more than the word size
+                        For negative shifts
+                        For shift of 1
+                >>=
+                <<=
+                >>
+                <<
+
+        Comparison:
+                Common cases:
+                        Around zero
+                        Constants on either side (reversal)
+                <=
+                >=
+                ==
+                !=
+                <
+                >
+
+        Basic arithmetic:
+                Common cases:
+                        For small constants (<3)
+                ++
+                --
+                +=
+                -=
+                -
+                +
+
+        Mul/Div/Mod arithmetic:
+                Common cases:
+                        For powers of 2                               
+                *=
+                /=
+                %=
+                *
+                /
+                %
+
+        Bitwise operations:
+                &=
+                ^=
+                |=
+                &
+                ~
+                ^
+                |
+
+        Logical operations:
+                &&
+                ||
+                !
+
+        Misc:
+                ->
+                        Test that members are not cached across
+function calls
+                =
+                .
+                ?
+                casts
+                        Test sign extension
+                arrays
+                        Test a[a[const]]
+                pointers
+
+        Language features (untestable):
+                ;
+                {
+                }
+                ,
+                :
+                (
+                )
+                [
+                ]
+
+Keywords:
+        Specificers:
+                const
+                register
+                signed
+                static
+                unsigned
+                volatile
+
+        Conditional:
+                break
+                case
+                default
+                else
+                goto
+                if
+                switch
+
+        Types:
+                char
+                double
+                float
+                int
+                long
+                short
+                void
+
+        Iterative:
+                continue
+                do
+                for
+                while
+
+        Language features:
+                enum
+                extern
+                sizeof
+                struct
+                typedef
+                union
+
+        Misc:
+                return
+
+        Unknown:
+                auto
+                interrupt
+
+Optional keywords:
+        banked
+        bit
+        flash
+        code
+        critical
+        near
+        data
+        eeprom
+        idata
+        nonbanked
+        pdata
+        reentrant
+        sbit
+        sfr
+        using
+        sram
+        xdata
+        far
+        _code
+        _flash
+        _eeprom
+        _generic
+        _idata
+        _data
+        _near
+        _pdata
+        _sram
+        _xdata
+
+Language features:
+        va args (...)
+
+Optional:
+        Constants:
+               Hex, dec, oct
+                Character constants    'x'
+                Specials               '\n', '\0', ...
diff --git a/support/regression/FAILURES b/support/regression/FAILURES
new file mode 100644 (file)
index 0000000..8642ad0
--- /dev/null
@@ -0,0 +1,7 @@
+ASSERT(result == (char)((char)-1560000000 << 1));
+
+Complains:
+gen/z80/shifts/shifts_attr_volatile_storage_none_type_char_vals_-1560000000.c(61):warning *** constant is out of range  compare operation 
+
+despite the cast.
+
index 5ad6aad332fbab1687c13aec01df916785111e4d..9fcc8a67879f1b3d0977ee797e4b110097ffc3de 100644 (file)
@@ -61,6 +61,8 @@ GENERATE_CASES = generate-cases.py
 # files and how to run the emulator.
 ALL_PORTS = $(filter-out CVS,$(notdir $(wildcard $(PORTS_DIR)/*)))
 
+all: test-ports
+
 # Test all of the ports
 test-ports:
        for i in $(ALL_PORTS); do $(MAKE) inter-port-clean test-port PORT=$$i; done
@@ -69,7 +71,10 @@ test-ports:
 test-z80:
        $(MAKE) inter-port-clean clean test-port PORT=z80
 
-test-z80:
+# Helper rule for testing the host cc only
+test-host:
+       $(MAKE) inter-port-clean clean test-port PORT=host
+
 # Begin per-port rules
 # List of all of the known source test suites.
 ALL_TESTS = $(shell find $(TESTS_DIR) -name "*.c")
index d9666ccc99fbd1a8b0a055f92554fdc042112f52..13cbfa859ddd3f03ea71137c586927affda0ede8 100644 (file)
@@ -10,7 +10,7 @@ EXTRAS = fwk/lib/testfwk$(OBJEXT) ports/$(PORT)/support$(OBJEXT)
 %.out: %$(EXEEXT)
        mkdir -p `dirname $@`
        -$< > $@
-       if grep -q FAIL $@; then echo FAILURES in $@; fi
+       -grep -n FAIL $@ /dev/null || true      
 
 %$(EXEEXT): %$(OBJEXT) $(EXTRAS)
        $(SDCC) $(SDCCFLAGS) -o $@ $< $(EXTRAS)
index 55c73c43e3f16d2555c42d94ef73b8c2d2b2edf7..aafc6f4b6a377c00610e9a213c4dc8a7937123b2 100644 (file)
@@ -5,7 +5,7 @@
 GBDK_LIB = ../../../gbdk-lib
 RRZ80 = $(SDCC_EXTRA_DIR)/emu/rrz80/rrz80
 
-SDCCFLAGS += -I$(GBDK_LIB)/include
+SDCCFLAGS += -I$(GBDK_LIB)/include --lesspedantic
 
 EXEEXT = .bin
 
index 3757d04ccbb9edfef1c3b01e80b45062193ef8c0..354501dc695f43be3e49e2de9474e9c48e63a356 100644 (file)
@@ -48,19 +48,24 @@ testDiv(void)
 }
 
 static void
-disabled_testMod(void)
+testMod(void)
 {
     {attr} {storage} {type} i;
 
+    // Disabled the LOG functions due to a bug in sdcc involving
+    // vaargs.
     i = 100;
-    LOG(("i%%17 == 15 = %u\n", (int)(i%9)));
+    //    LOG(("i%%17 == 15 = %u\n", (int)(i%9)));
     ASSERT(i%17 == 15);
-    LOG(("i%%-7 == 2 = %u\n", (int)i%-7));
+
+#if MOD_SIGN_FOLLOWS_DIVIDEND
+    //    LOG(("i%%-7 == 2 = %u\n", (int)i%-7));
     ASSERT(i%-7 == 2);
 
     i = -49;
-    LOG(("i%%3 == -1 = %u\n", (int)i%3));
+    //    LOG(("i%%3 == -1 = %u\n", (int)i%3));
     ASSERT(i%3 == -1);
-    LOG(("i%%-5 == -4 = %u\n", (int)i%-5));
+    //    LOG(("i%%-5 == -4 = %u\n", (int)i%-5));
     ASSERT(i%-5 == -4);
+#endif
 }
diff --git a/support/regression/tests/shifts.c b/support/regression/tests/shifts.c
new file mode 100644 (file)
index 0000000..60b6633
--- /dev/null
@@ -0,0 +1,71 @@
+/** Tests covering the shift operators.
+
+    type: char, int
+    storage: static, 
+    attr: volatile
+
+    vals: 3
+
+    pending - 1792, 851968, 1560281088, -3, -1792, -851968, -1560000000
+*/
+#include <testfwk.h>
+
+static void
+testShiftClasses(void)
+{
+    {attr} {storage} {type} i, result;
+
+    i = 50;
+    ASSERT(i>>3 == 6);
+    ASSERT(i<<2 == 200);
+    
+    result = i;
+    result >>= 2;
+    ASSERT(result == 12);
+
+    result = i;
+    result <<= 2;
+    ASSERT(result == 200);
+}
+
+/** PENDING: Disabled. */
+static void
+testShiftByteMultiples(void)
+{
+#if 0
+    {attr} {storage} {type} i;
+
+    i = ({type}){vals};
+    ASSERT(i>>8  == (({type}){vals} >> 8));
+    ASSERT(i>>16 == (({type}){vals} >> 16));
+    ASSERT(i>>24 == (({type}){vals} >> 24));
+
+    i = ({type}){vals};
+    ASSERT(i<<8 == (({type}){vals} << 8));
+    ASSERT(i<<16 == (({type}){vals} << 16));
+    ASSERT(i<<24 == (({type}){vals} << 24));
+#endif
+}
+
+static void
+testShiftOne(void)
+{
+    {attr} {storage} {type} i;
+    {type} result;
+
+    i = ({type}){vals};
+
+    result = i >> 1;
+    ASSERT(result == ({type})(({type}){vals} >> 1));
+
+    result = i;
+    result >>= 1;
+    ASSERT(result == ({type})(({type}){vals} >> 1));
+
+    result = i << 1;
+    ASSERT(result == ({type})(({type}){vals} << 1));
+
+    result = i;
+    result <<= 1;
+    ASSERT(result == ({type})(({type}){vals} << 1));
+}
diff --git a/support/regression/tests/storage.c b/support/regression/tests/storage.c
new file mode 100644 (file)
index 0000000..9a8b700
--- /dev/null
@@ -0,0 +1,43 @@
+/** Tests many of the basic operators from each of the storage types to every other.
+
+    source_storage: static, register,
+    dest_storage: static, register, 
+    type: char, int
+ */
+#include <testfwk.h>
+
+/** Simple function that spoils sdcc's optimiser by hiding an assign.
+ */
+static {type}
+spoilAssign({type} in)
+{
+    return in;
+}
+
+static void
+testStorageTypes(void)
+{
+    {source_storage} {type} source;
+    {dest_storage} {type} dest;
+
+    source = spoilAssign(17);
+    // Test compare against a const
+    ASSERT(source == 17);
+
+    dest = spoilAssign(134);
+    ASSERT(dest == 134);
+    ASSERT(dest != source);
+
+    // Test assignment
+    dest = source;
+    ASSERT(dest == source);
+
+    // Test cmp
+    dest--;
+    ASSERT(dest == 16);
+    ASSERT(dest < source);
+    
+    dest += 8;
+    ASSERT(dest == 24);
+    ASSERT(source < dest);
+}