| 1 |
# Copyright (C) 1988-2025 Free Software Foundation, Inc. |
| 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 |
| 5 |
# the Free Software Foundation; either version 3 of the License, or |
| 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 GCC; see the file COPYING3. If not see |
| 15 |
# <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
# This file was derived from mike-g++.exp written by Mike Stump <[email protected]> |
| 18 |
|
| 19 |
load_lib target-utils.exp |
| 20 |
|
| 21 |
# |
| 22 |
# mike_cleanup -- remove any files that are created by the testcase |
| 23 |
# |
| 24 |
proc mike_cleanup { src_code output_file assembly_file } { |
| 25 |
remote_file build delete $output_file $assembly_file |
| 26 |
} |
| 27 |
|
| 28 |
# |
| 29 |
# prebase -- sets up a Mike Stump ([email protected]) style gcc test |
| 30 |
# |
| 31 |
proc prebase { } { |
| 32 |
global compiler_output |
| 33 |
global not_compiler_output |
| 34 |
global compiler_result |
| 35 |
global not_compiler_result |
| 36 |
global program_output |
| 37 |
global groups |
| 38 |
global run |
| 39 |
global actions |
| 40 |
global target_regexp |
| 41 |
|
| 42 |
set compiler_output "^$" |
| 43 |
set not_compiler_output ".*Internal compiler error.*" |
| 44 |
set compiler_result "" |
| 45 |
set not_compiler_result "" |
| 46 |
set program_output ".*PASS.*" |
| 47 |
set groups {} |
| 48 |
set run no |
| 49 |
set actions assemble |
| 50 |
set target_regexp ".*" |
| 51 |
} |
| 52 |
|
| 53 |
# |
| 54 |
# run the test |
| 55 |
# |
| 56 |
proc postbase { src_code run groups args } { |
| 57 |
global verbose |
| 58 |
global srcdir |
| 59 |
global subdir |
| 60 |
global not_compiler_output |
| 61 |
global compiler_output |
| 62 |
global compiler_result |
| 63 |
global not_compiler_result |
| 64 |
global program_output |
| 65 |
global actions |
| 66 |
global target_regexp |
| 67 |
global host_triplet |
| 68 |
global target_triplet |
| 69 |
global tool |
| 70 |
global tmpdir |
| 71 |
global GCC_UNDER_TEST |
| 72 |
global GROUP |
| 73 |
|
| 74 |
if ![info exists GCC_UNDER_TEST] { |
| 75 |
error "No compiler specified for testing." |
| 76 |
} |
| 77 |
|
| 78 |
if ![regexp $target_regexp $target_triplet] { |
| 79 |
unsupported $subdir/$src_code |
| 80 |
return |
| 81 |
} |
| 82 |
|
| 83 |
if { [llength $args] > 0 } { |
| 84 |
set comp_options [lindex $args 0] |
| 85 |
} else { |
| 86 |
set comp_options "" |
| 87 |
} |
| 88 |
|
| 89 |
set fail_message $subdir/$src_code |
| 90 |
set pass_message $subdir/$src_code |
| 91 |
|
| 92 |
if [info exists GROUP] { |
| 93 |
if {[lsearch $groups $GROUP] == -1} { |
| 94 |
return |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
if [string match $run yes] { |
| 99 |
set actions run |
| 100 |
} |
| 101 |
|
| 102 |
set output_file "$tmpdir/[file tail [file rootname $src_code]]" |
| 103 |
set assembly_file "$output_file" |
| 104 |
append assembly_file ".S" |
| 105 |
|
| 106 |
set compile_type "none" |
| 107 |
|
| 108 |
switch $actions { |
| 109 |
compile |
| 110 |
{ |
| 111 |
set compile_type "assembly" |
| 112 |
set output_file $assembly_file |
| 113 |
} |
| 114 |
assemble |
| 115 |
{ |
| 116 |
set compile_type "object" |
| 117 |
append output_file ".o" |
| 118 |
} |
| 119 |
link |
| 120 |
{ |
| 121 |
set compile_type "executable" |
| 122 |
append output_file ".exe" |
| 123 |
} |
| 124 |
run |
| 125 |
{ |
| 126 |
set compile_type "executable" |
| 127 |
append output_file ".exe" |
| 128 |
set run yes |
| 129 |
} |
| 130 |
default |
| 131 |
{ |
| 132 |
set output_file "" |
| 133 |
set compile_type "none" |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
set src_file "$srcdir/$subdir/$src_code" |
| 138 |
set options "" |
| 139 |
lappend options "compiler=$GCC_UNDER_TEST" |
| 140 |
|
| 141 |
if { $comp_options != "" } { |
| 142 |
lappend options "additional_flags=$comp_options" |
| 143 |
} |
| 144 |
|
| 145 |
set comp_output [gcc_target_compile $src_file $output_file $compile_type $options] |
| 146 |
|
| 147 |
set pass no |
| 148 |
|
| 149 |
# Delete things like "ld.so warning" messages. |
| 150 |
set comp_output [prune_warnings $comp_output] |
| 151 |
|
| 152 |
if [regexp -- $not_compiler_output $comp_output] { |
| 153 |
if { $verbose > 1 } { |
| 154 |
send_user "\nChecking:\n$not_compiler_output\nto make sure it does not match:\n$comp_output\nbut it does.\n\n" |
| 155 |
} else { |
| 156 |
send_log "\nCompiler output:\n$comp_output\n\n" |
| 157 |
} |
| 158 |
fail $fail_message |
| 159 |
# The framework doesn't like to see any error remnants, |
| 160 |
# so remove them. |
| 161 |
uplevel { |
| 162 |
if [info exists errorInfo] { |
| 163 |
unset errorInfo |
| 164 |
} |
| 165 |
} |
| 166 |
mike_cleanup $src_code $output_file $assembly_file |
| 167 |
return |
| 168 |
} |
| 169 |
|
| 170 |
# remove any leftover CRs. |
| 171 |
regsub -all -- "\r" $comp_output "" comp_output |
| 172 |
|
| 173 |
regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $comp_output "" comp_output |
| 174 |
regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $comp_output "" comp_output |
| 175 |
|
| 176 |
set unsupported_message [${tool}_check_unsupported_p $comp_output] |
| 177 |
if { $unsupported_message != "" } { |
| 178 |
unsupported "$subdir/$src_code: $unsupported_message" |
| 179 |
mike_cleanup $src_code $output_file $assembly_file |
| 180 |
return |
| 181 |
} |
| 182 |
|
| 183 |
if { $verbose > 1 } { |
| 184 |
send_user "\nChecking:\n$compiler_output\nto see if it matches:\n$comp_output\n" |
| 185 |
} else { |
| 186 |
send_log "\nCompiler output:\n$comp_output\n\n" |
| 187 |
} |
| 188 |
if [regexp -- $compiler_output $comp_output] { |
| 189 |
if { $verbose > 1 } { |
| 190 |
send_user "Yes, it matches.\n\n" |
| 191 |
} |
| 192 |
set pass yes |
| 193 |
if [file exists [file rootname [file tail $src_code]].s] { |
| 194 |
set fd [open [file rootname [file tail $src_code]].s r] |
| 195 |
set dot_s [read $fd] |
| 196 |
close $fd |
| 197 |
if { $compiler_result != "" } { |
| 198 |
verbose "Checking .s file for $compiler_result" 2 |
| 199 |
if [regexp -- $compiler_result $dot_s] { |
| 200 |
verbose "Yes, it matches." 2 |
| 201 |
} else { |
| 202 |
verbose "Nope, doesn't match." 2 |
| 203 |
verbose $dot_s 4 |
| 204 |
set pass no |
| 205 |
} |
| 206 |
} |
| 207 |
if { $not_compiler_result != "" } { |
| 208 |
verbose "Checking .s file for not $not_compiler_result" 2 |
| 209 |
if ![regexp -- $not_compiler_result $dot_s] { |
| 210 |
verbose "Nope, not found (that's good)." 2 |
| 211 |
} else { |
| 212 |
verbose "Uh oh, it was found." 2 |
| 213 |
verbose $dot_s 4 |
| 214 |
set pass no |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
if [string match $run yes] { |
| 219 |
set result [gcc_load $output_file] |
| 220 |
set status [lindex $result 0] |
| 221 |
set output [lindex $result 1] |
| 222 |
if { $status == -1 } { |
| 223 |
mike_cleanup $src_code $output_file $assembly_file |
| 224 |
return |
| 225 |
} |
| 226 |
if { $verbose > 1 } { |
| 227 |
send_user "Checking:\n$program_output\nto see if it matches:\n$output\n\n" |
| 228 |
} |
| 229 |
if ![regexp -- $program_output $output] { |
| 230 |
set pass no |
| 231 |
if { $verbose > 1 } { |
| 232 |
send_user "Nope, does not match.\n\n" |
| 233 |
} |
| 234 |
} else { |
| 235 |
if { $verbose > 1 } { |
| 236 |
send_user "Yes, it matches.\n\n" |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
} else { |
| 241 |
if { $verbose > 1 } { |
| 242 |
send_user "Nope, does not match.\n\n" |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
if [string match $pass "yes"] { |
| 247 |
pass $pass_message |
| 248 |
} else { |
| 249 |
fail $fail_message |
| 250 |
} |
| 251 |
|
| 252 |
# The framework doesn't like to see any error remnants, |
| 253 |
# so remove them. |
| 254 |
uplevel { |
| 255 |
if [info exists errorInfo] { |
| 256 |
unset errorInfo |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
mike_cleanup $src_code $output_file $assembly_file |
| 261 |
} |