aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnthony Pesch <inolen@gmail.com>2013-08-29 12:01:43 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-09-03 14:41:30 -0700
commit6dc0883ca2f682fa49af16e9816cc4b9383e1313 (patch)
treeed13185125b22b35400abae8973e18e2d68f5d27 /tests
parente33179a36b1d6867e0a5c59a8e5a9e04b1b8459f (diff)
added dlopen test to test function pointers with signatures not found in the main module
Diffstat (limited to 'tests')
-rw-r--r--tests/test_core.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/test_core.py b/tests/test_core.py
index 285ba08e..d39ef9a9 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -5612,6 +5612,57 @@ The current type of b is: 9
else:
Settings.BUILD_AS_SHARED_LIB = 0
+ def test_dlfcn_unique_sig(self):
+ if not self.can_dlfcn(): return
+
+ self.prep_dlfcn_lib()
+ lib_src = '''
+ #include <stdio.h>
+ int myfunc(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m) {
+ return 13;
+ }
+ '''
+ Settings.EXPORTED_FUNCTIONS = ['_myfunc']
+ dirname = self.get_dir()
+ filename = os.path.join(dirname, 'liblib.c')
+ self.build(lib_src, dirname, filename)
+ shutil.move(filename + '.o.js', os.path.join(dirname, 'liblib.so'))
+
+ self.prep_dlfcn_main()
+ src = '''
+ #include <assert.h>
+ #include <stdio.h>
+ #include <dlfcn.h>
+
+ typedef int (*FUNCTYPE(int, int, int, int, int, int, int, int, int, int, int, int, int))();
+
+ int main() {
+ void *lib_handle;
+ FUNCTYPE *func_ptr;
+
+ lib_handle = dlopen("liblib.so", RTLD_NOW);
+ assert(lib_handle != NULL);
+
+ func_ptr = (FUNCTYPE*)dlsym(lib_handle, "myfunc");
+ assert(func_ptr != NULL);
+ assert(func_ptr(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0f, 0) == 13);
+
+ puts("success");
+
+ return 0;
+ }
+ '''
+ add_pre_run_and_checks = '''
+def process(filename):
+ src = open(filename, 'r').read().replace(
+ '// {{PRE_RUN_ADDITIONS}}',
+ "FS.createLazyFile('/', 'liblib.so', 'liblib.so', true, false);"
+ )
+ open(filename, 'w').write(src)
+'''
+ Settings.EXPORTED_FUNCTIONS = ['_main', '_malloc']
+ self.do_run(src, 'success', force_c=True, post_build=add_pre_run_and_checks)
+
def test_dlfcn_basic(self):
if not self.can_dlfcn(): return