196
196
del os.environ['EM_IGNORE_SANITY']
198
def test_llvm_fastcomp(self):
199
if os.environ.get('EMCC_FAST_COMPILER') != '1': return self.skip('not using fastcomp')
201
WARNING = 'fastcomp in use, but LLVM has not been built with the JavaScript backend as a target'
205
# Should see js backend during sanity check
206
assert check_fastcomp()
207
output = self.check_working(EMCC)
208
assert WARNING not in output, output
210
# Fake incorrect llc output, no mention of js backend
212
f = open(CONFIG_FILE, 'a')
213
f.write('LLVM_ROOT = "' + path_from_root('tests', 'fake') + '"')
216
if not os.path.exists(path_from_root('tests', 'fake')):
217
os.makedirs(path_from_root('tests', 'fake'))
219
f = open(path_from_root('tests', 'fake', 'llc'), 'w')
220
f.write('#!/bin/sh\n')
221
f.write('echo "llc fake output\nRegistered Targets:\nno j-s backend for you!"')
223
os.chmod(path_from_root('tests', 'fake', 'llc'), stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
224
output = self.check_working(EMCC, WARNING)
198
226
def test_node(self):
199
227
NODE_WARNING = 'node version appears too old'
200
228
NODE_WARNING_2 = 'cannot check node version'
219
247
os.environ['EM_IGNORE_SANITY'] = '1'
220
for version, succeed in [('v0.7.9', False), ('v0.8.0', True), ('v0.8.1', True), ('cheez', False)]:
248
for version, succeed in [('v0.7.9', False),
251
('v0.10.21-pre', True),
221
253
f = open(path_from_root('tests', 'fake', 'nodejs'), 'w')
222
254
f.write('#!/bin/sh\n')
223
255
f.write('''if [ $1 = "--version" ]; then
342
374
assert INCLUDING_MESSAGE.replace('X', 'libc') not in output
343
375
assert BUILDING_MESSAGE.replace('X', 'libc') not in output
344
376
self.assertContained('hello, world!', run_js('a.out.js'))
345
assert not os.path.exists(EMCC_CACHE)
346
377
try_delete('a.out.js')
348
379
basebc_name = os.path.join(TEMP_DIR, 'emscripten_temp', 'emcc-0-basebc.bc')
357
388
try_delete(basebc_name) # we might need to check this file later
358
389
try_delete(dcebc_name) # we might need to check this file later
359
390
for ll_name in ll_names: try_delete(ll_name)
360
output = self.do([compiler, '-O' + str(i), '-s', 'RELOOP=0', '--llvm-lto', '0', path_from_root('tests', filename)])
391
output = self.do([compiler, '-O' + str(i), '-s', 'RELOOP=0', '--llvm-lto', '0', path_from_root('tests', filename), '--save-bc', 'a.bc'])
362
393
assert INCLUDING_MESSAGE.replace('X', libname) in output
363
394
if libname == 'libc':
430
461
stdout=PIPE, stderr=PIPE).communicate()
431
462
self.assertContained('hello, world!', run_js('a.out.js'))
432
463
output = '\n'.join(output)
433
assert ('bootstrapping relooper succeeded' in output) == (i == 2), 'only bootstrap on first O2: ' + output
434
assert os.path.exists(RELOOPER) == (i >= 2), 'have relooper on O2: ' + output
464
assert ('bootstrapping relooper succeeded' in output) == (i == 1), 'only bootstrap on first O2: ' + output
465
assert os.path.exists(RELOOPER) == (i >= 1), 'have relooper on O2: ' + output
435
466
src = open('a.out.js').read()
436
467
main = src.split('function _main()')[1].split('\n}\n')[0]
437
assert ('while (1) {' in main or 'while(1){' in main or '} while ($' in main or '}while($' in main) == (i >= 2), 'reloop code on O2: ' + main
438
assert ('switch' not in main) == (i >= 2), 'reloop code on O2: ' + main
468
assert ('while (1) {' in main or 'while(1){' in main or 'while(1) {' in main or '} while ($' in main or '}while($' in main) == (i >= 1), 'reloop code on O2: ' + main
469
assert ('switch' not in main) == (i >= 1), 'reloop code on O2: ' + main
440
471
def test_jcache(self):
441
472
PRE_LOAD_MSG = 'loading pre from jcache'
478
509
(['--jcache'], 'hello_malloc.cpp', False, True, False, True, False, True, []),
479
510
([], 'hello_malloc.cpp', False, False, False, False, False, False, []),
481
([], 'hello_libcxx.cpp', False, False, False, False, False, False, ('3 chunks',)),
512
([], 'hello_libcxx.cpp', False, False, False, False, False, False, ('4 chunks',)),
482
513
(['--jcache'], 'hello_libcxx.cpp', True, False, True, False, True, False, []),
483
514
(['--jcache'], 'hello_libcxx.cpp', False, True, False, True, False, True, []),
484
515
([], 'hello_libcxx.cpp', False, False, False, False, False, False, []),
546
577
os.environ['EMCC_LLVM_TARGET'] = old
579
def test_emconfig(self):
582
(fd, custom_config_filename) = tempfile.mkstemp(prefix='.emscripten_config_')
584
orig_config = open(CONFIG_FILE, 'r').read()
586
# Move the ~/.emscripten to a custom location.
587
tfile = os.fdopen(fd, "w")
588
tfile.write(orig_config)
591
# Make a syntax error in the original config file so that attempting to access it would fail.
592
open(CONFIG_FILE, 'w').write('asdfasdfasdfasdf\n\'\'\'' + orig_config)
594
temp_dir = tempfile.mkdtemp(prefix='emscripten_temp_')
597
self.do([EMCC, '-O2', '--em-config', custom_config_filename, path_from_root('tests', 'hello_world.c')])
598
result = run_js('a.out.js')
600
# Clean up created temp files.
601
os.remove(custom_config_filename)
602
os.chdir(path_from_root())
603
shutil.rmtree(temp_dir)
605
self.assertContained('hello, world!', result)