diff options
-rw-r--r-- | src/library_fs.js | 16 | ||||
-rwxr-xr-x | tests/runner.py | 23 | ||||
-rw-r--r-- | tests/test_core.py | 10 | ||||
-rw-r--r-- | tests/test_other.py | 8 | ||||
-rw-r--r-- | tools/jsrun.py | 2 |
5 files changed, 36 insertions, 23 deletions
diff --git a/src/library_fs.js b/src/library_fs.js index a6bca77c..7932385e 100644 --- a/src/library_fs.js +++ b/src/library_fs.js @@ -1211,8 +1211,20 @@ mergeInto(LibraryManager.library, { FS.mkdev('/dev/tty', FS.makedev(5, 0)); FS.mkdev('/dev/tty1', FS.makedev(6, 0)); // setup /dev/[u]random - FS.createDevice('/dev', 'random', function() { return Math.floor(Math.random()*256); }); - FS.createDevice('/dev', 'urandom', function() { return Math.floor(Math.random()*256); }); + var random_device; + if (typeof crypto !== 'undefined') { + // for modern web browsers + var randomBuffer = new Uint8Array(1); + random_device = function() { crypto.getRandomValues(randomBuffer); return randomBuffer[0]; }; + } else if (ENVIRONMENT_IS_NODE) { + // for nodejs + random_device = function() { return require('crypto').randomBytes(1)[0]; }; + } else { + // default for ES5 platforms + random_device = function() { return Math.floor(Math.random()*256); }; + } + FS.createDevice('/dev', 'random', random_device); + FS.createDevice('/dev', 'urandom', random_device); // we're not going to emulate the actual shm device, // just create the tmp dirs that reside in it commonly FS.mkdir('/dev/shm'); diff --git a/tests/runner.py b/tests/runner.py index 6d3f55f8..e9479313 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -258,7 +258,7 @@ process(sys.argv[1]) err = '\n'.join(filter(lambda line: 'uccessfully compiled asm.js code' not in line, err.split('\n'))) return err - def run_generated_code(self, engine, filename, args=[], check_timeout=True, output_nicerizer=None): + def run_generated_code(self, engine, filename, args=[], check_timeout=True, output_nicerizer=None, assert_returncode=0): stdout = os.path.join(self.get_dir(), 'stdout') # use files, as PIPE can get too full and hang us stderr = os.path.join(self.get_dir(), 'stderr') try: @@ -266,7 +266,7 @@ process(sys.argv[1]) except: cwd = None os.chdir(self.get_dir()) - run_js(filename, engine, args, check_timeout, stdout=open(stdout, 'w'), stderr=open(stderr, 'w')) + run_js(filename, engine, args, check_timeout, stdout=open(stdout, 'w'), stderr=open(stderr, 'w'), assert_returncode=assert_returncode) if cwd is not None: os.chdir(cwd) out = open(stdout, 'r').read() @@ -445,7 +445,7 @@ process(sys.argv[1]) includes, force_c, build_ll_hook, extra_emscripten_args) ## Does a complete test - builds, runs, checks output, etc. - def do_run(self, src, expected_output, args=[], output_nicerizer=None, output_processor=None, no_build=False, main_file=None, additional_files=[], js_engines=None, post_build=None, basename='src.cpp', libraries=[], includes=[], force_c=False, build_ll_hook=None, extra_emscripten_args=[]): + def do_run(self, src, expected_output, args=[], output_nicerizer=None, output_processor=None, no_build=False, main_file=None, additional_files=[], js_engines=None, post_build=None, basename='src.cpp', libraries=[], includes=[], force_c=False, build_ll_hook=None, extra_emscripten_args=[], assert_returncode=None): if force_c or (main_file is not None and main_file[-2:]) == '.c': basename = 'src.c' Building.COMPILER = to_cc(Building.COMPILER) @@ -464,7 +464,7 @@ process(sys.argv[1]) js_engines = filter(lambda engine: engine not in self.banned_js_engines, js_engines) if len(js_engines) == 0: return self.skip('No JS engine present to run this test with. Check %s and the paths therein.' % EM_CONFIG) for engine in js_engines: - js_output = self.run_generated_code(engine, filename + '.o.js', args, output_nicerizer=output_nicerizer) + js_output = self.run_generated_code(engine, filename + '.o.js', args, output_nicerizer=output_nicerizer, assert_returncode=assert_returncode) self.assertContained(expected_output, js_output.replace('\r\n', '\n')) self.assertNotContained('ERROR', js_output) @@ -477,7 +477,7 @@ process(sys.argv[1]) test_index += 1 # No building - just process an existing .ll file (or .bc, which we turn into .ll) - def do_ll_run(self, ll_file, expected_output=None, args=[], js_engines=None, output_nicerizer=None, post_build=None, force_recompile=False, build_ll_hook=None, extra_emscripten_args=[]): + def do_ll_run(self, ll_file, expected_output=None, args=[], js_engines=None, output_nicerizer=None, post_build=None, force_recompile=False, build_ll_hook=None, extra_emscripten_args=[], assert_returncode=None): filename = os.path.join(self.get_dir(), 'src.cpp') self.prep_ll_run(filename, ll_file, force_recompile, build_ll_hook) @@ -485,12 +485,13 @@ process(sys.argv[1]) self.ll_to_js(filename, extra_emscripten_args, post_build) self.do_run(None, - expected_output, - args, - no_build=True, - js_engines=js_engines, - output_nicerizer=output_nicerizer, - post_build=None) # post_build was already done in ll_to_js, this do_run call is just to test the output + expected_output, + args, + no_build=True, + js_engines=js_engines, + output_nicerizer=output_nicerizer, + post_build=None, + assert_returncode=assert_returncode) # post_build was already done in ll_to_js, this do_run call is just to test the output # Run a server and a web page. When a test runs, we tell the server about it, diff --git a/tests/test_core.py b/tests/test_core.py index a4579800..20278d37 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -6244,7 +6244,7 @@ def process(filename): ''' try: - self.do_run(src, '*nothingatall*') + self.do_run(src, '*nothingatall*', assert_returncode=None) except Exception, e: # This test *should* fail, by throwing this exception assert 'Assertion failed: Load-store consistency assumption failure!' in str(e), str(e) @@ -6261,7 +6261,7 @@ def process(filename): Settings.SAFE_HEAP_LINES = ["src.cpp:99"] try: - self.do_run(src, '*nothingatall*') + self.do_run(src, '*nothingatall*', assert_returncode=None) except Exception, e: # This test *should* fail, by throwing this exception assert 'Assertion failed: Load-store consistency assumption failure!' in str(e), str(e) @@ -6311,7 +6311,7 @@ def process(filename): Building.link([module_name + '.o', main_name + '.o'], all_name) try: - self.do_ll_run(all_name, '*nothingatall*') + self.do_ll_run(all_name, '*nothingatall*', assert_returncode=None) except Exception, e: # This test *should* fail, by throwing this exception assert 'Assertion failed: Load-store consistency assumption failure!' in str(e), str(e) @@ -6328,7 +6328,7 @@ def process(filename): for lines in [["module.cpp:22", "main.cpp:9"], ["module.cpp:7", "main.cpp:29"], ["module.cpp:127", "main.cpp:449"], ["module.cpp:7"], ["main.cpp:9"]]: Settings.SAFE_HEAP_LINES = lines try: - self.do_ll_run(all_name, '*nothingatall*') + self.do_ll_run(all_name, '*nothingatall*', assert_returncode=None) except Exception, e: # This test *should* fail, by throwing this exception assert 'Assertion failed: Load-store consistency assumption failure!' in str(e), str(e) @@ -6353,7 +6353,7 @@ def process(filename): } ''' try: - self.do_run(src, '*nothingatall*') + self.do_run(src, '*nothingatall*', assert_returncode=None) except Exception, e: # This test *should* fail assert 'Assertion failed: x < 15' in str(e), str(e) diff --git a/tests/test_other.py b/tests/test_other.py index 4fb90b1a..9e3c59e8 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -245,7 +245,7 @@ Options that are modified or new in %s include: output = Popen([PYTHON, compiler, 'twopart_main.o', '-O1', '-g'] + args, stdout=PIPE, stderr=PIPE).communicate() assert os.path.exists(target), '\n'.join(output) #print '\n'.join(output) - self.assertContained('missing function', run_js(target, stderr=STDOUT)) + self.assertContained('missing function', run_js(target, stderr=STDOUT, assert_returncode=None)) try_delete(target) # Combining those bc files into js should work @@ -549,7 +549,7 @@ f.close() print args, expected, err_expected out, err = Popen([PYTHON, EMCC, 'src.c'] + args, stderr=PIPE).communicate() if err_expected: self.assertContained(err_expected, err) - self.assertContained(expected, run_js(self.in_dir('a.out.js'), stderr=PIPE, full_output=True)) + self.assertContained(expected, run_js(self.in_dir('a.out.js'), stderr=PIPE, full_output=True, assert_returncode=None)) return open(self.in_dir('a.out.js')).read() if os.environ.get('EMCC_FAST_COMPILER') == '0': @@ -2406,7 +2406,7 @@ var Module = { print: function(x) { throw '<{(' + x + ')}>' } }; ''') Popen([PYTHON, EMCC, 'code.cpp', '--pre-js', 'pre.js']).communicate() - output = run_js(os.path.join(self.get_dir(), 'a.out.js'), stderr=PIPE, full_output=True, engine=NODE_JS) + output = run_js(os.path.join(self.get_dir(), 'a.out.js'), stderr=PIPE, full_output=True, engine=NODE_JS, assert_returncode=None) assert r'<{(123456789)}>' in output, output def test_precompiled_headers(self): @@ -2793,7 +2793,7 @@ int main() { cmd = [PYTHON, EMCC, 'src.cpp', '-O' + str(opts), '-s', 'SAFE_HEAP=' + str(safe)] print cmd Popen(cmd).communicate() - output = run_js('a.out.js', stderr=PIPE, full_output=True) + output = run_js('a.out.js', stderr=PIPE, full_output=True, assert_returncode=None) if safe: assert 'Function table mask error' in output, output else: diff --git a/tools/jsrun.py b/tools/jsrun.py index d63451db..e2ec5439 100644 --- a/tools/jsrun.py +++ b/tools/jsrun.py @@ -17,7 +17,7 @@ def timeout_run(proc, timeout=None, note='unnamed process', full_output=False): logging.info('Process ' + str(proc.pid) + ' finished after ' + str(time.time() - start) + ' seconds. Exit code: ' + str(proc.returncode)) return '\n'.join(out) if full_output else out[0] -def run_js(filename, engine=None, args=[], check_timeout=False, stdin=None, stdout=PIPE, stderr=None, cwd=None, full_output=False, assert_returncode=None): +def run_js(filename, engine=None, args=[], check_timeout=False, stdin=None, stdout=PIPE, stderr=None, cwd=None, full_output=False, assert_returncode=0): if type(engine) is not list: engine = [engine] command = engine + [filename] + (['--'] if 'd8' in engine[0] or 'jsc' in engine[0] else []) + args |