* Makefile.tpl: Clean $(BUILD_SUBDIR).
[deliverable/binutils-gdb.git] / ld / testsuite / ld-d10v / d10v.exp
CommitLineData
4c0b7915
TR
1# Expect script for ld-d10v tests
2# Copyright 2002 Free Software Foundation, Inc.
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 Tom Rix, trix@redhat.com
19#
20
21# Test d10v
22
23if ![istarget d10v-*-*] {
24 return
25}
26
27# run_link_test FILE
28# Copied from run_dump_test, with the dumping part removed.
29#
30# Assemble a .s file, then run some utility on it and check the output.
31#
32# There should be an assembly language file named FILE.s in the test
33# suite directory. `run_link_test' will assemble and link FILE.s
34#
35# The FILE.lt file begins with zero or more option lines, which specify
36# flags to pass to the assembler, the program to run to dump the
37# assembler's output, and the options it wants. The option lines have
38# the syntax:
39#
40# # OPTION: VALUE
41#
42# OPTION is the name of some option, like "name" or "ld", and
43# VALUE is OPTION's value. The valid options are described below.
44# Whitespace is ignored everywhere, except within VALUE. The option
45# list ends with the first line that doesn't match the above syntax
46# (hmm, not great for error detection).
47#
48# The interesting options are:
49#
50# name: TEST-NAME
51# The name of this test, passed to DejaGNU's `pass' and `fail'
52# commands. If omitted, this defaults to FILE, the root of the
53# .s and .d files' names.
54#
55# as: FLAGS
56# When assembling, pass FLAGS to the assembler.
57# If assembling several files, you can pass different assembler
58# options in the "source" directives. See below.
59#
60# ld: FLAGS
61# Link assembled files using FLAGS, in the order of the "source"
62# directives, when using multiple files.
63#
64# source: SOURCE [FLAGS]
65# Assemble the file SOURCE.s using the flags in the "as" directive
66# and the (optional) FLAGS. If omitted, the source defaults to
67# FILE.s.
68# This is useful if several .x files want to share a .s file.
69# More than one "source" directive can be given, which is useful
70# when testing linking.
71#
72# xfail: TARGET
73# The test is expected to fail on TARGET. This may occur more than
74# once.
75#
76# target: TARGET
77# Only run the test for TARGET. This may occur more than once; the
78# target being tested must match at least one.
79#
80# notarget: TARGET
81# Do not run the test for TARGET. This may occur more than once;
82# the target being tested must not match any of them.
83#
84# Each option may occur at most once unless otherwise mentioned.
85#
86
87proc run_link_test { name } {
88 global subdir srcdir
89 global AS LD
90 global ASFLAGS LDFLAGS
91 global host_triplet runtests
92
93 if [string match "*/*" $name] {
94 set file $name
95 set name [file tail $name]
96 } else {
97 set file "$srcdir/$subdir/$name"
98 }
99
100 if ![runtest_file_p $runtests $name] then {
101 return
102 }
103
104 set opt_array [slurp_options "${file}.lt"]
105 if { $opt_array == -1 } {
106 perror "error reading options from $file.lt"
107 unresolved $subdir/$name
108 return
109 }
110 set dumpfile tmpdir/dump.out
111 set run_ld 0
112 set opts(as) {}
113 set opts(ld) {}
114 set opts(xfail) {}
115 set opts(target) {}
116 set opts(notarget) {}
117 set opts(name) {}
118 set opts(source) {}
119 set asflags(${file}.s) {}
120
121 foreach i $opt_array {
122 set opt_name [lindex $i 0]
123 set opt_val [lindex $i 1]
124 if ![info exists opts($opt_name)] {
125 perror "unknown option $opt_name in file $file.lt"
126 unresolved $subdir/$name
127 return
128 }
129
130 switch -- $opt_name {
131 xfail {}
132 target {}
133 notarget {}
134 source {
135 # Move any source-specific as-flags to a separate array to
136 # simplify processing.
137 if { [llength $opt_val] > 1 } {
138 set asflags([lindex $opt_val 0]) [lrange $opt_val 1 end]
139 set opt_val [lindex $opt_val 0]
140 } else {
141 set asflags($opt_val) {}
142 }
143 }
144 default {
145 if [string length $opts($opt_name)] {
146 perror "option $opt_name multiply set in $file.lt"
147 unresolved $subdir/$name
148 return
149 }
150 }
151 }
152 set opts($opt_name) [concat $opts($opt_name) $opt_val]
153 }
154
155 # Decide early whether we should run the test for this target.
156 if { [llength $opts(target)] > 0 } {
157 set targmatch 0
158 foreach targ $opts(target) {
159 if [istarget $targ] {
160 set targmatch 1
161 break
162 }
163 }
164 if { $targmatch == 0 } {
165 return
166 }
167 }
168 foreach targ $opts(notarget) {
169 if [istarget $targ] {
170 return
171 }
172 }
173
174 if { $opts(name) == "" } {
175 set testname "$subdir/$name"
176 } else {
177 set testname $opts(name)
178 }
179
180 if { $opts(source) == "" } {
181 set sourcefiles [list ${file}.s]
182 } else {
183 set sourcefiles {}
184 foreach sf $opts(source) {
185 lappend sourcefiles "$srcdir/$subdir/$sf"
186 # Must have asflags indexed on source name.
187 set asflags($srcdir/$subdir/$sf) $asflags($sf)
188 }
189 }
190
191 # Time to setup xfailures.
192 foreach targ $opts(xfail) {
193 setup_xfail $targ
194 }
195
196 # Assemble each file.
197 set objfiles {}
198 for { set i 0 } { $i < [llength $sourcefiles] } { incr i } {
199 set sourcefile [lindex $sourcefiles $i]
200
201 set objfile "tmpdir/dump$i.o"
202 lappend objfiles $objfile
203 set cmd "$AS $ASFLAGS $opts(as) $asflags($sourcefile) -o $objfile $sourcefile"
204
205 send_log "$cmd\n"
206 set cmdret [catch "exec $cmd" comp_output]
207 set comp_output [prune_warnings $comp_output]
208
209 # We accept errors at assembly stage too, unless we're supposed to
210 # link something.
211 if { $cmdret != 0 || ![string match "" $comp_output] } then {
212 send_log "$comp_output\n"
213 verbose "$comp_output" 3
214 fail $testname
215 return
216 }
217 }
218
219 # Link the file(s).
220 set objfile "tmpdir/dump"
221 set cmd "$LD $LDFLAGS $opts(ld) -o $objfile $objfiles"
222
223 send_log "$cmd\n"
224 set cmdret [catch "exec $cmd" comp_output]
225 set comp_output [prune_warnings $comp_output]
226
227 if { $cmdret != 0 || ![string match "" $comp_output] } then {
228
229 send_log "$comp_output\n"
230 verbose "$comp_output" 3
231 fail $testname
232 return
233 }
234 pass $testname
235}
236
237
238set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
239foreach test $test_list {
240 # We need to strip the ".d", but can leave the dirname.
241 verbose [file rootname $test]
242 run_dump_test [file rootname $test]
243}
244
245set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.lt]]
246foreach test $test_list {
247 # We need to strip the ".lt", but can leave the dirname.
248 verbose [file rootname $test]
249 run_link_test [file rootname $test]
250}
This page took 0.068122 seconds and 4 git commands to generate.