OSDN Git Service

* libjava.loader/loader.exp (gcj_loader_test_one): Use
[pf3gnuchains/gcc-fork.git] / libjava / testsuite / lib / libjava.exp
index 9b45f3c..a807c4c 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
+# Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation
 
 load_lib "libgloss.exp"
 
@@ -10,6 +10,22 @@ if ![info exists tmpdir] {
     set tmpdir "/tmp"
 }
 
+# This is like `prune_warnings', but it also prunes away a warning
+# from the bytecode front end that we don't care about.
+proc libjava_prune_warnings {text} {
+    set text [prune_warnings $text]
+    set tlist [split $text \n]
+    set len [llength $tlist]
+    for {set i [expr {$len - 1}]} {$i >= 2} {incr i -1} {
+       if {[string match "*unreachable bytecode*" [lindex $tlist $i]]} {
+           # Delete this line and the previous two lines.
+           set tlist [lreplace $tlist [expr {$i - 2}] $i]
+           incr i -2
+       }
+    }
+    return [join $tlist \n]
+}
+
 # This is like `target_compile' but it does some surgery to work
 # around stupid DejaGNU bugs.  In particular DejaGNU has very poor
 # quoting, so for instance a `$' will be re-evaluated at spawn time.
@@ -112,6 +128,9 @@ proc libjava_init { args } {
     global TOOL_EXECUTABLE
     global original_ld_library_path
     global env objdir
+    global env libgcj_jar
+    global tool_root_dir
+    global libjava_libgcc_s_path
 
     if { $libjava_initialized == 1 } { return; }
 
@@ -127,8 +146,17 @@ proc libjava_init { args } {
        }
     }
 
+    # Find the libgcj jar file.
+    set libgcj_jar [glob $objdir/../libgcj-*.jar]
+    verbose "jar file is $libgcj_jar"
+
+    # FIXME: This finds libgcj.spec for the default multilib.
+    # If thread models differ between multilibs, this has to be moved
+    # to libjava_arguments
+    set specdir [libjava_find_spec]
+
     # The -B is so we find libgcj.spec.
-    set text [eval exec "$GCJ_UNDER_TEST -B$objdir/../ -v 2>@ stdout"]
+    set text [eval exec "$GCJ_UNDER_TEST -B$specdir -v 2>@ stdout"]
     regexp -- "Thread model: (\[^\n\]+)\n" $text ignore model
     set libjava_uses_threads [expr {! ($model == "no"
                                       || $model == "none"
@@ -159,6 +187,29 @@ proc libjava_init { args } {
        }
     }
 
+    # Finally, add the gcc build directory so that we can find the
+    # shared libgcc.  This, like much of dejagnu, is hideous.
+    set libjava_libgcc_s_path {}
+    set gccdir [lookfor_file $tool_root_dir gcc/libgcc_s.so]
+    if {$gccdir != ""} {
+       set gccdir [file dirname $gccdir]
+       lappend libjava_libgcc_s_path $gccdir
+       set compiler ${gccdir}/xgcc
+       if { [is_remote host] == 0 && [which $compiler] != 0 } {
+           foreach i "[exec $compiler --print-multi-lib]" {
+               set mldir ""
+               regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
+               set mldir [string trimright $mldir "\;@"]
+               if { "$mldir" == "." } {
+                   continue
+               }
+               if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] == 1 } {
+                   lappend libjava_libgcc_s_path "${gccdir}/${mldir}"
+               }
+           }
+       }
+    }
+
     set libjava_initialized 1
 }
 
