ChangeLog rotatation and copyright year update
[deliverable/binutils-gdb.git] / binutils / testsuite / lib / utils-lib.exp
index 3ee76754a5a63ce119145a4aadb0b34923ce0a8a..8dac718784b184faa14d9ae3fe5d34805a91f284 100644 (file)
@@ -1,16 +1,15 @@
-# Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2003, 2004
-# Free Software Foundation, Inc.
+# Copyright (C) 1993-2015 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,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # 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.
 # This file was written by Rob Savoye <rob@cygnus.com>
 # and extended by Ian Lance Taylor <ian@cygnus.com>
 
+proc load_common_lib { name } {
+    load_lib $name
+}
+
+load_common_lib binutils-common.exp
+
 proc binutil_version { prog } {
     if ![is_remote host] {
        set path [which $prog]
@@ -84,10 +89,10 @@ proc default_binutils_run { prog progargs } {
 }
 
 #
-# default_binutils_assemble
+# default_binutils_assemble_flags
 #      assemble a file
 #
-proc default_binutils_assemble { source object } {
+proc default_binutils_assemble_flags { source object asflags } {
     global srcdir
     global host_triplet
 
@@ -105,7 +110,7 @@ proc default_binutils_assemble { source object } {
        set source asm.s
     }
 
-    set exec_output [target_assemble $source $object ""]
+    set exec_output [target_assemble $source $object $asflags]
     set exec_output [prune_warnings $exec_output]
 
     if [string match "" $exec_output] {
@@ -118,50 +123,12 @@ proc default_binutils_assemble { source object } {
     }
 }
 
-#
-# is_elf_format
-#      true if the object format is known to be ELF
-#
-proc is_elf_format {} {
-    if { ![istarget *-*-sysv4*] \
-        && ![istarget *-*-unixware*] \
-        && ![istarget *-*-elf*] \
-        && ![istarget *-*-eabi*] \
-        && ![istarget hppa*64*-*-hpux*] \
-        && ![istarget ia64-*-hpux*] \
-        && ![istarget *-*-linux*] \
-        && ![istarget *-*-irix5*] \
-        && ![istarget *-*-irix6*] \
-        && ![istarget *-*-netbsd*] \
-        && ![istarget *-*-solaris2*] } {
-       return 0
-    }
-
-    if { [istarget *-*-linux*aout*] \
-        || [istarget *-*-linux*oldld*] } {
-       return 0
-    }
-
-    if { ![istarget *-*-netbsdelf*] \
-        && ([istarget *-*-netbsd*aout*] \
-            || [istarget *-*-netbsdpe*] \
-            || [istarget arm*-*-netbsd*] \
-            || [istarget sparc-*-netbsd*] \
-            || [istarget i*86-*-netbsd*] \
-            || [istarget m68*-*-netbsd*] \
-            || [istarget vax-*-netbsd*] \
-            || [istarget ns32k-*-netbsd*]) } {
-       return 0
-    }
-    return 1
-}
-
 #
 # exe_ext
 #      Returns target executable extension, if any.
 #
 proc exe_ext {} {
-    if { [istarget *-*-mingw32] || [istarget *-*-cygwin*] } {
+    if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] } {
         return ".exe"
     } else {
         return ""
@@ -274,13 +241,14 @@ proc exe_ext {} {
 #
 # After the option lines come regexp lines.  `run_dump_test' calls
 # `regexp_diff' to compare the output of the dumping tool against the
-# regexps in FILE.d.  `regexp_diff' is defined later in this file; see
-# further comments there.
+# regexps in FILE.d.  `regexp_diff' is defined in binutils-common.exp;
+# see further comments there.
 
 proc run_dump_test { name {extra_options {}} } {
     global subdir srcdir
-    global OBJDUMP NM OBJCOPY READELF
-    global OBJDUMPFLAGS NMFLAGS OBJCOPYFLAGS READELFFLAGS
+    global OBJDUMP NM OBJCOPY READELF STRIP
+    global OBJDUMPFLAGS NMFLAGS OBJCOPYFLAGS READELFFLAGS STRIPFLAGS
+    global ELFEDIT ELFEDITFLAGS
     global host_triplet
     global env
     global copyfile
@@ -300,6 +268,7 @@ proc run_dump_test { name {extra_options {}} } {
     }
     set opts(addr2line) {}
     set opts(ar) {}
+    set opts(as) {}
     set opts(nm) {}
     set opts(objcopy) {}
     set opts(objdump) {}
@@ -309,6 +278,7 @@ proc run_dump_test { name {extra_options {}} } {
     set opts(size) {}
     set opts(strings) {}
     set opts(name) {}
+    set opts(elfedit) {}
     set opts(PROG) {}
     set opts(DUMPPROG) {}
     set opts(source) {}
@@ -325,6 +295,11 @@ proc run_dump_test { name {extra_options {}} } {
            unresolved $subdir/$name
            return
        }
+
+       # Permit the option to use $srcdir to refer to the source
+       # directory.
+       regsub -all "\\\$srcdir" "$opt_val" "$srcdir/$subdir" opt_val
+
        if [string length $opts($opt_name)] {
            perror "option $opt_name multiply set in $file.d"
            unresolved $subdir/$name
@@ -341,6 +316,11 @@ proc run_dump_test { name {extra_options {}} } {
            unresolved $subdir/$name
            return
        }
+
+       # Permit the option to use $srcdir to refer to the source
+       # directory.
+       regsub -all "\\\$srcdir" "$opt_val" "$srcdir/$subdir" opt_val
+
        # add extra option to end of existing option, adding space
        # if necessary.
        if [string length $opts($opt_name)] {
@@ -362,12 +342,18 @@ proc run_dump_test { name {extra_options {}} } {
        return
     }
 
+    set destopt ""
     switch -- $opts(PROG) {
        ar      { set program ar }
        objcopy { set program objcopy }
        ranlib  { set program ranlib }
-       strip   { set program strip }
+       strip   {
+           set program strip
+           set destopt "-o"
+       }
        strings { set program strings }
+       elfedit { set program elfedit }
+       nm      { set program nm }
        default {
            perror "unrecognized program option $opts(PROG) in $file.d"
            unresolved $testname
@@ -418,7 +404,7 @@ proc run_dump_test { name {extra_options {}} } {
     if { $opts(not-skip) != "" } then {
        set skip 1
        foreach glob $opts(not-skip) {
-           if {[istarget $glob]} { 
+           if {[istarget $glob]} {
                set skip 0
                break
            }
@@ -433,32 +419,38 @@ proc run_dump_test { name {extra_options {}} } {
        }
        set skip 1
        foreach glob $opts(target) {
-           if {[istarget $glob]} { 
+           if {[istarget $glob]} {
                set skip 0
                break
            }
        }
-       if {$skip} { 
+       if {$skip} {
            unsupported $testname
-           return 
+           return
        }
     }
     if { $opts(not-target) != "" } then {
        foreach glob $opts(not-target) {
            if {[istarget $glob]} {
                unsupported $testname
-               return 
+               return
            }
        }
     }
 
+    if { [string match "*--compress-debug-sections*" $opts(as)] \
+        && ![is_zlib_supported] } {
+       unsupported $testname
+       return
+    }
+
     if { $opts(source) == "" } {
        set srcfile ${file}.s
     } else {
        set srcfile $srcdir/$subdir/$opts(source)
     }
 
-    set exec_output [binutils_assemble ${srcfile} tmpdir/bintest.o]
+    set exec_output [binutils_assemble_flags ${srcfile} $tempfile $opts(as)]
     if [string match "" $exec_output] then {
        send_log "$exec_output\n"
        verbose "$exec_output"
@@ -470,7 +462,7 @@ proc run_dump_test { name {extra_options {}} } {
     eval set progopts \$[string toupper $program]FLAGS
     eval set binary \$[string toupper $program]
 
-    set exec_output [binutils_run $binary "$progopts $progopts1 $tempfile ${copyfile}.o"]
+    set exec_output [binutils_run $binary "$progopts $progopts1 $tempfile $destopt ${copyfile}.o"]
     if ![string match "" $exec_output] {
        send_log "$exec_output\n"
        verbose "$exec_output"
@@ -482,14 +474,14 @@ proc run_dump_test { name {extra_options {}} } {
     eval set progopts \$[string toupper $dumpprogram]FLAGS
     eval set binary \$[string toupper $dumpprogram]
 
-    if { [which $binary] == 0 } {
+    if { ![is_remote host] && [which $binary] == 0 } {
        untested $testname
        return
     }
 
     verbose "running $binary $progopts $progopts1" 3
 
-    set cmd "$binary $progopts $progopts1 ${copyfile}.o > tmpdir/dump.out"
+    set cmd "$binary $progopts $progopts1 ${copyfile}.o"
 
     # Ensure consistent sorting of symbols
     if {[info exists env(LC_ALL)]} {
@@ -497,13 +489,18 @@ proc run_dump_test { name {extra_options {}} } {
     }
     set env(LC_ALL) "C"
     send_log "$cmd\n"
-    catch "exec $cmd" comp_output
+    set comp_output [remote_exec host $cmd "" "/dev/null" "tmpdir/dump.out"]
     if {[info exists old_lc_all]} {
        set env(LC_ALL) $old_lc_all
     } else {
        unset env(LC_ALL)
     }
-    set comp_output [prune_warnings $comp_output]
+    if { [lindex $comp_output 0] != 0 } then {
+       send_log "$comp_output\n"
+       fail $testname
+       return
+    }
+    set comp_output [prune_warnings [lindex $comp_output 1]]
     if ![string match "" $comp_output] then {
        send_log "$comp_output\n"
        fail $testname
@@ -547,110 +544,6 @@ proc slurp_options { file } {
     return $opt_array
 }
 
-# regexp_diff, based on simple_diff taken from ld test suite
-#      compares two files line-by-line
-#      file1 contains strings, file2 contains regexps and #-comments
-#      blank lines are ignored in either file
-#      returns non-zero if differences exist
-#
-proc regexp_diff { file_1 file_2 } {
-
-    set eof -1
-    set end_1 0
-    set end_2 0
-    set differences 0
-    set diff_pass 0
-
-    if [file exists $file_1] then {
-       set file_a [open $file_1 r]
-    } else {
-       perror "$file_1 doesn't exist"
-       return 1
-    }
-
-    if [file exists $file_2] then {
-       set file_b [open $file_2 r]
-    } else {
-       perror "$file_2 doesn't exist"
-       close $file_a
-       return 1
-    }
-
-    verbose " Regexp-diff'ing: $file_1 $file_2" 2
-
-    while { 1 } {
-       set line_a ""
-       set line_b ""
-       while { [string length $line_a] == 0 } {
-           if { [gets $file_a line_a] == $eof } {
-               set end_1 1
-               break
-           }
-       }
-       while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
-           if [ string match "#pass" $line_b ] {
-               set end_2 1
-               set diff_pass 1
-               break
-           } elseif [ string match "#..." $line_b ] {
-               if { [gets $file_b line_b] == $eof } {
-                   set end_2 1
-                   set diff_pass 1
-                   break
-               }
-               verbose "looking for \"^$line_b$\"" 3
-               while { ![regexp "^$line_b$" "$line_a"] } {
-                   verbose "skipping    \"$line_a\"" 3
-                   if { [gets $file_a line_a] == $eof } {
-                       set end_1 1
-                       break
-                   }
-               }
-               break
-           }
-           if { [gets $file_b line_b] == $eof } {
-               set end_2 1
-               break
-           }
-       }
-
-        if { $diff_pass } {
-            break
-        } elseif { $end_1 && $end_2 } {
-            break
-        } elseif { $end_1 } {
-            send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
-            verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
-            set differences 1
-            break
-        } elseif { $end_2 } {
-            send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
-            verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
-            set differences 1
-            break
-        } else {
-            verbose "regexp \"^$line_b$\"\nline   \"$line_a\"" 3
-            if ![regexp "^$line_b$" "$line_a"] {
-               send_log "regexp_diff match failure\n"
-               send_log "regexp \"^$line_b$\"\nline   \"$line_a\"\n"
-               verbose "regexp_diff match failure\n" 3
-               set differences 1
-            }
-        }
-    }
-
-    if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
-       send_log "$file_1 and $file_2 are different lengths\n"
-       verbose "$file_1 and $file_2 are different lengths" 3
-       set differences 1
-    }
-
-    close $file_a
-    close $file_b
-
-    return $differences
-}
-
 proc file_contents { filename } {
     set file [open $filename r]
     set contents [read $file]
This page took 0.028302 seconds and 4 git commands to generate.