Skip to content

Commit

Permalink
Remove Runner.ll_to_js
Browse files Browse the repository at this point in the history
Also, move and rename do_ll_run to do_run_object
  • Loading branch information
sbc100 committed Apr 1, 2019
1 parent e9b4597 commit 5a67663
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 38 deletions.
44 changes: 14 additions & 30 deletions tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,6 @@ def get_emcc_args(self):
# TODO(sbc): We should probably unify Building.COMPILER_TEST_OPTS and self.emcc_args
return self.serialize_settings() + self.emcc_args + Building.COMPILER_TEST_OPTS

# Generate JS from ll
def ll_to_js(self, filename):
Building.emcc(filename + '.o', self.get_emcc_args(), filename + '.o.js')

# Build JavaScript code from source code
def build(self, src, dirname, filename, main_file=None,
additional_files=[], libraries=[], includes=[], build_ll_hook=None,
Expand Down Expand Up @@ -523,7 +519,7 @@ def build(self, src, dirname, filename, main_file=None,
self.prep_ll_run(filename, object_file, build_ll_hook=build_ll_hook)

# BC => JS
self.ll_to_js(filename)
Building.emcc(object_file, self.get_emcc_args(), object_file + '.js')
else:
# "fast", new path: just call emcc and go straight to JS
all_files = [filename] + additional_files + libraries
Expand Down Expand Up @@ -956,15 +952,23 @@ def do_run(self, src, expected_output, args=[], output_nicerizer=None,
basename = 'src.c'
Building.COMPILER = to_cc(Building.COMPILER)

dirname = self.get_dir()
filename = os.path.join(dirname, basename)
if not no_build:
self.build(src, dirname, filename, main_file=main_file, additional_files=additional_files, libraries=libraries, includes=includes,
if no_build:
if src:
js_file = src
else:
js_file = basename + '.o.js'
else:
dirname = self.get_dir()
filename = os.path.join(dirname, basename)
self.build(src, dirname, filename, main_file=main_file,
additional_files=additional_files, libraries=libraries,
includes=includes,
build_ll_hook=build_ll_hook, post_build=post_build)
js_file = filename + '.o.js'
self.assertExists(js_file)

# Run in both JavaScript engines, if optimizing - significant differences there (typed arrays)
js_engines = self.filtered_js_engines(js_engines)
js_file = filename + '.o.js'
if len(js_engines) == 0:
self.skipTest('No JS engine present to run this test with. Check %s and the paths therein.' % EM_CONFIG)
if len(js_engines) > 1 and not self.use_all_engines:
Expand All @@ -986,32 +990,12 @@ def do_run(self, src, expected_output, args=[], output_nicerizer=None,
print('(test did not pass in JS engine: %s)' % engine)
raise

# shutil.rmtree(dirname) # TODO: leave no trace in memory. But for now nice for debugging

if self.save_JS:
global test_index
self.hardcode_arguments(js_file, args)
shutil.copyfile(js_file, os.path.join(TEMP_DIR, str(test_index) + '.js'))
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, force_recompile=False,
build_ll_hook=None, assert_returncode=None):
filename = os.path.join(self.get_dir(), 'src.cpp')

self.prep_ll_run(filename, ll_file, force_recompile, build_ll_hook)

self.ll_to_js(filename)

self.do_run(None,
expected_output,
args,
no_build=True,
js_engines=js_engines,
output_nicerizer=output_nicerizer,
assert_returncode=assert_returncode)


# Run a server and a web page. When a test runs, we tell the server about it,
# which tells the web page, which then opens a window with the test. Doing
Expand Down
22 changes: 14 additions & 8 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def test_cube2hash(self):
for text, output in [('fleefl', '892BDB6FD3F62E863D63DA55851700FDE3ACF30204798CE9'),
('fleefl2', 'AA2CC5F96FC9D540CA24FDAF1F71E2942753DB83E8A81B61'),
('64bitisslow', '64D8470573635EC354FEE7B7F87C566FCAF1EFB491041670')]:
self.do_run('', 'hash value: ' + output, [text], no_build=True)
self.do_run('src.cpp.o.js', 'hash value: ' + output, [text], no_build=True)

def test_unaligned(self):
self.skipTest('LLVM marks the reads of s as fully aligned, making this test invalid')
Expand Down Expand Up @@ -562,6 +562,12 @@ def test_getgep(self):
# Generated code includes getelementptr (getelementptr, 0, 1), i.e., GEP as the first param to GEP
self.do_run_in_out_file_test('tests', 'core', 'test_getgep')

# No compiling from C/C++ - just process an existing .o/.ll/.bc file.
def do_run_object(self, obj_file, expected_output=None, **kwargs):
js_file = obj_file + '.js'
Building.emcc(obj_file, self.get_emcc_args(), js_file)
self.do_run(js_file, expected_output, no_build=True, **kwargs)

def test_multiply_defined_symbols(self):
create_test_file('a1.c', 'int f() { return 1; }')
create_test_file('a2.c', 'void x() {}')
Expand All @@ -587,7 +593,7 @@ def test_multiply_defined_symbols(self):

Building.link_to_object(['main.c.o', 'liba.a', 'libb.a'], 'all.o')

self.do_ll_run('all.o', 'result: 1')
self.do_run_object('all.o', 'result: 1')

def test_if(self):
self.do_run_in_out_file_test('tests', 'core', 'test_if')
Expand Down Expand Up @@ -1035,9 +1041,9 @@ def test_exceptions_3(self):
print('0')
self.do_run(src, 'Caught C string: a c string\nDone.', ['0'])
print('1')
self.do_run(src, 'Caught exception: std::exception\nDone.', ['1'], no_build=True)
self.do_run(None, 'Caught exception: std::exception\nDone.', ['1'], no_build=True)
print('2')
self.do_run(src, 'Caught exception: Hello\nDone.', ['2'], no_build=True)
self.do_run(None, 'Caught exception: Hello\nDone.', ['2'], no_build=True)

def test_exceptions_white_list(self):
self.set_setting('DISABLE_EXCEPTION_CATCHING', 2)
Expand Down Expand Up @@ -5732,10 +5738,10 @@ def test_python(self):
print('lto:', lto)
if lto == 1:
self.emcc_args += ['--llvm-lto', '1']
self.do_ll_run(bitcode, pyoutput, args=['-S', '-c', pyscript])
self.do_run_object(bitcode, pyoutput, args=['-S', '-c', pyscript])

def test_lifetime(self):
self.do_ll_run(path_from_root('tests', 'lifetime.ll'), 'hello, world!\n')
self.do_run_object(path_from_root('tests', 'lifetime.ll'), 'hello, world!\n')
if '-O1' in self.emcc_args or '-O2' in self.emcc_args:
assert 'a18' not in open('src.cpp.o.js').read(), 'lifetime stuff and their vars must be culled'

Expand Down Expand Up @@ -5835,7 +5841,7 @@ def test_zzz_cases(self):
self.emcc_args += json.loads(open(shortname + '.emcc').read())

with env_modify({'EMCC_LEAVE_INPUTS_RAW': leave_inputs}):
self.do_ll_run(path_from_root('tests', 'cases', name), output)
self.do_run_object(path_from_root('tests', 'cases', name), output)

# Optional source checking, a python script that gets a global generated with the source
src_checker = path_from_root('tests', 'cases', shortname + '.py')
Expand Down Expand Up @@ -5909,7 +5915,7 @@ def do_autodebug(filename):
do_autodebug(filename)

# Compare to each other, and to expected output
self.do_ll_run(filename + '.o.ll.ll', 'AD:-1,1')
self.do_run_object(filename + '.o.ll.ll', 'AD:-1,1')

# Test using build_ll_hook
src = '''
Expand Down

0 comments on commit 5a67663

Please sign in to comment.