2002-07-17 H.J. Lu <hjl@gnu.org>
[binutils.git] / ld / testsuite / ld-cdtest / cdtest.exp
blob1c51f0d21398271715f198995252b5fdf5cc22ed
1 # Expect script for LD cdtest Tests
2 #   Copyright 1993, 1994, 1995, 1997, 2001 Free Software Foundation, Inc.
4 # This file is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Written by Jeffrey Wheat (cassidy@cygnus.com)
19 # Rewritten by Ian Lance Taylor (ian@cygnus.com)
22 # Make sure that constructors are handled correctly.
24 set test1 "cdtest"
25 set test2 "cdtest with -Ur"
27 # This test requires running the executable generated by ld.
28 if ![isnative] {
29     return
32 if { [which $CXX] == 0 } {
33     untested $test1
34     untested $test2
35     return
38 if {   ![ld_compile "$CXX $CXXFLAGS -fgnu-linker -fno-exceptions" $srcdir/$subdir/cdtest-foo.cc tmpdir/cdtest-foo.o]
39     || ![ld_compile "$CXX $CXXFLAGS -fgnu-linker -fno-exceptions" $srcdir/$subdir/cdtest-bar.cc tmpdir/cdtest-bar.o]
40     || ![ld_compile "$CXX $CXXFLAGS -fgnu-linker -fno-exceptions" $srcdir/$subdir/cdtest-main.cc tmpdir/cdtest-main.o] } {
41     unresolved $test1
42     unresolved $test2
43     return
46 set expected_output "$srcdir/$subdir/cdtest.dat"
48 if ![ld_link $ld tmpdir/cdtest {tmpdir/cdtest-foo.o tmpdir/cdtest-bar.o tmpdir/cdtest-main.o}] {
49     fail $test1
50 } else {
51     send_log   "tmpdir/cdtest >tmpdir/cdtest.out\n"
52     verbose    "tmpdir/cdtest >tmpdir/cdtest.out"
53     catch "exec tmpdir/cdtest >tmpdir/cdtest.out" exec_output
55     if ![string match "" $exec_output] then {
56         send_log "$exec_output\n"
57         verbose "$exec_output" 1
59         fail $test1
60     } else {
61         send_log   "diff tmpdir/cdtest.out $expected_output\n"
62         verbose    "diff tmpdir/cdtest.out $expected_output"
63         catch "exec diff tmpdir/cdtest.out $expected_output" exec_output
64         set exec_output [prune_warnings $exec_output]
66         if ![string match "" $exec_output] then {
67             send_log "$exec_output\n"
68             verbose  "$exec_output" 1
70             send_log "Checking against Named Return Value optimization\n"
71             verbose  "Checking against Named Return Value optimization" 1
73             set expected_output "$srcdir/$subdir/cdtest-nrv.dat"
75             send_log   "diff tmpdir/cdtest.out $expected_output\n"
76             verbose    "diff tmpdir/cdtest.out $expected_output"
77             catch "exec diff tmpdir/cdtest.out $expected_output" exec_output
78             set exec_output [prune_warnings $exec_output]
79         }
81         if [string match "" $exec_output] then {
82             pass $test1
83         } else {
84             send_log "$exec_output\n"
85             verbose  "$exec_output" 1
87             fail $test1
88         }
89     }
92 if ![ld_relocate $ld tmpdir/cdtest.o {-Ur tmpdir/cdtest-foo.o tmpdir/cdtest-bar.o tmpdir/cdtest-main.o}] {
93     fail $test2
94 } else {
95     if ![ld_link $ld tmpdir/cdtest tmpdir/cdtest.o] {
96         fail $test2
97     } else {
98         send_log   "tmpdir/cdtest >tmpdir/cdtest.out\n"
99         verbose    "tmpdir/cdtest >tmpdir/cdtest.out"
100         catch "exec tmpdir/cdtest >tmpdir/cdtest.out" exec_output
102         if ![string match "" $exec_output] then {
103             send_log "$exec_output\n"
104             verbose  "$exec_output" 1
106             fail $test2
107         } else {
108             send_log   "diff tmpdir/cdtest.out $expected_output\n"
109             verbose    "diff tmpdir/cdtest.out $expected_output"
110             catch "exec diff tmpdir/cdtest.out $expected_output" exec_output
111             set exec_output [prune_warnings $exec_output]
113             if [string match "" $exec_output] then {
114                 pass $test2
115             } else {
116                 send_log "$exec_output\n"
117                 verbose  "$exec_output" 1
119                 fail $test2
120             }
121         }
122     }