aboutsummaryrefslogtreecommitdiff
path: root/tests/runner.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/runner.py')
-rw-r--r--tests/runner.py85
1 files changed, 76 insertions, 9 deletions
diff --git a/tests/runner.py b/tests/runner.py
index b8de669e..30f5f62c 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -129,7 +129,11 @@ process(sys.argv[1])
f = open(filename, 'w')
f.write(src)
f.close()
- assert len(additional_files) == 0
+ final_additional_files = []
+ for f in additional_files:
+ final_additional_files.append(os.path.join(dirname, os.path.basename(f)))
+ shutil.copyfile(f, final_additional_files[-1])
+ additional_files = final_additional_files
else:
# copy whole directory, and use a specific main .cpp file
shutil.rmtree(dirname)
@@ -139,8 +143,6 @@ process(sys.argv[1])
additional_files = map(lambda f: os.path.join(dirname, f), additional_files)
# C++ => LLVM binary
- os.chdir(dirname)
- cwd = os.getcwd()
for f in [filename] + additional_files:
try:
@@ -155,8 +157,6 @@ process(sys.argv[1])
output = Popen(args, stdout=PIPE, stderr=self.stderr_redirect).communicate()[0]
assert os.path.exists(f + '.o'), 'Source compilation error: ' + output
- os.chdir(cwd)
-
# Link all files
if len(additional_files) + len(libraries) > 0:
shutil.move(filename + '.o', filename + '.o.alone')
@@ -3820,6 +3820,30 @@ def process(filename):
self.do_run(src, expected)
CORRECT_SIGNS = 0
+ def test_atomic(self):
+ src = '''
+ #include <stdio.h>
+ int main() {
+ int x = 10;
+ int y = __sync_add_and_fetch(&x, 5);
+ printf("*%d,%d*\\n", x, y);
+ x = 10;
+ y = __sync_fetch_and_add(&x, 5);
+ printf("*%d,%d*\\n", x, y);
+ x = 10;
+ y = __sync_lock_test_and_set(&x, 6);
+ printf("*%d,%d*\\n", x, y);
+ x = 10;
+ y = __sync_bool_compare_and_swap(&x, 9, 7);
+ printf("*%d,%d*\\n", x, y);
+ y = __sync_bool_compare_and_swap(&x, 10, 7);
+ printf("*%d,%d*\\n", x, y);
+ return 0;
+ }
+ '''
+
+ self.do_run(src, '*15,15*\n*15,10*\n*6,10*\n*10,0*\n*7,1*')
+
# libc++ tests
def test_iostream(self):
@@ -3833,7 +3857,9 @@ def process(filename):
}
'''
- self.do_run(src, 'hello world\n77.\n')
+ # FIXME: should not have so many newlines in output here
+ self.do_run(src, 'hello world\n\n77.\n',
+ additional_files=map(lambda f: path_from_root('system', 'lib', 'libcxx', f+'.cpp'), ['ios', 'iostream', 'locale', 'string', 'mutex', 'future', 'memory', 'stdexcept', 'system_error'])) # XXX temporary
def test_stdvec(self):
src = '''
@@ -5873,6 +5899,9 @@ elif 'sanity' in str(sys.argv):
commands = [[EMCC], ['python', path_from_root('tests', 'runner.py'), 'blahblah']]
+ def mtime(filename):
+ return os.stat(filename).st_mtime
+
class sanity(RunnerCore):
def setUp(self):
wipe()
@@ -5960,9 +5989,6 @@ elif 'sanity' in str(sys.argv):
assert os.path.exists('a.out.js')
def test_emcc(self):
- def mtime(filename):
- return os.stat(filename).st_mtime
-
SANITY_MESSAGE = 'Emscripten: Running sanity checks'
SANITY_FAIL_MESSAGE = 'sanity check failed to run'
@@ -6000,6 +6026,47 @@ elif 'sanity' in str(sys.argv):
assert mtime(SANITY_FILE) >= mtime(CONFIG_FILE)
self.assertNotContained(SANITY_FAIL_MESSAGE, output)
+ def test_emcc_caching(self):
+ INCLUDING_MESSAGE = 'emcc: including X'
+ BUILDING_MESSAGE = 'emcc: building X for cache'
+
+ EMCC_CACHE = Cache.dirname
+
+ restore()
+
+ Cache.erase()
+ assert not os.path.exists(EMCC_CACHE)
+
+ try:
+ emcc_debug = os.environ.get('EMCC_DEBUG')
+ os.environ['EMCC_DEBUG'] ='1'
+
+ # Building a file that doesn't need cached stuff should not trigger cache generation
+ output = self.do([EMCC, path_from_root('tests', 'hello_world.cpp')])
+ assert INCLUDING_MESSAGE.replace('X', 'dlmalloc') not in output
+ assert BUILDING_MESSAGE.replace('X', 'dlmalloc') not in output
+ self.assertContained('hello, world!', run_js('a.out.js'))
+ assert not os.path.exists(EMCC_CACHE)
+ try_delete('a.out.js')
+
+ # Building a file that *does* need dlmalloc *should* trigger cache generation, but only the first time
+ for filename, libname, otherlibname in [('hello_malloc.cpp', 'dlmalloc', 'libcxx'), ('hello_libcxx.cpp', 'libcxx', 'dlmalloc')]:
+ for i in range(3):
+ try_delete(os.path.join(EMSCRIPTEN_TEMP_DIR, 'emcc-0-bc.bc')) # we might need to check this file later
+ output = self.do([EMCC, path_from_root('tests', filename)])
+ assert INCLUDING_MESSAGE.replace('X', libname) in output
+ assert INCLUDING_MESSAGE.replace('X', otherlibname) not in output
+ assert (BUILDING_MESSAGE.replace('X', libname) in output) == (i == 0), 'Must only build the first time'
+ self.assertContained('hello, world!', run_js('a.out.js'))
+ assert os.path.exists(EMCC_CACHE)
+ assert os.path.exists(os.path.join(EMCC_CACHE, libname + '.bc'))
+ if libname == 'libcxx':
+ assert os.stat(os.path.join(EMCC_CACHE, libname + '.bc')).st_size > 4000000, 'libc++ is big'
+ assert os.stat(os.path.join(EMSCRIPTEN_TEMP_DIR, 'emcc-0-bc.bc')).st_size < 2000000, 'Dead code elimination must remove most of libc++'
+ finally:
+ if emcc_debug:
+ os.environ['EMCC_DEBUG'] = emcc_debug
+
else:
raise Exception('Test runner is confused: ' + str(sys.argv))