# Copyright (C) 1992-1998, 1999, 2000, 2007 Free Software Foundation, Inc.
|
# Copyright (C) 1992-1998, 1999, 2000, 2007 Free Software Foundation, Inc.
|
|
|
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
# the Free Software Foundation; either version 3 of the License, or
|
# the Free Software Foundation; either version 3 of the License, or
|
# (at your option) any later version.
|
# (at your option) any later version.
|
#
|
#
|
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
#
|
#
|
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
# along with GCC; see the file COPYING3. If not see
|
# along with GCC; see the file COPYING3. If not see
|
# .
|
# .
|
|
|
# This file was written by Rob Savoye. (rob@cygnus.com)
|
# This file was written by Rob Savoye. (rob@cygnus.com)
|
|
|
load_lib file-format.exp
|
load_lib file-format.exp
|
|
|
# The default option list can be overridden by
|
# The default option list can be overridden by
|
# TORTURE_OPTIONS="{ { list1 } ... { listN } }"
|
# TORTURE_OPTIONS="{ { list1 } ... { listN } }"
|
|
|
if ![info exists OBJC_RUNTIME_OPTIONS] {
|
if ![info exists OBJC_RUNTIME_OPTIONS] {
|
set OBJC_RUNTIME_OPTIONS ""
|
set OBJC_RUNTIME_OPTIONS ""
|
foreach type {-fgnu-runtime -fnext-runtime} {
|
foreach type {-fgnu-runtime -fnext-runtime} {
|
global srcdir subdir
|
global srcdir subdir
|
|
|
set comp_output [objc_target_compile \
|
set comp_output [objc_target_compile \
|
"$srcdir/$subdir/trivial.m" "trivial.exe" executable "additional_flags=$type"]
|
"$srcdir/$subdir/trivial.m" "trivial.exe" executable "additional_flags=$type"]
|
|
|
# If we get any error, then we failed
|
# If we get any error, then we failed
|
if ![string match "" $comp_output] then {
|
if ![string match "" $comp_output] then {
|
continue;
|
continue;
|
}
|
}
|
lappend OBJC_RUNTIME_OPTIONS $type
|
lappend OBJC_RUNTIME_OPTIONS $type
|
}
|
}
|
}
|
}
|
verbose -log "Using the following runtimes: $OBJC_RUNTIME_OPTIONS"
|
verbose -log "Using the following runtimes: $OBJC_RUNTIME_OPTIONS"
|
|
|
|
|
if ![info exists TORTURE_OPTIONS] {
|
if ![info exists TORTURE_OPTIONS] {
|
# It is theoretically beneficial to group all of the O2/O3 options together,
|
# It is theoretically beneficial to group all of the O2/O3 options together,
|
# as in many cases the compiler will generate identical executables for
|
# as in many cases the compiler will generate identical executables for
|
# all of them--and the objc-torture testsuite will skip testing identical
|
# all of them--and the objc-torture testsuite will skip testing identical
|
# executables multiple times.
|
# executables multiple times.
|
# Also note that -finline-functions is explicitly included in one of the
|
# Also note that -finline-functions is explicitly included in one of the
|
# items below, even though -O3 is also specified, because some ports may
|
# items below, even though -O3 is also specified, because some ports may
|
# choose to disable inlining functions by default, even when optimizing.
|
# choose to disable inlining functions by default, even when optimizing.
|
set TORTURE_OPTIONS [list \
|
set TORTURE_OPTIONS [list \
|
" -O0 " \
|
" -O0 " \
|
" -O1 " \
|
" -O1 " \
|
" -O2 " \
|
" -O2 " \
|
" -O3 -fomit-frame-pointer " \
|
" -O3 -fomit-frame-pointer " \
|
" -O3 -fomit-frame-pointer -funroll-loops " \
|
" -O3 -fomit-frame-pointer -funroll-loops " \
|
" -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions " \
|
" -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions " \
|
" -O3 -g " \
|
" -O3 -g " \
|
" -Os " ]
|
" -Os " ]
|
}
|
}
|
|
|
|
|
# Split TORTURE_OPTIONS into two choices: one for testcases with loops and
|
# Split TORTURE_OPTIONS into two choices: one for testcases with loops and
|
# one for testcases without loops. Add in the objc runtime options also.
|
# one for testcases without loops. Add in the objc runtime options also.
|
|
|
set torture_with_loops ""
|
set torture_with_loops ""
|
set torture_without_loops ""
|
set torture_without_loops ""
|
foreach objc_option $OBJC_RUNTIME_OPTIONS {
|
foreach objc_option $OBJC_RUNTIME_OPTIONS {
|
foreach option $TORTURE_OPTIONS {
|
foreach option $TORTURE_OPTIONS {
|
|
|
if ![string match "*loop*" $option] {
|
if ![string match "*loop*" $option] {
|
lappend torture_without_loops "$option $objc_option"
|
lappend torture_without_loops "$option $objc_option"
|
}
|
}
|
lappend torture_with_loops "$option $objc_option"
|
lappend torture_with_loops "$option $objc_option"
|
}
|
}
|
}
|
}
|
|
|
|
|
#
|
#
|
# objc-torture-compile -- runs the Tege OBJC-torture test
|
# objc-torture-compile -- runs the Tege OBJC-torture test
|
#
|
#
|
# SRC is the full pathname of the testcase.
|
# SRC is the full pathname of the testcase.
|
# OPTION is the specific compiler flag we're testing (eg: -O2).
|
# OPTION is the specific compiler flag we're testing (eg: -O2).
|
#
|
#
|
proc objc-torture-compile { src option } {
|
proc objc-torture-compile { src option } {
|
global output
|
global output
|
global srcdir tmpdir
|
global srcdir tmpdir
|
global host_triplet
|
global host_triplet
|
|
|
set output "$tmpdir/[file tail [file rootname $src]].o"
|
set output "$tmpdir/[file tail [file rootname $src]].o"
|
|
|
regsub "(?q)$srcdir/" $src "" testcase
|
regsub "(?q)$srcdir/" $src "" testcase
|
# If we couldn't rip $srcdir out of `src' then just do the best we can.
|
# If we couldn't rip $srcdir out of `src' then just do the best we can.
|
# The point is to reduce the unnecessary noise in the logs. Don't strip
|
# The point is to reduce the unnecessary noise in the logs. Don't strip
|
# out too much because different testcases with the same name can confuse
|
# out too much because different testcases with the same name can confuse
|
# `test-tool'.
|
# `test-tool'.
|
if [string match "/*" $testcase] {
|
if [string match "/*" $testcase] {
|
set testcase "[file tail [file dirname $src]]/[file tail $src]"
|
set testcase "[file tail [file dirname $src]]/[file tail $src]"
|
}
|
}
|
|
|
verbose "Testing $testcase, $option" 1
|
verbose "Testing $testcase, $option" 1
|
|
|
# Run the compiler and analyze the results.
|
# Run the compiler and analyze the results.
|
set options ""
|
set options ""
|
lappend options "additional_flags=-w $option"
|
lappend options "additional_flags=-w $option"
|
|
|
set comp_output [objc_target_compile "$src" "$output" object $options]
|
set comp_output [objc_target_compile "$src" "$output" object $options]
|
objc_check_compile $testcase $option $output $comp_output
|
objc_check_compile $testcase $option $output $comp_output
|
remote_file build delete $output
|
remote_file build delete $output
|
}
|
}
|
|
|
#
|
#
|
# objc-torture-execute -- utility to compile and execute a testcase
|
# objc-torture-execute -- utility to compile and execute a testcase
|
#
|
#
|
# SRC is the full pathname of the testcase.
|
# SRC is the full pathname of the testcase.
|
#
|
#
|
# If the testcase has an associated .x file, we source that to run the
|
# If the testcase has an associated .x file, we source that to run the
|
# test instead. We use .x so that we don't lengthen the existing filename
|
# test instead. We use .x so that we don't lengthen the existing filename
|
# to more than 14 chars.
|
# to more than 14 chars.
|
#
|
#
|
proc objc-torture-execute { src args } {
|
proc objc-torture-execute { src args } {
|
global tmpdir tool srcdir output compiler_conditional_xfail_data
|
global tmpdir tool srcdir output compiler_conditional_xfail_data
|
|
|
if { [llength $args] > 0 } {
|
if { [llength $args] > 0 } {
|
set additional_flags [lindex $args 0]
|
set additional_flags [lindex $args 0]
|
} else {
|
} else {
|
set additional_flags ""
|
set additional_flags ""
|
}
|
}
|
# Check for alternate driver.
|
# Check for alternate driver.
|
if [file exists [file rootname $src].x] {
|
if [file exists [file rootname $src].x] {
|
verbose "Using alternate driver [file rootname [file tail $src]].x" 2
|
verbose "Using alternate driver [file rootname [file tail $src]].x" 2
|
set done_p 0
|
set done_p 0
|
catch "set done_p \[source [file rootname $src].x\]"
|
catch "set done_p \[source [file rootname $src].x\]"
|
if { $done_p } {
|
if { $done_p } {
|
return
|
return
|
}
|
}
|
}
|
}
|
|
|
# Look for a loop within the source code - if we don't find one,
|
# Look for a loop within the source code - if we don't find one,
|
# don't pass -funroll[-all]-loops.
|
# don't pass -funroll[-all]-loops.
|
global torture_with_loops torture_without_loops
|
global torture_with_loops torture_without_loops
|
if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
|
if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
|
set option_list $torture_with_loops
|
set option_list $torture_with_loops
|
} else {
|
} else {
|
set option_list $torture_without_loops
|
set option_list $torture_without_loops
|
}
|
}
|
|
|
set executable $tmpdir/[file tail [file rootname $src].x]
|
set executable $tmpdir/[file tail [file rootname $src].x]
|
|
|
regsub "(?q)$srcdir/" $src "" testcase
|
regsub "(?q)$srcdir/" $src "" testcase
|
# If we couldn't rip $srcdir out of `src' then just do the best we can.
|
# If we couldn't rip $srcdir out of `src' then just do the best we can.
|
# The point is to reduce the unnecessary noise in the logs. Don't strip
|
# The point is to reduce the unnecessary noise in the logs. Don't strip
|
# out too much because different testcases with the same name can confuse
|
# out too much because different testcases with the same name can confuse
|
# `test-tool'.
|
# `test-tool'.
|
if [string match "/*" $testcase] {
|
if [string match "/*" $testcase] {
|
set testcase "[file tail [file dirname $src]]/[file tail $src]"
|
set testcase "[file tail [file dirname $src]]/[file tail $src]"
|
}
|
}
|
|
|
set count 0
|
set count 0
|
set oldstatus "foo"
|
set oldstatus "foo"
|
foreach option $option_list {
|
foreach option $option_list {
|
if { $count > 0 } {
|
if { $count > 0 } {
|
set oldexec $execname
|
set oldexec $execname
|
}
|
}
|
set execname "${executable}${count}"
|
set execname "${executable}${count}"
|
incr count
|
incr count
|
|
|
# torture_{compile,execute}_xfail are set by the .x script
|
# torture_{compile,execute}_xfail are set by the .x script
|
# (if present)
|
# (if present)
|
if [info exists torture_compile_xfail] {
|
if [info exists torture_compile_xfail] {
|
setup_xfail $torture_compile_xfail
|
setup_xfail $torture_compile_xfail
|
}
|
}
|
|
|
# torture_execute_before_{compile,execute} can be set by the .x script
|
# torture_execute_before_{compile,execute} can be set by the .x script
|
# (if present)
|
# (if present)
|
if [info exists torture_eval_before_compile] {
|
if [info exists torture_eval_before_compile] {
|
set ignore_me [eval $torture_eval_before_compile]
|
set ignore_me [eval $torture_eval_before_compile]
|
}
|
}
|
|
|
remote_file build delete $execname
|
remote_file build delete $execname
|
verbose "Testing $testcase, $option" 1
|
verbose "Testing $testcase, $option" 1
|
|
|
set options ""
|
set options ""
|
lappend options "additional_flags=-w $option"
|
lappend options "additional_flags=-w $option"
|
if { $additional_flags != "" } {
|
if { $additional_flags != "" } {
|
lappend options "additional_flags=$additional_flags"
|
lappend options "additional_flags=$additional_flags"
|
}
|
}
|
set comp_output [objc_target_compile "$src" "${execname}" executable $options]
|
set comp_output [objc_target_compile "$src" "${execname}" executable $options]
|
|
|
if ![objc_check_compile "$testcase compilation" $option $execname $comp_output] {
|
if ![objc_check_compile "$testcase compilation" $option $execname $comp_output] {
|
unresolved "$testcase execution, $option"
|
unresolved "$testcase execution, $option"
|
remote_file build delete $execname
|
remote_file build delete $execname
|
continue
|
continue
|
}
|
}
|
|
|
# See if this source file uses "long long" types, if it does, and
|
# See if this source file uses "long long" types, if it does, and
|
# no_long_long is set, skip execution of the test.
|
# no_long_long is set, skip execution of the test.
|
if [target_info exists no_long_long] then {
|
if [target_info exists no_long_long] then {
|
if [expr [search_for $src "long long"]] then {
|
if [expr [search_for $src "long long"]] then {
|
unsupported "$testcase execution, $option"
|
unsupported "$testcase execution, $option"
|
continue
|
continue
|
}
|
}
|
}
|
}
|
|
|
if [info exists torture_execute_xfail] {
|
if [info exists torture_execute_xfail] {
|
setup_xfail $torture_execute_xfail
|
setup_xfail $torture_execute_xfail
|
}
|
}
|
|
|
if [info exists torture_eval_before_execute] {
|
if [info exists torture_eval_before_execute] {
|
set ignore_me [eval $torture_eval_before_execute]
|
set ignore_me [eval $torture_eval_before_execute]
|
}
|
}
|
|
|
|
|
# Sometimes we end up creating identical executables for two
|
# Sometimes we end up creating identical executables for two
|
# consecutive sets of different of compiler options.
|
# consecutive sets of different of compiler options.
|
#
|
#
|
# In such cases we know the result of this test will be identical
|
# In such cases we know the result of this test will be identical
|
# to the result of the last test.
|
# to the result of the last test.
|
#
|
#
|
# So in cases where the time to load and run/simulate the test
|
# So in cases where the time to load and run/simulate the test
|
# is relatively high, compare the two binaries and avoid rerunning
|
# is relatively high, compare the two binaries and avoid rerunning
|
# tests if the executables are identical.
|
# tests if the executables are identical.
|
#
|
#
|
# Do not do this for native testing since the cost to load/execute
|
# Do not do this for native testing since the cost to load/execute
|
# the test is fairly small and the comparison step actually slows
|
# the test is fairly small and the comparison step actually slows
|
# the entire process down because it usually does not "hit".
|
# the entire process down because it usually does not "hit".
|
set skip 0
|
set skip 0
|
if { ![isnative] && [info exists oldexec] } {
|
if { ![isnative] && [info exists oldexec] } {
|
if { [remote_file build cmp $oldexec $execname] == 0 } {
|
if { [remote_file build cmp $oldexec $execname] == 0 } {
|
set skip 1
|
set skip 1
|
}
|
}
|
}
|
}
|
if { $skip == 0 } {
|
if { $skip == 0 } {
|
set result [objc_load "$execname" "" ""]
|
set result [objc_load "$execname" "" ""]
|
set status [lindex $result 0]
|
set status [lindex $result 0]
|
set output [lindex $result 1]
|
set output [lindex $result 1]
|
}
|
}
|
if { $oldstatus == "pass" } {
|
if { $oldstatus == "pass" } {
|
remote_file build delete $oldexec
|
remote_file build delete $oldexec
|
}
|
}
|
$status "$testcase execution, $option"
|
$status "$testcase execution, $option"
|
set oldstatus $status
|
set oldstatus $status
|
}
|
}
|
if [info exists status] {
|
if [info exists status] {
|
if { $status == "pass" } {
|
if { $status == "pass" } {
|
remote_file build delete $execname
|
remote_file build delete $execname
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
#
|
#
|
# search_for -- looks for a string match in a file
|
# search_for -- looks for a string match in a file
|
#
|
#
|
proc search_for { file pattern } {
|
proc search_for { file pattern } {
|
set fd [open $file r]
|
set fd [open $file r]
|
while { [gets $fd cur_line]>=0 } {
|
while { [gets $fd cur_line]>=0 } {
|
if [string match "*$pattern*" $cur_line] then {
|
if [string match "*$pattern*" $cur_line] then {
|
close $fd
|
close $fd
|
return 1
|
return 1
|
}
|
}
|
}
|
}
|
close $fd
|
close $fd
|
return 0
|
return 0
|
}
|
}
|
|
|
#
|
#
|
# objc-torture -- the objc-torture testcase source file processor
|
# objc-torture -- the objc-torture testcase source file processor
|
#
|
#
|
# This runs compilation only tests (no execute tests).
|
# This runs compilation only tests (no execute tests).
|
# SRC is the full pathname of the testcase, or just a file name in which case
|
# SRC is the full pathname of the testcase, or just a file name in which case
|
# we prepend $srcdir/$subdir.
|
# we prepend $srcdir/$subdir.
|
#
|
#
|
# If the testcase has an associated .x file, we source that to run the
|
# If the testcase has an associated .x file, we source that to run the
|
# test instead. We use .x so that we don't lengthen the existing filename
|
# test instead. We use .x so that we don't lengthen the existing filename
|
# to more than 14 chars.
|
# to more than 14 chars.
|
#
|
#
|
proc objc-torture { args } {
|
proc objc-torture { args } {
|
global srcdir subdir compiler_conditional_xfail_data
|
global srcdir subdir compiler_conditional_xfail_data
|
|
|
set src [lindex $args 0]
|
set src [lindex $args 0]
|
if { [llength $args] > 1 } {
|
if { [llength $args] > 1 } {
|
set options [lindex $args 1]
|
set options [lindex $args 1]
|
} else {
|
} else {
|
set options ""
|
set options ""
|
}
|
}
|
|
|
# Prepend $srdir/$subdir if missing.
|
# Prepend $srdir/$subdir if missing.
|
if ![string match "*/*" $src] {
|
if ![string match "*/*" $src] {
|
set src "$srcdir/$subdir/$src"
|
set src "$srcdir/$subdir/$src"
|
}
|
}
|
|
|
# Check for alternate driver.
|
# Check for alternate driver.
|
if [file exists [file rootname $src].x] {
|
if [file exists [file rootname $src].x] {
|
verbose "Using alternate driver [file rootname [file tail $src]].x" 2
|
verbose "Using alternate driver [file rootname [file tail $src]].x" 2
|
set done_p 0
|
set done_p 0
|
catch "set done_p \[source [file rootname $src].x\]"
|
catch "set done_p \[source [file rootname $src].x\]"
|
if { $done_p } {
|
if { $done_p } {
|
return
|
return
|
}
|
}
|
}
|
}
|
|
|
# Look for a loop within the source code - if we don't find one,
|
# Look for a loop within the source code - if we don't find one,
|
# don't pass -funroll[-all]-loops.
|
# don't pass -funroll[-all]-loops.
|
global torture_with_loops torture_without_loops
|
global torture_with_loops torture_without_loops
|
if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
|
if [expr [search_for $src "for*("]+[search_for $src "while*("]] then {
|
set option_list $torture_with_loops
|
set option_list $torture_with_loops
|
} else {
|
} else {
|
set option_list $torture_without_loops
|
set option_list $torture_without_loops
|
}
|
}
|
|
|
# loop through all the options
|
# loop through all the options
|
foreach option $option_list {
|
foreach option $option_list {
|
# torture_compile_xfail is set by the .x script (if present)
|
# torture_compile_xfail is set by the .x script (if present)
|
if [info exists torture_compile_xfail] {
|
if [info exists torture_compile_xfail] {
|
setup_xfail $torture_compile_xfail
|
setup_xfail $torture_compile_xfail
|
}
|
}
|
|
|
# torture_execute_before_compile is set by the .x script (if present)
|
# torture_execute_before_compile is set by the .x script (if present)
|
if [info exists torture_eval_before_compile] {
|
if [info exists torture_eval_before_compile] {
|
set ignore_me [eval $torture_eval_before_compile]
|
set ignore_me [eval $torture_eval_before_compile]
|
}
|
}
|
|
|
objc-torture-compile $src "$option $options"
|
objc-torture-compile $src "$option $options"
|
}
|
}
|
}
|
}
|
|
|