aboutsummaryrefslogtreecommitdiff
path: root/tests/runner.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/runner.py')
-rwxr-xr-xtests/runner.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py
index cef14e95..3dfef3e9 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -7850,6 +7850,70 @@ f.close()
self.assertContained('hello from lib', run_js(os.path.join(self.get_dir(), 'a.out.js')))
assert not os.path.exists('a.out') and not os.path.exists('a.exe'), 'Must not leave unneeded linker stubs'
+ def test_multiply_defined_libsymbols(self):
+ lib = "int mult() { return 1; }"
+ lib_name = os.path.join(self.get_dir(), 'libA.c')
+ open(lib_name, 'w').write(lib)
+ a2 = "void x() {}"
+ a2_name = os.path.join(self.get_dir(), 'a2.c')
+ open(a2_name, 'w').write(a2)
+ b2 = "void y() {}"
+ b2_name = os.path.join(self.get_dir(), 'b2.c')
+ open(b2_name, 'w').write(b2)
+ main = r'''
+ #include <stdio.h>
+ int mult();
+ int main() {
+ printf("result: %d\n", mult());
+ return 0;
+ }
+ '''
+ main_name = os.path.join(self.get_dir(), 'main.c')
+ open(main_name, 'w').write(main)
+
+ Building.emcc(lib_name, output_filename='libA.so')
+
+ Building.emcc(a2_name, ['-L.', '-lA'])
+ Building.emcc(b2_name, ['-L.', '-lA'])
+
+ Building.emcc(main_name, ['-L.', '-lA', a2_name+'.o', b2_name+'.o'], output_filename='a.out.js')
+
+ self.assertContained('result: 1', run_js(os.path.join(self.get_dir(), 'a.out.js')))
+
+ def test_multiply_defined_libsymbols_2(self):
+ a = "int x() { return 55; }"
+ a_name = os.path.join(self.get_dir(), 'a.c')
+ open(a_name, 'w').write(a)
+ b = "int y() { return 2; }"
+ b_name = os.path.join(self.get_dir(), 'b.c')
+ open(b_name, 'w').write(b)
+ c = "int z() { return 5; }"
+ c_name = os.path.join(self.get_dir(), 'c.c')
+ open(c_name, 'w').write(c)
+ main = r'''
+ #include <stdio.h>
+ int x();
+ int y();
+ int z();
+ int main() {
+ printf("result: %d\n", x() + y() + z());
+ return 0;
+ }
+ '''
+ main_name = os.path.join(self.get_dir(), 'main.c')
+ open(main_name, 'w').write(main)
+
+ Building.emcc(a_name) # a.c.o
+ Building.emcc(b_name) # b.c.o
+ Building.emcc(c_name) # c.c.o
+ lib_name = os.path.join(self.get_dir(), 'libLIB.a')
+ Building.emar('cr', lib_name, [a_name + '.o', b_name + '.o']) # libLIB.a with a and b
+
+ # a is in the lib AND in an .o, so should be ignored in the lib. We do still need b from the lib though
+ Building.emcc(main_name, ['-L.', '-lLIB', a_name+'.o', c_name + '.o'], output_filename='a.out.js')
+
+ self.assertContained('result: 62', run_js(os.path.join(self.get_dir(), 'a.out.js')))
+
def test_abspaths(self):
# Includes with absolute paths are generally dangerous, things like -I/usr/.. will get to system local headers, not our portable ones.