gas run_dump_test rename not-target and not-skip
[binutils-gdb.git] / gas / testsuite / lib / gas-defs.exp
index 3102aa0c3916f533b399674573bd4a57690a3460..e040e947a97811a0e7fb6be8332ae77e7c37b7a4 100644 (file)
@@ -1,5 +1,4 @@
-# Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-# 2004, 2005, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
+# Copyright (C) 1993-2018 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
 
 # This file was written by Ken Raeburn (raeburn@cygnus.com).
 
+proc load_common_lib { name } {
+    global srcdir
+    load_file $srcdir/../../binutils/testsuite/lib/$name
+}
+
+load_common_lib binutils-common.exp
+
 proc gas_version {} {
     global AS
     if [is_remote host] then {
@@ -64,7 +70,7 @@ proc gas_host_run { cmd redir } {
        set return_contents_of "gas.stderr"
     } elseif [regexp ">&.*" $redir] then {
        # See PR 5322 for why the following line is used.
-       regsub ">&" $redir "" output_file       
+       regsub ">&" $redir "" output_file
        set command "$cmd 2>&1"
     } elseif [regexp "2>.*" $redir] then {
        set output_file "gas.out"
@@ -277,119 +283,16 @@ proc gas_init { args } {
     return
 }
 
-# True if the object format is known to be ELF.
-#
-proc is_elf_format {} {
-    if { ![istarget *-*-sysv4*]
-        && ![istarget *-*-unixware*]
-        && ![istarget *-*-elf*]
-        && ![istarget *-*-eabi*]
-        && ![istarget *-*-rtems*]
-        && ![istarget hppa*64*-*-hpux*]
-        && ![istarget ia64-*-hpux*]
-        && ![istarget *-*-linux*]
-        && ![istarget *-*-gnu*]
-        && ![istarget frv-*-uclinux*]
-        && ![istarget bfin-*-uclinux]
-        && ![istarget sh*-*-uclinux*]
-        && ![istarget *-*-irix5*]
-        && ![istarget *-*-irix6*]
-        && ![istarget *-*-netbsd*]
-        && ![istarget *-*-openbsd*]
-        && ![istarget *-*-solaris2*] } {
-       return 0
-    }
-
-    if { [istarget *-*-linux*aout*]
-        || [istarget *-*-linux*oldld*]
-        || [istarget h8500-*-rtems*]
-        || [istarget i960-*-rtems*]
-        || [istarget *-*-rtemscoff*] } {
-       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
-    }
-
-    if { [istarget arm-*-openbsd*]
-        || [istarget i386-*-openbsd\[0-2\].*]
-        || [istarget i386-*-openbsd3.\[0-2\]]
-        || [istarget m68*-*-openbsd*]
-        || [istarget ns32k-*-openbsd*]
-        || [istarget sparc-*-openbsd\[0-2\].*]
-        || [istarget sparc-*-openbsd3.\[0-1\]]
-        || [istarget vax-*-openbsd*] } {
-       return 0
-    }
-
-    return 1
-}
-
-# True if the object format is known to be a.out.
-#
-proc is_aout_format {} {
-    if { [istarget *-*-netbsdelf]
-        || [istarget sparc64-*-netbsd*]
-        || [istarget sparc64-*-openbsd*] } {
-       return 0
-    }
-    if { [istarget *-*-*\[ab\]out*]
-        || [istarget *-*-linux*oldld*]
-        || [istarget *-*-bsd*]
-        || [istarget *-*-msdos*]
-        || [istarget arm-*-netbsd*]
-        || [istarget arm-*-openbsd*]
-        || [istarget arm-*-riscix*]
-        || [istarget i?86-*-freebsd\[12\]*]
-        || [istarget i?86-*-netbsd*]
-        || [istarget i?86-*-openbsd\[0-2\]*]
-        || [istarget i?86-*-openbsd3.\[0-2\]*]
-        || [istarget i?86-*-vsta]
-        || [istarget i?86-*-mach*]
-        || [istarget m68*-*-netbsd*]
-        || [istarget m68*-*-openbsd*]
-        || [istarget ns32k-*-*]
-        || [istarget pdp11-*-*]
-        || [istarget sparc*-*-sunos4*]
-        || [istarget sparc*-*-netbsd*]
-        || [istarget sparc*-*-openbsd\[0-2\]*]
-        || [istarget sparc*-*-openbsd3.\[0-1\]*]
-        || [istarget sparc*-fujitsu-none]
-        || [istarget vax-dec-ultrix*]
-        || [istarget vax-*-netbsd] } {
-       return 1
-    }
-    return 0
-}
-
-# True if the object format is known to be PE COFF.
-#
-proc is_pecoff_format {} {
-    if { ![istarget *-*-mingw*]
-        && ![istarget *-*-cygwin*]
-        && ![istarget *-*-cegcc*]
-        && ![istarget *-*-pe*] } {
-       return 0
-    }
-
-    return 1
-}
-
 # Internal procedure: return the names of the standard sections
 #
 proc get_standard_section_names {} {
     if [istarget "rx-*-*"] {
         return { "P" "D_1" "B_1" }
     }
+    if [istarget "alpha*-*-*vms*"] {
+        # Double quote: for TCL and for sh.
+        return { "\\\$CODE\\\$" "\\\$DATA\\\$" "\\\$BSS\\\$" }
+    }
     return
 }
 
@@ -456,14 +359,13 @@ proc run_dump_tests { testcases {extra_options {}} } {
 #
 #   addr2line: 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.  If no FLAGS are needed then use:
-#        PROG: [nm objcopy objdump readelf addr2line]
+#        PROG: [nm objdump readelf addr2line]
 #       instead.
 #      Note: for objdump, we automatically replaces the standard section
 #      names (.text, .data and .bss) by target ones if any (eg. rx-elf
@@ -480,31 +382,39 @@ proc run_dump_tests { testcases {extra_options {}} } {
 #      is useful if several .d files differ by options only.  Options are
 #      always read from FILE.d.
 #
-#   target: GLOBS...
-#       Run this test only on a specified list of targets.  More precisely,
-#       each glob in the space-separated list is passed to "istarget"; if
-#       it evaluates true for any of them, the test will be run, otherwise
-#       it will be marked unsupported.
+#   target: GLOB|PROC ...
+#      Run this test only on a specified list of targets.  More precisely,
+#      in the space-separated list each glob is passed to "istarget" and
+#      each proc is called as a TCL procedure.  List items are interpreted
+#      such that procs are denoted by surrounding square brackets, and any
+#      other items are consired globs.  If the call evaluates true for any
+#      of them, the test will be run, otherwise it will be marked
+#      unsupported.
 #
-#   not-target: GLOBS...
-#       Do not run this test on a specified list of targets.  Again,
-#       the each glob in the space-separated list is passed to
-#       "istarget", and the test is run if it evaluates *false* for
-#       *all* of them.  Otherwise it will be marked unsupported.
+#   notarget: GLOB|PROC ...
+#      Do not run this test on a specified list of targets.  Again, each
+#      glob in the space-separated list is passed to "istarget" and each
+#      proc is called as a TCL procedure, and the test is run if it
+#      evaluates *false* for *all* of them.  Otherwise it will be marked
+#      unsupported.
 #
-#   skip: GLOBS...
-#   not-skip: GLOBS...
-#       These are exactly the same as "not-target" and "target",
+#   skip: GLOB|PROC ...
+#   noskip: GLOB|PROC ...
+#       These are exactly the same as "notarget" and "target",
 #       respectively, except that they do nothing at all if the check
 #       fails.  They should only be used in groups, to construct a single
 #       test which is run on all targets but with variant options or
 #       expected output on some targets.  (For example, see
 #       gas/arm/inst.d and gas/arm/wince_inst.d.)
 #
+#   xfail: GLOB|PROC ...
+#      Run this test and it is is expected to fail on a specified list
+#      of targets.
+#
 #   error: REGEX
 #      An error with message matching REGEX must be emitted for the test
-#      to pass.  The PROG, objdump, nm and objcopy options have no
-#      meaning and need not supplied if this is present.
+#      to pass.  The PROG, addr2line, nm, objdump, and readelf options
+#      have no meaning and need not supplied if this is present.
 #
 #   warning: REGEX
 #      Expect a gas warning matching REGEX.  It is an error to issue
@@ -513,12 +423,12 @@ proc run_dump_tests { testcases {extra_options {}} } {
 #   stderr: FILE
 #       FILE contains regexp lines to be matched against the diagnostic
 #       output of the assembler.  This does not preclude the use of
-#       PROG, nm, objdump, or objcopy.
+#       PROG, addr2line, nm, objdump, or readelf.
 #
 #   error-output: FILE
 #       Means the same as 'stderr', but also indicates that the assembler
-#       is expected to exit unsuccessfully (therefore PROG, objdump, nm,
-#       and objcopy have no meaning and should not be supplied).
+#       is expected to exit unsuccessfully (therefore PROG, addr2line, nm,
+#      objdump, and readelf have no meaning and should not be supplied).
 #
 #   section-subst: no
 #       Means that the section substitution for objdump is disabled.
@@ -527,8 +437,8 @@ proc run_dump_tests { testcases {extra_options {}} } {
 #
 # 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
@@ -554,7 +464,6 @@ proc run_dump_test { name {extra_options {}} } {
     set opts(as) {}
     set opts(objdump) {}
     set opts(nm) {}
-    set opts(objcopy) {}
     set opts(readelf) {}
     set opts(name) {}
     set opts(PROG) {}
@@ -565,9 +474,10 @@ proc run_dump_test { name {extra_options {}} } {
     set opts(error-output) {}
     set opts(warning) {}
     set opts(target) {}
-    set opts(not-target) {}
+    set opts(notarget) {}
     set opts(skip) {}
-    set opts(not-skip) {}
+    set opts(noskip) {}
+    set opts(xfail) {}
     set opts(section-subst) {}
 
     foreach i $opt_array {
@@ -634,7 +544,6 @@ proc run_dump_test { name {extra_options {}} } {
                addr2line { set program addr2line }
                objdump { set program objdump }
                nm      { set program nm }
-               objcopy { set program objcopy }
                readelf { set program readelf }
                default {
                    perror "unrecognized program option $opts(PROG) in $file.d"
@@ -643,7 +552,7 @@ proc run_dump_test { name {extra_options {}} } {
            }
        } else {
            # Guess which program to run, by seeing which option was specified.
-           foreach p {objdump objcopy nm readelf addr2line} {
+           foreach p {objdump nm readelf addr2line} {
                if {$opts($p) != ""} {
                    if {$program != ""} {
                        perror "ambiguous dump program in $file.d"
@@ -663,22 +572,22 @@ proc run_dump_test { name {extra_options {}} } {
     }
 
     # Handle skipping the test on specified targets.
-    # You can have both skip/not-skip and target/not-target, but you can't
-    # have both skip and not-skip, or target and not-target, in the same file.
+    # You can have both skip/noskip and target/notarget, but you can't
+    # have both skip and noskip, or target and notarget, in the same file.
     if { $opts(skip) != "" } then {
-       if { $opts(not-skip) != "" } then {
-           perror "$testname: mixing skip and not-skip directives is invalid"
+       if { $opts(noskip) != "" } then {
+           perror "$testname: mixing skip and noskip directives is invalid"
            unresolved $testname
            return
        }
        foreach glob $opts(skip) {
-           if {[istarget $glob]} { return }
+           if {[match_target $glob]} { return }
        }
     }
-    if { $opts(not-skip) != "" } then {
+    if { $opts(noskip) != "" } then {
        set skip 1
-       foreach glob $opts(not-skip) {
-           if {[istarget $glob]} { 
+       foreach glob $opts(noskip) {
+           if {[match_target $glob]} {
                set skip 0
                break
            }
@@ -686,32 +595,36 @@ proc run_dump_test { name {extra_options {}} } {
        if {$skip} { return }
     }
     if { $opts(target) != "" } then {
-       if { $opts(not-target) != "" } then {
-           perror "$testname: mixing target and not-target directives is invalid"
+       if { $opts(notarget) != "" } then {
+           perror "$testname: mixing target and notarget directives is invalid"
            unresolved $testname
            return
        }
        set skip 1
        foreach glob $opts(target) {
-           if {[istarget $glob]} { 
+           if {[match_target $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]} {
+    if { $opts(notarget) != "" } then {
+       foreach glob $opts(notarget) {
+           if {[match_target $glob]} {
                unsupported $testname
-               return 
+               return
            }
        }
     }
 
+    # Setup xfailures.
+    foreach targ $opts(xfail) {
+       setup_xfail $targ
+    }
 
     if { $opts(source) == "" } {
        set sourcefile ${file}.s
@@ -779,7 +692,7 @@ proc run_dump_test { name {extra_options {}} } {
            }
            set stderrfile $srcdir/$subdir/$opts(stderr)
            verbose "wrote pruned stderr to dump.stderr" 3
-           if { [regexp_diff "dump.stderr" "$stderrfile" ""] } then {
+           if { [regexp_diff "dump.stderr" "$stderrfile"] } then {
                if { $opts(error) != "" } {
                    verbose -log "$exitstat with: <$comp_output>, expected: <$opts(error)>"
                    if [regexp $opts(error) $comp_output] {
@@ -825,28 +738,11 @@ proc run_dump_test { name {extra_options {}} } {
     if { $progopts1 == "" } { set $progopts1 "-r" }
     verbose "running $binary $progopts $progopts1" 3
 
-    # 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"
     set redir ">dump.out"
-    if { $program == "objcopy" } {
-       set cmd "$binary $progopts $progopts1 dump.o dump.out"
-       set redir ""
-    }
-
-    # Ensure consistent sorting of symbols
-    if {[info exists env(LC_ALL)]} {
-       set old_lc_all $env(LC_ALL)
-    }
-    set env(LC_ALL) "C"
     send_log "$cmd\n"
     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 {
-       unset env(LC_ALL)
-    }
     set comp_output [prune_warnings $comp_output]
     if ![string match "" $comp_output] then {
        send_log "$comp_output\n"
@@ -939,120 +835,6 @@ expect_after -i {
     eof                                { perror "eof" }
 }
 
-# regexp_diff, based on simple_diff taken from ld test suite.
-#      Compares two files line-by-line.
-#      FILE_1 contains strings, FILE_2 contains regexps and #-comments
-#      Blank lines are ignored in either file.
-#      Subsitutions in REF_SUBST are applied on FILE_2 lines.
-#      Returns non-zero if differences exist.
-#
-proc regexp_diff { file_1 file_2 ref_subst} {
-
-    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 } {
-            # Ignore blank line in FILE_1.
-           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
-               }
-                # Substitute on the reference.
-                foreach {name value} $ref_subst {
-                    regsub -- $name $line_b $value line_b
-                }
-               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 {
-            # Substitute on the reference.
-            foreach {name value} $ref_subst {
-                regsub -- $name $line_b $value line_b
-            }
-            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]
@@ -1108,7 +890,7 @@ proc run_list_test { name {opts {}} {testname {}} } {
     }
     set file $srcdir/$subdir/$name
     gas_run ${name}.s $opts ">&dump.out"
-    if { [regexp_diff "dump.out" "${file}.l" ""] } then {
+    if { [regexp_diff "dump.out" "${file}.l"] } then {
        fail $testname
        verbose "output is [file_contents "dump.out"]" 2
        return
@@ -1127,7 +909,7 @@ proc run_list_test_stdin { name {opts {}} {testname {}} } {
     }
     set file $srcdir/$subdir/$name
     gas_run_stdin ${name}.s $opts ">&dump.out"
-    if { [regexp_diff "dump.out" "${file}.l" ""] } then {
+    if { [regexp_diff "dump.out" "${file}.l"] } then {
        fail $testname
        verbose "output is [file_contents "dump.out"]" 2
        return