summaryrefslogtreecommitdiff
path: root/testsuite/tests/ghci/linking
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/ghci/linking')
-rw-r--r--testsuite/tests/ghci/linking/Makefile123
-rw-r--r--testsuite/tests/ghci/linking/T3333.c4
-rw-r--r--testsuite/tests/ghci/linking/T3333.hs5
-rw-r--r--testsuite/tests/ghci/linking/T3333.stdout1
-rw-r--r--testsuite/tests/ghci/linking/TestLink.hs8
-rw-r--r--testsuite/tests/ghci/linking/all.T47
-rw-r--r--testsuite/tests/ghci/linking/f.c4
-rw-r--r--testsuite/tests/ghci/linking/ghcilink001.stdout1
-rw-r--r--testsuite/tests/ghci/linking/ghcilink002.stderr-mingw321
-rw-r--r--testsuite/tests/ghci/linking/ghcilink002.stdout1
-rw-r--r--testsuite/tests/ghci/linking/ghcilink003.stdout0
-rw-r--r--testsuite/tests/ghci/linking/ghcilink004.stdout1
-rw-r--r--testsuite/tests/ghci/linking/ghcilink005.stderr-mingw321
-rw-r--r--testsuite/tests/ghci/linking/ghcilink005.stdout1
14 files changed, 198 insertions, 0 deletions
diff --git a/testsuite/tests/ghci/linking/Makefile b/testsuite/tests/ghci/linking/Makefile
new file mode 100644
index 0000000000..60cb9cbfda
--- /dev/null
+++ b/testsuite/tests/ghci/linking/Makefile
@@ -0,0 +1,123 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+LOCAL_GHC_PKG = '$(GHC_PKG)' --no-user-package-db -f $(LOCAL_PKGCONF)
+
+# Test 1: ghci -Ldir -lfoo
+# with dir/libfoo.a
+
+.PHONY: ghcilink001
+ghcilink001 :
+ $(RM) -rf dir001
+ mkdir dir001
+ "$(TEST_HC)" -c f.c -o dir001/foo.o
+ "$(AR)" cqs dir001/libfoo.a dir001/foo.o
+ echo "test" | "$(TEST_HC)" --interactive -ignore-dot-ghci -v0 -Ldir001 -lfoo TestLink.hs
+
+# Test 2: ghci -Ldir -lfoo
+# with dir/libfoo.so
+
+ifeq "$(WINDOWS)" "YES"
+DLL = $1.dll
+else ifeq "$(DARWIN)" "YES"
+DLL = lib$1.dylib
+else
+DLL = lib$1.so
+endif
+
+.PHONY: ghcilink002
+ghcilink002 :
+ $(RM) -rf dir002
+ mkdir dir002
+ "$(TEST_HC)" -c -dynamic f.c -o dir002/foo.o
+ "$(TEST_HC)" -no-auto-link-packages -shared -v0 -o dir002/$(call DLL,foo) dir002/foo.o
+ echo "test" | "$(TEST_HC)" --interactive -ignore-dot-ghci -v0 -Ldir002 -lfoo TestLink.hs
+
+# Test 3: ghci -lstdc++
+# where libstdc++.so is normally found in a directory private to gcc,
+# so only gcc can find it (see #5289)
+
+.PHONY: ghcilink003
+ghcilink003 :
+ echo ":q" | "$(TEST_HC)" --interactive -ignore-dot-ghci -v0 -lstdc++
+
+# Test 4:
+# package P
+# library-dirs: `pwd`/dir004
+# extra-libraries: foo
+# with
+# dir004/libfoo.a
+
+LOCAL_PKGCONF004=dir004/local.package.conf
+PKG004=dir004/pkg.conf
+
+ghcilink004 :
+ $(RM) -rf dir004
+ mkdir dir004
+ #
+ rm -f $(PKG004)
+ echo 'name: test' >>$(PKG004)
+ echo 'version: 1.0' >>$(PKG004)
+ echo 'id: test-XXX' >>$(PKG004)
+ echo 'library-dirs: $${pkgroot}' >>$(PKG004)
+ echo 'extra-libraries: foo' >>$(PKG004)
+ echo '[]' >$(LOCAL_PKGCONF004)
+ '$(GHC_PKG)' --no-user-package-db -f $(LOCAL_PKGCONF004) register $(PKG004) -v0
+ #
+ "$(TEST_HC)" -c f.c -o dir004/foo.o
+ "$(AR)" cqs dir004/libfoo.a dir004/foo.o
+ echo "test" | "$(TEST_HC)" --interactive -ignore-dot-ghci -v0 -package-db $(LOCAL_PKGCONF004) -package test TestLink.hs
+
+# Test 5:
+# package P
+# library-dirs: `pwd`/dir005
+# extra-libraries: foo
+# with
+# dir005/libfoo.so
+
+LOCAL_PKGCONF005=dir005/ghcilink005.package.conf
+PKG005=dir005/pkg.conf
+
+ghcilink005 :
+ $(RM) -rf dir005
+ mkdir dir005
+ #
+ rm -f $(PKG005)
+ echo 'name: test' >>$(PKG005)
+ echo 'version: 1.0' >>$(PKG005)
+ echo 'id: test-XXX' >>$(PKG005)
+ echo 'library-dirs: $${pkgroot}' >>$(PKG005)
+ echo 'extra-libraries: foo' >>$(PKG005)
+ echo '[]' >$(LOCAL_PKGCONF005)
+ '$(GHC_PKG)' --no-user-package-db -f $(LOCAL_PKGCONF005) register $(PKG005) -v0
+ #
+ "$(TEST_HC)" -c -dynamic f.c -o dir005/foo.o
+ "$(TEST_HC)" -no-auto-link-packages -shared -o dir005/$(call DLL,foo) dir005/foo.o
+ echo "test" | "$(TEST_HC)" --interactive -ignore-dot-ghci -v0 -package-db $(LOCAL_PKGCONF005) -package test TestLink.hs
+
+# Test 6:
+# package P
+# extra-libraries: stdc++
+
+LOCAL_PKGCONF006=dir006/ghcilink006.package.conf
+PKG006=dir006/pkg.conf
+
+ghcilink006 :
+ $(RM) -rf dir006
+ mkdir dir006
+ #
+ rm -f $(PKG006)
+ echo "name: test" >>$(PKG006)
+ echo "version: 1.0" >>$(PKG006)
+ echo "id: test-XXX" >>$(PKG006)
+ echo "extra-libraries: stdc++" >>$(PKG006)
+ echo "[]" >$(LOCAL_PKGCONF006)
+ '$(GHC_PKG)' --no-user-package-db -f $(LOCAL_PKGCONF006) register $(PKG006) -v0
+ #
+ echo ":q" | "$(TEST_HC)" --interactive -ignore-dot-ghci -v0 -package-db $(LOCAL_PKGCONF006) -package test
+
+.PHONY: T3333
+T3333:
+ "$(TEST_HC)" -c T3333.c -o T3333.o
+ echo "weak_test 10" | "$(TEST_HC)" --interactive -ignore-dot-ghci -v0 T3333.hs T3333.o
diff --git a/testsuite/tests/ghci/linking/T3333.c b/testsuite/tests/ghci/linking/T3333.c
new file mode 100644
index 0000000000..92fe332c16
--- /dev/null
+++ b/testsuite/tests/ghci/linking/T3333.c
@@ -0,0 +1,4 @@
+
+int weak_test(int) __attribute__((weak));
+
+int weak_test(int x) {return x + 1;}
diff --git a/testsuite/tests/ghci/linking/T3333.hs b/testsuite/tests/ghci/linking/T3333.hs
new file mode 100644
index 0000000000..82c89095f7
--- /dev/null
+++ b/testsuite/tests/ghci/linking/T3333.hs
@@ -0,0 +1,5 @@
+module WeakTest where
+
+import Foreign.C.Types
+
+foreign import ccall weak_test :: CInt -> IO CInt
diff --git a/testsuite/tests/ghci/linking/T3333.stdout b/testsuite/tests/ghci/linking/T3333.stdout
new file mode 100644
index 0000000000..b4de394767
--- /dev/null
+++ b/testsuite/tests/ghci/linking/T3333.stdout
@@ -0,0 +1 @@
+11
diff --git a/testsuite/tests/ghci/linking/TestLink.hs b/testsuite/tests/ghci/linking/TestLink.hs
new file mode 100644
index 0000000000..808f6e3bea
--- /dev/null
+++ b/testsuite/tests/ghci/linking/TestLink.hs
@@ -0,0 +1,8 @@
+module TestLink where
+
+import Foreign.C
+
+foreign import ccall "f" f :: CInt -> IO CInt
+
+test :: IO ()
+test = f 42 >>= print
diff --git a/testsuite/tests/ghci/linking/all.T b/testsuite/tests/ghci/linking/all.T
new file mode 100644
index 0000000000..38ec046427
--- /dev/null
+++ b/testsuite/tests/ghci/linking/all.T
@@ -0,0 +1,47 @@
+test('ghcilink001',
+ [when(ghci_dynamic(), expect_fail), # dynamic ghci can't load '.a's
+ unless(doing_ghci, skip),
+ extra_clean(['dir001/*','dir001'])],
+ run_command,
+ ['$MAKE -s --no-print-directory ghcilink001'])
+
+test('ghcilink002',
+ [unless(doing_ghci, skip), extra_clean(['dir002/*','dir002'])],
+ run_command,
+ ['$MAKE -s --no-print-directory ghcilink002'])
+
+test('ghcilink003',
+ [
+ # still cannot load libstdc++ on Windows. See also #4468.
+ when(opsys('mingw32'), expect_broken(5289)),
+ unless(doing_ghci, skip),
+ extra_clean(['dir003/*','dir003'])
+ ],
+ run_command,
+ ['$MAKE -s --no-print-directory ghcilink003'])
+
+test('ghcilink004',
+ [unless(doing_ghci, skip),
+ extra_clean(['dir004/*','dir004'])],
+ run_command,
+ ['$MAKE -s --no-print-directory ghcilink004'])
+
+test('ghcilink005',
+ [unless(doing_ghci, skip), extra_clean(['dir005/*','dir005'])],
+ run_command,
+ ['$MAKE -s --no-print-directory ghcilink005'])
+
+test('ghcilink006',
+ [
+ # still cannot load libstdc++ on Windows. See also #4468.
+ when(opsys('mingw32'), expect_broken(5289)),
+ unless(doing_ghci, skip),
+ extra_clean(['dir006/*','dir006'])
+ ],
+ run_command,
+ ['$MAKE -s --no-print-directory ghcilink006'])
+
+test('T3333',
+ [extra_clean('T3333.o'), unless(doing_ghci, skip), unless(opsys('linux'), expect_broken(3333))],
+ run_command,
+ ['$MAKE -s --no-print-directory T3333'])
diff --git a/testsuite/tests/ghci/linking/f.c b/testsuite/tests/ghci/linking/f.c
new file mode 100644
index 0000000000..caf249d601
--- /dev/null
+++ b/testsuite/tests/ghci/linking/f.c
@@ -0,0 +1,4 @@
+int f(int x)
+{
+ return x*2;
+}
diff --git a/testsuite/tests/ghci/linking/ghcilink001.stdout b/testsuite/tests/ghci/linking/ghcilink001.stdout
new file mode 100644
index 0000000000..871727de1f
--- /dev/null
+++ b/testsuite/tests/ghci/linking/ghcilink001.stdout
@@ -0,0 +1 @@
+84
diff --git a/testsuite/tests/ghci/linking/ghcilink002.stderr-mingw32 b/testsuite/tests/ghci/linking/ghcilink002.stderr-mingw32
new file mode 100644
index 0000000000..c0649dab12
--- /dev/null
+++ b/testsuite/tests/ghci/linking/ghcilink002.stderr-mingw32
@@ -0,0 +1 @@
+Creating library file: dir002/foo.dll.a
diff --git a/testsuite/tests/ghci/linking/ghcilink002.stdout b/testsuite/tests/ghci/linking/ghcilink002.stdout
new file mode 100644
index 0000000000..871727de1f
--- /dev/null
+++ b/testsuite/tests/ghci/linking/ghcilink002.stdout
@@ -0,0 +1 @@
+84
diff --git a/testsuite/tests/ghci/linking/ghcilink003.stdout b/testsuite/tests/ghci/linking/ghcilink003.stdout
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/testsuite/tests/ghci/linking/ghcilink003.stdout
diff --git a/testsuite/tests/ghci/linking/ghcilink004.stdout b/testsuite/tests/ghci/linking/ghcilink004.stdout
new file mode 100644
index 0000000000..871727de1f
--- /dev/null
+++ b/testsuite/tests/ghci/linking/ghcilink004.stdout
@@ -0,0 +1 @@
+84
diff --git a/testsuite/tests/ghci/linking/ghcilink005.stderr-mingw32 b/testsuite/tests/ghci/linking/ghcilink005.stderr-mingw32
new file mode 100644
index 0000000000..7929095d94
--- /dev/null
+++ b/testsuite/tests/ghci/linking/ghcilink005.stderr-mingw32
@@ -0,0 +1 @@
+Creating library file: dir005/foo.dll.a
diff --git a/testsuite/tests/ghci/linking/ghcilink005.stdout b/testsuite/tests/ghci/linking/ghcilink005.stdout
new file mode 100644
index 0000000000..871727de1f
--- /dev/null
+++ b/testsuite/tests/ghci/linking/ghcilink005.stdout
@@ -0,0 +1 @@
+84