@@ -169,17 +220,26 @@ proc libjava_init { args } {
 # find the appropriate libraries so we must add -L options for their
 # paths.  However we can't simply use those libraries; we still need
 # libtool for linking.
+# Don't return the the lib${name}.la files here, since this causes the
+# libraries to be linked twice: once as lib${name}.so and another time
+# via gcj's implicit -l${name}.  This is both unnecessary and causes the
+# Solaris ld to warn: attempted multiple inclusion of file.  This warning
+# is not ignored by the dejagnu framework and cannot be disabled.
 proc libjava_find_lib {dir name} {
     global base_dir
     set gp [get_multilibs]
     foreach sub {.libs _libs} {
        if {$gp != ""} {
            if {[file exists $gp/$dir/$sub/lib${name}.a]} then {
-               return "$gp/$dir/lib${name}.la -L$gp/$dir/$sub"
+               # Just return the `-L' option.  The library itself
+               # will be picked up via the spec file.
+               return "-L$gp/$dir/$sub"
            }
        }
+       # Just return the `-L' option.  The library itself will be
+       # picked up via the spec file.
        set lib [findfile $base_dir/../../$dir/$sub/lib${name}.a \
-                  "$base_dir/../../$dir/lib${name}.la -L$base_dir/../../$dir/$sub" \
+                  "-L$base_dir/../../$dir/$sub" \
                   ""]
        if {$lib != ""} {
            return $lib
@@ -188,6 +248,35 @@ proc libjava_find_lib {dir name} {
     return ""
 }
 
+# Find libgcj.spec.  We need to use the file corresponding to the multilib
+# under test since they might differ.  Append a trailing slash since this
+# is used with -B.
+proc libjava_find_spec {} {
+    global objdir
+    set gp [get_multilibs]
+
+    if {[file exists $gp/libjava/libgcj.spec]} then {
+       return "$gp/libjava/"
+    }
+    return "$objdir/../"
+}
+
+# Find `gij'.
+proc libjava_find_gij {} {
+    global base_dir
+    set gp [get_multilibs]
+    if {$gp != ""} {
+       set file $gp/libjava/gij
+    } else {
+       set file $base_dir/../gij
+    }
+
+    if {[file exists $file]} {
+       return $file
+    }
+    return gij
+}
+
 # Remove a bunch of files.
 proc gcj_cleanup {args} {
     foreach file $args {
@@ -218,6 +307,8 @@ proc libjava_arguments {{mode compile}} {
     global runtests
     global env
     global tool_root_dir
+    global libgcj_jar
+    global libjava_libgcc_s_path
 
     if [info exists LIBJAVA] {
        set libjava $LIBJAVA;
@@ -267,13 +358,7 @@ proc libjava_arguments {{mode compile}} {
        }
     }
 
-    # Finally, add the gcc build directory so that we can find the
-    # shared libgcc.  This, like much of dejagnu, is hideous.
-    set gccdir [lookfor_file $tool_root_dir gcc/libgcc_s.so]
-    if {$gccdir != ""} {
-       lappend lpath [file dirname $gccdir]
-    }
-
+    set lpath [concat $lpath $libjava_libgcc_s_path]
     set ld_library_path [join $lpath :]
 
     # That's enough to make things work for the normal case.
@@ -288,18 +373,20 @@ proc libjava_arguments {{mode compile}} {
     verbose "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
 
     # Set the CLASSPATH environment variable
-    verbose "CLASSPATH is .:$srcdir/$subdir:$objdir:$objdir/../libgcj.jar"
+    verbose "CLASSPATH is .:$srcdir/$subdir:$objdir:$libgcj_jar"
     global env
-    set env(CLASSPATH) ".:$srcdir/$subdir:$objdir:$objdir/../libgcj.jar"
+    set env(CLASSPATH) ".:$srcdir/$subdir:$objdir:$libgcj_jar"
 
-    global wrapper_file wrap_compile_flags;
-    lappend args "additional_flags=$wrap_compile_flags";
-    lappend args "libs=$wrapper_file";
-    lappend args "libs=$libjava";
-    lappend args "libs=$libgc";
-    lappend args "libs=$libqthreads"
-    lappend args "libs=$libz"
-    lappend args debug
+    if {$mode == "link"} {
+       global wrapper_file wrap_compile_flags;
+       lappend args "additional_flags=$wrap_compile_flags";
+       lappend args "libs=$wrapper_file";
+       lappend args "libs=$libjava";
+       lappend args "libs=$libgc";
+       lappend args "libs=$libqthreads"
+       lappend args "libs=$libz"
+       lappend args debug
+    }
 
     if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
        lappend args "libs=${gluefile}"
@@ -310,6 +397,9 @@ proc libjava_arguments {{mode compile}} {
        lappend args "additional_flags=$TOOL_OPTIONS"
     }
 
+    # Determine libgcj.spec corresponding to multilib under test.
+    set specdir [libjava_find_spec]
+
     # Search for libtool.  We need it to link.
     set found_compiler 0
     set d [absolute $objdir]
@@ -317,20 +407,23 @@ proc libjava_arguments {{mode compile}} {
        if {[file exists $d/$x/libtool]} then {
            # We have to run silently to avoid DejaGNU lossage.
            lappend args \
-             "compiler=$d/$x/libtool --silent --tag=GCJ --mode=$mode $GCJ_UNDER_TEST -B$objdir/../"
+             "compiler=$d/$x/libtool --silent --tag=GCJ --mode=$mode $GCJ_UNDER_TEST -B$specdir"
            set found_compiler 1
            break
        }
     }
     if {! $found_compiler} {
-       # Append -B$objdir/../ so that we find libgcj.spec before it
+       # Append -B$specdir so that we find libgcj.spec before it
        # is installed.
-       lappend args "compiler=$GCJ_UNDER_TEST -B$objdir/../"
+       lappend args "compiler=$GCJ_UNDER_TEST -B$specdir"
     }
 
     # Avoid libtool wrapper scripts when possible.
+    # but not if libtool warnings results in FAILs
     if {$mode == "link"} {
-        lappend args "additional_flags=-no-install"
+        if {! [istarget "*-*-cygwin*"] && ! [istarget "*-*-mingw*"] } {
+            lappend args "additional_flags=-no-install"
+        }
     }
 
     return $args
@@ -344,8 +437,8 @@ proc gcj_link {program main files {options {}}} {
        eval lappend arguments $options
     }
     lappend arguments "additional_flags=--main=$main"
-    set x [prune_warnings [libjava_tcompile $files $program executable \
-                            $arguments]]
+    set x [libjava_prune_warnings \
+            [libjava_tcompile $files $program executable $arguments]]
     if {$x != ""} {
        verbose "link failure: $x" 2
        fail "linking $program"
@@ -358,6 +451,73 @@ proc gcj_link {program main files {options {}}} {
     return 1
 }
 
+# Invoke a program and check its output.  EXECUTABLE is the program;
+# ARGS are the arguments to the program.  Returns 1 if tests passed
+# (or things were left untested), 0 otherwise.
+proc libjava_invoke {errname testName optName executable inpfile resultfile args} {
+    upvar $optName opts
+
+    if {[info exists opts(no-exec)]} {
+       if {[info exists opts(need-threads)]} {
+           # This means we wanted to try to run it but we couldn't
+           # because threads aren't supported.  So we have to
+           # generate an `untested'.
+           untested "$errname execution - $testName"
+           untested "$errname output - $testName"
+       }
+       return 1
+    }
+
+    set result [libjava_load $executable $args "$inpfile"]
+    set status [lindex $result 0]
+    set output [lindex $result 1]
+    if {[info exists opts(xfail-exec)]} then {
+       setup_xfail *-*-*
+    }
+    $status "$errname execution - $testName"
+    if { $status != "pass" } {
+       untested "$errname output - $testName"
+       return 0
+    }
+
+    verbose "resultfile is $resultfile"
+    set id [open $resultfile r]
+    set expected ""
+    append expected [read $id]
+    regsub -all "\r" "$output" "" output
+    regsub "\n*$" $expected "" expected
+    regsub "\n*$" $output "" output
+    regsub "^\n*" $expected "" expected
+    regsub "^\n*" $output "" output
+    regsub -all "\[ \t\]\[ \t\]*" $expected " " expected
+    regsub -all "\[ \t\]*\n\n*" $expected "\n" expected
+    regsub -all "\[ \t\]\[ \t\]*" $output " " output
+    regsub -all "\[ \t\]*\n\n*" $output "\n" output
+    verbose "expected is $expected"
+    verbose "actual is $output"
+    set passed 0
+    if {[info exists opts(regexp_match)]} {
+       if [regexp $expected $output] {
+           set passed 1
+       }
+    } else {
+       if { $expected == $output } {
+           set passed 1
+       }
+    }
+    if {[info exists opts(xfail-output)]} {
+       setup_xfail *-*-*
+    }
+    if { $passed == 1 } {
+       pass "$errname output - $testName"
+    } else {
+       fail "$errname output - $testName"
+    }
+    close $id
+
+    return $passed
+}
+
 #
 # Run the test specified by srcfile and resultfile. compile_args and
 # exec_args are options telling this proc how to work.
@@ -413,6 +573,10 @@ proc test_libjava_from_source { options srcfile compile_args inpfile resultfile
        append executable ".o"
        set target object
     } else {
+        # DOS/win32 targets default to .exe if no suffix is given
+        # We then try to delete a file that doesn't exist.  It is
+        # simpler to add the suffix everywhere.
+        append executable ".exe"
        set target executable
     }
     if { $compile_args != "" } {
@@ -421,7 +585,7 @@ proc test_libjava_from_source { options srcfile compile_args inpfile resultfile
 
     set removeList [list $executable]
 
-    set x [prune_warnings \
+    set x [libjava_prune_warnings \
             [libjava_tcompile $srcfile "$executable" $target $args]]
     if {[info exists opts(xfail-gcj)]} {
        setup_xfail *-*-*
@@ -450,71 +614,15 @@ proc test_libjava_from_source { options srcfile compile_args inpfile resultfile
     }
     pass "$errname compilation from source"
 
-    if {[info exists opts(no-exec)]} {
-       if {[info exists opts(need-threads)]} {
-           # This means we wanted to try to run it but we couldn't
-           # because threads aren't supported.  So we have to
-           # generate an `untested'.
-           untested "$errname execution from source compiled test"
-           untested "$errname output from source compiled test"
-       }
-       eval gcj_cleanup $removeList
-       return
-    }
-    if {[info exists opts(no-link)]} {
-       eval gcj_cleanup $removeList
-       return
-    }
-
-    set result [libjava_load $executable "" "$inpfile"];
-    set status [lindex $result 0];
-    set output [lindex $result 1];
-    if {[info exists opts(xfail-exec)]} then {
-       setup_xfail *-*-*
-    }
-    $status "$errname execution from source compiled test"
-    if { $status != "pass" } {
-       untested "$errname output from source compiled test"
-       return;
-    }
-
-    verbose "resultfile is $resultfile"
-    set id [open $resultfile r];
-    set expected ""
-    append expected [read $id];
-    regsub -all "\r" "$output" "" output;
-    regsub "\n*$" $expected "" expected
-    regsub "\n*$" $output "" output
-    regsub "^\n*" $expected "" expected
-    regsub "^\n*" $output "" output
-    regsub -all "\[ \t\]\[ \t\]*" $expected " " expected
-    regsub -all "\[ \t\]*\n\n*" $expected "\n" expected
-    regsub -all "\[ \t\]\[ \t\]*" $output " " output
-    regsub -all "\[ \t\]*\n\n*" $output "\n" output
-    verbose "expected is $expected"
-    verbose "actual is $output"
-    set passed 0;
-    if {$options == "regexp_match"} {
-       if [regexp $expected $output] {
-           set passed 1;
-       }
-    } else {
-       if { $expected == $output } {
-           set passed 1;
-       }
-    }
-    if {[info exists opts(xfail-output)]} {
-       setup_xfail *-*-*
+    # Set up the options the way they are expected by libjava_invoke.
+    if {[info exists opts(xfail-source-output)]} {
+       set opts(xfail-output) x
     }
-    if { $passed == 1 } {
-       pass "$errname output from source compiled test"
+    if {[libjava_invoke $errname "source compiled test" opts $executable \
+          $inpfile $resultfile]} {
+       # Everything ok, so clean up.
        eval gcj_cleanup $removeList
-    } else {
-       clone_output "expected was $expected"
-       clone_output "output was $output"
-       fail "$errname output from source compiled test"
     }
-    close $id;
 }
 
 #
@@ -530,6 +638,7 @@ proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile e
     global GCJ_UNDER_TEST
     global tmpdir
     global runtests
+    global INTERPRETER
 
     # Make opts into an array.
     set opts(_) x
@@ -590,11 +699,11 @@ proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile e
     set jvscan [find_jvscan]
     verbose "jvscan is $jvscan"
     set main_name [string trim \
-                    [prune_warnings \
+                    [libjava_prune_warnings \
                        [lindex [local_exec "$jvscan --encoding=UTF-8 $srcfile --print-main" "" "" 300] 1]]]
     verbose "main name is $main_name"
     set class_out [string trim \
-                    [prune_warnings \
+                    [libjava_prune_warnings \
                        [lindex [local_exec "$jvscan --encoding=UTF-8 $srcfile --list-class" "" "" 300] 1]]]
     verbose "class list is $class_out"
 
@@ -636,10 +745,23 @@ proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile e
     } else {
        set type executable
        lappend largs "additional_flags=--main=$main_name"
-       set executable "${objdir}/$main_name"
+       # DOS/win32 targets default to .exe if no suffix is given
+        # We then try to delete a file that doesn't exist.  It is
+       # simpler to add the suffix everywhere.
+       set executable "${objdir}/${main_name}.exe"
        set mode link
     }
 
+    # We purposely ignore errors here; we still want to run the other
+    # appropriate tests.
+    set gij [libjava_find_gij]
+    # libjava_find_gij will return `gij' if it couldn't find the
+    # program; in this case we want to skip the test.
+    if {$INTERPRETER == "yes" && $gij != "gij"} {
+       libjava_invoke $errname "gij test" opts $gij \
+         $inpfile $resultfile $main_name
+    }
+
     # Initial arguments.
     set args [libjava_arguments $mode]
     eval lappend args $largs
@@ -659,7 +781,7 @@ proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile e
     if {$mode == "compile"} {
        foreach c_file $class_files {
            set executable [file rootname [file tail $c_file]].o
-           set x [prune_warnings \
+           set x [libjava_prune_warnings \
                     [libjava_tcompile $c_file "$executable" $type $args]]
            lappend removeList $executable
            if {$x != ""} {
@@ -675,7 +797,7 @@ proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile e
            set hack "$hack $stupid"
        }
        lappend removeList $executable
-       set x [prune_warnings \
+       set x [libjava_prune_warnings \
                 [libjava_tcompile $hack "$executable" $type $args]]
     }
     if {[info exists opts(xfail-byte)]} {
@@ -693,64 +815,15 @@ proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile e
     }
     pass "$errname compilation from bytecode"
 
-    if {[info exists opts(no-exec)]} {
-       if {[info exists opts(need-threads)]} {
-           untested "$errname execution from bytecode->native test"
-           untested "$errname output from bytecode->native test"
-       }
-       eval gcj_cleanup $removeList
-       return
+    # Set up the options the way they are expected by libjava_invoke.
+    if {[info exists opts(xfail-byte-output)]} {
+       set opts(xfail-output) x
     }
-
-    set result [libjava_load $executable "" "$inpfile"];
-    set status [lindex $result 0];
-    set output [lindex $result 1];
-    if {[info exists opts(xfail-exec)]} {
-       setup_xfail *-*-*
-    }
-    $status "$errname execution from bytecode->native test"
-    if { $status != "pass" } {
-       untested "$errname output from bytecode->native test"
-       return
-    }
-
-    verbose "resultfile is $resultfile"
-    set id [open $resultfile r];
-    set expected ""
-    append expected [read $id];
-    regsub -all "\r" "$output" "" output;
-    regsub "\n*$" $expected "" expected
-    regsub "\n*$" $output "" output
-    regsub "^\n*" $expected "" expected
-    regsub "^\n*" $output "" output
-    regsub -all "\[ \t\]\[ \t\]*" $expected " " expected
-    regsub -all "\[ \t\]*\n\n*" $expected "\n" expected
-    regsub -all "\[ \t\]\[ \t\]*" $output " " output
-    regsub -all "\[ \t\]*\n\n*" $output "\n" output
-    verbose "expected is $expected"
-    verbose "actual is $output"
-    set passed 0;
-    if {[info exists opts(xfail-output)]} {
-       setup_xfail *-*-*
-    }
-    if {$options == "regexp_match"} {
-       if [regexp $expected $output] {
-           set passed 1;
-       }
-    } else {
-       if { $expected == $output } {
-           set passed 1;
-       }
-    }
-    if { $passed == 1 } {
-       pass "$errname output from bytecode->native test"
+    if {[libjava_invoke $errname "bytecode->native test" opts $executable \
+          $inpfile $resultfile]} {
+       # Everything ok, so clean up.
        eval gcj_cleanup $removeList
-    } else {
-       clone_output "expected was $expected"
-       clone_output "output was $output"
-       fail "$errname output from bytecode->native test"
     }
-    close $id;
 }
 
 #
@@ -763,13 +836,17 @@ proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile e
 #   `xfail-gcjC'  compilation with gcj -C will fail
 #   `shouldfail'  compilation from source is supposed to fail
 #                 This is different from xfail, which marks a known
-#                 failure that we just havne't fixed.
+#                 failure that we just haven't fixed.
 #                 A compilation marked this way should fail with any
 #                 front end.
 #   `xfail-byte'  compilation from bytecode will fail
 #   `xfail-exec'  exec will fail
 #   `xfail-output'
 #                 output will be wrong
+#   `xfail-byte-output'
+#                 output will be wrong when compiled from bytecode
+#   `xfail-source-output'
+#                 output will be wrong when compiled from source code
 #   `need-threads'
 #                 test relies on thread support
 #