update copyright dates
[deliverable/binutils-gdb.git] / gas / testsuite / lib / gas-defs.exp
index 827e22f70f0750418faae3e216ad50955fc20eeb..07d6445938ee25fbd95daae9809c209a64692871 100644 (file)
@@ -1,9 +1,9 @@
 # Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-# 2004, 2005 Free Software Foundation, Inc.
+# 2004, 2005, 2007, 2008, 2009  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
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
@@ -13,7 +13,8 @@
 #
 # 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
 
 # Please email any bugs, comments, and/or additions to this file to:
 # dejagnu@gnu.org
 
 proc gas_version {} {
     global AS
-    catch "exec $AS -version < /dev/null" tmp
+    if [is_remote host] then {
+       remote_exec host "$AS -version < /dev/null" "" "" "gas.version"
+       remote_exec host "which $AS" "" "" "gas.which"
+
+       remote_upload host "gas.version"
+       remote_upload host "gas.which"
+
+       set which_as [file_contents "gas.which"]
+       set tmp [file_contents "gas.version"]
+
+       remote_file build delete "gas.version"
+       remote_file build delete "gas.which"
+       remote_file host delete "gas.version"
+       remote_file host delete "gas.which"
+    } else {
+       set which_as [which $AS]
+       catch "exec $AS -version < /dev/null" tmp
+    }
+
     # Should find a way to discard constant parts, keep whatever's
     # left, so the version string could be almost anything at all...
     regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" $tmp version cyg number
     if ![info exists number] then {
-        return "[which $AS] (no version number)\n"
+        return "$which_as (no version number)\n"
     }
-    clone_output "[which $AS] $number\n"
+    clone_output "$which_as $number\n"
     unset version
 }
 
