aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2011-01-14 22:44:52 -0800
committerAlon Zakai <azakai@mozilla.com>2011-01-14 22:44:52 -0800
commit9d209878f9819ffd1aa92c7306123392609db845 (patch)
tree2a6093cc6ce7fce34ea2a0473a639388b0a37d4e /tests
parent60122ddc2e157b1cf117e6e098a2fc336c92d5a7 (diff)
refactor shared components of python tools, and add emmaken.py
Diffstat (limited to 'tests')
-rw-r--r--tests/runner.py65
-rw-r--r--tests/settings.py13
2 files changed, 36 insertions, 42 deletions
diff --git a/tests/runner.py b/tests/runner.py
index 27f93224..86647fbb 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -7,25 +7,25 @@ See settings.py file for options&params. Edit as needed.
from subprocess import Popen, PIPE, STDOUT
import os, unittest, tempfile, shutil, time, inspect, sys, math, glob
-# Params
+# Setup
abspath = os.path.abspath(os.path.dirname(__file__))
-def path_from_root(pathelems):
- return os.path.join(os.path.sep, *(abspath.split(os.sep)[:-1] + pathelems))
+def path_from_root(*pathelems):
+ return os.path.join(os.path.sep, *(abspath.split(os.sep)[:-1] + list(pathelems)))
+exec(open(path_from_root('tools', 'shared.py'), 'r').read())
-EMSCRIPTEN = path_from_root(['emscripten.py'])
+# Sanity check for config
-exec(open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'settings.py'), 'r').read())
+try:
+ assert COMPILERS != None
+except:
+ raise Exception('Cannot find "COMPILERS" definition. Is ~/.emscripten set up properly? You may need to copy the template at ~/tests/settings.py into it.')
-def timeout_run(proc, timeout, note):
- start = time.time()
- if timeout is not None:
- while time.time() - start < timeout and proc.poll() is None:
- time.sleep(0.1)
- if proc.poll() is None:
- proc.kill() # XXX bug: killing emscripten.py does not kill it's child process!
- raise Exception("Timed out: " + note)
- return proc.communicate()[0]
+# Paths
+
+EMSCRIPTEN = path_from_root('emscripten.py')
+DEMANGLER = path_from_root('third_party', 'demangler.py')
+NAMESPACER = path_from_root('tools', 'namespacer.py')
class RunnerCore(unittest.TestCase):
def get_dir(self):
@@ -106,7 +106,7 @@ class RunnerCore(unittest.TestCase):
shutil.move(os.path.join(dirname, main_file), filename)
# Copy Emscripten C++ API
- shutil.copy(path_from_root(['src', 'include', 'emscripten.h']), dirname)
+ shutil.copy(path_from_root('src', 'include', 'emscripten.h'), dirname)
# C++ => LLVM binary
try:
@@ -1288,25 +1288,25 @@ if 'benchmark' not in sys.argv:
def test_fannkuch(self):
results = [ (1,0), (2,1), (3,2), (4,4), (5,7), (6,10), (7, 16), (8,22) ]
for i, j in results:
- src = open(path_from_root(['tests', 'fannkuch.cpp']), 'r').read()
+ src = open(path_from_root('tests', 'fannkuch.cpp'), 'r').read()
self.do_test(src, 'Pfannkuchen(%d) = %d.' % (i,j), [str(i)], no_build=i>1)
def test_raytrace(self):
- src = open(path_from_root(['tests', 'raytrace.cpp']), 'r').read()
- output = open(path_from_root(['tests', 'raytrace.ppm']), 'r').read()
+ src = open(path_from_root('tests', 'raytrace.cpp'), 'r').read()
+ output = open(path_from_root('tests', 'raytrace.ppm'), 'r').read()
self.do_test(src, output, ['3', '16'])
def test_dlmalloc(self):
# XXX Warning: Running this in SpiderMonkey can lead to an extreme amount of memory being
# used, see Mozilla bug 593659.
- src = open(path_from_root(['tests', 'dlmalloc.c']), 'r').read()
+ src = open(path_from_root('tests', 'dlmalloc.c'), 'r').read()
self.do_test(src, '*1,0*')
def test_fasta(self):
results = [ (1,'''GG*ctt**tgagc*'''), (20,'''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTT*cttBtatcatatgctaKggNcataaaSatgtaaaDcDRtBggDtctttataattcBgtcg**tacgtgtagcctagtgtttgtgttgcgttatagtctatttgtggacacagtatggtcaaa**tgacgtcttttgatctgacggcgttaacaaagatactctg*'''),
(50,'''GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGGGAGGCCGAGGCGGGCGGA*TCACCTGAGGTCAGGAGTTCGAGACCAGCCTGGCCAACAT*cttBtatcatatgctaKggNcataaaSatgtaaaDcDRtBggDtctttataattcBgtcg**tactDtDagcctatttSVHtHttKtgtHMaSattgWaHKHttttagacatWatgtRgaaa**NtactMcSMtYtcMgRtacttctWBacgaa**agatactctgggcaacacacatacttctctcatgttgtttcttcggacctttcataacct**ttcctggcacatggttagctgcacatcacaggattgtaagggtctagtggttcagtgagc**ggaatatcattcgtcggtggtgttaatctatctcggtgtagcttataaatgcatccgtaa**gaatattatgtttatttgtcggtacgttcatggtagtggtgtcgccgatttagacgtaaa**ggcatgtatg*''') ]
for i, j in results:
- src = open(path_from_root(['tests', 'fasta.cpp']), 'r').read()
+ src = open(path_from_root('tests', 'fasta.cpp'), 'r').read()
self.do_test(src, j, [str(i)], lambda x: x.replace('\n', '*'), no_build=i>1)
def zzztest_gl(self):
@@ -1323,7 +1323,7 @@ if 'benchmark' not in sys.argv:
};'''
)
open(filename, 'w').write(src)
- self.do_test(path_from_root(['tests', 'gl']), '*?*', main_file='sdl_ogl.c', post_build=post)
+ self.do_test(path_from_root('tests', 'gl'), '*?*', main_file='sdl_ogl.c', post_build=post)
def test_cubescript(self):
# XXX Warning: Running this in SpiderMonkey can lead to an extreme amount of memory being
@@ -1333,10 +1333,10 @@ if 'benchmark' not in sys.argv:
# Overflows happen in hash loop
global CORRECT_OVERFLOWS; CORRECT_OVERFLOWS = 1
- self.do_test(path_from_root(['tests', 'cubescript']), '*\nTemp is 33\n9\n5\nhello, everyone\n*', main_file='command.cpp')
+ self.do_test(path_from_root('tests', 'cubescript'), '*\nTemp is 33\n9\n5\nhello, everyone\n*', main_file='command.cpp')
def test_gcc_unmangler(self):
- self.do_test(path_from_root(['third_party']), '*d_demangle(char const*, int, unsigned int*)*', args=['_ZL10d_demanglePKciPj'], main_file='gcc_demangler.c')
+ self.do_test(path_from_root('third_party'), '*d_demangle(char const*, int, unsigned int*)*', args=['_ZL10d_demanglePKciPj'], main_file='gcc_demangler.c')
#### Code snippet that is helpful to search for nonportable optimizations ####
#global LLVM_OPT_OPTS
@@ -1350,13 +1350,13 @@ if 'benchmark' not in sys.argv:
def test_bullet(self):
global SAFE_HEAP; SAFE_HEAP = 0 # Too slow for that
- self.do_ll_test(path_from_root(['tests', 'bullet', 'bulletTest.ll']), open(path_from_root(['tests', 'bullet', 'output.txt']), 'r').read())
+ self.do_ll_test(path_from_root('tests', 'bullet', 'bulletTest.ll'), open(path_from_root('tests', 'bullet', 'output.txt'), 'r').read())
def test_lua(self):
# Overflows in luaS_newlstr hash loop
global CORRECT_OVERFLOWS; CORRECT_OVERFLOWS = 1
- self.do_ll_test(path_from_root(['tests', 'lua', 'lua.ll']),
+ self.do_ll_test(path_from_root('tests', 'lua', 'lua.ll'),
'hello lua world!\n17.00000000000\n1.00000000000\n2.00000000000\n3.00000000000\n4.00000000000\n7.00000000000',
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'))
@@ -1367,7 +1367,7 @@ if 'benchmark' not in sys.argv:
global RELOOP; RELOOP = 0 # Too slow; we do care about typed arrays and OPTIMIZE though
global SAFE_HEAP; SAFE_HEAP = 0 # Has bitfields which are false positives. Also the PyFloat_Init tries to detect endianness.
- self.do_ll_test(path_from_root(['tests', 'python', 'python.ll']),
+ self.do_ll_test(path_from_root('tests', 'python', 'python.ll'),
'hello python world!\n\n[0, 2, 4, 6]\n\n5\n\n22\n\n5.470',
args=['-S', '-c' '''print "hello python world!"; print [x*2 for x in range(4)]; t=2; print 10-3-t; print (lambda x: x*2)(11); print '%f' % 5.47'''],
js_engines=[V8_ENGINE]) # script stack space exceeded in SpiderMonkey, TODO
@@ -1376,15 +1376,15 @@ if 'benchmark' not in sys.argv:
def test_cases(self):
if LLVM_OPTS: return # Our code is not exactly 'normal' llvm assembly
- for name in glob.glob(path_from_root(['tests', 'cases', '*.ll'])):
+ for name in glob.glob(path_from_root('tests', 'cases', '*.ll')):
shortname = name.replace('.ll', '')
print "Testing case '%s'..." % shortname
- output_file = path_from_root(['tests', 'cases', shortname + '.txt'])
+ output_file = path_from_root('tests', 'cases', shortname + '.txt')
if os.path.exists(output_file):
output = open(output_file, 'r').read()
else:
output = 'hello, world!'
- self.do_ll_test(path_from_root(['tests', 'cases', name]), output)
+ self.do_ll_test(path_from_root('tests', 'cases', name), output)
### Integration tests
@@ -1417,7 +1417,6 @@ if 'benchmark' not in sys.argv:
'Module["_"] = ' + open(filename + '.tmp2', 'r').read().rstrip() + ';\n\n' + script_src + '\n\n' +
'// {{MODULE_ADDITIONS}'
)
-
open(filename, 'w').write(src)
self.do_test(src, '*166*\n*ok*', post_build=post)
@@ -1598,12 +1597,12 @@ else:
self.do_benchmark(src, [], 'lastprime: 348949.')
def test_fannkuch(self):
- src = open(path_from_root(['tests', 'fannkuch.cpp']), 'r').read()
+ src = open(path_from_root('tests', 'fannkuch.cpp'), 'r').read()
self.do_benchmark(src, ['9'], 'Pfannkuchen(9) = 30.')
def test_raytrace(self):
- src = open(path_from_root(['tests', 'raytrace.cpp']), 'r').read()
- self.do_benchmark(src, ['5', '64'], open(path_from_root(['tests', 'raytrace_5_64.ppm']), 'r').read())
+ src = open(path_from_root('tests', 'raytrace.cpp'), 'r').read()
+ self.do_benchmark(src, ['5', '64'], open(path_from_root('tests', 'raytrace_5_64.ppm'), 'r').read())
if __name__ == '__main__':
sys.argv = [sys.argv[0]] + ['-v'] + sys.argv[1:] # Verbose output by default
diff --git a/tests/settings.py b/tests/settings.py
index a52d6c6f..c2607a49 100644
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -1,10 +1,3 @@
-# XXX: Aside from these settings, you should create ~/.emscripten, and fill it with
-# something like this:
-#
-# JS_ENGINE=[os.path.expanduser('~/Dev/tracemonkey/js/src/js'), '-m']
-# JS_ENGINE_PARAMS=[]
-#
-
TEMP_DIR='/dev/shm'
LLVM_ROOT=os.path.expanduser('~/Dev/llvm-2.8/cbuild/Release/bin') # Might not need 'Release'
@@ -43,6 +36,10 @@ V8_ENGINE = [os.path.expanduser('~/Dev/v8/d8')]
#COMPILER_ENGINE=SPIDERMONKEY_ENGINE
COMPILER_ENGINE=V8_ENGINE
+JS_ENGINE=V8_ENGINE
+JS_ENGINE_PARAMS = ['--'] # For V8
+JS_ENGINE_PARAMS = [] # For SpiderMonkey
+
OUTPUT_TO_SCREEN = 0 # useful for debugging specific tests, or for subjectively seeing what parts are slow
TIMEOUT = None
@@ -50,6 +47,4 @@ TIMEOUT = None
# Tools
CLOSURE_COMPILER = os.path.expanduser('~/Dev/closure-compiler/compiler.jar')
-DEMANGLER = path_from_root(['third_party', 'demangler.py'])
-NAMESPACER = path_from_root(['tools', 'namespacer.py'])