aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormax99x <max99x@gmail.com>2011-08-25 10:53:27 +0300
committermax99x <max99x@gmail.com>2011-08-25 10:53:27 +0300
commita23a1bd38f5eff1db1a032d59a0a56730a9b2fa5 (patch)
tree74c2cd9af5b55e9de1ef6d619919af6e51a3b7d7
parent96189e4f02f5e78481925ab2add6044a2a55fa5e (diff)
Added a failing test for calling parent vararg functions inside shared libs.
-rw-r--r--tests/runner.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py
index 06e2e99a..d40de496 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -2090,6 +2090,60 @@ if 'benchmark' not in sys.argv:
output_nicerizer=lambda x: x.replace('\n', '*'),
post_build=add_pre_run_and_checks)
+ def test_dlfcn_varargs(self):
+ global BUILD_AS_SHARED_LIB, EXPORTED_FUNCTIONS
+ lib_src = r'''
+ void print_ints(int n, ...);
+ void func() {
+ print_ints(2, 13, 42);
+ }
+ '''
+ dirname = self.get_dir()
+ filename = os.path.join(dirname, 'liblib.cpp')
+ BUILD_AS_SHARED_LIB = 1
+ EXPORTED_FUNCTIONS = ['__Z4funcv']
+ self.build(lib_src, dirname, filename)
+ shutil.move(filename + '.o.js', os.path.join(dirname, 'liblib.so'))
+
+ src = r'''
+ #include <stdarg.h>
+ #include <stdio.h>
+ #include <dlfcn.h>
+
+ void print_ints(int n, ...) {
+ va_list args;
+ va_start(args, n);
+ for (int i = 0; i < n; i++) {
+ printf("%d\n", va_arg(args, int));
+ }
+ va_end(args);
+ }
+
+ int main() {
+ void* lib_handle;
+ void (*fptr)();
+
+ print_ints(2, 100, 200);
+
+ lib_handle = dlopen("liblib.so", RTLD_NOW);
+ fptr = (void (*)())dlsym(lib_handle, "_Z4funcv");
+ fptr();
+
+ return 0;
+ }
+ '''
+ BUILD_AS_SHARED_LIB = 0
+ EXPORTED_FUNCTIONS = ['_main']
+ def add_pre_run_and_checks(filename):
+ src = open(filename, 'r').read().replace(
+ '// {{PRE_RUN_ADDITIONS}}',
+ '''FS.createLazyFile('/', 'liblib.so', 'liblib.so', true, false);'''
+ )
+ open(filename, 'w').write(src)
+ self.do_test(src, 'Parent global: 123.*Parent global: 456.*',
+ output_nicerizer=lambda x: x.replace('\n', '*'),
+ post_build=add_pre_run_and_checks)
+
def test_rand(self):
src = r'''
#include <stdio.h>