summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2011-12-09 10:31:19 +0000
committerPeter Wu <lekensteyn@gmail.com>2011-12-09 10:31:19 +0000
commit8391b13848fc9dea3548cc1d78965792ad600324 (patch)
treefeac72f386b26fdcded89a084a7dd11b7a1a6426 /tests
parentc772807a8bb8b868cfae952367f9f90bbc6405bd (diff)
downloadpp2cc-8391b13848fc9dea3548cc1d78965792ad600324.tar.gz
Add some tests
Diffstat (limited to 'tests')
-rw-r--r--tests/enable-leds.c57
-rw-r--r--tests/infinite.c4
-rw-r--r--tests/lextab.py9
-rw-r--r--tests/mask.c6
-rw-r--r--tests/strange-array.c11
-rw-r--r--tests/ternary-op.c6
-rw-r--r--tests/var-bug.c6
-rw-r--r--tests/write-retval.c7
8 files changed, 106 insertions, 0 deletions
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<t_ppline_FILENAME>"([^"\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))*")|(?P<t_ppline_LINE_NUMBER>(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<t_ppline_NEWLINE>\\n)|(?P<t_ppline_PPLINE>line)', [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_PPHASH>[ \\t]*\\#)|(?P<t_NEWLINE>\\n+)|(?P<t_FLOAT_CONST>((((([0-9]*\\.[0-9]+)|([0-9]+\\.))([eE][-+]?[0-9]+)?)|([0-9]+([eE][-+]?[0-9]+)))[FfLl]?))|(?P<t_INT_CONST_HEX>0[xX][0-9a-fA-F]+(u?ll|U?LL|([uU][lL])|([lL][uU])|[uU]|[lL])?)|(?P<t_BAD_CONST_OCT>0[0-7]*[89])|(?P<t_INT_CONST_OCT>0[0-7]*(u?ll|U?LL|([uU][lL])|([lL][uU])|[uU]|[lL])?)|(?P<t_INT_CONST_DEC>(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<t_CHAR_CONST>\'([^\'\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))\')|(?P<t_WCHAR_CONST>L\'([^\'\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))\')|(?P<t_UNMATCHED_QUOTE>(\'([^\'\\\\\\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<t_BAD_CHAR_CONST>(\'([^\'\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))[^\'\n]+\')|(\'\')|(\'([\\\\][^a-zA-Z\\\\?\'"x0-7])[^\'\\n]*\'))|(?P<t_WSTRING_LITERAL>L"([^"\\\\\\n]|(\\\\(([a-zA-Z\\\\?\'"])|([0-7]{1,3})|(x[0-9a-fA-F]+))))*")|(?P<t_BAD_STRING_LITERAL>"([^"\\\\\\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<t_ID>[a-zA-Z_][0-9a-zA-Z_]*)|(?P<t_STRING_LITERAL>"([^"\\\\\\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<t_ELLIPSIS>\\.\\.\\.)|(?P<t_PLUSPLUS>\\+\\+)|(?P<t_LOR>\\|\\|)|(?P<t_XOREQUAL>\\^=)|(?P<t_OREQUAL>\\|=)|(?P<t_LSHIFTEQUAL><<=)|(?P<t_RSHIFTEQUAL>>>=)|(?P<t_TIMESEQUAL>\\*=)|(?P<t_PLUSEQUAL>\\+=)|(?P<t_PLUS>\\+)|(?P<t_MODEQUAL>%=)|(?P<t_LBRACE>\\{)|(?P<t_DIVEQUAL>/=)|(?P<t_RBRACKET>\\])|(?P<t_CONDOP>\\?)', [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<t_XOR>\\^)|(?P<t_LSHIFT><<)|(?P<t_LE><=)|(?P<t_LPAREN>\\()|(?P<t_ARROW>->)|(?P<t_EQ>==)|(?P<t_RBRACE>\\})|(?P<t_NE>!=)|(?P<t_MINUSMINUS>--)|(?P<t_OR>\\|)|(?P<t_TIMES>\\*)|(?P<t_LBRACKET>\\[)|(?P<t_GE>>=)|(?P<t_RPAREN>\\))|(?P<t_LAND>&&)|(?P<t_RSHIFT>>>)|(?P<t_ANDEQUAL>&=)|(?P<t_MINUSEQUAL>-=)|(?P<t_PERIOD>\\.)|(?P<t_EQUALS>=)|(?P<t_LT><)|(?P<t_COMMA>,)|(?P<t_DIVIDE>/)|(?P<t_AND>&)|(?P<t_MOD>%)|(?P<t_SEMI>;)|(?P<t_MINUS>-)|(?P<t_GT>>)|(?P<t_COLON>:)|(?P<t_NOT>~)|(?P<t_LNOT>!)', [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;
+}