From 8391b13848fc9dea3548cc1d78965792ad600324 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 9 Dec 2011 10:31:19 +0000 Subject: Add some tests --- tests/enable-leds.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/infinite.c | 4 ++++ tests/lextab.py | 9 ++++++++ tests/mask.c | 6 ++++++ tests/strange-array.c | 11 ++++++++++ tests/ternary-op.c | 6 ++++++ tests/var-bug.c | 6 ++++++ tests/write-retval.c | 7 +++++++ 8 files changed, 106 insertions(+) create mode 100644 tests/enable-leds.c create mode 100644 tests/infinite.c create mode 100644 tests/lextab.py create mode 100644 tests/mask.c create mode 100644 tests/strange-array.c create mode 100644 tests/ternary-op.c create mode 100644 tests/var-bug.c create mode 100644 tests/write-retval.c diff --git a/tests/enable-leds.c b/tests/enable-leds.c new file mode 100644 index 0000000..315f665 --- /dev/null +++ b/tests/enable-leds.c @@ -0,0 +1,57 @@ +/* + * File: enable_digit.c + * Author: Peter Wu + */ + +/** + * Determines the bitmask necessary for enabling LED segments on a LED + * @param number The number to be displayed + * @return The segment bits to be enabled + */ +static int segment_mask(int number) { + switch (number) { + case 0: + return 0x7e;// 01111110 + case 1: + return 0x30;// 00110000 + case 2: + return 0x6d;// 01101101 + case 3: + return 0x79;// 01111001 + case 4: + return 0x33;// 00110011 + case 5: + return 0x5b;// 01011011 + case 6: + return 0x5f;// 01011111 + case 7: + return 0x70;// 01110000 + case 8: + return 0x7f;// 01111111 + case 9: + return 0x7b;// 01111011 + } + // in case you do not pass the right arguments, turn everything on + return 0xff; +} + +/** + * Displays a digit at a certain index + * @param digit The digit to be displayed (between 0 and 9 inclusive) + * @param index The number of the LED segment to be enabled, counting from the + * right side. index 0 means that all LEDS are disabled. The n-th LED can be + * selected with index n with 1 <= n <= 6 + */ +void enable_digit(int digit, int index) { + int *digitp = (int*)-7; + int *segmentp = (int*)-8; + + // first set the segments to be enabled + *segmentp = segment_mask(digit); + // enable bit "index" if index > 0 + *digitp = index ? 1 << (index - 1) : 0; +} +int main() { + enable_digit(0, 0); + return 0; +} diff --git a/tests/infinite.c b/tests/infinite.c new file mode 100644 index 0000000..3f9a656 --- /dev/null +++ b/tests/infinite.c @@ -0,0 +1,4 @@ +int main() { + while (1) {} + return 0; +} diff --git a/tests/lextab.py b/tests/lextab.py new file mode 100644 index 0000000..a53520c --- /dev/null +++ b/tests/lextab.py @@ -0,0 +1,9 @@ +# pycparser.lextab.py. This file automatically created by PLY (version 3.3). Don't edit! +_tabversion = '3.3' +_lextokens = {'VOID': 1, 'LBRACKET': 1, 'WCHAR_CONST': 1, 'FLOAT_CONST': 1, 'MINUS': 1, 'RPAREN': 1, 'LONG': 1, 'PLUS': 1, 'ELLIPSIS': 1, 'GT': 1, 'RBRACE': 1, 'ENUM': 1, 'PERIOD': 1, 'GE': 1, 'INT_CONST_DEC': 1, 'ARROW': 1, 'DOUBLE': 1, 'MINUSEQUAL': 1, 'INT_CONST_OCT': 1, 'TIMESEQUAL': 1, 'OR': 1, 'SHORT': 1, 'RETURN': 1, 'RSHIFTEQUAL': 1, 'RESTRICT': 1, 'STATIC': 1, 'SIZEOF': 1, 'UNSIGNED': 1, 'UNION': 1, 'COLON': 1, 'WSTRING_LITERAL': 1, 'DIVIDE': 1, 'FOR': 1, 'PLUSPLUS': 1, 'EQUALS': 1, 'ELSE': 1, 'INLINE': 1, 'EQ': 1, 'AND': 1, 'TYPEID': 1, 'LBRACE': 1, 'PPHASH': 1, 'INT': 1, 'SIGNED': 1, 'CONTINUE': 1, 'NOT': 1, 'OREQUAL': 1, 'MOD': 1, 'RSHIFT': 1, 'DEFAULT': 1, 'CHAR': 1, 'WHILE': 1, 'DIVEQUAL': 1, 'EXTERN': 1, 'CASE': 1, 'LAND': 1, 'REGISTER': 1, 'MODEQUAL': 1, 'NE': 1, 'SWITCH': 1, 'INT_CONST_HEX': 1, 'PLUSEQUAL': 1, 'STRUCT': 1, 'CONDOP': 1, 'BREAK': 1, 'VOLATILE': 1, 'ANDEQUAL': 1, 'DO': 1, 'LNOT': 1, 'CONST': 1, 'LOR': 1, 'CHAR_CONST': 1, 'LSHIFT': 1, 'GOTO': 1, '_BOOL': 1, 'LE': 1, 'SEMI': 1, 'LT': 1, 'COMMA': 1, 'TYPEDEF': 1, 'XOR': 1, 'AUTO': 1, 'TIMES': 1, 'LPAREN': 1, 'MINUSMINUS': 1, 'ID': 1, 'IF': 1, 'STRING_LITERAL': 1, 'FLOAT': 1, 'XOREQUAL': 1, 'LSHIFTEQUAL': 1, 'RBRACKET': 1} +_lexreflags = 0 +_lexliterals = '' +_lexstateinfo = {'ppline': 'exclusive', 'INITIAL': 'inclusive'} +_lexstatere = {'ppline': [('(?P"([^"\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))*")|(?P(0(u?ll|U?LL|([uU][lL])|([lL][uU])|[uU]|[lL])?)|([1-9][0-9]*(u?ll|U?LL|([uU][lL])|([lL][uU])|[uU]|[lL])?))|(?P\\n)|(?Pline)', [None, ('t_ppline_FILENAME', 'FILENAME'), None, None, None, None, None, None, ('t_ppline_LINE_NUMBER', 'LINE_NUMBER'), None, None, None, None, None, None, None, None, ('t_ppline_NEWLINE', 'NEWLINE'), ('t_ppline_PPLINE', 'PPLINE')])], 'INITIAL': [('(?P[ \\t]*\\#)|(?P\\n+)|(?P((((([0-9]*\\.[0-9]+)|([0-9]+\\.))([eE][-+]?[0-9]+)?)|([0-9]+([eE][-+]?[0-9]+)))[FfLl]?))|(?P0[xX][0-9a-fA-F]+(u?ll|U?LL|([uU][lL])|([lL][uU])|[uU]|[lL])?)|(?P0[0-7]*[89])|(?P0[0-7]*(u?ll|U?LL|([uU][lL])|([lL][uU])|[uU]|[lL])?)|(?P(0(u?ll|U?LL|([uU][lL])|([lL][uU])|[uU]|[lL])?)|([1-9][0-9]*(u?ll|U?LL|([uU][lL])|([lL][uU])|[uU]|[lL])?))|(?P\'([^\'\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))\')|(?PL\'([^\'\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))\')|(?P(\'([^\'\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))*\\n)|(\'([^\'\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))*$))|(?P(\'([^\'\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))[^\'\n]+\')|(\'\')|(\'([\\\\][^a-zA-Z\\\\?\'"x0-7])[^\'\\n]*\'))|(?PL"([^"\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))*")|(?P"([^"\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))*([\\\\][^a-zA-Z\\\\?\'"x0-7])([^"\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))*")|(?P[a-zA-Z_][0-9a-zA-Z_]*)|(?P"([^"\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))*")', [None, ('t_PPHASH', 'PPHASH'), ('t_NEWLINE', 'NEWLINE'), ('t_FLOAT_CONST', 'FLOAT_CONST'), None, None, None, None, None, None, None, None, None, ('t_INT_CONST_HEX', 'INT_CONST_HEX'), None, None, None, ('t_BAD_CONST_OCT', 'BAD_CONST_OCT'), ('t_INT_CONST_OCT', 'INT_CONST_OCT'), None, None, None, ('t_INT_CONST_DEC', 'INT_CONST_DEC'), None, None, None, None, None, None, None, None, ('t_CHAR_CONST', 'CHAR_CONST'), None, None, None, None, None, None, ('t_WCHAR_CONST', 'WCHAR_CONST'), None, None, None, None, None, None, ('t_UNMATCHED_QUOTE', 'UNMATCHED_QUOTE'), None, None, None, None, None, None, None, None, None, None, None, None, None, None, ('t_BAD_CHAR_CONST', 'BAD_CHAR_CONST'), None, None, None, None, None, None, None, None, None, None, ('t_WSTRING_LITERAL', 'WSTRING_LITERAL'), None, None, None, None, None, None, ('t_BAD_STRING_LITERAL', 'BAD_STRING_LITERAL'), None, None, None, None, None, None, None, None, None, None, None, None, None, ('t_ID', 'ID'), (None, 'STRING_LITERAL')]), ('(?P\\.\\.\\.)|(?P\\+\\+)|(?P\\|\\|)|(?P\\^=)|(?P\\|=)|(?P<<=)|(?P>>=)|(?P\\*=)|(?P\\+=)|(?P\\+)|(?P%=)|(?P\\{)|(?P/=)|(?P\\])|(?P\\?)', [None, (None, 'ELLIPSIS'), (None, 'PLUSPLUS'), (None, 'LOR'), (None, 'XOREQUAL'), (None, 'OREQUAL'), (None, 'LSHIFTEQUAL'), (None, 'RSHIFTEQUAL'), (None, 'TIMESEQUAL'), (None, 'PLUSEQUAL'), (None, 'PLUS'), (None, 'MODEQUAL'), (None, 'LBRACE'), (None, 'DIVEQUAL'), (None, 'RBRACKET'), (None, 'CONDOP')]), ('(?P\\^)|(?P<<)|(?P<=)|(?P\\()|(?P->)|(?P==)|(?P\\})|(?P!=)|(?P--)|(?P\\|)|(?P\\*)|(?P\\[)|(?P>=)|(?P\\))|(?P&&)|(?P>>)|(?P&=)|(?P-=)|(?P\\.)|(?P=)|(?P<)|(?P,)|(?P/)|(?P&)|(?P%)|(?P;)|(?P-)|(?P>)|(?P:)|(?P~)|(?P!)', [None, (None, 'XOR'), (None, 'LSHIFT'), (None, 'LE'), (None, 'LPAREN'), (None, 'ARROW'), (None, 'EQ'), (None, 'RBRACE'), (None, 'NE'), (None, 'MINUSMINUS'), (None, 'OR'), (None, 'TIMES'), (None, 'LBRACKET'), (None, 'GE'), (None, 'RPAREN'), (None, 'LAND'), (None, 'RSHIFT'), (None, 'ANDEQUAL'), (None, 'MINUSEQUAL'), (None, 'PERIOD'), (None, 'EQUALS'), (None, 'LT'), (None, 'COMMA'), (None, 'DIVIDE'), (None, 'AND'), (None, 'MOD'), (None, 'SEMI'), (None, 'MINUS'), (None, 'GT'), (None, 'COLON'), (None, 'NOT'), (None, 'LNOT')])]} +_lexstateignore = {'ppline': ' \t', 'INITIAL': ' \t'} +_lexstateerrorf = {'ppline': 't_ppline_error', 'INITIAL': 't_error'} diff --git a/tests/mask.c b/tests/mask.c new file mode 100644 index 0000000..d26546f --- /dev/null +++ b/tests/mask.c @@ -0,0 +1,6 @@ +int a = -1;//11111...11 +int main() { + a &= ~3;// 111..00 + e:goto e; + return 0; +} diff --git a/tests/strange-array.c b/tests/strange-array.c new file mode 100644 index 0000000..98f3ccb --- /dev/null +++ b/tests/strange-array.c @@ -0,0 +1,11 @@ +int m, n, o, q; +int main() { + int x = 9; + int *p = &x; + int b[] = {1, 2}; + int *B = {3, 4}; + m = *b; + n = *p; + o = *B; + return 0; +} diff --git a/tests/ternary-op.c b/tests/ternary-op.c new file mode 100644 index 0000000..936e011 --- /dev/null +++ b/tests/ternary-op.c @@ -0,0 +1,6 @@ +int res, second; +int main() { + res = 0 ? 2 : 3; + second = 1 ? 2 : 3; + return 0; +} diff --git a/tests/var-bug.c b/tests/var-bug.c new file mode 100644 index 0000000..f15538e --- /dev/null +++ b/tests/var-bug.c @@ -0,0 +1,6 @@ +int main() { + while ( +( (*((int*)-9) &2) /2 ) +) ; + return 0; +} diff --git a/tests/write-retval.c b/tests/write-retval.c new file mode 100644 index 0000000..0904e3b --- /dev/null +++ b/tests/write-retval.c @@ -0,0 +1,7 @@ +int f() { + return 0xff; +} +void main() { + *((int*)-5) = f(); + e:goto e; +} -- cgit v1.2.1