+proc gas_host_run { cmd redir } {
+    verbose "Executing $cmd $redir"
+    set return_contents_of ""
+    if [regexp ">& */dev/null" $redir] then {
+       set output_file ""
+       set command "$cmd $redir"
+    } elseif [regexp "> */dev/null" $redir] then {
+       set output_file ""
+       set command "$cmd 2>gas.stderr"
+       set return_contents_of "gas.stderr"
+    } elseif [regexp ">&.*" $redir] then {
+       # See PR 5322 for why the following line is used.
+       regsub ">&" $redir "" output_file       
+       set command "$cmd 2>&1"
+    } elseif [regexp "2>.*" $redir] then {
+       set output_file "gas.out"
+       set command "$cmd $redir"
+       set return_contents_of "gas.out"
+    } elseif [regexp ">.*" $redir] then {
+       set output_file ""
+       set command "$cmd $redir 2>gas.stderr"
+       set return_contents_of "gas.stderr"
+    } elseif { "$redir" == "" } then {
+       set output_file "gas.out"
+       set command "$cmd 2>&1"
+       set return_contents_of "gas.out"
+    } else {
+       fail "gas_host_run: unknown form of redirection string"
+    }
+
+    set status [remote_exec host [concat sh -c [list $command]] "" "/dev/null" "$output_file"]
+    set to_return ""
+    if { "$return_contents_of" != "" } then {
+       remote_upload host "$return_contents_of"
+       set to_return [file_contents "$return_contents_of"]
+       regsub "\n$" $to_return "" to_return
+    }
+
+    if { [lindex $status 0] == 0 && "$output_file" != ""
+        && "$output_file" != "$return_contents_of" } then {
+       remote_upload host "$output_file"
+    }
+
+    return [list [lindex $status 0] "$to_return"]
+}
+
 proc gas_run { prog as_opts redir } {
     global AS
     global ASFLAGS
@@ -41,8 +106,11 @@ proc gas_run { prog as_opts redir } {
     global subdir
     global host_triplet
 
-    verbose -log "Executing $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog $redir"
-    catch "exec $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog $redir" comp_output
+    set status [gas_host_run "$AS $ASFLAGS $as_opts $srcdir/$subdir/$prog" "$redir"]
+    set comp_output [lindex $status 1]
+    if { [lindex $status 0] != 0 && [regexp "2>.*" $redir] } then {
+       append comp_output "child process exited abnormally"
+    }
     set comp_output [prune_warnings $comp_output]
     verbose "output was $comp_output"
     return [list $comp_output ""]
@@ -53,27 +121,36 @@ proc all_ones { args } {
     return 1
 }
 
+# ${tool}_finish (gas_finish) will be called by runtest.exp.  But
+# gas_finish should only be used with gas_start.  We use gas_started
+# to tell gas_finish if gas_start has been called so that runtest.exp
+# can call gas_finish without closing the wrong fd.
+set gas_started 0
+
 proc gas_start { prog as_opts } {
     global AS
     global ASFLAGS
     global srcdir
     global subdir
     global spawn_id
+    global gas_started
+
+    set gas_started 1
 
     verbose -log "Starting $AS $ASFLAGS $as_opts $prog" 2
-    catch {
-       spawn -noecho -nottycopy $srcdir/lib/run $AS $ASFLAGS $as_opts $srcdir/$subdir/$prog
-    } foo
-    if ![regexp {^[0-9]+} $foo] then {
-       perror "Can't run $subdir/$prog: $foo"
-    }
+    set status [gas_host_run "$AS $ASFLAGS $as_opts $srcdir/$subdir/$prog" ">&gas.out"]
+    spawn -noecho -nottycopy cat gas.out
 }
 
 proc gas_finish { } {
     global spawn_id
+    global gas_started
 
-    catch "close"
-    catch "wait"
+    if { $gas_started == 1 } {
+       catch "close"
+       catch "wait"
+       set gas_started 0
+    }
 }
 
 proc want_no_output { testname } {
@@ -233,6 +310,18 @@ proc is_elf_format {} {
     return 1
 }
 
+# True if the object format is known to be PE COFF.
+#
+proc is_pecoff_format {} {
+    if { ![istarget *-*-mingw*] \
+        && ![istarget *-*-cygwin*] \
+        && ![istarget *-*-pe*] } {
+       return 0
+    }
+
+    return 1
+}
+
 # run_dump_tests TESTCASES EXTRA_OPTIONS
 # Wrapper for run_dump_test, which is suitable for invoking as
 #   run_dump_tests [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
@@ -294,19 +383,16 @@ proc run_dump_tests { testcases {extra_options {}} } {
 #   as: FLAGS
 #      When assembling FILE.s, pass FLAGS to the assembler.
 #
-#   PROG: PROGRAM-NAME
-#       The name of the program to run to analyze the .o file produced
-#       by the assembler.  This can be omitted; run_dump_test will guess
-#       which program to run by seeing which of the flags options below
-#      is present.
-#
-#   objdump: FLAGS
 #   nm: FLAGS
 #   objcopy: FLAGS
+#   objdump: FLAGS
+#   readelf: FLAGS
 #      Use the specified program to analyze the .o file, and pass it
 #      FLAGS, in addition to the .o file name.  Note that they are run
 #      with LC_ALL=C in the environment to give consistent sorting
-#      of symbols.
+#      of symbols.  If no FLAGS are needed then use:
+#        PROG: [nm objcopy objdump readelf]
+#       instead.
 #
 #   source: SOURCE
 #      Assemble the file SOURCE.s.  If omitted, this defaults to FILE.s.
@@ -408,6 +494,9 @@ proc run_dump_test { name {extra_options {}} } {
            unresolved $subdir/$name
            return
        }
+       if { $opt_name == "as" } {
+           set opt_val [subst $opt_val]
+       }
        set opts($opt_name) $opt_val
     }
 
@@ -540,10 +629,11 @@ proc run_dump_test { name {extra_options {}} } {
        set sourcefile $srcdir/$subdir/$opts(source)
     }
 
-    set cmd "$srcdir/lib/run $AS $ASFLAGS $opts(as) -o dump.o $sourcefile"
+    set cmd "$AS $ASFLAGS $opts(as) -o dump.o $sourcefile"
     send_log "$cmd\n"
-    set cmdret [catch "exec $cmd" comp_output]
-    set comp_output [prune_warnings $comp_output]
+    set status [gas_host_run $cmd ""]
+    set cmdret [lindex $status 0]
+    set comp_output [prune_warnings [lindex $status 1]]
 
     set expmsg $opts(error)
     if { $opts(warning) != "" } {
@@ -609,6 +699,10 @@ proc run_dump_test { name {extra_options {}} } {
                return
            }
        }
+    } else {
+       if { $opts(error) != "" || $opts(error-output) != "" } {
+           fail $testname
+       }
     }
 
     if { $program == "" } {
@@ -618,7 +712,7 @@ proc run_dump_test { name {extra_options {}} } {
     eval set progopts \$[string toupper $program]FLAGS
     eval set binary \$[string toupper $program]
 
-    if { [which $binary] == 0 } {
+    if { ![is_remote host] && [which $binary] == 0 } {
        untested $testname
        return
     }
@@ -628,9 +722,11 @@ proc run_dump_test { name {extra_options {}} } {
 
     # Objcopy, unlike the other two, won't send its output to stdout,
     # so we have to run it specially.
-    set cmd "$binary $progopts $progopts1 dump.o > dump.out"
+    set cmd "$binary $progopts $progopts1 dump.o"
+    set redir ">dump.out"
     if { $program == "objcopy" } {
        set cmd "$binary $progopts $progopts1 dump.o dump.out"
+       set redir ""
     }
 
     # Ensure consistent sorting of symbols
@@ -639,7 +735,8 @@ proc run_dump_test { name {extra_options {}} } {
     }
     set env(LC_ALL) "C"
     send_log "$cmd\n"
-    catch "exec $cmd" comp_output
+    set status [gas_host_run "$cmd" "$redir"]
+    set comp_output [prune_warnings [lindex $status 1]]
     if {[info exists old_lc_all]} {
        set env(LC_ALL) $old_lc_all
     } else {
@@ -694,8 +791,8 @@ proc objdump { opts } {
     global comp_output
     global host_triplet
 
-    catch "exec $OBJDUMP $opts" comp_output
-    set comp_output [prune_warnings $comp_output]
+    set status [gas_host_run "$OBJDUMP $opts" ""]
+    set comp_output [prune_warnings [lindex $status 1]]
     verbose "objdump output=$comp_output\n" 3
 }
 
@@ -705,12 +802,8 @@ proc objdump_start_no_subdir { prog opts } {
     global spawn_id
 
     verbose "Starting $OBJDUMP $opts $prog" 2
-    catch {
-       spawn -noecho -nottyinit $srcdir/lib/run $OBJDUMP $opts $prog
-    } foo
-    if ![regexp {^[0-9]+} $foo] then {
-       perror "Can't run $prog: $foo"
-    }
+    set status [gas_host_run "$OBJDUMP $opts $prog" ">&gas.out"]
+    spawn -noecho -nottycopy cat gas.out
 }
 
 proc objdump_finish { } {
@@ -875,3 +968,25 @@ if ![string length [info proc prune_warnings]] {
        return $text
     }
 }
+
+# run_list_test NAME (optional): OPTS TESTNAME
+#
+# Assemble the file "NAME.s" with command line options OPTS and
+# compare the assembler standard error output against the regular
+# expressions given in the file "NAME.l".  If TESTNAME is provided,
+# it will be used as the name of the test.
+
+proc run_list_test { name {opts {}} {testname {}} } {
+    global srcdir subdir
+    if { [string length $testname] == 0 } then {
+       set testname "[file tail $subdir] $name"
+    }
+    set file $srcdir/$subdir/$name
+    gas_run ${name}.s $opts ">&dump.out"
+    if { [regexp_diff "dump.out" "${file}.l"] } then {
+       fail $testname
+       verbose "output is [file_contents "dump.out"]" 2
+       return
+    }
+    pass $testname
+}
This page took 0.026904 seconds and 4 git commands to generate.