Skip to content

Commit cb5cf56

Browse files
authored
Consolidate test_multidynamic_link and test_multiply_defined_libsymbols. NFC (#26986)
Since these tests were largely redundant, consolidate them into a single parameterized test. Specifically, `test_multiply_defined_libsymbols` was more comprehensive but `test_multidynamic_link tested` versioned suffixes and full path linking. `test_multiply_defined_libsymbols` now covers those cases.
1 parent 1666285 commit cb5cf56

1 file changed

Lines changed: 16 additions & 64 deletions

File tree

test/test_other.py

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,15 +1342,21 @@ def test_symlink_has_bad_suffix(self):
13421342
expected = ['unknown file type: foobar.xxx', "archive member 'native.o' is neither Wasm object file nor LLVM bitcode"]
13431343
self.assert_fail([EMCC, 'foobar.xxx', '-o', 'foobar.js'], expected)
13441344

1345-
def test_multiply_defined_libsymbols(self):
1345+
@parameterized({
1346+
'': (['-lA'], 'libA.so'),
1347+
'suffixed': (['./libA.so.1.2.3'], 'libA.so.1.2.3'),
1348+
})
1349+
def test_multiply_defined_libsymbols(self, link_flags, so_name):
13461350
create_file('libA.c', 'int mult() { return 1; }')
1347-
create_file('a2.c', 'void x() {}')
1348-
create_file('b2.c', 'void y() {}')
1351+
create_file('a2.c', 'int x() { return 42; }')
1352+
create_file('b2.c', 'int y() { return 43; }')
13491353
create_file('main.c', r'''
13501354
#include <stdio.h>
1355+
int x();
1356+
int y();
13511357
int mult();
13521358
int main() {
1353-
printf("result: %d\n", mult());
1359+
printf("result: %d %d %d\n", x(), y(), mult());
13541360
return 0;
13551361
}
13561362
''')
@@ -1360,14 +1366,14 @@ def test_multiply_defined_libsymbols(self):
13601366
# we model shared libraries using regular object files. Without special handling
13611367
# fake `libA.so` could get linked multiple times.
13621368
self.cflags.remove('-Werror')
1363-
self.emcc('libA.c', ['-shared', '-o', 'libA.so'])
1369+
self.emcc('libA.c', ['-shared', '-o', so_name])
13641370

1365-
err = self.emcc('a2.c', ['-shared', '-L.', '-lA', '-o', 'liba2.so'], stderr=PIPE).stderr
1366-
self.assertContained('emcc: warning: ignoring dynamic library libA.so when generating an object file', err)
1367-
err = self.emcc('b2.c', ['-shared', '-L.', '-lA', '-o', 'libb2.so'], stderr=PIPE).stderr
1368-
self.assertContained('emcc: warning: ignoring dynamic library libA.so when generating an object file', err)
1371+
err = self.emcc('a2.c', ['-shared', '-L.'] + link_flags + ['-o', 'liba2.so'], stderr=PIPE).stderr
1372+
self.assertContained(f'emcc: warning: ignoring dynamic library {os.path.basename(so_name)} when generating an object file', err)
1373+
err = self.emcc('b2.c', ['-shared', '-L.'] + link_flags + ['-o', 'libb2.so'], stderr=PIPE).stderr
1374+
self.assertContained(f'emcc: warning: ignoring dynamic library {os.path.basename(so_name)} when generating an object file', err)
13691375

1370-
self.do_runf('main.c', 'result: 1', cflags=['-L.', '-lA', 'liba2.so', 'libb2.so'])
1376+
self.do_runf('main.c', 'result: 42 43 1', cflags=['-L.'] + link_flags + ['liba2.so', 'libb2.so'])
13711377

13721378
def test_multiply_defined_libsymbols_2(self):
13731379
create_file('a.c', "int x() { return 55; }")
@@ -2113,60 +2119,6 @@ def test_dylink_exceptions_and_assertions(self):
21132119
'side.wasm',
21142120
])
21152121

2116-
@parameterized({
2117-
'': (['-lfile'], ''), # -l, auto detection from library path
2118-
'suffixed': (['libdir/libfile.so.3.1.4.1.5.9'], '.3.1.4.1.5.9'), # handle libX.so.1.2.3 as well
2119-
})
2120-
def test_multidynamic_link(self, link_flags, lib_suffix):
2121-
# Linking the same dynamic library in statically will error, normally, since we statically link
2122-
# it, causing dupe symbols
2123-
ensure_dir('libdir')
2124-
2125-
create_file('main.c', r'''
2126-
#include <stdio.h>
2127-
extern void printey();
2128-
extern void printother();
2129-
int main() {
2130-
printf("*");
2131-
printey();
2132-
printf("\n");
2133-
printother();
2134-
printf("\n");
2135-
printf("*\n");
2136-
return 0;
2137-
}
2138-
''')
2139-
2140-
create_file('libdir/libfile.c', '''
2141-
#include <stdio.h>
2142-
void printey() {
2143-
printf("hello from lib");
2144-
}
2145-
''')
2146-
2147-
create_file('libdir/libother.c', '''
2148-
#include <stdio.h>
2149-
extern void printey();
2150-
void printother() {
2151-
printf("|");
2152-
printey();
2153-
printf("|");
2154-
}
2155-
''')
2156-
2157-
# Build libfile normally into an .so
2158-
self.run_process([EMCC, 'libdir/libfile.c', '-shared', '-o', 'libdir/libfile.so' + lib_suffix])
2159-
# Build libother and dynamically link it to libfile
2160-
self.run_process([EMCC, '-Llibdir', 'libdir/libother.c'] + link_flags + ['-shared', '-o', 'libdir/libother.so'])
2161-
# Build the main file, linking in both the libs
2162-
self.run_process([EMCC, '-Llibdir', os.path.join('main.c')] + link_flags + ['-lother', '-c'])
2163-
print('...')
2164-
# The normal build system is over. We need to do an additional step to link in the dynamic
2165-
# libraries, since we ignored them before
2166-
self.run_process([EMCC, '-Llibdir', 'main.o'] + link_flags + ['-lother'])
2167-
2168-
self.assertContained('*hello from lib\n|hello from lib|\n*\n', self.run_js('a.out.js'))
2169-
21702122
@requires_pthreads
21712123
@also_with_modularize
21722124
def test_dylink_pthread_static_data(self):

0 commit comments

Comments
 (0)