X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fforeign.test.sh;h=045d36bb63f1e900d40a3665d6645df8459570bf;hb=7e24349c17298e2959e853ea411b5f65d9f7f332;hp=0afbf39179098ee06301aef4425a0a9a78657542;hpb=416152f084604094445a758ff399871132dff2bd;p=sbcl.git diff --git a/tests/foreign.test.sh b/tests/foreign.test.sh index 0afbf39..045d36b 100644 --- a/tests/foreign.test.sh +++ b/tests/foreign.test.sh @@ -1,6 +1,7 @@ #!/bin/sh -# tests related to foreign function interface and LOAD-FOREIGN +# tests related to foreign function interface and loading of shared +# libraries # This software is part of the SBCL system. See the README file for # more information. @@ -8,35 +9,284 @@ # While most of SBCL is derived from the CMU CL system, the test # files (like this one) were written from scratch after the fork # from CMU CL. -# +# # This software is in the public domain and is provided with # absolutely no warranty. See the COPYING and CREDITS files for # more information. -testfilestem=$TMPDIR/sbcl-foreign-test-$$ +echo //entering foreign.test.sh + +# simple way to make sure we're not punting by accident: +# setting PUNT to anything other than 104 will make non-dlopen +# and non-linkage-table platforms fail this +PUNT=104 + +testfilestem=${TMPDIR:-/tmp}/sbcl-foreign-test-$$ + +## Make some shared object files to test with. + +build_so() { + echo building $1.so + if [ "`uname -m`" = x86_64 ]; then + CFLAGS="$CFLAGS -fPIC" + fi + if [ "`uname`" = Darwin ]; then + SO_FLAGS="-bundle" + else + SO_FLAGS="-shared" + fi + cc -c $1.c -o $1.o $CFLAGS + ld $SO_FLAGS -o $1.so $1.o +} + +cat > $testfilestem.c < $testfilestem.c -make $testfilestem.o -ld -shared -o $testfilestem.so $testfilestem.o +short negative_short() { return -1; } +int negative_int() { return -2; } +long negative_long() { return -3; } + +long long powish(unsigned int x, unsigned int y) { + long long acc = 1; + long long xx = (long long) x; + for(; y != 1; y /= 2) { + if (y & 1) { + acc *= xx; + y -= 1; + } + xx *= xx; + } + return xx*acc; +} + +float return9th(float f1, float f2, float f3, float f4, float f5, + float f6, float f7, float f8, float f9, float f10, + float f11, float f12) { + return f9; +} + +double return9thd(double f1, double f2, double f3, double f4, double f5, + double f6, double f7, double f8, double f9, double f10, + double f11, double f12) { + return f9; +} + +int long_test8(int a1, int a2, int a3, int a4, int a5, + int a6, int a7, long long l1) { + return (l1 == powish(2,34)); +} + +int long_test9(int a1, int a2, int a3, int a4, int a5, + int a6, int a7, long long l1, int a8) { + return (l1 == powish(2,35)); +} + +int long_test2(int i1, int i2, int i3, int i4, int i5, int i6, + int i7, int i8, int i9, long long l1, long long l2) { + return (l1 == (1 + powish(2,37))); +} + +long long return_long_long() { + return powish(2,33); +} +EOF -${SBCL:-sbcl} < $testfilestem-b.c +echo 'int bar() { return 42; }' >> $testfilestem-b.c +build_so $testfilestem-b + +echo 'int foo = 42;' > $testfilestem-b2.c +echo 'int bar() { return 13; }' >> $testfilestem-b2.c +build_so $testfilestem-b2 + +echo 'int late_foo = 43;' > $testfilestem-c.c +echo 'int late_bar() { return 14; }' >> $testfilestem-c.c +build_so $testfilestem-c + +## Foreign definitions & load + +cat > $testfilestem.def.lisp < $testfilestem.test.lisp <