Skip to content

Commit

Permalink
Add failing test of rtti (dynamic_cast) combined with dynamic librari…
Browse files Browse the repository at this point in the history
…es (#8377)

See #8376 and #8268.
  • Loading branch information
sbc100 authored Apr 1, 2019
1 parent e9b4597 commit d995936
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 14 deletions.
19 changes: 10 additions & 9 deletions tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,15 +976,16 @@ def do_run(self, src, expected_output, args=[], output_nicerizer=None,
# print 'test in', engine
js_output = self.run_generated_code(engine, js_file, args, output_nicerizer=output_nicerizer, assert_returncode=assert_returncode)
js_output = js_output.replace('\r\n', '\n')
try:
if assert_identical:
self.assertIdentical(expected_output, js_output)
else:
self.assertContained(expected_output, js_output)
self.assertNotContained('ERROR', js_output)
except Exception:
print('(test did not pass in JS engine: %s)' % engine)
raise
if expected_output:
try:
if assert_identical:
self.assertIdentical(expected_output, js_output)
else:
self.assertContained(expected_output, js_output)
self.assertNotContained('ERROR', js_output)
except Exception:
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

Expand Down
54 changes: 49 additions & 5 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,10 +1329,10 @@ def test_segfault(self):
self.do_run(src, 'segmentation fault' if addr.isdigit() else 'marfoosh')

def test_dynamic_cast(self):
self.do_run_in_out_file_test('tests', 'core', 'test_dynamic_cast')
self.do_run_in_out_file_test('tests', 'core', 'test_dynamic_cast')

def test_dynamic_cast_b(self):
self.do_run_in_out_file_test('tests', 'core', 'test_dynamic_cast_b')
self.do_run_in_out_file_test('tests', 'core', 'test_dynamic_cast_b')

def test_dynamic_cast_2(self):
self.do_run_in_out_file_test('tests', 'core', 'test_dynamic_cast_2')
Expand Down Expand Up @@ -3194,7 +3194,7 @@ def indir(name):
'''
self.do_run(src, 'a: loaded\nb: loaded\na: loaded\n')

def dylink_test(self, main, side, expected, header=None, main_emcc_args=[], force_c=False, need_reverse=True, auto_load=True):
def dylink_test(self, main, side, expected=None, header=None, main_emcc_args=[], force_c=False, need_reverse=True, auto_load=True, **kwargs):
# shared settings
self.set_setting('EXPORT_ALL', 1)

Expand Down Expand Up @@ -3234,9 +3234,9 @@ def dylink_test(self, main, side, expected, header=None, main_emcc_args=[], forc
# main is just a library
try_delete('src.cpp.o.js')
run_process([PYTHON, EMCC] + main + self.emcc_args + self.serialize_settings() + ['-o', 'src.cpp.o.js'])
self.do_run(None, expected, no_build=True)
self.do_run(None, expected, no_build=True, **kwargs)
else:
self.do_run(main, expected, force_c=force_c)
self.do_run(main, expected, force_c=force_c, **kwargs)

self.emcc_args = old_args

Expand Down Expand Up @@ -4072,6 +4072,50 @@ def test_dylink_zlib(self):
# open(path_from_root('tests', 'bullet', 'output2.txt')).read(),
# open(path_from_root('tests', 'bullet', 'output3.txt')).read()])

@needs_dlfcn
def test_dylink_rtti(self):
header = '''
#include <cstddef>
class Foo {
public:
virtual ~Foo() {}
};
class Bar : public Foo {
public:
virtual ~Bar() {}
};
bool is_bar(Foo* foo);
'''

main = '''
#include "header.h"
int main() {
Bar bar;
if (!is_bar(&bar))
return 1;
return 0;
}
'''

side = '''
#include "header.h"
bool is_bar(Foo* foo) {
return dynamic_cast<Bar*>(foo) != nullptr;
}
'''

# TODO(sbc): This tests should instead return zero. Update expectations
# once we fix https://github.com/emscripten-core/emscripten/issues/8376
self.dylink_test(main=main,
side=side,
header=header,
assert_returncode=1)

def test_random(self):
src = r'''#include <stdlib.h>
#include <stdio.h>
Expand Down

0 comments on commit d995936

Please sign in to comment.