aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2011-01-16 13:52:25 -0800
committerAlon Zakai <azakai@mozilla.com>2011-01-16 13:52:25 -0800
commit6a6e842688afe7e15f6a957d4179da982c0f940b (patch)
tree9f31de60b019df0c8c6b0ca23d0ba963e2b1ed76 /tests
parent9d209878f9819ffd1aa92c7306123392609db845 (diff)
initial emulation for stdio file reading, and other preparations for poppler
Diffstat (limited to 'tests')
-rw-r--r--tests/files.cpp33
-rw-r--r--tests/runner.py37
2 files changed, 66 insertions, 4 deletions
diff --git a/tests/files.cpp b/tests/files.cpp
new file mode 100644
index 00000000..a07ef42b
--- /dev/null
+++ b/tests/files.cpp
@@ -0,0 +1,33 @@
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main() {
+ FILE *file = fopen("somefile.binary", "rb");
+ assert(file);
+
+ fseek(file, 0, SEEK_END);
+ int size = ftell(file);
+ rewind (file);
+ printf("size: %d\n", size);
+
+ char *buffer = (char*) malloc (sizeof(char)*size);
+ assert(buffer);
+
+ size_t read = fread(buffer, 1, size, file);
+ assert(read == size);
+
+ printf("data: %d", buffer[0]);
+ for (int i = 1; i < size; i++)
+ printf(",%d", buffer[i]);
+ printf("\n");
+
+ fclose (file);
+ free (buffer);
+
+ fwrite("texto\n", 1, 6, stdout);
+ fwrite("texte\n", 1, 6, stderr);
+
+ return 0;
+}
+
diff --git a/tests/runner.py b/tests/runner.py
index 86647fbb..817a681a 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -91,7 +91,11 @@ class RunnerCore(unittest.TestCase):
if LLVM_OPTS:
shutil.move(filename + '.o', filename + '.o.pre')
output = Popen([LLVM_OPT, filename + '.o.pre'] + LLVM_OPT_OPTS + ['-o=' + filename + '.o'], stdout=PIPE, stderr=STDOUT).communicate()[0]
-
+
+ def do_llvm_dis(self, filename):
+ # LLVM binary ==> LLVM assembly
+ Popen([LLVM_DIS, filename + '.o'] + LLVM_DIS_OPTS + ['-o=' + filename + '.o.ll'], stdout=PIPE, stderr=STDOUT).communicate()[0]
+
# Build JavaScript code from source code
def build(self, src, dirname, filename, output_processor=None, main_file=None):
# Copy over necessary files for compiling the source
@@ -125,8 +129,7 @@ class RunnerCore(unittest.TestCase):
self.do_llvm_opts(filename)
- # LLVM binary ==> LLVM assembly
- output = Popen([LLVM_DIS, filename + '.o'] + LLVM_DIS_OPTS + ['-o=' + filename + '.o.ll'], stdout=PIPE, stderr=STDOUT).communicate()[0]
+ self.do_llvm_dis(filename)
self.do_emscripten(filename, output_processor)
@@ -187,11 +190,19 @@ if 'benchmark' not in sys.argv:
#shutil.rmtree(dirname) # TODO: leave no trace in memory. But for now nice for debugging
- # No building - just process an existing .ll file
+ # No building - just process an existing .ll file (or .bc, which we turn into .ll)
def do_ll_test(self, ll_file, output, args=[], js_engines=None, output_nicerizer=None):
if COMPILER != LLVM_GCC: return # We use existing .ll, so which compiler is unimportant
filename = os.path.join(self.get_dir(), 'src.cpp')
+
+ if ll_file.endswith('.bc'):
+ shutil.copy(ll_file, filename + '.o')
+ self.do_llvm_dis(filename)
+ shutil.copy(filename + '.o.ll', filename + '.o.ll.in')
+ os.remove(filename + '.o.ll')
+ ll_file = filename + '.o.ll.in'
+
if LLVM_OPTS:
shutil.copy(ll_file, filename + '.o.ll.pre')
Popen([LLVM_AS, filename + '.o.ll.pre'] + ['-o=' + filename + '.o'], stdout=PIPE, stderr=STDOUT).communicate()[0]
@@ -1283,6 +1294,16 @@ if 'benchmark' not in sys.argv:
# Bloated memory; same layout as C/C++
self.do_test(src, '*16,0,4,8,8,12|20,0,4,4,8,12,12,16|24,0,20,0,4,4,8,12,12,16*\n*0,0,0,1,2,64,68,69,72*\n*2*')
+ def test_files(self):
+ def post(filename):
+ src = open(filename, 'r').read().replace(
+ '// {{PRE_RUN_ADDITIONS}}',
+ '''this._STDIO.prepare('somefile.binary', [100, 200, 50, 25, 10, 77, 123]);'''
+ )
+ open(filename, 'w').write(src)
+ src = open(path_from_root('tests', 'files.cpp'), 'r').read()
+ self.do_test(src, 'size: 7\ndata: 100,200,50,25,10,77,123\ntexto\ntexte\n', post_build=post)
+
### 'Big' tests
def test_fannkuch(self):
@@ -1361,6 +1382,14 @@ if 'benchmark' not in sys.argv:
args=['-e', '''print("hello lua world!");print(17);for x = 1,4 do print(x) end;print(10-3)'''],
output_nicerizer=lambda string: string.replace('\n\n', '\n').replace('\n\n', '\n'))
+ def zzztest_poppler(self):
+ # Has 'Object', which has a big union with a value that can be of any type (like a dynamic value)
+ global SAFE_HEAP; SAFE_HEAP = 0
+
+ self.do_ll_test(path_from_root('tests', 'poppler', 'pdftoppm.bc'),
+ 'halp',
+ args='-png -l 1 -scale-to 512 ~/Dev/emscripten/docs/paper.pdf filename'.split(' '))
+
def test_python(self):
# Overflows in string_hash
global CORRECT_OVERFLOWS; CORRECT_OVERFLOWS = 1