aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-12-18 11:34:19 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-12-18 11:34:19 -0800
commit0e8e6a82b7ac67805f59546e653720894c3006b3 (patch)
tree496b1c4174d47373bc4977b8eff0f75fa41e74eb
parent6a64cb415ac127214d90a0bd209d67a3ae4757e4 (diff)
sanity checks
-rwxr-xr-xemcc5
-rw-r--r--tests/runner.py81
-rw-r--r--tools/shared.py69
3 files changed, 145 insertions, 10 deletions
diff --git a/emcc b/emcc
index a0f59f0b..460f0b79 100755
--- a/emcc
+++ b/emcc
@@ -82,6 +82,8 @@ TEMP_DIR = os.environ.get('EMCC_TEMP_DIR')
if DEBUG: print >> sys.stderr, 'emcc: ', ' '.join(sys.argv)
+shared.check_sanity()
+
# Handle some global flags
if len(sys.argv) == 1:
@@ -281,6 +283,9 @@ try:
if llvm_opt_level is None: llvm_opt_level = 1 if opt_level >= 1 else 0
if closure is None: closure = 1 if opt_level >= 2 else 0
+ if closure:
+ assert os.path.exists(shared.CLOSURE_COMPILER), 'emcc: fatal: Closure compiler (%s) does not exist' % CLOSURE_COMPILER
+
settings_changes = []
for i in range(len(newargs)):
if newargs[i] == '-s':
diff --git a/tests/runner.py b/tests/runner.py
index 6d818b4d..9989bf35 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -217,7 +217,7 @@ class RunnerCore(unittest.TestCase):
sys.argv = map(lambda arg: arg if not arg.startswith('test_') else 'default.' + arg, sys.argv)
-if 'benchmark' not in str(sys.argv):
+if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv):
# Tests
print "Running Emscripten tests..."
@@ -5114,7 +5114,7 @@ Options that are modified or new in %s include:
stdin=PIPE, stdout=PIPE).communicate(input)[0]
self.assertIdentical(expected, output.replace('\n\n', '\n'))
-else:
+elif 'benchmark' in str(sys.argv):
# Benchmarks. Run them with argument |benchmark|. To run a specific test, do
# |benchmark.test_X|.
@@ -5150,7 +5150,7 @@ else:
JS_ENGINE = JS_ENGINES[0]
for i in range(1, len(sys.argv)):
arg = sys.argv[i]
- if not arg.startswith('test_'):
+ if not arg.startswith('benchmark.test_'):
JS_ENGINE = eval(arg)
sys.argv[i] = None
sys.argv = filter(lambda arg: arg is not None, sys.argv)
@@ -5206,9 +5206,11 @@ else:
f.close()
final_filename = os.path.join(dirname, 'src.js')
+ try_delete(final_filename)
output = Popen([EMCC, filename, '-O3', '-s', 'USE_TYPED_ARRAYS=1', '-s', 'QUANTUM_SIZE=1',
'-s', 'TOTAL_MEMORY=100*1024*1024', '-s', 'FAST_MEMORY=10*1024*1024',
'-o', final_filename] + emcc_args, stdout=PIPE, stderr=PIPE).communicate()
+ assert os.path.exists(final_filename), 'Failed to compile file: ' + '\n'.join(output)
# Run JS
global total_times, tests_done
@@ -5330,14 +5332,79 @@ else:
src = open(path_from_root('src', 'dlmalloc.c'), 'r').read() + '\n\n\n' + open(path_from_root('tests', 'dlmalloc_test.c'), 'r').read()
self.do_benchmark(src, ['400', '400'], '*400,0*', emcc_args=['-g', '-s', 'CORRECT_SIGNS=2', '-s', 'CORRECT_SIGNS_LINES=[4820, 4195, 4250, 4203, 4209, 4239, 4231]'])
+elif 'sanity' in str(sys.argv):
+
+ # Run some sanity checks on the test runner and emcc.
+
+ sys.argv = filter(lambda x: x != 'sanity', sys.argv)
+
+ print 'Running sanity checks. WARNING: This will modify ~/.emscripten, and in theory can break it. A backup will be saved in ~/.emscripten_backup'
+
+ assert os.path.exists(CONFIG_FILE), 'To run these tests, we need a (working!) ~/.emscripten file to already exist'
+
+ shutil.copyfile(CONFIG_FILE, CONFIG_FILE + '_backup')
+ def restore():
+ shutil.copyfile(CONFIG_FILE + '_backup', CONFIG_FILE)
+
+ def wipe():
+ try_delete(CONFIG_FILE)
+ try_delete(CONFIG_FILE + '_sanity')
+
+ commands = [[EMCC], ['python', path_from_root('tests', 'runner.py'), 'blahblah']]
+
+ class sanity(RunnerCore):
+ def setUp(self):
+ wipe()
+
+ def tearDown(self):
+ restore()
+
+ def test_normal(self):
+ for command in commands:
+ # Your existing ~/.emscripten should work!
+ restore()
+ output = Popen(command, stdout=PIPE, stderr=STDOUT).communicate()[0]
+
+ if command[0] == EMCC:
+ self.assertContained('no input files', output)
+ else:
+ self.assertContained("has no attribute 'blahblah'", output)
+
+ def test_firstrun(self):
+ for command in commands:
+ wipe()
+ output = Popen(command, stdout=PIPE, stderr=STDOUT).communicate()[0]
+
+ self.assertContained('Welcome to Emscripten!', output)
+ self.assertContained('This is the first time any of the Emscripten tools has been run.', output)
+ self.assertContained('A settings file has been copied to ~/.emscripten, at absolute path: %s' % CONFIG_FILE, output)
+ self.assertContained('Please edit that file and change the paths to fit your system', output)
+ self.assertContained('make sure LLVM_ROOT and NODE_JS are correct', output)
+ self.assertContained('This command will now exit. When you are done editing those paths, re-run it.', output)
+ assert output.replace('\n', '').endswith('===='), 'We should have stopped: ' + output
+ assert (open(CONFIG_FILE).read() == open(path_from_root('settings.py')).read()), 'Settings should be copied from settings.py'
+
+ # Second run, with bad ~/.emscripten
+ for settings in ['blah', 'LLVM_ROOT="blah"; JS_ENGINES=[]; COMPILER_ENGINE=NODE_JS=SPIDERMONKEY_ENGINE=[]']:
+ f = open(CONFIG_FILE, 'w')
+ f.write(settings)
+ f.close()
+ output = Popen(command, stdout=PIPE, stderr=STDOUT).communicate()[0]
+
+ if 'LLVM_ROOT' not in settings:
+ self.assertContained('Error in evaluating ~/.emscripten', output)
+ else:
+ self.assertContained('FATAL', output)
+
+else:
+ raise Exception('Test runner is confused: ' + str(sys.argv))
if __name__ == '__main__':
sys.argv = [sys.argv[0]] + ['-v'] + sys.argv[1:] # Verbose output by default
# Sanity checks
- if not check_engine(COMPILER_ENGINE):
- print 'WARNING: The JavaScript shell used for compiling does not seem to work'
+ check_sanity(force=True)
total_engines = len(JS_ENGINES)
JS_ENGINES = filter(check_engine, JS_ENGINES)
@@ -5346,10 +5413,6 @@ if __name__ == '__main__':
elif len(JS_ENGINES) < total_engines:
print 'WARNING: Not all the JS engines in JS_ENGINES appears to work, ignoring those.'
- for cmd in [CLANG, LLVM_DIS]:
- if not os.path.exists(cmd) and not os.path.exists(cmd + '.exe'): # .exe extension required for Windows
- print 'WARNING: Cannot find', cmd
-
# Go
unittest.main()
diff --git a/tools/shared.py b/tools/shared.py
index f109d9d2..ed6ac645 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -5,10 +5,77 @@ __rootpath__ = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
def path_from_root(*pathelems):
return os.path.join(__rootpath__, *pathelems)
+# Config file
+
CONFIG_FILE = os.path.expanduser('~/.emscripten')
if not os.path.exists(CONFIG_FILE):
shutil.copy(path_from_root('settings.py'), CONFIG_FILE)
-exec(open(CONFIG_FILE, 'r').read())
+ print >> sys.stderr, '''
+==============================================================================
+Welcome to Emscripten!
+
+This is the first time any of the Emscripten tools has been run.
+
+A settings file has been copied to ~/.emscripten, at absolute path: %s
+
+Please edit that file and change the paths to fit your system. Specifically,
+make sure LLVM_ROOT and NODE_JS are correct.
+
+This command will now exit. When you are done editing those paths, re-run it.
+==============================================================================
+''' % CONFIG_FILE
+ sys.exit(0)
+try:
+ exec(open(CONFIG_FILE, 'r').read())
+except Exception, e:
+ print >> sys.stderr, 'Error in evaluating ~/.emscripten (at %s): %s' % (CONFIG_FILE, str(e))
+ sys.exit(1)
+
+# Check that basic stuff we need (a JS engine to compile, Node.js, and Clang and LLVM)
+# exists.
+# The test runner always does this check (through |force|). emcc does this less frequently,
+# only when ~/.emscripten_sanity does not exist or is older than ~/.emscripten (so,
+# we re-check sanity when the settings are changed)
+def check_sanity(force=False):
+ try:
+ if not force:
+ settings_mtime = os.stat(CONFIG_FILE).st_mtime
+ sanity_file = CONFIG_FILE + '_sanity'
+ try:
+ sanity_mtime = os.stat(sanity_file).st_mtime
+ except:
+ sanity_mtime = None
+ if sanity_mtime is not None and sanity_mtime > settings_mtime:
+ return # sanity has been checked
+
+ if not check_engine(COMPILER_ENGINE):
+ print >> sys.stderr, 'FATAL: The JavaScript shell used for compiling (%s) does not seem to work, check the paths in ~/.emscripten' % COMPILER_ENGINE
+ sys.exit(0)
+
+ if NODE_JS != COMPILER_ENGINE:
+ if not check_engine(NODE_JS):
+ print >> sys.stderr, 'FATAL: Node.js (%s) does not seem to work, check the paths in ~/.emscripten' % NODE_JS
+ sys.exit(0)
+
+ for cmd in [CLANG, LLVM_DIS]:
+ if not os.path.exists(cmd) and not os.path.exists(cmd + '.exe'): # .exe extension required for Windows
+ print >> sys.stderr, 'FATAL: Cannot find %s, check the paths in ~/.emscripten' % cmd
+ sys.exit(0)
+
+ if not os.path.exists(CLOSURE_COMPILER):
+ print >> sys.stderr, 'WARNING: Closure compiler (%s) does not exist, check the paths in ~/.emscripten. -O2 and above will fail' % CLOSURE_COMPILER
+
+ # Sanity check passed!
+
+ if not force:
+ # Only create/update this file if the sanity check succeeded, i.e., we got here
+ f = open(sanity_file, 'w')
+ f.write('certified\n')
+ f.close()
+
+ except Exception, e:
+ # Any error here is not worth failing on
+ print 'WARNING: sanity check failed to run', e
# Tools/paths