1 # Expect script for direct linking from dll tests
3 # Free Software Foundation, Inc.
5 # This file is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
19 # Written by Pedro Alves <pedro_alves@portugalmail.pt>
24 # This test checks the "direct linking to a dll" functionality.
26 # The test has 7 stages:
28 # 1. compile and link a test dll with ".dll" extension.
30 # 2. compile and link a test dll with ".sl" (i.e. != ".dll") extension.
32 # 3. compile and link a client application linking directly to the ".dll" dll built in 1.
33 # This should produce no errors.
35 # 4. compile and link a client application linking directly to the ".sl" dll built in 2.
36 # This should produce no errors.
38 # 5. compile and link a client application linking directly to a symlink into
39 # the ".dll" dll built in 1.
40 # This should produce no errors.
42 # 6. compile and link a client application linking directly to a symlink into
43 # the ".sl" dll built in 1.
44 # This should produce no errors.
46 # 7. run the produced executables
48 # This test can only be run on PE/COFF platforms.
49 if { ![istarget *-*-cygwin*]
50 && ![istarget *-*-mingw*]
51 && ![istarget *-*-pe] } {
55 # No compiler, no test.
56 if { [which $CC] == 0 } {
57 untested "Direct linking to dll test"
63 proc test_direct_link_dll {} {
71 if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/direct_dll.c $tmpdir/direct_dll.o ] {
72 fail "compiling shared lib"
73 } elseif ![ld_simple_link "$CC -shared" $tmpdir/direct_dll.dll "$tmpdir/direct_dll.o" ] {
74 fail "linking shared lib (.dll)"
75 } elseif ![ld_simple_link "$CC -shared" $tmpdir/direct_dll.sl "$tmpdir/direct_dll.o" ] {
76 fail "linking shared lib (.sl)"
78 # Compile and link the client program.
79 if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/direct_client.c $tmpdir/direct_client.o ] {
80 fail "compiling client"
82 # Check linking directly to direct_dll.dll.
83 set msg "linking client (.dll)"
84 if [ld_simple_link $CC $tmpdir/direct_client_dll.exe "$tmpdir/direct_client.o $tmpdir/direct_dll.dll" ] {
90 # Check linking directly to direct_dll.sl.
91 set msg "linking client (.sl)"
92 if [ld_simple_link $CC $tmpdir/direct_client_sl.exe "$tmpdir/direct_client.o $tmpdir/direct_dll.sl" ] {
98 # Check dll direct linking through symlink to .dll.
99 # Create symbolic link.
100 catch "exec ln -fs direct_dll.dll $tmpdir/libdirect_dll.dll.a" ln_catch
101 set msg "linking client (symlink -> .dll)"
102 if [ld_simple_link $CC $tmpdir/direct_client_symlink_dll.exe "$tmpdir/direct_client.o $tmpdir/libdirect_dll.dll.a" ] {
108 # Check dll direct linking through symlink to .sl.
109 # Create symbolic link.
110 catch "exec ln -fs direct_dll.sl $tmpdir/libdirect_sl.dll.a" ln_catch
111 set msg "linking client (symlink -> .sl)"
112 if [ld_simple_link $CC $tmpdir/direct_client_symlink_sl.exe "$tmpdir/direct_client.o $tmpdir/libdirect_sl.dll.a" ] {
121 proc directdll_execute {exe msg} {
123 catch "exec $exe" prog_output
124 if [string match $expected $prog_output] then {
134 # This is as far as we can go with a cross-compiler
135 if ![isnative] then {
136 verbose "Not running natively, so cannot execute binaries"
140 directdll_execute "$tmpdir/direct_client_dll.exe" "running direct linked dll (.dll)"
141 directdll_execute "$tmpdir/direct_client_sl.exe" "running direct linked dll (.sl)"
142 directdll_execute "$tmpdir/direct_client_symlink_sl.exe" "running direct linked dll (symlink -> .sl)"
143 directdll_execute "$tmpdir/direct_client_symlink_dll.exe" "running direct linked dll (symlink -> .dll)"