sync config/ChangeLog
[binutils.git] / ld / testsuite / ld-pe / pe-run.exp
blob709fb19a8fa77002c23bf90f52e28b9ed48cda7f
1 # Expect script for complex PE tests that require a C compiler and the ability
2 # to run target executables natively, in addition to the just-built binutils.
3 # Copyright 2006, 2007, 2009
4 # Free Software Foundation, Inc.
6 # This file is part of the GNU Binutils.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 # MA 02110-1301, USA.
23 # Written by Pedro Alves <pedro_alves@portugalmail.pt>
26 # Note:
28 # This test checks the "direct linking to a dll" functionality.
30 # The test has 7 stages:
32 # 1. compile and link a test dll with ".dll" extension.
34 # 2. compile and link a test dll with ".sl" (i.e. != ".dll") extension.
36 # 3. compile and link a client application linking directly to the ".dll" dll built in 1.
37 # This should produce no errors.
39 # 4. compile and link a client application linking directly to the ".sl" dll built in 2.
40 # This should produce no errors.
42 # 5. compile and link a client application linking directly to a symlink into
43 # the ".dll" dll built in 1.
44 # This should produce no errors.
46 # 6. compile and link a client application linking directly to a symlink into
47 # the ".sl" dll built in 1.
48 # This should produce no errors.
50 # 7. run the produced executables
52 # This test can only be run on PE/COFF platforms.
53 if {![is_pecoff_format]} {
54 return
57 # No compiler, no test.
58 if { [which $CC] == 0 } {
59 untested "Direct linking to dll test"
60 return
63 set tmpdir tmpdir
65 proc test_direct_link_dll {} {
66 global CC
67 global CFLAGS
68 global srcdir
69 global subdir
70 global tmpdir
72 # Compile the dll.
73 if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/direct_dll.c $tmpdir/direct_dll.o ] {
74 fail "compiling shared lib"
75 } elseif ![ld_simple_link "$CC -shared" $tmpdir/direct_dll.dll "$tmpdir/direct_dll.o" ] {
76 fail "linking shared lib (.dll)"
77 } elseif ![ld_simple_link "$CC -shared" $tmpdir/direct_dll.sl "$tmpdir/direct_dll.o" ] {
78 fail "linking shared lib (.sl)"
79 } else {
80 # Compile and link the client program.
81 if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/direct_client.c $tmpdir/direct_client.o ] {
82 fail "compiling client"
83 } else {
84 # Check linking directly to direct_dll.dll.
85 set msg "linking client (.dll)"
86 if [ld_simple_link "$CC -Wl,--enable-auto-import" $tmpdir/direct_client_dll.exe \
87 "$tmpdir/direct_client.o $tmpdir/direct_dll.dll" ] {
88 pass $msg
89 } else {
90 fail $msg
93 # Check linking directly to direct_dll.sl.
94 set msg "linking client (.sl)"
95 if [ld_simple_link "$CC -Wl,--enable-auto-import" $tmpdir/direct_client_sl.exe \
96 "$tmpdir/direct_client.o $tmpdir/direct_dll.sl" ] {
97 pass $msg
98 } else {
99 fail $msg
102 # Check dll direct linking through symlink to .dll.
103 # Create symbolic link.
104 catch "exec ln -fs direct_dll.dll $tmpdir/libdirect_dll.dll.a" ln_catch
105 set msg "linking client (symlink -> .dll)"
106 if [ld_simple_link "$CC -Wl,--enable-auto-import" $tmpdir/direct_client_symlink_dll.exe \
107 "$tmpdir/direct_client.o $tmpdir/libdirect_dll.dll.a" ] {
108 pass $msg
109 } else {
110 fail $msg
113 # Check dll direct linking through symlink to .sl.
114 # Create symbolic link.
115 catch "exec ln -fs direct_dll.sl $tmpdir/libdirect_sl.dll.a" ln_catch
116 set msg "linking client (symlink -> .sl)"
117 if [ld_simple_link "$CC -Wl,--enable-auto-import" $tmpdir/direct_client_symlink_sl.exe \
118 "$tmpdir/direct_client.o $tmpdir/libdirect_sl.dll.a" ] {
119 pass $msg
120 } else {
121 fail $msg
127 proc directdll_execute {exe msg} {
128 set expected ""
129 catch "exec $exe" prog_output
130 if [string match $expected $prog_output] then {
131 pass $msg
132 } else {
133 verbose $prog_output
134 fail $msg
138 test_direct_link_dll
140 # This is as far as we can go with a cross-compiler
141 if ![isnative] then {
142 verbose "Not running natively, so cannot execute binaries"
143 return
146 directdll_execute "$tmpdir/direct_client_dll.exe" "running direct linked dll (.dll)"
147 directdll_execute "$tmpdir/direct_client_sl.exe" "running direct linked dll (.sl)"
148 directdll_execute "$tmpdir/direct_client_symlink_sl.exe" "running direct linked dll (symlink -> .sl)"
149 directdll_execute "$tmpdir/direct_client_symlink_dll.exe" "running direct linked dll (symlink -> .dll)"