From ca304bc2f0188ac8538c97c07c1f2ee96190b455 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Sat, 15 Nov 2025 11:42:41 -0800 Subject: [PATCH] Convert test_multidynamic_link to parameteraized. NFC --- test/test_other.py | 96 ++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 50 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index 43a59a5a3bb0e..9764963205091 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2131,63 +2131,59 @@ def test_dylink_exceptions_and_assertions(self): 'side.wasm', ]) - def test_multidynamic_link(self): + @parameterized({ + '': (['-lfile'], ''), # -l, auto detection from library path + 'suffixed': (['libdir/libfile.so.3.1.4.1.5.9'], '.3.1.4.1.5.9'), # handle libX.so.1.2.3 as well + }) + def test_multidynamic_link(self, link_flags, lib_suffix): # Linking the same dynamic library in statically will error, normally, since we statically link # it, causing dupe symbols + ensure_dir('libdir') - def test(link_flags, lib_suffix): - print(link_flags, lib_suffix) - - self.clear() - ensure_dir('libdir') + create_file('main.c', r''' + #include + extern void printey(); + extern void printother(); + int main() { + printf("*"); + printey(); + printf("\n"); + printother(); + printf("\n"); + printf("*\n"); + return 0; + } + ''') - create_file('main.c', r''' - #include - extern void printey(); - extern void printother(); - int main() { - printf("*"); - printey(); - printf("\n"); - printother(); - printf("\n"); - printf("*\n"); - return 0; - } - ''') + create_file('libdir/libfile.c', ''' + #include + void printey() { + printf("hello from lib"); + } + ''') - create_file('libdir/libfile.c', ''' - #include - void printey() { - printf("hello from lib"); - } - ''') + create_file('libdir/libother.c', ''' + #include + extern void printey(); + void printother() { + printf("|"); + printey(); + printf("|"); + } + ''') - create_file('libdir/libother.c', ''' - #include - extern void printey(); - void printother() { - printf("|"); - printey(); - printf("|"); - } - ''') + # Build libfile normally into an .so + self.run_process([EMCC, 'libdir/libfile.c', '-shared', '-o', 'libdir/libfile.so' + lib_suffix]) + # Build libother and dynamically link it to libfile + self.run_process([EMCC, '-Llibdir', 'libdir/libother.c'] + link_flags + ['-shared', '-o', 'libdir/libother.so']) + # Build the main file, linking in both the libs + self.run_process([EMCC, '-Llibdir', os.path.join('main.c')] + link_flags + ['-lother', '-c']) + print('...') + # The normal build system is over. We need to do an additional step to link in the dynamic + # libraries, since we ignored them before + self.run_process([EMCC, '-Llibdir', 'main.o'] + link_flags + ['-lother']) - # Build libfile normally into an .so - self.run_process([EMCC, 'libdir/libfile.c', '-shared', '-o', 'libdir/libfile.so' + lib_suffix]) - # Build libother and dynamically link it to libfile - self.run_process([EMCC, '-Llibdir', 'libdir/libother.c'] + link_flags + ['-shared', '-o', 'libdir/libother.so']) - # Build the main file, linking in both the libs - self.run_process([EMCC, '-Llibdir', os.path.join('main.c')] + link_flags + ['-lother', '-c']) - print('...') - # The normal build system is over. We need to do an additional step to link in the dynamic - # libraries, since we ignored them before - self.run_process([EMCC, '-Llibdir', 'main.o'] + link_flags + ['-lother']) - - self.assertContained('*hello from lib\n|hello from lib|\n*\n', self.run_js('a.out.js')) - - test(['-lfile'], '') # -l, auto detection from library path - test(['libdir/libfile.so.3.1.4.1.5.9'], '.3.1.4.1.5.9') # handle libX.so.1.2.3 as well + self.assertContained('*hello from lib\n|hello from lib|\n*\n', self.run_js('a.out.js')) @node_pthreads @also_with_modularize