summaryrefslogtreecommitdiffstats
path: root/libacc/tests
diff options
context:
space:
mode:
Diffstat (limited to 'libacc/tests')
-rw-r--r--libacc/tests/Android.mk20
-rw-r--r--libacc/tests/data/constants.c30
-rw-r--r--libacc/tests/data/expr-ansi.c60
-rw-r--r--libacc/tests/data/expr2.c6
-rw-r--r--libacc/tests/data/locals.c71
-rw-r--r--libacc/tests/data/otcc-ansi.c25
-rw-r--r--libacc/tests/data/otcc.c2
-rw-r--r--libacc/tests/data/returnval-ansi.c3
-rw-r--r--libacc/tests/data/returnval.c3
-rw-r--r--libacc/tests/main.cpp26
-rwxr-xr-xlibacc/tests/testarm2
-rwxr-xr-xlibacc/tests/testlocal36
12 files changed, 250 insertions, 34 deletions
diff --git a/libacc/tests/Android.mk b/libacc/tests/Android.mk
index 2cff9d3..f8907b4 100644
--- a/libacc/tests/Android.mk
+++ b/libacc/tests/Android.mk
@@ -1,5 +1,9 @@
LOCAL_PATH:= $(call my-dir)
+
+# Executable for host
+# ========================================================
include $(CLEAR_VARS)
+LOCAL_MODULE:= acc
LOCAL_SRC_FILES:= \
main.cpp
@@ -7,9 +11,23 @@ LOCAL_SRC_FILES:= \
LOCAL_SHARED_LIBRARIES := \
libacc
+LOCAL_MODULE_TAGS := tests
+
+include $(BUILD_HOST_EXECUTABLE)
+
+# Executable for target
+# ========================================================
+include $(CLEAR_VARS)
LOCAL_MODULE:= acc
+LOCAL_SRC_FILES:= \
+ main.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+ libacc
+
+LOCAL_CFLAGS := -O0 -g
+
LOCAL_MODULE_TAGS := tests
include $(BUILD_EXECUTABLE)
-
diff --git a/libacc/tests/data/constants.c b/libacc/tests/data/constants.c
new file mode 100644
index 0000000..230109a
--- /dev/null
+++ b/libacc/tests/data/constants.c
@@ -0,0 +1,30 @@
+#define FOO 0x10
+
+int main() {
+ printf("0 = %d\n", 0);
+ printf("010 = %d\n", 010);
+ printf("0x10 = %d\n", FOO);
+ printf("'\\a' = %d\n", '\a');
+ printf("'\\b' = %d\n", '\b');
+ printf("'\\f' = %d\n", '\f');
+ printf("'\\n' = %d\n", '\n');
+ printf("'\\r' = %d\n", '\r');
+ printf("'\\t' = %d\n", '\t');
+ printf("'\\v' = %d\n", '\v');
+ // Undefined
+ // printf("'\\z' = %d\n", '\z');
+ printf("'\\\\' = %d\n", '\\');
+ printf("'\\'' = %d\n", '\'');
+ printf("'\\\"' = %d\n", '\"');
+ printf("'\\?' = %d\n", '\?');
+ printf("'\\0' = %d\n", '\0');
+ printf("'\\1' = %d\n", '\1');
+ printf("'\\12' = %d\n", '\12');
+ printf("'\\123' = %d\n", '\123');
+ printf("'\\x0' = %d\n", '\x0');
+ printf("'\\x1' = %d\n", '\x1');
+ printf("'\\x12' = %d\n", '\x12');
+ printf("'\\x123' = %d\n", '\x123');
+ printf("'\\x1f' = %d\n", '\x1f');
+ printf("'\\x1F' = %d\n", '\x1F');
+}
diff --git a/libacc/tests/data/expr-ansi.c b/libacc/tests/data/expr-ansi.c
new file mode 100644
index 0000000..d463659
--- /dev/null
+++ b/libacc/tests/data/expr-ansi.c
@@ -0,0 +1,60 @@
+/* Test operators */
+
+void testInc() { int a, b; a = 3; b = a++; printf("3++ = %d %d\n", b, a); }
+void testDec() { int a, b; a = 3; b = a--; printf("3-- = %d %d\n", b, a); }
+void testTimes(){ printf("%d * %d = %d\n", 10, 4, 10 * 4); }
+void testDiv(){ printf("%d / %d = %d\n", 11, 4, 11 / 4); }
+void testMod(){ printf("%d %% %d = %d\n", 11, 4, 11 % 4); }
+void testPlus(){ printf("%d + %d = %d\n", 10, 4, 10 + 4); }
+void testMinus(){ printf("%d - %d = %d\n", 10, 4, 10 - 4); }
+void testShiftLeft(){ printf("%d << %d = %d\n", 10, 4, 10 << 4); }
+void testShiftRight(){ printf("%d >> %d = %d\n", 100, 4, 100 >> 4); }
+void testLess(){ printf("%d < %d = %d\n", 10, 4, 10 < 4); }
+void testLesEqual(){ printf("%d <= %d = %d\n", 10, 4, 10 <= 4); }
+void testGreater(){ printf("%d > %d = %d\n", 10, 4, 10 > 4); }
+void testGreaterEqual(){ printf("%d >= %d = %d\n", 10, 4, 10 >= 4); }
+void testEqualTo(){ printf("%d == %d = %d\n", 10, 4, 10 == 4); }
+void testNotEqualTo(){ printf("%d != %d = %d\n", 10, 4, 10 != 4); }
+void testBitAnd(){ printf("%d & %d = %d\n", 10, 7, 10 & 7); }
+void testBitXor(){ printf("%d ^ %d = %d\n", 10, 7, 10 ^ 7); }
+void testBitOr(){ printf("%d | %d = %d\n", 10, 4, 10 | 4); }
+void testAssignment(){ int a, b; a = 3; b = a; printf("b == %d\n", b); }
+void testLogicalAnd(){ printf("%d && %d = %d\n", 10, 4, 10 && 4); }
+void testLogicalOr(){ printf("%d || %d = %d\n", 10, 4, 10 || 4); }
+void testAddressOf(){ int a; printf("&a is %d\n", &a); }
+void testPointerIndirection(){ int a, b; a = &b; b = 17; printf("*%d = %d =?= %d\n", a, * (int*) a, b); }
+void testNegation(){ printf("-%d = %d\n", 10, -10); }
+void testUnaryPlus(){ printf("+%d = %d\n", 10, +10); }
+void testUnaryNot(){ printf("!%d = %d\n", 10, !10); }
+void testBitNot(){ printf("~%d = %d\n", 10, ~10); }
+
+int main(int a, char** b) {
+ testInc();
+ testDec();
+ testTimes();
+ testDiv();
+ testMod();
+ testPlus();
+ testMinus();
+ testShiftLeft();
+ testShiftRight();
+ testLess();
+ testLesEqual();
+ testGreater();
+ testGreaterEqual();
+ testEqualTo();
+ testNotEqualTo();
+ testBitAnd();
+ testBinXor();
+ testBitOr();
+ testAssignment();
+ testLogicalAnd();
+ testLogicalOr();
+ testAddressOf();
+ testPointerIndirection();
+ testNegation();
+ testUnaryPlus();
+ testUnaryNot();
+ testBitNot();
+ return 0;
+}
diff --git a/libacc/tests/data/expr2.c b/libacc/tests/data/expr2.c
new file mode 100644
index 0000000..04b6a38
--- /dev/null
+++ b/libacc/tests/data/expr2.c
@@ -0,0 +1,6 @@
+/* Test operators */
+
+main() {
+ int a;
+ a = a++;
+}
diff --git a/libacc/tests/data/locals.c b/libacc/tests/data/locals.c
new file mode 100644
index 0000000..f1ef363
--- /dev/null
+++ b/libacc/tests/data/locals.c
@@ -0,0 +1,71 @@
+int a;
+
+int f() {
+ int a;
+ // Undefined variable b
+ // printf("f 0: a = %d b = %d\n", a, b);
+ printf("f 0: a = %d\n", a);
+ a = 2;
+ printf("f 1: a = %d\n", a);
+}
+
+int g(int a) {
+ printf("g 0: a = %d\n", a);
+ a = 3;
+ printf("g 1: a = %d\n", a);
+}
+
+int h(int a) {
+ // int a; // gcc 4.3 says error: 'a' redeclared as different kind of symbol
+
+ printf("h 0: a = %d\n", a);
+ a = 4;
+ printf("h 1: a = %d\n", a);
+}
+
+// Already defined global
+// int h() {}
+int globCheck() {
+ fprintf(stdout, "globCheck()\n");
+}
+
+int fwdCheck() {
+ b();
+ // Undefined forward reference
+ // c();
+}
+
+int b() {
+ printf("b()\n");
+}
+
+int nested() {
+ int a;
+ printf("nested 0: a = %d\n", a);
+ a = 50;
+ printf("nested 1: a = %d\n", a);
+ {
+ int a;
+ printf("nested 2: a = %d\n", a);
+ a = 51;
+ printf("nested 3: a = %d\n", a);
+ }
+ printf("nested 4: a = %d\n", a);
+}
+
+int main() {
+ globCheck();
+ fwdCheck();
+ printf("main 0: a = %d\n", a);
+ a = 5;
+ printf("main 1: a = %d\n", a);
+ f();
+ printf("main 2: a = %d\n", a);
+ g(77);
+ printf("main 3: a = %d\n", a);
+ h(30);
+ printf("main 4: a = %d\n", a);
+ nested();
+ printf("main 5: a = %d\n", a);
+ return 0;
+}
diff --git a/libacc/tests/data/otcc-ansi.c b/libacc/tests/data/otcc-ansi.c
index 069514b..72580e9 100644
--- a/libacc/tests/data/otcc-ansi.c
+++ b/libacc/tests/data/otcc-ansi.c
@@ -50,7 +50,7 @@ void ad() {
o();
}
C = 0;
- d = h;
+ d = h;
if (X()) {
E(32);
M = D;
@@ -162,7 +162,7 @@ void Z(int e) {
void N(int j, int e) {
ae(j + 131);
- s((e < 512) << 7 | 5, e);
+ s((e > -512 && e < 512) << 7 | 5, e);
}
void T (int j) {
@@ -404,7 +404,7 @@ void ab (int j) {
v=v +4;
}
ad();
- if( d == 44)ad();
+ if( d == 44)ad() ;
}
ad();
}
@@ -432,11 +432,20 @@ void ab (int j) {
}
}
+int run(int g, int e) {
+ return (*(int(*)()) *(int*) (P + 592))(g, e);
+}
+
int main(int g, int e) {
+ int result;
Q = stdin;
if (g-- > 1) {
e = e + 4;
Q = fopen(*(int*) e, "r");
+ if (!Q) {
+ fprintf(stderr, "otcc-ansi.c: could not open file %s\n", *(int*) e);
+ return -2;
+ }
}
D = strcpy(R = calloc(1, 99999), " int if else while break return for define main ") + 48;
v = calloc(1, 99999);
@@ -445,5 +454,13 @@ int main(int g, int e) {
o();
ad();
ab(0);
- return (*(int(*)()) *(int*) (P + 592))(g, e);
+ if (mprotect(ac & (~ 4095), (99999 + 4095) & (~ 4095), 7)) {
+ printf("Mprotect failed. %d\n", errno);
+ return -1;
+ }
+ fprintf(stderr, "otcc-ansi.c: About to execute compiled code:\n");
+ result = run(g, e);
+ fprintf(stderr, "atcc-ansi.c: result: %d\n", result);
+ return result;
}
+
diff --git a/libacc/tests/data/otcc.c b/libacc/tests/data/otcc.c
index 577fcf3..433ae2e 100644
--- a/libacc/tests/data/otcc.c
+++ b/libacc/tests/data/otcc.c
@@ -441,6 +441,8 @@ P V;
o f;
c;
ab(0);
+mprotect(ac & (~ 4095), (99999 + 4095) & (~ 4095), 7);
+fprintf(stderr, "otcc.c: about to execute compiled code.\n");
J(*(int(*)f)k(P+592))(g,n;
}
diff --git a/libacc/tests/data/returnval-ansi.c b/libacc/tests/data/returnval-ansi.c
index 42802c5..6b53fd5 100644
--- a/libacc/tests/data/returnval-ansi.c
+++ b/libacc/tests/data/returnval-ansi.c
@@ -1,7 +1,8 @@
+
int main(int argc, char** argv) {
return f();
}
int f() {
- return 10;
+ return 42;
}
diff --git a/libacc/tests/data/returnval.c b/libacc/tests/data/returnval.c
index 1b9dd81..1cf5bae 100644
--- a/libacc/tests/data/returnval.c
+++ b/libacc/tests/data/returnval.c
@@ -1,6 +1,3 @@
-#pragma foo3(bar) //sdfsfd
-#pragma a(b)
-
main() {
return 42;
}
diff --git a/libacc/tests/main.cpp b/libacc/tests/main.cpp
index acee09d..4f8a65d 100644
--- a/libacc/tests/main.cpp
+++ b/libacc/tests/main.cpp
@@ -32,6 +32,7 @@ int run(MainPtr mainFunc, int argc, char** argv) {
int main(int argc, char** argv) {
const char* inFile = NULL;
bool printListing;
+ bool runResults = false;
FILE* in = stdin;
int i;
for (i = 1; i < argc; i++) {
@@ -41,6 +42,9 @@ int main(int argc, char** argv) {
case 'S':
printListing = true;
break;
+ case 'R':
+ runResults = true;
+ break;
default:
fprintf(stderr, "Unrecognized flag %s\n", arg);
return 3;
@@ -105,16 +109,20 @@ int main(int argc, char** argv) {
}
}
- accGetScriptLabel(script, "main", (ACCvoid**) & mainPointer);
+ if (runResults) {
+ accGetScriptLabel(script, "main", (ACCvoid**) & mainPointer);
- result = accGetError(script);
- if (result == ACC_NO_ERROR) {
- fprintf(stderr, "Executing compiled code:\n");
- int codeArgc = argc - i + 1;
- char** codeArgv = argv + i - 1;
- codeArgv[0] = (char*) (inFile ? inFile : "stdin");
- result = run(mainPointer, codeArgc, codeArgv);
- fprintf(stderr, "result: %d\n", result);
+ result = accGetError(script);
+ if (result != ACC_NO_ERROR) {
+ fprintf(stderr, "Could not find main: %d\n", result);
+ } else {
+ fprintf(stderr, "Executing compiled code:\n");
+ int codeArgc = argc - i + 1;
+ char** codeArgv = argv + i - 1;
+ codeArgv[0] = (char*) (inFile ? inFile : "stdin");
+ result = run(mainPointer, codeArgc, codeArgv);
+ fprintf(stderr, "result: %d\n", result);
+ }
}
exit:
diff --git a/libacc/tests/testarm b/libacc/tests/testarm
index 24fbc42..1d4b866 100755
--- a/libacc/tests/testarm
+++ b/libacc/tests/testarm
@@ -6,4 +6,4 @@ cd ..
mm -j8
cd tests
adb sync
-adb shell /system/bin/acc -S /system/bin/returnval-ansi.c
+adb shell /system/bin/acc -R -S /system/bin/returnval-ansi.c
diff --git a/libacc/tests/testlocal b/libacc/tests/testlocal
index ccabf7d..1a0b4c5 100755
--- a/libacc/tests/testlocal
+++ b/libacc/tests/testlocal
@@ -1,17 +1,23 @@
-#!/bin/sh
-rm -f test-acc
-cd ..
-g++ -I../include acc.cpp disassem.cpp tests/main.cpp -g -ldl -o tests/test-acc
-cd tests
-if [ -x "test-acc" ]; then
- ./test-acc -S data/returnval-ansi.c
+#!/bin/bash
- if [ "$(uname)" = "Linux" ]; then
- if [ "$(uname -m)" = "i686" ]; then
- echo "Linux i686. Testing otcc-ansi.c"
- ./test-acc data/otcc-ansi.c data/returnval.c
- echo "Linux i686. Testing otcc-ansi.c data/otcc.c"
- ./test-acc data/otcc-ansi.c data/otcc.c data/returnval.c
- fi
- fi
+SCRIPT_DIR=`dirname $BASH_SOURCE`
+DATA=$SCRIPT_DIR/data
+ACC=`which acc`
+
+echo "Compiling returnval-ansi.c"
+$ACC -S $DATA/returnval-ansi.c
+
+echo "Compiling whole compiler."
+$ACC -S "$DATA/otcc-ansi.c"
+
+if file $ACC | grep -q "ELF 32-bit LSB executable, Intel 80386"; then
+ echo "Linux 32bit Intel."
+ echo "TESTING returnval-ansi.c:"
+ $ACC -R $DATA/returnval-ansi.c
+ echo TESTING otcc-ansi.c returnval-ansi.c
+ $ACC -R "$DATA/otcc-ansi.c" "$DATA/returnval.c"
+ echo TESTING otcc-ansi.c otcc.c returnval-ansi.c
+ $ACC -R $DATA/otcc-ansi.c $DATA/otcc.c $DATA/returnval.c
fi
+
+echo "Done with tests."