From afff3c43107e27a024275fc643ca574c5c27c220 Mon Sep 17 00:00:00 2001 From: michaelh Date: Mon, 14 May 2001 01:24:23 +0000 Subject: [PATCH] More tests git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@811 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- support/Util/SDCCerr.c | 70 ++++++---- support/Util/SDCCerr.h | 25 +++- support/cpp/cpplib.c | 3 + support/regression/COVERAGE | 180 ++++++++++++++++++++++++++ support/regression/FAILURES | 7 + support/regression/Makefile | 7 +- support/regression/ports/host/spec.mk | 2 +- support/regression/ports/z80/spec.mk | 2 +- support/regression/tests/muldiv.c | 15 ++- support/regression/tests/shifts.c | 71 ++++++++++ support/regression/tests/storage.c | 43 ++++++ 11 files changed, 391 insertions(+), 34 deletions(-) create mode 100644 support/regression/COVERAGE create mode 100644 support/regression/FAILURES create mode 100644 support/regression/tests/shifts.c create mode 100644 support/regression/tests/storage.c diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index d949a6ff..59aef76a 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -20,6 +20,7 @@ #include "SDCCerr.h" + #define USE_STDOUT_FOR_ERRORS 0 #if USE_STDOUT_FOR_ERRORS @@ -28,10 +29,17 @@ #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 ); } diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index 9c4e0d87..ee134615 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -13,7 +13,7 @@ SDCCERR - SDCC Standard error handler #include #include -/* 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 diff --git a/support/cpp/cpplib.c b/support/cpp/cpplib.c index acf8d69d..4f71d82b 100644 --- a/support/cpp/cpplib.c +++ b/support/cpp/cpplib.c @@ -87,6 +87,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #endif +// PENDING: Straighten this out into configure #ifdef __MINGW32__ #include #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 #include /* for __DATE__ and __TIME__ */ #include #else diff --git a/support/regression/COVERAGE b/support/regression/COVERAGE new file mode 100644 index 00000000..e06e4977 --- /dev/null +++ b/support/regression/COVERAGE @@ -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 index 00000000..8642ad0a --- /dev/null +++ b/support/regression/FAILURES @@ -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. + diff --git a/support/regression/Makefile b/support/regression/Makefile index 5ad6aad3..9fcc8a67 100644 --- a/support/regression/Makefile +++ b/support/regression/Makefile @@ -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") diff --git a/support/regression/ports/host/spec.mk b/support/regression/ports/host/spec.mk index d9666ccc..13cbfa85 100644 --- a/support/regression/ports/host/spec.mk +++ b/support/regression/ports/host/spec.mk @@ -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) diff --git a/support/regression/ports/z80/spec.mk b/support/regression/ports/z80/spec.mk index 55c73c43..aafc6f4b 100644 --- a/support/regression/ports/z80/spec.mk +++ b/support/regression/ports/z80/spec.mk @@ -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 diff --git a/support/regression/tests/muldiv.c b/support/regression/tests/muldiv.c index 3757d04c..354501dc 100644 --- a/support/regression/tests/muldiv.c +++ b/support/regression/tests/muldiv.c @@ -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 index 00000000..60b66332 --- /dev/null +++ b/support/regression/tests/shifts.c @@ -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 + +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 index 00000000..9a8b7005 --- /dev/null +++ b/support/regression/tests/storage.c @@ -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 + +/** 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); +} -- 2.39.5