~ubuntu-branches/ubuntu/trusty/emscripten/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/test_sanity.py

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-01-19 14:12:40 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20140119141240-jg1l42cc158j59tn
Tags: 1.9.0~20140119~7dc8c2f-1
* New snapshot release (Closes: #733714)
* Provide sources for javascript and flash. Done in orig-tar.sh
  Available in third_party/websockify/include/web-socket-js/src/
  (Closes: #735903)

Show diffs side-by-side

added added

removed removed

Lines of Context:
195
195
    finally:
196
196
      del os.environ['EM_IGNORE_SANITY']
197
197
 
 
198
  def test_llvm_fastcomp(self):
 
199
    if os.environ.get('EMCC_FAST_COMPILER') != '1': return self.skip('not using fastcomp')
 
200
 
 
201
    WARNING = 'fastcomp in use, but LLVM has not been built with the JavaScript backend as a target'
 
202
 
 
203
    restore()
 
204
 
 
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
 
209
 
 
210
    # Fake incorrect llc output, no mention of js backend
 
211
    restore()
 
212
    f = open(CONFIG_FILE, 'a')
 
213
    f.write('LLVM_ROOT = "' + path_from_root('tests', 'fake') + '"')
 
214
    f.close()
 
215
 
 
216
    if not os.path.exists(path_from_root('tests', 'fake')):
 
217
      os.makedirs(path_from_root('tests', 'fake'))
 
218
 
 
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!"')
 
222
    f.close()
 
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)
 
225
 
198
226
  def test_node(self):
199
227
    NODE_WARNING = 'node version appears too old'
200
228
    NODE_WARNING_2 = 'cannot check node version'
217
245
 
218
246
    try:
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),
 
249
                               ('v0.8.0', True),
 
250
                               ('v0.8.1', True),
 
251
                               ('v0.10.21-pre', True),
 
252
                               ('cheez', False)]:
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')
347
378
 
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'])
361
392
            #print output
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
439
470
 
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, []),
480
511
        # new, huge file
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, []),
545
576
      if old:
546
577
        os.environ['EMCC_LLVM_TARGET'] = old
547
578
 
 
579
  def test_emconfig(self):
 
580
    restore()
 
581
    
 
582
    (fd, custom_config_filename) = tempfile.mkstemp(prefix='.emscripten_config_')
 
583
 
 
584
    orig_config = open(CONFIG_FILE, 'r').read()
 
585
 
 
586
    # Move the ~/.emscripten to a custom location.
 
587
    tfile = os.fdopen(fd, "w")
 
588
    tfile.write(orig_config)
 
589
    tfile.close()
 
590
 
 
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)
 
593
 
 
594
    temp_dir = tempfile.mkdtemp(prefix='emscripten_temp_')
 
595
 
 
596
    os.chdir(temp_dir)
 
597
    self.do([EMCC, '-O2', '--em-config', custom_config_filename, path_from_root('tests', 'hello_world.c')])
 
598
    result = run_js('a.out.js')
 
599
    
 
600
    # Clean up created temp files.
 
601
    os.remove(custom_config_filename)
 
602
    os.chdir(path_from_root())
 
603
    shutil.rmtree(temp_dir)
 
604
 
 
605
    self.assertContained('hello, world!', result)
 
606