summaryrefslogtreecommitdiffstats
path: root/libacc/tests
diff options
context:
space:
mode:
Diffstat (limited to 'libacc/tests')
-rw-r--r--libacc/tests/.gitignore2
-rw-r--r--libacc/tests/Android.mk15
-rw-r--r--libacc/tests/data/bellard.otccex.c (renamed from libacc/tests/bellard.otccex.c)0
-rw-r--r--libacc/tests/data/expr.c (renamed from libacc/tests/expr.c)0
-rw-r--r--libacc/tests/data/hello.c (renamed from libacc/tests/hello.c)0
-rw-r--r--libacc/tests/data/missing-main.c (renamed from libacc/tests/missing-main.c)0
-rw-r--r--libacc/tests/data/otcc.c (renamed from libacc/tests/otcc.c)0
-rw-r--r--libacc/tests/data/returnval.c (renamed from libacc/tests/returnval.c)0
-rw-r--r--libacc/tests/data/simplest.c (renamed from libacc/tests/simplest.c)0
-rw-r--r--libacc/tests/hello.out-origbin40 -> 0 bytes
-rw-r--r--libacc/tests/main.cpp102
-rw-r--r--libacc/tests/otcc.out-origbin8591 -> 0 bytes
-rwxr-xr-xlibacc/tests/testarm9
-rwxr-xr-xlibacc/tests/testlocal15
14 files changed, 142 insertions, 1 deletions
diff --git a/libacc/tests/.gitignore b/libacc/tests/.gitignore
index 9974532..a26b298 100644
--- a/libacc/tests/.gitignore
+++ b/libacc/tests/.gitignore
@@ -1,2 +1,2 @@
-acc
+test-acc
*.out
diff --git a/libacc/tests/Android.mk b/libacc/tests/Android.mk
new file mode 100644
index 0000000..2cff9d3
--- /dev/null
+++ b/libacc/tests/Android.mk
@@ -0,0 +1,15 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ main.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+ libacc
+
+LOCAL_MODULE:= acc
+
+LOCAL_MODULE_TAGS := tests
+
+include $(BUILD_EXECUTABLE)
+
diff --git a/libacc/tests/bellard.otccex.c b/libacc/tests/data/bellard.otccex.c
index e8f0989..e8f0989 100644
--- a/libacc/tests/bellard.otccex.c
+++ b/libacc/tests/data/bellard.otccex.c
diff --git a/libacc/tests/expr.c b/libacc/tests/data/expr.c
index 4f2d2e7..4f2d2e7 100644
--- a/libacc/tests/expr.c
+++ b/libacc/tests/data/expr.c
diff --git a/libacc/tests/hello.c b/libacc/tests/data/hello.c
index 585ce6c..585ce6c 100644
--- a/libacc/tests/hello.c
+++ b/libacc/tests/data/hello.c
diff --git a/libacc/tests/missing-main.c b/libacc/tests/data/missing-main.c
index e73eec4..e73eec4 100644
--- a/libacc/tests/missing-main.c
+++ b/libacc/tests/data/missing-main.c
diff --git a/libacc/tests/otcc.c b/libacc/tests/data/otcc.c
index 577fcf3..577fcf3 100644
--- a/libacc/tests/otcc.c
+++ b/libacc/tests/data/otcc.c
diff --git a/libacc/tests/returnval.c b/libacc/tests/data/returnval.c
index 3142fe2..3142fe2 100644
--- a/libacc/tests/returnval.c
+++ b/libacc/tests/data/returnval.c
diff --git a/libacc/tests/simplest.c b/libacc/tests/data/simplest.c
index bae895a..bae895a 100644
--- a/libacc/tests/simplest.c
+++ b/libacc/tests/data/simplest.c
diff --git a/libacc/tests/hello.out-orig b/libacc/tests/hello.out-orig
deleted file mode 100644
index 1fb7bf5..0000000
--- a/libacc/tests/hello.out-orig
+++ /dev/null
Binary files differ
diff --git a/libacc/tests/main.cpp b/libacc/tests/main.cpp
new file mode 100644
index 0000000..8cfc196
--- /dev/null
+++ b/libacc/tests/main.cpp
@@ -0,0 +1,102 @@
+/*
+ * Android "Almost" C Compiler.
+ * This is a compiler for a small subset of the C language, intended for use
+ * in scripting environments where speed and memory footprint are important.
+ *
+ * This code is based upon the "unobfuscated" version of the
+ * Obfuscated Tiny C compiler, see the file LICENSE for details.
+ *
+ */
+
+#include <ctype.h>
+#include <dlfcn.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(__arm__)
+#include <unistd.h>
+#endif
+
+#include <acc/acc.h>
+
+
+typedef int (*MainPtr)(int, char**);
+// This is a separate function so it can easily be set by breakpoint in gdb.
+int run(MainPtr mainFunc, int argc, char** argv) {
+ return mainFunc(argc, argv);
+}
+
+int main(int argc, char** argv) {
+ const char* inFile = NULL;
+ bool printListing;
+ FILE* in = stdin;
+ int i;
+ for (i = 1; i < argc; i++) {
+ char* arg = argv[i];
+ if (arg[0] == '-') {
+ switch (arg[1]) {
+ case 'S':
+ printListing = true;
+ break;
+ default:
+ fprintf(stderr, "Unrecognized flag %s\n", arg);
+ return 3;
+ }
+ } else if (inFile == NULL) {
+ inFile = arg;
+ } else {
+ break;
+ }
+ }
+
+ if (! inFile) {
+ fprintf(stderr, "input file required\n");
+ return 2;
+ }
+
+ if (inFile) {
+ in = fopen(inFile, "r");
+ if (!in) {
+ fprintf(stderr, "Could not open input file %s\n", inFile);
+ return 1;
+ }
+ }
+
+ fseek(in, 0, SEEK_END);
+ size_t fileSize = (size_t) ftell(in);
+ rewind(in);
+ ACCchar* text = new ACCchar[fileSize];
+ size_t bytesRead = fread(text, 1, fileSize, in);
+ if (bytesRead != fileSize) {
+ fprintf(stderr, "Could not read all of file %s\n", inFile);
+ }
+
+ ACCscript* script = accCreateScript();
+
+ const ACCchar* scriptSource[] = {text};
+ accScriptSource(script, 1, scriptSource, NULL);
+ delete[] text;
+
+ accCompileScript(script);
+
+ MainPtr mainPointer = 0;
+
+ accGetScriptLabel(script, "main", (ACCvoid**) & mainPointer);
+
+ int 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);
+ }
+
+ accDeleteScript(script);
+
+ return result;
+}
diff --git a/libacc/tests/otcc.out-orig b/libacc/tests/otcc.out-orig
deleted file mode 100644
index fa14c72..0000000
--- a/libacc/tests/otcc.out-orig
+++ /dev/null
Binary files differ
diff --git a/libacc/tests/testarm b/libacc/tests/testarm
new file mode 100755
index 0000000..db7ebe5
--- /dev/null
+++ b/libacc/tests/testarm
@@ -0,0 +1,9 @@
+#!/bin/sh
+adb remount
+adb shell rm /system/bin/acc
+adb push data/returnval.c /system/bin/returnval.c
+cd ..
+mm -j8
+cd tests
+adb sync
+adb shell /system/bin/acc -S /system/bin/returnval.c
diff --git a/libacc/tests/testlocal b/libacc/tests/testlocal
new file mode 100755
index 0000000..a76322b
--- /dev/null
+++ b/libacc/tests/testlocal
@@ -0,0 +1,15 @@
+#!/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.c
+
+ if [ "$(uname)" = "Linux" ]; then
+ if [ "$(uname -m)" = "i686" ]; then
+ echo "Linux i686. Testing otcc.c"
+ ./test-acc data/otcc.c data/otcc.c data/returnval.c
+ fi
+ fi
+fi