bfd/
[platform/upstream/binutils.git] / ld / testsuite / lib / ld-lib.exp
index c1e141a..34de7c8 100644 (file)
@@ -1,6 +1,7 @@
 # Support routines for LD testsuite.
 #   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-#    2004, 2005, 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
+#    2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+#    Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
 #
@@ -294,14 +295,14 @@ proc default_ld_compile { cc source object } {
 
 # Assemble a file.
 #
-proc default_ld_assemble { as source object } {
+proc default_ld_assemble { as in_flags source object } {
     global ASFLAGS
     global host_triplet
 
     if ![info exists ASFLAGS] { set ASFLAGS "" }
 
     set flags [big_or_little_endian]
-    set exec_output [run_host_cmd "$as" "$flags $ASFLAGS -o $object $source"]
+    set exec_output [run_host_cmd "$as" "$flags $in_flags $ASFLAGS -o $object $source"]
     set exec_output [prune_warnings $exec_output]
     if [string match "" $exec_output] then {
        return 1
@@ -369,10 +370,7 @@ proc ld_simple_link_defsyms {} {
     set flags "--defsym __stack_chk_fail=0"
 
     # ARM targets call __gccmain
-    if {[istarget arm*-*-*]       || \
-        [istarget strongarm*-*-*] || \
-        [istarget xscale*-*-*]    || \
-        [istarget thumb-*-*] } {
+    if {[istarget arm*-*-*]} {
         append flags " --defsym __gccmain=0"
     }
 
@@ -408,75 +406,6 @@ proc ld_simple_link_defsyms {} {
     return $flags
 }
 
-# Compares two files line-by-line.
-#   Returns differences if exist.
-#   Returns null if file(s) cannot be opened.
-#
-proc simple_diff { file_1 file_2 } {
-    global target
-
-    set eof -1
-    set differences 0
-
-    if [file exists $file_1] then {
-       set file_a [open $file_1 r]
-    } else {
-       warning "$file_1 doesn't exist"
-       return
-    }
-
-    if [file exists $file_2] then {
-       set file_b [open $file_2 r]
-    } else {
-       fail "$file_2 doesn't exist"
-       return
-    }
-
-    verbose "# Diff'ing: $file_1 $file_2\n" 2
-
-    while { [gets $file_a line] != $eof } {
-       if [regexp "^#.*$" $line] then {
-           continue
-       } else {
-           lappend list_a $line
-       }
-    }
-    close $file_a
-
-    while { [gets $file_b line] != $eof } {
-       if [regexp "^#.*$" $line] then {
-           continue
-       } else {
-           lappend list_b $line
-       }
-    }
-    close $file_b
-
-    for { set i 0 } { $i < [llength $list_a] } { incr i } {
-       set line_a [lindex $list_a $i]
-       set line_b [lindex $list_b $i]
-
-       verbose "\t$file_1: $i: $line_a\n" 3
-       verbose "\t$file_2: $i: $line_b\n" 3
-       if [string compare $line_a $line_b] then {
-           verbose -log "\t$file_1: $i: $line_a\n"
-           verbose -log "\t$file_2: $i: $line_b\n"
-
-           fail "Test: $target"
-           return
-       }
-    }
-
-    if { [llength $list_a] != [llength $list_b] } {
-       fail "Test: $target"
-       return
-    }
-
-    if $differences<1 then {
-       pass "Test: $target"
-    }
-}
-
 # run_dump_test FILE
 # Copied from gas testsuite, tweaked and further extended.
 #
@@ -577,8 +506,8 @@ proc simple_diff { file_1 file_2 } {
 #
 # 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 } {
     global subdir srcdir
@@ -943,123 +872,6 @@ proc slurp_options { file } {
     return $opt_array
 }
 
-# regexp_diff, copied from gas, based on simple_diff above.
-#      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
-    set fail_if_match 0
-
-    if [file exists $file_1] then {
-       set file_a [open $file_1 r]
-    } else {
-       warning "$file_1 doesn't exist"
-       return 1
-    }
-
-    if [file exists $file_2] then {
-       set file_b [open $file_2 r]
-    } else {
-       fail "$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 "#failif" $line_b ] {
-               send_log "fail if no difference\n"
-               verbose "fail if no difference" 3
-               set fail_if_match 1
-           } 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"] {
-               verbose "regexp_diff match failure\n" 3
-               send_log "regexp_diff match failure\n"
-               send_log "regexp \"^$line_b$\"\nline   \"$line_a\"\n"
-               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
-    }
-
-    if { $fail_if_match } {
-       if { $differences == 0 } {
-           set differences 1
-       } else {
-           set differences 0
-       }
-    }
-
-    close $file_a
-    close $file_b
-
-    return $differences
-}
-
 proc file_contents { filename } {
     set file [open $filename r]
     set contents [read $file]
@@ -1166,26 +978,21 @@ proc run_ld_link_tests { ldtests } {
        }
 
        # Catch assembler errors.
-       if { $is_unresolved != 0 } {
+       if { $is_unresolved } {
            unresolved $testname
            continue
        }
 
        if { [regexp ".*\\.a$" $binfile] } {
            if { ![ar_simple_create $ar $ld_options $binfile "$objfiles"] } {
-               fail $testname
                set failed 1
-           } else {
-               set failed 0
            }
        } elseif { ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles"] } {
            set maybe_failed 1
            set ld_output "$exec_output"
-       } else {
-           set failed 0
        }
 
-       if { $failed == 0 } {
+       if { !$failed } {
            foreach actionlist $actions {
                set action [lindex $actionlist 0]
                set progopts [lindex $actionlist 1]
@@ -1222,10 +1029,7 @@ proc run_ld_link_tests { ldtests } {
                        break
                    }
                    set maybe_failed 0
-               } elseif { $maybe_failed != 0 } {
-                   set failed 1
-                   break
-               } elseif { $dump_prog != "" } {
+               } elseif { !$maybe_failed && $dump_prog != "" } {
                    set dumpfile [lindex $actionlist 2]
                    set binary $dump_prog
 
@@ -1267,18 +1071,14 @@ proc run_ld_link_tests { ldtests } {
                    remote_file host delete "dump.out"
                }
            }
-
-           if { $failed != 0 } {
-               fail $testname
-           } else { if { $is_unresolved == 0 } {
-               pass $testname
-           } }
        }
 
-       # Catch action errors.
-       if { $is_unresolved != 0 } {
+       if { $is_unresolved } {
            unresolved $testname
-           continue
+       } elseif { $maybe_failed || $failed } {
+           fail $testname
+       } else {
+           pass $testname
        }
     }
 }