Commit missing pieces.
[deliverable/binutils-gdb.git] / ld / testsuite / ld-pe / direct.exp
1 # Expect script for direct linking from dll tests
2 # Copyright 2006
3 # Free Software Foundation, Inc.
4 #
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.
9 #
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.
14 #
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.
18 #
19 # Written by Pedro Alves <pedro_alves@portugalmail.pt>
20 #
21
22 # Note:
23 #
24 # This test checks the "direct linking to a dll" functionality.
25 #
26 # The test has 7 stages:
27 #
28 # 1. compile and link a test dll with ".dll" extension.
29 #
30 # 2. compile and link a test dll with ".sl" (i.e. != ".dll") extension.
31 #
32 # 3. compile and link a client application linking directly to the ".dll" dll built in 1.
33 # This should produce no errors.
34 #
35 # 4. compile and link a client application linking directly to the ".sl" dll built in 2.
36 # This should produce no errors.
37 #
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.
41 #
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.
45 #
46 # 7. run the produced executables
47
48 # This test can only be run on PE/COFF platforms.
49 if { ![istarget *-*-cygwin*]
50 && ![istarget *-*-mingw*]
51 && ![istarget *-*-pe] } {
52 return
53 }
54
55 # No compiler, no test.
56 if { [which $CC] == 0 } {
57 untested "Direct linking to dll test"
58 return
59 }
60
61 set tmpdir tmpdir
62
63 proc test_direct_link_dll {} {
64 global CC
65 global CFLAGS
66 global srcdir
67 global subdir
68 global tmpdir
69
70 # Compile the 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)"
77 } else {
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"
81 } else {
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" ] {
85 pass $msg
86 } else {
87 fail $msg
88 }
89
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" ] {
93 pass $msg
94 } else {
95 fail $msg
96 }
97
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" ] {
103 pass $msg
104 } else {
105 fail $msg
106 }
107
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" ] {
113 pass $msg
114 } else {
115 fail $msg
116 }
117 }
118 }
119 }
120
121 proc directdll_execute {exe msg} {
122 set expected ""
123 catch "exec $exe" prog_output
124 if [string match $expected $prog_output] then {
125 pass $msg
126 } else {
127 verbose $prog_output
128 fail $msg
129 }
130 }
131
132 test_direct_link_dll
133
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"
137 return
138 }
139
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)"
This page took 0.03485 seconds and 4 git commands to generate.