| 1 |
# Copyright (C) 2003-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 written by Gaius Mulley ([email protected]) |
| 18 |
# for GNU Modula-2 |
| 19 |
|
| 20 |
load_lib file-format.exp |
| 21 |
load_lib gm2.exp |
| 22 |
|
| 23 |
set gm2_keep_executable 0 |
| 24 |
|
| 25 |
# |
| 26 |
# gm2-simple-compile -- runs the compiler |
| 27 |
# |
| 28 |
# SRC is the full pathname of the testcase. |
| 29 |
# OPTION is the specific compiler flag we're testing (eg: -O2). |
| 30 |
# |
| 31 |
proc gm2-simple-compile { src option } { |
| 32 |
global output |
| 33 |
global srcdir tmpdir |
| 34 |
global host_triplet |
| 35 |
|
| 36 |
set output "$tmpdir/[file tail [file rootname $src]].o" |
| 37 |
|
| 38 |
regsub "^$srcdir/?" $src "" testcase |
| 39 |
# If we couldn't rip $srcdir out of `src' then just do the best we can. |
| 40 |
# The point is to reduce the unnecessary noise in the logs. Don't strip |
| 41 |
# out too much because different testcases with the same name can confuse |
| 42 |
# `test-tool'. |
| 43 |
if [string match "/*" $testcase] { |
| 44 |
set testcase "[file tail [file dirname $src]]/[file tail $src]" |
| 45 |
} |
| 46 |
|
| 47 |
verbose "Testing $testcase, $option" 1 |
| 48 |
|
| 49 |
# Run the compiler and analyze the results. |
| 50 |
set options "" |
| 51 |
lappend options "additional_flags=$option" |
| 52 |
|
| 53 |
set comp_output [gm2_target_compile "$src" "$output" object $options]; |
| 54 |
gm2_check_compile $testcase $option $output $comp_output |
| 55 |
remote_file build delete $output |
| 56 |
verbose "$comp_output" 1 |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
# |
| 61 |
# gm2-simple-execute -- utility to compile and execute a testcase |
| 62 |
# |
| 63 |
# SOURCES is a list of full pathnames to the test source files. |
| 64 |
# The first filename in this list forms the "testcase". |
| 65 |
# |
| 66 |
# If the testcase has an associated .x file, we source that to run the |
| 67 |
# test instead. We use .x so that we don't lengthen the existing filename |
| 68 |
# to more than 14 chars. |
| 69 |
# |
| 70 |
proc gm2-simple-execute { sources args option } { |
| 71 |
global tmpdir tool srcdir output compiler_conditional_xfail_data; |
| 72 |
global gm2_link_libraries; |
| 73 |
global gm2_link_path; |
| 74 |
global gm2_link_objects; |
| 75 |
global gm2_keep_executable; |
| 76 |
|
| 77 |
# Use the first source filename given as the filename under test. |
| 78 |
set src [lindex $sources 0]; |
| 79 |
|
| 80 |
if { [llength $args] > 0 } { |
| 81 |
set additional_flags [lindex $args 0]; |
| 82 |
} else { |
| 83 |
set additional_flags ""; |
| 84 |
} |
| 85 |
# Check for alternate driver. |
| 86 |
if [file exists [file rootname $src].x] { |
| 87 |
verbose "Using alternate driver [file rootname [file tail $src]].x" 2 |
| 88 |
set done_p 0; |
| 89 |
catch "set done_p \[source [file rootname $src].x\]" |
| 90 |
if { $done_p } { |
| 91 |
return |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
set executable $tmpdir/[file tail [file rootname $src].x]; |
| 96 |
set objectfile $tmpdir/[file tail [file rootname $src].o]; |
| 97 |
|
| 98 |
regsub "^$srcdir/?" $src "" testcase |
| 99 |
# If we couldn't rip $srcdir out of `src' then just do the best we can. |
| 100 |
# The point is to reduce the unnecessary noise in the logs. Don't strip |
| 101 |
# out too much because different testcases with the same name can confuse |
| 102 |
# `test-tool'. |
| 103 |
if [string match "/*" $testcase] { |
| 104 |
set testcase "[file tail [file dirname $src]]/[file tail $src]" |
| 105 |
} |
| 106 |
|
| 107 |
set execname "${executable}"; |
| 108 |
|
| 109 |
remote_file build delete $execname; |
| 110 |
verbose "Testing $testcase, $option" 1 |
| 111 |
|
| 112 |
# start by setting options with option |
| 113 |
set options [concat "{additional_flags=$gm2_link_objects} " $option] |
| 114 |
# now append path -fno-libs=- and objects |
| 115 |
set options [concat "{additional_flags=$gm2_link_path} " $options] |
| 116 |
set options [concat "{additional_flags=-fno-libs=-} " $options] |
| 117 |
|
| 118 |
set comp_output [gm2_target_compile "${sources}" "${execname}" executable ${options}]; |
| 119 |
|
| 120 |
if ![gm2_check_compile "${testcase} compilation" ${option} ${execname} $comp_output] { |
| 121 |
unresolved "${testcase} execution, ${option}" |
| 122 |
remote_file build delete $objectfile |
| 123 |
return 0 |
| 124 |
} |
| 125 |
|
| 126 |
set result [gm2_load "$execname" "" ""] |
| 127 |
|
| 128 |
set status [lindex $result 0]; |
| 129 |
set output [lindex $result 1]; |
| 130 |
if { $status == "fail" } { |
| 131 |
${tool}_fail $testcase $option |
| 132 |
send_log "executed $execname with result $status" |
| 133 |
} |
| 134 |
if { $status == "pass" } { |
| 135 |
${tool}_pass $testcase $option |
| 136 |
# puts stderr $execname |
| 137 |
if { ! $gm2_keep_executable } { |
| 138 |
remote_file build delete $execname; |
| 139 |
} |
| 140 |
} |
| 141 |
return 1 |
| 142 |
} |