| 1 |
# Copyright (C) 2008-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 |
# Prepare to use a new set of torture options. |
| 18 |
# |
| 19 |
# Letting options leak from one set of tests to another can be confusing. |
| 20 |
# Make sure variables are not set at the time we're called, because that |
| 21 |
# would mean they were set without being cleared. |
| 22 |
proc torture-init { args } { |
| 23 |
global torture_without_loops global_with_loops |
| 24 |
|
| 25 |
if [info exists torture_without_loops] { |
| 26 |
error "torture-init: torture_without_loops is not empty as expected = \"${torture_without_loops}\"" |
| 27 |
} |
| 28 |
if [info exists torture_with_loops] { |
| 29 |
error "torture-init: torture_with_loops is not empty as expected = \"${torture_with_loops}\"" |
| 30 |
} |
| 31 |
|
| 32 |
global LTO_TORTURE_OPTIONS |
| 33 |
if [info exists LTO_TORTURE_OPTIONS] { |
| 34 |
error "torture-init: LTO_TORTURE_OPTIONS is not empty as expected = \"${LTO_TORTURE_OPTIONS}\"" |
| 35 |
} |
| 36 |
set LTO_TORTURE_OPTIONS "" |
| 37 |
if [check_effective_target_lto] { |
| 38 |
# When having plugin test both slim and fat LTO and plugin/nonplugin |
| 39 |
# path. |
| 40 |
if [check_linker_plugin_available] { |
| 41 |
set LTO_TORTURE_OPTIONS [list \ |
| 42 |
{ -O2 -flto -fno-use-linker-plugin -flto-partition=none } \ |
| 43 |
{ -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects } |
| 44 |
] |
| 45 |
} else { |
| 46 |
set LTO_TORTURE_OPTIONS [list \ |
| 47 |
{ -O2 -flto -flto-partition=none } \ |
| 48 |
{ -O2 -flto } |
| 49 |
] |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
# Return 1 if 'torture-init' has already been done, 0 otherwise. |
| 55 |
proc torture-init-done { args } { |
| 56 |
global LTO_TORTURE_OPTIONS |
| 57 |
return [info exists LTO_TORTURE_OPTIONS] |
| 58 |
} |
| 59 |
|
| 60 |
# Return 1 if torture options have already been set, 0 otherwise. |
| 61 |
proc torture-options-exist { args } { |
| 62 |
global torture_with_loops |
| 63 |
return [info exists torture_with_loops] |
| 64 |
} |
| 65 |
|
| 66 |
# Return 1 if compiler option ARG only affects loops, 0 otherwise. |
| 67 |
proc contains-loop-option-p { arg } { |
| 68 |
switch -glob -- $arg { |
| 69 |
"*loop*" { return 1 } |
| 70 |
default { return 0 } |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
# Set torture options variables for tests with and without loops. |
| 75 |
# |
| 76 |
# Argument 0 is the list to use as torture options |
| 77 |
# Argument 1 is the list to combine with the torture options. |
| 78 |
# Argument 2 is the list to be appended to the torture options after |
| 79 |
# combining argument 0 and 1. |
| 80 |
proc set-torture-options { args } { |
| 81 |
global torture_with_loops torture_without_loops |
| 82 |
|
| 83 |
set torture_list [lindex $args 0] |
| 84 |
|
| 85 |
if { [llength $args] > 1 } { |
| 86 |
set other_list [lindex $args 1] |
| 87 |
} else { |
| 88 |
set other_list [list {}] |
| 89 |
} |
| 90 |
|
| 91 |
set torture_with_loops "" |
| 92 |
set torture_without_loops "" |
| 93 |
foreach torture_opts $torture_list { |
| 94 |
foreach other_opts $other_list { |
| 95 |
# Remove trailing space[s] to match previous output. |
| 96 |
set torture_opts [string trimright $torture_opts] |
| 97 |
if ![contains-loop-option-p $torture_opts] { |
| 98 |
lappend torture_without_loops "$torture_opts $other_opts" |
| 99 |
} |
| 100 |
lappend torture_with_loops "$torture_opts $other_opts" |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
if { [llength $args] > 2 } { |
| 105 |
set append_list [lindex $args 2] |
| 106 |
append torture_with_loops " $append_list" |
| 107 |
append torture_without_loops " $append_list" |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
# Finish up after using a set of torture options. |
| 112 |
# |
| 113 |
# Letting options leak from one set of tests to another can be confusing. |
| 114 |
# Make sure variables are set at the time we're called, and then unset |
| 115 |
# them to prevent interference with other sets of tests. |
| 116 |
proc torture-finish { args } { |
| 117 |
global torture_without_loops torture_with_loops |
| 118 |
|
| 119 |
if [info exists torture_without_loops] { |
| 120 |
unset torture_without_loops |
| 121 |
} else { |
| 122 |
error "torture-finish: torture_without_loops is not defined" |
| 123 |
} |
| 124 |
|
| 125 |
if [info exists torture_with_loops] { |
| 126 |
unset torture_with_loops |
| 127 |
} else { |
| 128 |
error "torture-finish: torture_with_loops is not defined" |
| 129 |
} |
| 130 |
|
| 131 |
global LTO_TORTURE_OPTIONS |
| 132 |
if [info exists LTO_TORTURE_OPTIONS] { |
| 133 |
unset LTO_TORTURE_OPTIONS |
| 134 |
} else { |
| 135 |
error "torture-finish: LTO_TORTURE_OPTIONS is not defined" |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
# Useful for debugging .exp files. |
| 140 |
proc dump-torture-options { args } { |
| 141 |
global torture_without_loops torture_with_loops |
| 142 |
|
| 143 |
if [info exists torture_without_loops] { |
| 144 |
verbose "torture_without_loops = \"${torture_without_loops}\"" 1 |
| 145 |
} else { |
| 146 |
verbose "torture_without_loops is not defined" 1 |
| 147 |
} |
| 148 |
|
| 149 |
if [info exists torture_with_loops] { |
| 150 |
verbose "torture_with_loops = \"${torture_with_loops}\"" 1 |
| 151 |
} else { |
| 152 |
verbose "torture_with_loops is not defined" 1 |
| 153 |
} |
| 154 |
} |