summaryrefslogtreecommitdiff
path: root/testsuite/tests/dynlibs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/dynlibs')
-rw-r--r--testsuite/tests/dynlibs/Makefile32
-rw-r--r--testsuite/tests/dynlibs/T3807-export.c21
-rw-r--r--testsuite/tests/dynlibs/T3807-load.c39
-rw-r--r--testsuite/tests/dynlibs/T3807.stdout1
-rw-r--r--testsuite/tests/dynlibs/T3807Export.hs11
-rw-r--r--testsuite/tests/dynlibs/T4464.stderr4
-rw-r--r--testsuite/tests/dynlibs/T4464.stdout2
-rw-r--r--testsuite/tests/dynlibs/T4464B.c21
-rw-r--r--testsuite/tests/dynlibs/T4464C.c15
-rw-r--r--testsuite/tests/dynlibs/T4464H.hs7
-rw-r--r--testsuite/tests/dynlibs/all.T21
11 files changed, 174 insertions, 0 deletions
diff --git a/testsuite/tests/dynlibs/Makefile b/testsuite/tests/dynlibs/Makefile
new file mode 100644
index 0000000000..b746326062
--- /dev/null
+++ b/testsuite/tests/dynlibs/Makefile
@@ -0,0 +1,32 @@
+TOP=../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+.PHONY: T3807
+T3807:
+ $(RM) T3807Export_stub.c T3807Export_stub.h T3807Export_stub.o
+ $(RM) T3807Export.o T3807Export.hi
+ $(RM) T3807-export.o T3807-load.o
+ $(RM) T3807test.so
+ $(RM) T3807-load
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 --make -dynamic -fPIC -shared T3807Export.hs T3807-export.c -o T3807test.so -lHSrts-ghc`'$(TEST_HC)' $(TEST_HC_OPTS) --numeric-version`
+ '$(TEST_HC)' $(TEST_HC_OPTS) T3807-load.c -o T3807-load -ldl
+ ./T3807-load
+
+.PHONY: T4464
+T4464:
+ $(RM) T4464B.o T4464C.o T4464H.hi T4464H.o
+ $(RM) T4464H_stub.c T4464H_stub.h T4464H_stub.o
+ $(RM) HS4464.dll HS4464.dll.a t4464.exe
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 -shared T4464H.hs T4464B.c -o HS4464.dll
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 T4464C.c HS4464.dll.a -o t4464.exe
+ -./t4464.exe
+ echo "====="
+ echo "=====" >&2
+ $(RM) T4464B.o T4464C.o T4464H.hi T4464H.o
+ $(RM) T4464H_stub.c T4464H_stub.h T4464H_stub.o
+ $(RM) HS4464.dll HS4464.dll.a t4464.exe
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 -shared T4464H.hs T4464B.c -o HS4464.dll -rtsopts
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 T4464C.c HS4464.dll.a -o t4464.exe
+ ./t4464.exe
+
diff --git a/testsuite/tests/dynlibs/T3807-export.c b/testsuite/tests/dynlibs/T3807-export.c
new file mode 100644
index 0000000000..aba129e944
--- /dev/null
+++ b/testsuite/tests/dynlibs/T3807-export.c
@@ -0,0 +1,21 @@
+
+#include <HsFFI.h>
+
+extern void __stginit_T3807Export(void);
+
+void
+test_init (void)
+{
+ static char *argv[] = { "T3807test.so", 0 };
+ static char **argv_ = argv;
+ static int argc = 1;
+
+ hs_init (&argc, &argv_);
+ hs_add_root (__stginit_T3807Export);
+}
+
+void
+test_exit (void)
+{
+ hs_exit ();
+}
diff --git a/testsuite/tests/dynlibs/T3807-load.c b/testsuite/tests/dynlibs/T3807-load.c
new file mode 100644
index 0000000000..8c6f252c5f
--- /dev/null
+++ b/testsuite/tests/dynlibs/T3807-load.c
@@ -0,0 +1,39 @@
+#include <dlfcn.h>
+#include <stdio.h>
+
+int main(void) {
+ int i;
+ void *dh;
+ void (*test_init)(void);
+ int (*test_foo)(void);
+ void (*test_exit)(void);
+
+ dh = dlopen("./T3807test.so", RTLD_NOW | RTLD_GLOBAL);
+ if (!dh) {
+ printf("Failed to open shared library: %s\n", dlerror());
+ return 1;
+ }
+
+ test_init = dlsym(dh, "test_init");
+ if (!test_init) {
+ printf("Failed to find test_init: %s", dlerror());
+ return 1;
+ }
+ test_foo = dlsym(dh, "foo");
+ if (!test_foo) {
+ printf("Failed to find test_foo: %s", dlerror());
+ return 1;
+ }
+ test_exit = dlsym(dh, "test_exit");
+ if (!test_exit) {
+ printf("Failed to find test_exit: %s", dlerror());
+ return 1;
+ }
+
+ test_init();
+ i = test_foo();
+ printf("i is %d\n", i);
+ test_exit();
+
+ return 0;
+}
diff --git a/testsuite/tests/dynlibs/T3807.stdout b/testsuite/tests/dynlibs/T3807.stdout
new file mode 100644
index 0000000000..05d58b6eb5
--- /dev/null
+++ b/testsuite/tests/dynlibs/T3807.stdout
@@ -0,0 +1 @@
+i is 126
diff --git a/testsuite/tests/dynlibs/T3807Export.hs b/testsuite/tests/dynlibs/T3807Export.hs
new file mode 100644
index 0000000000..70d9e9b5fb
--- /dev/null
+++ b/testsuite/tests/dynlibs/T3807Export.hs
@@ -0,0 +1,11 @@
+
+{-# LANGUAGE ForeignFunctionInterface #-}
+module T3807Export where
+
+import Foreign.C
+
+foo :: IO CInt
+foo = return (3 + read "123")
+
+foreign export ccall foo :: IO CInt
+
diff --git a/testsuite/tests/dynlibs/T4464.stderr b/testsuite/tests/dynlibs/T4464.stderr
new file mode 100644
index 0000000000..0ec9bb989d
--- /dev/null
+++ b/testsuite/tests/dynlibs/T4464.stderr
@@ -0,0 +1,4 @@
+Creating library file: HS4464.dll.a
+ghcDll: Most RTS options are disabled. Link with -rtsopts to enable them.
+=====
+Creating library file: HS4464.dll.a
diff --git a/testsuite/tests/dynlibs/T4464.stdout b/testsuite/tests/dynlibs/T4464.stdout
new file mode 100644
index 0000000000..68a1093c21
--- /dev/null
+++ b/testsuite/tests/dynlibs/T4464.stdout
@@ -0,0 +1,2 @@
+=====
+f 12 = 13
diff --git a/testsuite/tests/dynlibs/T4464B.c b/testsuite/tests/dynlibs/T4464B.c
new file mode 100644
index 0000000000..0cd2845895
--- /dev/null
+++ b/testsuite/tests/dynlibs/T4464B.c
@@ -0,0 +1,21 @@
+
+#include <Rts.h>
+
+extern void __stginit_T4464H(void);
+
+void HsStart(void) {
+ int argc = 3;
+ char* argv[] = {"ghcDll", "+RTS", "-H50M", NULL}; // argv must end with NULL
+
+ // Initialize Haskell runtime
+ char** args = argv;
+ hs_init(&argc, &args);
+
+ // Tell Haskell about all root modules
+ hs_add_root(__stginit_T4464H);
+}
+
+void HsEnd(void) {
+ hs_exit();
+}
+
diff --git a/testsuite/tests/dynlibs/T4464C.c b/testsuite/tests/dynlibs/T4464C.c
new file mode 100644
index 0000000000..d013b99684
--- /dev/null
+++ b/testsuite/tests/dynlibs/T4464C.c
@@ -0,0 +1,15 @@
+
+#include "HsFFI.h"
+#include "T4464H_stub.h"
+#include <stdio.h>
+
+void HsStart(void);
+void HsEnd(void);
+
+int main(void) {
+ HsStart();
+ printf("f 12 = %i\n", f(12));
+ HsEnd();
+ return 0;
+}
+
diff --git a/testsuite/tests/dynlibs/T4464H.hs b/testsuite/tests/dynlibs/T4464H.hs
new file mode 100644
index 0000000000..f620866c86
--- /dev/null
+++ b/testsuite/tests/dynlibs/T4464H.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+module T4464H where
+
+f :: Int -> Int
+f x = x + 1
+
+foreign export ccall f :: Int -> Int
diff --git a/testsuite/tests/dynlibs/all.T b/testsuite/tests/dynlibs/all.T
new file mode 100644
index 0000000000..2ed477255b
--- /dev/null
+++ b/testsuite/tests/dynlibs/all.T
@@ -0,0 +1,21 @@
+
+test('T3807',
+ [extra_clean(['T3807Export_stub.c', 'T3807Export_stub.h',
+ 'T3807Export_stub.o',
+ 'T3807Export.o', 'T3807Export.hi',
+ 'T3807-export.o', 'T3807-load.o',
+ 'T3807test.so',
+ 'T3807-load']),
+ if_os('mingw32', skip),
+ if_os('darwin', expect_broken(4264))],
+ run_command,
+ ['$MAKE --no-print-directory -s T3807'])
+
+test('T4464',
+ [extra_clean(['T4464B.o', 'T4464C.o', 'T4464H.hi', 'T4464H.o',
+ 'T4464H_stub.c', 'T4464H_stub.h', 'T4464H_stub.o',
+ 'HS4464.dll', 'HS4464.dll.a', 't4464.exe']),
+ unless_os('mingw32', skip)],
+ run_command,
+ ['$MAKE --no-print-directory -s T4464'])
+