==> bfd/ChangeLog <==
[deliverable/binutils-gdb.git] / ld / testsuite / ld-pe / pe-run.exp
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
4 # Free Software Foundation, Inc.
5 #
6 # This file is part of the GNU Binutils.
7 #
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.
12 #
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.
17 #
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.
22 #
23 # Written by Pedro Alves <pedro_alves@portugalmail.pt>
24 #
25
26 # Note:
27 #
28 # This test checks the "direct linking to a dll" functionality.
29 #
30 # The test has 7 stages:
31 #
32 # 1. compile and link a test dll with ".dll" extension.
33 #
34 # 2. compile and link a test dll with ".sl" (i.e. != ".dll") extension.
35 #
36 # 3. compile and link a client application linking directly to the ".dll" dll built in 1.
37 # This should produce no errors.
38 #
39 # 4. compile and link a client application linking directly to the ".sl" dll built in 2.
40 # This should produce no errors.
41 #
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.
45 #
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.
49 #
50 # 7. run the produced executables
51
52 # This test can only be run on PE/COFF platforms.
53 if {![is_pecoff_format]} {
54 return
55 }
56
57 # No compiler, no test.
58 if { [which $CC] == 0 } {
59 untested "Direct linking to dll test"
60 return
61 }
62
63 set tmpdir tmpdir
64
65 proc test_direct_link_dll {} {
66 global CC
67 global CFLAGS
68 global srcdir
69 global subdir
70 global tmpdir
71
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 $tmpdir/direct_client_dll.exe "$tmpdir/direct_client.o $tmpdir/direct_dll.dll" ] {
87 pass $msg
88 } else {
89 fail $msg
90 }
91
92 # Check linking directly to direct_dll.sl.
93 set msg "linking client (.sl)"
94 if [ld_simple_link $CC $tmpdir/direct_client_sl.exe "$tmpdir/direct_client.o $tmpdir/direct_dll.sl" ] {
95 pass $msg
96 } else {
97 fail $msg
98 }
99
100 # Check dll direct linking through symlink to .dll.
101 # Create symbolic link.
102 catch "exec ln -fs direct_dll.dll $tmpdir/libdirect_dll.dll.a" ln_catch
103 set msg "linking client (symlink -> .dll)"
104 if [ld_simple_link $CC $tmpdir/direct_client_symlink_dll.exe "$tmpdir/direct_client.o $tmpdir/libdirect_dll.dll.a" ] {
105 pass $msg
106 } else {
107 fail $msg
108 }
109
110 # Check dll direct linking through symlink to .sl.
111 # Create symbolic link.
112 catch "exec ln -fs direct_dll.sl $tmpdir/libdirect_sl.dll.a" ln_catch
113 set msg "linking client (symlink -> .sl)"
114 if [ld_simple_link $CC $tmpdir/direct_client_symlink_sl.exe "$tmpdir/direct_client.o $tmpdir/libdirect_sl.dll.a" ] {
115 pass $msg
116 } else {
117 fail $msg
118 }
119 }
120 }
121 }
122
123 proc directdll_execute {exe msg} {
124 set expected ""
125 catch "exec $exe" prog_output
126 if [string match $expected $prog_output] then {
127 pass $msg
128 } else {
129 verbose $prog_output
130 fail $msg
131 }
132 }
133
134 test_direct_link_dll
135
136 # This is as far as we can go with a cross-compiler
137 if ![isnative] then {
138 verbose "Not running natively, so cannot execute binaries"
139 return
140 }
141
142 directdll_execute "$tmpdir/direct_client_dll.exe" "running direct linked dll (.dll)"
143 directdll_execute "$tmpdir/direct_client_sl.exe" "running direct linked dll (.sl)"
144 directdll_execute "$tmpdir/direct_client_symlink_sl.exe" "running direct linked dll (symlink -> .sl)"
145 directdll_execute "$tmpdir/direct_client_symlink_dll.exe" "running direct linked dll (symlink -> .dll)"
This page took 0.03333 seconds and 4 git commands to generate.