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