* ld-selective/selective.exp: Rearrange to be table-driven.
[deliverable/binutils-gdb.git] / ld / testsuite / ld-selective / selective.exp
1 # Expect script for LD selective linking tests
2 # Copyright (C) 1998, 1999, 2000 Free Software Foundation
3 #
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.
17 #
18 # Written by Catherine Moore (clm@cygnus.com)
19 # Make sure that constructors are handled correctly.
20
21
22 # COFF based ports do not support selective linking
23 if {[istarget "*-*-coff"]} {
24 return
25 }
26 if {[istarget "*-*-pe"]} {
27 return
28 }
29
30 # List contains test-items with three items followed by four lists:
31 # 1:name 2:test-type (CC or C++; add as needed) 3:filename 4:ld-flags
32 # 5:must-have-symbols 6:must-not-have-symbols 7:xfail-targets.
33 #
34 # If a must(-not)-have symbol is a list, then that list must have two
35 # items; the symbol name and a value the symbol must (not) have.
36 #
37 # Note: ld_nm trims leading `_' from _start
38 #
39 # FIXME: Instead of table, read settings from each source-file.
40 set seltests {
41 {selective1 C 1.c {} {} {dropme1 dropme2} {}}
42 {selective2 C 2.c {} {} {foo} {}}
43 {selective3 C 2.c {-u foo} {foo} {{foo 0}} {}}
44 {selective4 C++ 3.cc {} {start foo__1A foo__1B} {bar__1A} {v850*-*-elf}}
45 {selective5 C++ 4.cc {} {} {foo__1B foo__1A} {}}
46 {selective6 C++ 5.cc {} {} {foo__1B foo__1A dropme1__Fv dropme2__Fv} {*-*-*}}
47 }
48
49 set cflags "-w -O2 -ffunction-sections -fdata-sections"
50 set cxxflags "-fvtable-gc -fno-exceptions -fno-rtti"
51 set ldflags "--gc-sections -Bstatic"
52
53 # If we don't have g++ for the target, mark all tests as untested.
54 if { [which $CXX] == 0 } {
55 foreach testitem $seltests {
56 untested "[lindex $seltests 0]"
57 }
58 return
59 }
60
61 foreach testitem $seltests {
62 set testname [lindex $testitem 0]
63 set testtype [lindex $testitem 1]
64 set testfile [lindex $testitem 2]
65 set objfile "tmpdir/[file rootname $testfile].o"
66 set ldfile "tmpdir/[file rootname $testfile].x"
67 set failed 0
68
69 set ldargs [lindex $testitem 3]
70 set mustsyms [lindex $testitem 4]
71 set mustnotsyms [lindex $testitem 5]
72 set xfails [lindex $testitem 6]
73
74 foreach xfail_target $xfails {
75 setup_xfail $xfail_target
76 }
77
78 # It's either C or C++ at the moment.
79 if { $testtype == "C++" } {
80 set testflags "$cflags $cxxflags"
81 } {
82 set testflags "$cflags"
83 }
84
85 # Note that we do not actually *use* CXX; we just add cxxflags for C++
86 # tests. It might have been a buglet originally; now I think better
87 # leave as is.
88 if { ![ld_compile "$CC $testflags" $srcdir/$subdir/$testfile $objfile] } {
89 unresolved $testname
90 return
91 }
92
93 if ![ld_simple_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] {
94 fail $testname
95 continue
96 }
97
98 if ![ld_nm $nm $ldfile] {
99 unresolved $testname
100 continue
101 }
102
103 # Check each mandated symbol and optionally mandated values.
104 foreach mustsym $mustsyms {
105 if { [llength [concat $mustsym]] == 1 } {
106 if { ![info exists nm_output($mustsym)] } {
107 verbose -log "$testname: missing $mustsym"
108 fail $testname
109 set failed 1
110 break
111 }
112 } {
113 set mustsymname [lindex $mustsym 0]
114 set mustsymvalue [lindex $mustsym 1]
115 if { ![info exists nm_output($mustsymname)] } {
116 verbose -log "$testname: missing $mustsymname"
117 fail $testname
118 set failed 1
119 break
120 } {
121 if { $nm_output($mustsymname) != $mustsymvalue } {
122 verbose -log "$testname: $mustsymname != $mustsymvalue"
123 verbose -log "is instead $nm_output($mustsymname)"
124 fail $testname
125 set failed 1
126 break
127 }
128 }
129 }
130 }
131
132 if { $failed != 0 } {
133 continue
134 }
135
136 # Check each unwanted symbol, or that symbols do not have specific
137 # values.
138 foreach mustnotsym $mustnotsyms {
139 if { [llength [concat $mustnotsym]] == 1 } {
140 if { [info exists nm_output($mustnotsym)] } {
141 verbose -log "$testname: $mustnotsym == $nm_output($mustnotsym)"
142 fail $testname
143 set failed 1
144 break
145 }
146 } {
147 set mustnotsymname [lindex $mustnotsym 0]
148 set mustnotsymvalue [lindex $mustnotsym 1]
149 if { [info exists nm_output($mustnotsymname)] \
150 && $nm_output($mustnotsymname) == $mustnotsymvalue} {
151 verbose -log "$testname: $mustnotsymname == $mustnotsymvalue"
152 fail $testname
153 set failed 1
154 break
155 }
156 }
157 }
158
159 if { $failed == 0 } {
160 pass $testname
161 }
162 }
163
This page took 0.034032 seconds and 5 git commands to generate.