]>
Commit | Line | Data |
---|---|---|
d87bef3a | 1 | # Copyright (C) 2004-2023 Free Software Foundation, Inc. |
5b9b7d81 JR |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
ec2655a6 | 5 | # the Free Software Foundation; either version 3 of the License, or |
5b9b7d81 JR |
6 | # (at your option) any later version. |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program; if not, write to the Free Software | |
4b4da160 | 15 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
5b9b7d81 JR |
16 | |
17 | # Please email any bugs, comments, and/or additions to this file to: | |
e38bc3b5 | 18 | # binutils@sources.redhat.com |
5b9b7d81 JR |
19 | |
20 | # This scripts tests all available SH architectures with all the assembler | |
21 | # options related to the architecture. It ensures that those combinations | |
22 | # which should not work do not work, and that those that should work | |
23 | # produce the correct output architecture. | |
24 | # | |
25 | # It looks for files in the same directory as this file named sh*.s . | |
e38bc3b5 | 26 | # Each file must contain all the instructions available within |
5b9b7d81 JR |
27 | # that architecture. The architecture name is inferred from the file name. |
28 | # | |
e38bc3b5 NC |
29 | # The sh*.s files should NOT be hand edited. Whenever the script is run |
30 | # (e.g. with 'make check') it creates a set of new (usually identical) files | |
31 | # in the <objdir>/gas/testsuite directory. These are compared against the | |
32 | # old ones in the testsuite. When the expected results change (or new | |
33 | # architectures are added) these new files can be used to replace the old | |
34 | # ones with no modification required. | |
35 | # | |
5b9b7d81 JR |
36 | # The script generates the architecture/option permutations automatically, |
37 | # but it reads the expected results from the file arch_expected.txt (also | |
38 | # found in the same directory as this script). | |
39 | # | |
40 | # The arch_expected.txt file should NOT be hand edited. Whenever the script | |
41 | # is run (e.g. with 'make check') it creates a new (usually identical) file | |
42 | # named arch_results.txt in the <objdir>/gas/testsuite directory. When the | |
43 | # expected results change (or new architectures are added) this new file | |
44 | # can be used to replace arch_expected.txt with no modification required. | |
45 | ||
e38bc3b5 NC |
46 | if {[istarget sh*-*-*]} then { |
47 | ||
5b9b7d81 | 48 | |
e38bc3b5 | 49 | # This procedure extracts the architecture name from the objdump output. |
5b9b7d81 JR |
50 | # If there is no architecture name (or objdump output changes significantly) |
51 | # then the behaviour is undefined, but it will most likely return junk. | |
52 | ||
53 | proc get_sh_arch { ofile } { | |
54 | global comp_output | |
55 | ||
56 | objdump "-f $ofile" | |
57 | send_log $comp_output | |
58 | ||
59 | set comp_output [string replace $comp_output 0 \ | |
60 | [expr [string first "architecture:" $comp_output] + 13] ""] | |
61 | ||
62 | return [string range $comp_output 0 [expr [string first "," $comp_output] - 1]] | |
63 | } | |
64 | ||
65 | ||
66 | # This procedure runs two tests: | |
67 | # Test 1: Check the assembler can assemble the given file with | |
68 | # given options. | |
69 | # Test 2: Check that the resultant architecture is as expected. | |
70 | # It also writes an entry to the arch_results.txt file. | |
71 | ||
72 | proc test_arch { file opt arch resultfile } { | |
73 | global comp_output | |
74 | ||
75 | set name [file tail $file] | |
76 | set rootname [file rootname $name] | |
77 | ||
78 | if [string equal $opt "default-options"] then { | |
79 | gas_run $name "-o ${rootname}-#${opt}#.o" "" | |
80 | } else { | |
81 | gas_run $name "$opt -o ${rootname}-#${opt}#.o" "" | |
82 | } | |
83 | ||
84 | if [want_no_output "$rootname file should assemble with $opt"] then { | |
85 | set result [get_sh_arch "${rootname}-#${opt}#.o"] | |
86 | puts $resultfile [format "%-20s %-25s %s" $file $opt $result] | |
87 | ||
88 | if {$result == $arch} then { | |
89 | pass "$rootname file with $opt should assemble to arch $arch" | |
90 | file delete "${rootname}-#${opt}#.o" | |
91 | } else { | |
92 | send_log $comp_output | |
93 | fail "$rootname file with $opt should assemble to arch $arch" | |
94 | } | |
95 | } else { | |
96 | puts $resultfile [format "%-20s %-25s ERROR" $file $opt] | |
97 | untested "$rootname file with $opt should assemble to arch $arch" | |
98 | } | |
99 | ||
100 | } | |
101 | ||
102 | ||
c29ae970 | 103 | # This procedure tests that a file that is not supposed to assemble |
5b9b7d81 JR |
104 | # with a given option does, in fact, not assemble. |
105 | # It also writes an entry to the arch_results.txt file. | |
106 | ||
107 | proc test_arch_error { file opt resultfile} { | |
108 | global comp_output | |
109 | ||
110 | set name [file tail $file] | |
111 | set rootname [file rootname $name] | |
112 | ||
113 | if [string equal $opt "default-options"] then { | |
114 | gas_run $name "-o ${rootname}-#${opt}#.o" "" | |
115 | } else { | |
116 | gas_run $name "$opt -o ${rootname}-#${opt}#.o" "" | |
117 | } | |
118 | ||
119 | if [string match "" $comp_output] then { | |
120 | fail "$rootname file with $opt should not assemble" | |
121 | puts $resultfile [format "%-20s %-25s [get_sh_arch ${rootname}-#${opt}#.o]" $file $opt] | |
122 | } else { | |
123 | pass "$rootname file with $opt should not assemble" | |
124 | puts $resultfile [format "%-20s %-25s ERROR" $file $opt] | |
125 | } | |
126 | } | |
127 | ||
128 | # These tests are not suitable for sh-coff because | |
129 | # coff does not store the architecture information. | |
130 | ||
131 | if [istarget sh*-*-elf] then { | |
132 | global subdir srcdir | |
133 | ||
134 | # Find all the architectures and generate the | |
135 | # list of options we will test. | |
136 | ||
137 | set filelist [lsort -ascii [glob "$srcdir/$subdir/sh*.s"]] | |
138 | set optlist {"default-options" "-dsp" "-isa=any" "-isa=dsp" "-isa=fp"} | |
139 | foreach file $filelist { | |
140 | set arch [file rootname [file tail $file]] | |
141 | lappend optlist "-isa=$arch" "-isa=${arch}-up" | |
142 | } | |
143 | ||
144 | # Initialise the results file | |
145 | ||
146 | set outfile [open "arch_results.txt" w 0666] | |
147 | puts $outfile "# Generated file. DO NOT EDIT" | |
148 | puts $outfile "#" | |
149 | puts $outfile "# This file is generated by gas/testsuite/gas/sh/arch/arch.exp ." | |
150 | puts $outfile "# It contains the expected results of the tests." | |
151 | puts $outfile "# If the tests are failing because the expected results" | |
152 | puts $outfile "# have changed then run 'make check' and copy the new file" | |
153 | puts $outfile "# from <objdir>/gas/testsuite/arch_results.txt" | |
154 | puts $outfile "# to <srcdir>/gas/testsuite/gas/sh/arch/arch_expected.txt ." | |
155 | puts $outfile "# Make sure the new expected results are ALL correct." | |
156 | puts $outfile "#" | |
157 | puts $outfile [format "# %-18s %-25s %s" "FILE" "OPTION" "OUTPUT"] | |
158 | puts $outfile [format "# %-18s %-25s %s" "----" "------" "------"] | |
159 | ||
160 | # Open the expected results file and skip the header | |
161 | ||
162 | set infile [open "$srcdir/$subdir/arch_expected.txt" r] | |
163 | while {[gets $infile line] >= 0 && [string match {\#*} $line]} {send_log "reading '$line'\n"} | |
164 | ||
165 | foreach file $filelist { | |
166 | foreach opt $optlist { | |
167 | set name [file tail $file] | |
168 | set rootname [file rootname $name] | |
169 | ||
170 | # Decode the expected result from the file | |
171 | ||
172 | scan $line "%s %s %s" exfile exopt exarch | |
173 | send_log "exfile = '$exfile', exopt = '$exopt', exarch = '$exarch'\n" | |
174 | send_log " name = '$name', opt = '$opt'\n" | |
175 | ||
176 | if {[string equal $exfile $name] && [string equal $exopt $opt]} then { | |
177 | # The expected result file makes sense and | |
178 | # appears up-to-date (the file and options match) | |
179 | ||
180 | if {[string equal $exarch "ERROR"]} then { | |
181 | test_arch_error $name $opt $outfile | |
182 | } else { | |
183 | test_arch $name $opt $exarch $outfile | |
184 | } | |
185 | } else { | |
186 | # The expected result file isn't right somehow | |
187 | # so just try any old test. This will cause | |
e38bc3b5 | 188 | # many failures, but will generate the results file. |
5b9b7d81 JR |
189 | |
190 | test_arch $name $opt $rootname $outfile | |
191 | } | |
192 | ||
193 | # Read the next line from the expected result file. | |
194 | # This is at the end because the process of skipping | |
195 | # the header reads the first real line | |
196 | ||
197 | if [gets $infile line] then { | |
198 | send_log "reading '$line'\n" | |
199 | } | |
200 | } | |
201 | } | |
202 | ||
203 | close $infile | |
204 | close $outfile | |
205 | } | |
e38bc3b5 | 206 | |
52b5ca5b | 207 | } ;# istarget sh*-*-* |