OSDN Git Service

* lib/compat.exp (compat-execute): Fix processing of file names.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / compat.exp
index 1965f3d..6e15f91 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2002 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
 # 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
@@ -12,7 +12,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
 # This file was written by Janis Johnson, <janis187@us.ibm.com>
 
@@ -49,18 +49,53 @@ if ![info exists COMPAT_OPTIONS] {
 
 set option_list $COMPAT_OPTIONS
 
+# Subsets of tests can be selectively disabled by members of this list:
+#  - ATTRIBUTE: disable all tests using the __attribute__ extension,
+#  - COMPLEX_INT: disable all tests using the complex integral types extension,
+#  - VA: disable all tests using the variable number of arguments feature,
+#  - ZERO_ARRAY: disable all tests using the zero-sized arrays extension.
+# The default skip lists can be overriden by
+# COMPAT_SKIPS="[list {skip_1}...{skip_n}]"
+# where skip_i are skip identifiers.  You can put this in the environment
+# before site.exp is written or add it to site.exp directly.
+if ![info exists COMPAT_SKIPS] {
+    set COMPAT_SKIPS [list {}]
+}
+
+global compat_skip_list
+set compat_skip_list $COMPAT_SKIPS
+
+load_lib dg.exp
+load_lib gcc-dg.exp
+
 #
 # compat-obj -- compile to an object file
 #
 # SOURCE is the source file
 # DEST is the object file
-# OPTIONS is the list of compiler options
+# OPTALL is the list of compiler options to use with all tests
+# OPTFILE is the list of compiler options to use with this file
 # OPTSTR is the options to print with test messages
+# XFAILDATA is the xfail data to be passed to the compiler
 #
-proc compat-obj { source dest options optstr } {
+proc compat-obj { source dest optall optfile optstr xfaildata } {
     global testcase
     global tool
+    global compiler_conditional_xfail_data
+    global compat_skip_list
+
+    # Add the skip specifiers.
+    foreach skip $compat_skip_list {
+       if { ![string match $skip ""] } {
+           lappend optall "-DSKIP_$skip"
+       }
+    }
+
+    # Set up the options for compiling this file.
+    set options ""
+    lappend options "additional_flags=$optfile $optall"
 
+    set compiler_conditional_xfail_data $xfaildata
     set comp_output [${tool}_target_compile "$source" "$dest" object $options]
     ${tool}_check_compile "$testcase $dest compile" $optstr $dest $comp_output
 }
@@ -70,10 +105,11 @@ proc compat-obj { source dest options optstr } {
 # TESTNAME is the mixture of object files to link
 # OBJLIST is the list of object files to link
 # DEST is the name of the executable
-# OPTIONS is a list of compiler and linker options to use
+# OPTALL is a list of compiler and linker options to use for all tests
+# OPTFILE is a list of compiler and linker options to use for this test
 # OPTSTR is the list of options to list in messages
 #
-proc compat-run { testname objlist dest options optstr } {
+proc compat-run { testname objlist dest optall optfile optstr } {
     global testcase
     global tool
 
@@ -86,6 +122,10 @@ proc compat-run { testname objlist dest options optstr } {
        }
     }
 
+    # Set up the options for linking this test.
+    set options ""
+    lappend options "additional_flags=$optfile $optall"
+
     # Link the objects into an executable.
     set comp_output [${tool}_target_compile "$objlist" $dest executable \
                     "$options"]
@@ -96,6 +136,9 @@ proc compat-run { testname objlist dest options optstr } {
     }
 
     # Run the self-checking executable.
+    if ![string match "*/*" $dest] then {
+       set dest "./$dest"
+    }
     set result [${tool}_load $dest "" ""]
     set status [lindex $result 0]
     if { $status == "pass" } then {
@@ -105,49 +148,153 @@ proc compat-run { testname objlist dest options optstr } {
 }
 
 #
+# compat-get-options-main -- get target requirements for a test and
+# options for the primary source file and the test as a whole
+#
+# SRC is the full pathname of the primary source file.
+#
+proc compat-get-options-main { src } {
+    # dg-options sets a variable called dg-extra-tool-flags.
+    set dg-extra-tool-flags ""
+
+    # dg-require-* sets dg-do-what.
+    upvar dg-do-what dg-do-what 
+
+    set tmp [dg-get-options $src]
+    foreach op $tmp {
+       set cmd [lindex $op 0]
+       if { ![string compare "dg-options" $cmd] \
+            || [string match "dg-require-*" $cmd]  } {
+           set status [catch "$op" errmsg]
+           if { $status != 0 } {
+               perror "src: $errmsg for \"$op\"\n"
+               unresolved "$src: $errmsg for \"$op\""
+               return
+           }
+       } elseif { ![string compare "dg-xfail-if" $cmd] } {
+           warning "compat.exp does not support $cmd in primary source file"
+       } else {
+           # Ignore unrecognized dg- commands, but warn about them.
+           warning "compat.exp does not support $cmd"
+       }
+    }
+
+    # Return flags to use for compiling the primary source file and for
+    # linking.
+    return ${dg-extra-tool-flags}
+}
+
+#
+# compat-get-options -- get special tool flags to use for a secondary
+# source file
+#
+# SRC is the full pathname of the source file.
+# The result is a list of options to use.
+#
+# This code is copied from proc dg-test in dg.exp from DejaGNU.
+#
+proc compat-get-options { src } {
+    # dg-options sets a variable called dg-extra-tool-flags.
+    set dg-extra-tool-flags ""
+
+    # dg-xfail-if sets compiler_conditional_xfail_data.
+    global compiler_conditional_xfail_data
+    set compiler_conditional_xfail_data ""
+
+    # dg-xfail-if needs access to dg-do-what.
+    upvar dg-do-what dg-do-what 
+
+    set tmp [dg-get-options $src]
+    foreach op $tmp {
+       set cmd [lindex $op 0]
+       if { ![string compare "dg-options" $cmd] \
+            || ![string compare "dg-xfail-if" $cmd] } {
+           set status [catch "$op" errmsg]
+           if { $status != 0 } {
+               perror "src: $errmsg for \"$op\"\n"
+               unresolved "$src: $errmsg for \"$op\""
+               return
+           }
+       } elseif { [string match "dg-require-*" $cmd] } {
+           warning "compat.exp does not support $cmd in secondary source files"
+       } else {
+           # Ignore unrecognized dg- commands, but warn about them.
+           warning "compat.exp does not support $cmd"
+       }
+    }
+
+    return ${dg-extra-tool-flags}
+}
+
+#
 # compat-execute -- compile with compatible compilers
 #
 # SRC1 is the full pathname of the main file of the testcase.
+# SID identifies a test suite in the names of temporary files.
 # USE_ALT is nonzero if we're using an alternate compiler as well as
 #   the compiler under test.
 #
-proc compat-execute { src1 use_alt } {
+proc compat-execute { src1 sid use_alt } {
     global srcdir tmpdir
     global option_list
     global tool
     global verbose
     global testcase
+    global gluefile
+    global compiler_conditional_xfail_data
+    global dg-do-what-default
+
+    # Get extra flags for this test from the primary source file, and
+    # process other dg-* options that this suite supports.  Warn about
+    # unsupported flags.
+    verbose "compat-execute: $src1" 1
+    set dg-do-what [list ${dg-do-what-default} "" P]
+    set extra_flags_1 [compat-get-options-main $src1]
 
-    # Use the dg-options mechanism to specify extra flags for this test.
-    # FIXME: This does not handle other uses of dg-options, and it only
-    # processes the first one.
-    set extra_tool_flags ""
-    set tmp [grep $src1 "{\[ \t\]\*dg-options.*\[ \t\]\+}"]
-    if ![string match "" $tmp] {
-       set tmp0 [lindex $tmp 0]
-       # Extract the compiler options.
-       regexp "dg-options\[ \t\]\+(.*)\[ \t\]\+\}" \
-              $tmp0 all args
-       # Sometime the options are in quotes, sometimes not.
-       regsub -all "\"" $args "" args
-       set extra_tool_flags $args
+    # Check whether this test is supported for this target.
+    if { [lindex ${dg-do-what} 1 ] == "N" } {
+       unsupported "$src1"
+       verbose "$src1 not supported on this target, skipping it" 3
+       return
     }
 
     # Set up the names of the other source files.
-    regsub "_main.*" $src1 "" base
-    regsub ".*/" $base "" base
-    regsub "_main" $src1 "_x" src2
-    regsub "_main" $src1 "_y" src3
+    set dir [file dirname $src1]
+    set ext [file extension $src1]
+    set base [file rootname $src1]
+    set base [string range $base [string length $dir] end]
+    regsub "_main" $base "" base
+    set src2 "${dir}/${base}_x${ext}"
+    set src3 "${dir}/${base}_y${ext}"
+
+    # Use the dg-options mechanism to specify extra flags for this test. 
+    # The extra flags in each file are used to compile that file, and the
+    # extra flags in *_main.* are also used for linking.
+    set extra_flags_2 [compat-get-options $src2]
+    set compile_xfail_2 $compiler_conditional_xfail_data
+    set extra_flags_3 [compat-get-options $src3]
+    set compile_xfail_3 $compiler_conditional_xfail_data
 
     # Define the names of the object files.
-    set obj1 "main_tst.o"
-    set obj2_tst "x_tst.o"
-    set obj2_alt "x_alt.o"
-    set obj3_tst "y_tst.o"
-    set obj3_alt "y_alt.o"
+    regsub "sid" "sid_main_tst.o" $sid obj1
+    regsub "sid" "sid_x_tst.o" $sid obj2_tst
+    regsub "sid" "sid_x_alt.o" $sid obj2_alt
+    regsub "sid" "sid_y_tst.o" $sid obj3_tst
+    regsub "sid" "sid_y_alt.o" $sid obj3_alt
 
     # Get the base name of this test, for use in messages.
-    regsub "^$srcdir/?" $src1 "" testcase
+    set testcase "$src1"
+    # Remove the $srcdir and $tmpdir prefixes from $src1.  (It would
+    # be possible to use "regsub" here, if we were careful to escape
+    # all regular expression characters in $srcdir and $tmpdir, but
+    # that would be more complicated that this approach.) 
+    if {[string first "$srcdir/" "$src1"] == 0} {
+       set testcase [string range "$src1" [string length "$srcdir/"] end]
+    }
+    if {[string first "$tmpdir/" "$testcase"] == 0} {
+       set testcase [string range "$testcase" [string length "$tmpdir/"] end]
+       set testcase "tmpdir-$testcase"
+    }
     regsub "_main.*" $testcase "" testcase
     # Set up the base name of executable files so they'll be unique.
     regsub -all "\[./\]" $testcase "-" execbase
@@ -175,13 +322,6 @@ proc compat-execute { src1 use_alt } {
        }
        verbose "Testing $testcase, $optstr" 1
 
-       set tst_options ""
-       set alt_options ""
-       if ![string match $extra_tool_flags ""] then {
-           lappend tst_options "additional_flags=$extra_tool_flags $tst_option"
-           lappend alt_options "additional_flags=$extra_tool_flags $alt_option"
-       }
-
        # There's a unique name for each executable we generate, based on
        # the set of options and how the pieces of the tests are compiled.
        set execname1 "${execbase}-${count}1"
@@ -199,34 +339,43 @@ proc compat-execute { src1 use_alt } {
        # later.  Skip this if we don't have an alternate compiler.
        if { $use_alt != 0 } then {
            compat-use-alt-compiler
-           compat-obj "$src2" "$obj2_alt" $alt_options $optstr
-           compat-obj "$src3" "$obj3_alt" $alt_options $optstr
+           compat-obj "$src2" "$obj2_alt" $alt_option $extra_flags_2 \
+                      $optstr $compile_xfail_2
+           compat-obj "$src3" "$obj3_alt" $alt_option $extra_flags_3 \
+                      $optstr $compile_xfail_3
        }
 
        # Compile pieces with the compiler under test.
        compat-use-tst-compiler
-       compat-obj "$src1" "$obj1" $tst_options $optstr
-       compat-obj "$src2" "$obj2_tst" $tst_options $optstr
-       compat-obj "$src3" "$obj3_tst" $tst_options $optstr
+       compat-obj "$src1" "$obj1" $tst_option $extra_flags_1 $optstr ""
+       compat-obj "$src2" "$obj2_tst" $tst_option $extra_flags_2 \
+                  $optstr $compile_xfail_2
+       compat-obj "$src3" "$obj3_tst" $tst_option $extra_flags_3 \
+                  $optstr $compile_xfail_3
 
        # Link (using the compiler under test), run, and clean up tests.
        compat-run "${obj2_tst}-${obj3_tst}" \
-           "$obj1 $obj2_tst $obj3_tst" $execname1 $tst_options $optstr
+           "$obj1 $obj2_tst $obj3_tst" $execname1 \
+           $tst_option $extra_flags_1 $optstr
 
        # If we've got an alternate compiler try some combinations.
        if { $use_alt != 0 } then {
            compat-run "${obj2_tst}-${obj3_alt}" "$obj1 $obj2_tst $obj3_alt" \
-                      $execname2 $tst_options $optstr
+                      $execname2 $tst_option $extra_flags_1 $optstr
            compat-run "${obj2_alt}-${obj3_tst}" "$obj1 $obj2_alt $obj3_tst" \
-                      $execname3 $tst_options $optstr
+                      $execname3 $tst_option $extra_flags_1 $optstr
            compat-run "${obj2_alt}-${obj3_alt}" "$obj1 $obj2_alt $obj3_alt" \
-                      $execname4 $tst_options $optstr
+                      $execname4 $tst_option $extra_flags_1 $optstr
        }
 
        # Clean up object files.
-       set files [glob -nocomplain *.o]
+       set files [glob -nocomplain ${sid}_*.o]
        if { $files != "" } {
-           eval "remote_file build delete $files"
+           foreach objfile $files {
+               if { ![info exists gluefile] || $objfile != $gluefile } {
+                   eval "remote_file build delete $objfile"
+               }
+           }
        }
     }
 }