1 # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007 Free Software Foundation
3 proc load_gcc_lib { filename } {
5 load_file $srcdir/../../gcc/testsuite/lib/$filename
9 load_gcc_lib target-libpath.exp
11 # GCJ_UNDER_TEST is the compiler under test.
15 if ![info exists tmpdir] {
19 # This is like `prune_warnings', but it also prunes away a warning
20 # from the bytecode front end that we don't care about.
21 proc libjava_prune_warnings {text} {
22 set text [prune_warnings $text]
23 set tlist [split $text \n]
24 set len [llength $tlist]
25 for {set i [expr {$len - 1}]} {$i >= 2} {incr i -1} {
26 if {[string match "*unreachable bytecode*" [lindex $tlist $i]]} {
27 # Delete this line, all other unreachable warnings and the previous
28 # two lines containing the method and class.
30 while {[string match "*unreachable bytecode*" [lindex $tlist $j]]} {
34 set tlist [lreplace $tlist $j $i]
38 return [join $tlist \n]
41 # This is like `target_compile' but it does some surgery to work
42 # around stupid DejaGNU bugs. In particular DejaGNU has very poor
43 # quoting, so for instance a `$' will be re-evaluated at spawn time.
45 proc libjava_tcompile {source destfile type options} {
46 # This strange-looking expression really does quote the `$'.
47 regsub -all -- {\$} $source {\$} source
48 regsub -all -- {\$} $destfile {\$} destfile
49 return [target_compile $source $destfile $type $options]
52 # Read an `xfail' file if it exists. Returns a list of xfail tokens.
53 proc libjava_read_xfail {file} {
54 if {! [file exists $file]} {
58 set tokens [string trim [read $fd]]
63 # Find a particular executable. FIXME: this relies on DejaGnu
64 # internals. These should probably be exposed in a better way.
65 proc libjava_find_program {prog} {
68 set file [lookfor_file $tool_root_dir $prog]
70 set file [lookfor_file $tool_root_dir gcc/$prog];
80 return [libjava_find_program gjavah]
84 global SUN_JAVAC GCJ_UNDER_TEST env libgcj_jar
85 # If JDK doesn't run on your platform but some other
86 # JDK-compatible javac does, you may set SUN_JAVAC to point to it.
87 # One of the most important properties of a SUN_JAVAC is that it
88 # must create class-files even for classes that have not been
89 # specified in the command line, but that were needed to compile
90 # those that have. For example, Pizza won't do it, but you can
91 # use `kaffe sun.tools.javac.Main', if you have Sun's classes.zip
92 # in the kaffe's default search path.
93 if {![info exists SUN_JAVAC]} {
94 if {[info exists env(SUN_JAVAC)]} {
95 set SUN_JAVAC $env(SUN_JAVAC)
97 set SUN_JAVAC "$GCJ_UNDER_TEST -C -I$libgcj_jar"
103 proc bytecompile_file { file objdir {classpath {}} } {
105 set dirname [file dirname $file]
107 set javac [find_javac]
108 if {$classpath != ""} then {
109 set env(CLASSPATH) $classpath
113 send_log "byte compile: $javac -g [list $file] -d $objdir 2>@ stdout\n"
115 set q [eval exec "$javac -g [list $file] -d $objdir 2>@ stdout"]
117 send_log "couldn't compile $file: $msg\n"
126 set libjava_initialized 0
129 # Build the status wrapper library as needed.
131 proc libjava_init { args } {
133 global wrap_compile_flags;
134 global libjava_initialized libjava_uses_threads
135 global GCJ_UNDER_TEST
136 global TOOL_EXECUTABLE
138 global env libgcj_jar
140 global libjava_libgcc_s_path
141 global target_triplet
142 global libjava_version
144 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
148 if { $libjava_initialized == 1 } { return; }
150 if ![info exists GCJ_UNDER_TEST] {
151 if [info exists TOOL_EXECUTABLE] {
152 set GCJ_UNDER_TEST $TOOL_EXECUTABLE;
154 if [info exists env(GCJ)] {
155 set GCJ_UNDER_TEST $env(GCJ)
157 set GCJ_UNDER_TEST "[find_gcj]"
162 # Find the libgcj jar file.
164 # FIXME: This finds libgcj.spec for the default multilib.
165 # If thread models differ between multilibs, this has to be moved
166 # to libjava_arguments
167 set specdir [libjava_find_spec]
169 set text [eval exec "$GCJ_UNDER_TEST -B$specdir -v 2>@ stdout"]
170 regexp " version \[^\n\r\]*" $text version
171 set libjava_version [lindex $version 1]
173 verbose "version: $libjava_version"
175 set libgcj_jar [glob $objdir/../libgcj-$libjava_version.jar]
176 verbose "jar file is $libgcj_jar"
178 # The -B is so we find libgcj.spec.
179 regexp -- "Thread model: (\[^\n\]+)\n" $text ignore model
180 set libjava_uses_threads [expr {! ($model == "no"
182 || $model == "single")}]
184 # Always set encoding used by gcj.
185 append GCJ_UNDER_TEST " --encoding=UTF-8"
188 set wrap_compile_flags "";
189 if [target_info exists needs_status_wrapper] {
190 set result [build_wrapper "testglue.o"];
191 if { $result != "" } {
192 set wrapper_file [lindex $result 0];
193 set wrap_compile_flags [lindex $result 1];
195 warning "Status wrapper failed to build."
199 # Finally, add the gcc build directory so that we can find the
200 # shared libgcc. This, like much of dejagnu, is hideous.
201 set libjava_libgcc_s_path {}
203 if { [istarget "*-*-darwin*"] } {
204 set so_extension "dylib"
205 } elseif { [istarget "*-*-cygwin*"] || [istarget "*-*-mingw*"] } {
206 set so_extension "dll"
208 set so_extension "so"
210 set gccdir [lookfor_file $tool_root_dir gcc/libgcc_s.${so_extension}]
212 set gccdir [file dirname $gccdir]
213 lappend libjava_libgcc_s_path $gccdir
214 verbose "libjava_libgcc_s_path = $libjava_libgcc_s_path"
215 set compiler ${gccdir}/xgcc
216 if { [is_remote host] == 0 && [which $compiler] != 0 } {
217 foreach i "[exec $compiler --print-multi-lib]" {
219 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
220 set mldir [string trimright $mldir "\;@"]
221 if { "$mldir" == "." } {
224 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.${so_extension}.*]] >= 1 } {
225 lappend libjava_libgcc_s_path "${gccdir}/${mldir}"
231 set libjava_initialized 1
234 # Find a library. We know where libtool puts the actual libraries,
235 # and we look there. The implementation is fairly hacky. We can't
236 # compile with -nodefaultlibs, because that will also eliminate the
237 # system libraries we need. In order to have gcj still work, it must
238 # find the appropriate libraries so we must add -L options for their
239 # paths. However we can't simply use those libraries; we still need
240 # libtool for linking.
241 # Don't return the the lib${name}.la files here, since this causes the
242 # libraries to be linked twice: once as lib${name}.so/dylib and another time
243 # via gcj's implicit -l${name}. This is both unnecessary and causes the
244 # Solaris ld to warn: attempted multiple inclusion of file. This warning
245 # is not ignored by the dejagnu framework and cannot be disabled.
246 proc libjava_find_lib {dir name} {
248 set gp [get_multilibs]
249 foreach extension {so dll dylib sl a} {
250 foreach sub {.libs _libs} {
252 if {[file exists $gp/$dir/$sub/lib${name}.${extension}]} then {
253 # Just return the `-L' option. The library itself
254 # will be picked up via the spec file.
255 return "-L$gp/$dir/$sub"
258 # Just return the `-L' option. The library itself will be
259 # picked up via the spec file.
261 $base_dir/../../$dir/$sub/lib${name}.${extension} \
262 "-L$base_dir/../../$dir/$sub" \
272 # Find libgcj.spec. We need to use the file corresponding to the multilib
273 # under test since they might differ. Append a trailing slash since this
275 proc libjava_find_spec {} {
280 # Find `gij'. Return empty string if not found.
281 proc libjava_find_gij {} {
282 global base_dir objdir
284 set gijdir [lookfor_file [get_multilibs] libjava];
285 # Fall back if get_multilibs fails.
287 set gijdir "$objdir/.."
289 if {! [file exists $gijdir/gij]} {
295 # Remove a bunch of files.
296 proc gcj_cleanup {args} {
298 if {[string match *.o $file]} {
299 verbose "removing [file rootname $file].lo"
300 file delete -force [file rootname $file].lo
302 file delete -force -- $file
303 verbose "removing $file"
305 # It is simplest to do this instead of trying to figure out what
306 # bits in .libs ought to be removed.
307 catch {system "rm -rf .libs"}
310 # Compute arguments needed for compiler. MODE is a libtool mode:
311 # either compile or link.
312 proc libjava_arguments {{mode compile}} {
315 global srcdir subdir objdir
317 global GCJ_UNDER_TEST
323 global libjava_libgcc_s_path
324 global libjava_ld_library_path
325 global ld_library_path
326 global target_triplet
328 if [info exists LIBJAVA] {
329 set libjava $LIBJAVA;
331 set libjava [libjava_find_lib libjava gcj]
334 verbose "using LIBJAVA = $libjava" 2
337 # Basically we want to build up a colon separated path list from
338 # the value of $libjava.
341 foreach dir [list $libjava] {
342 foreach item [split $dir " "] {
343 switch -glob -- $item {
345 lappend lpath [string range $item 2 end]
351 set lpath [concat $lpath $libjava_libgcc_s_path]
352 verbose "lpath = $lpath ; libgcc_s_path = $libjava_libgcc_s_path"
353 set ld_library_path [join $lpath :]
354 set libjava_ld_library_path "$ld_library_path"
356 # That's enough to make things work for the normal case.
357 # If we wanted to handle an arbitrary value of libjava,
358 # then we'd have to do a lot more work.
360 set_ld_library_path_env_vars
361 if [info exists env(LD_LIBRARY_PATH)] {
362 verbose "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
365 # Determine CLASSPATH separator
366 if { [string match "i?86-pc-mingw32*" $target_triplet] } {
372 # Set the CLASSPATH environment variable
375 [join [list . $srcdir/$subdir $objdir $libgcj_jar] $sep]
376 verbose "CLASSPATH is $env(CLASSPATH)"
378 # Disable all warnings, as ecj is rather chatty.
379 lappend args "additional_flags=-w"
381 if {$mode == "link"} {
382 global wrapper_file wrap_compile_flags
383 lappend args "additional_flags=$wrap_compile_flags"
385 if { [regexp "linux" $target_triplet] } {
386 lappend args "additional_flags=-specs=libgcj-test.spec"
389 lappend args "libs=$wrapper_file"
390 lappend args "libs=$libjava"
394 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
395 lappend args "libs=${gluefile}"
396 lappend args "ldflags=$wrap_flags"
399 if [info exists TOOL_OPTIONS] {
400 lappend args "additional_flags=$TOOL_OPTIONS"
403 # Determine libgcj.spec corresponding to multilib under test.
404 set specdir [libjava_find_spec]
406 # Search for libtool. We need it to link.
408 set d [absolute $objdir]
409 foreach x {. .. ../.. ../../..} {
410 if {[file exists $d/$x/libtool]} then {
411 # We have to run silently to avoid DejaGNU lossage.
413 "compiler=$d/$x/libtool --silent --tag=GCJ --mode=$mode $GCJ_UNDER_TEST -B$specdir"
418 if {! $found_compiler} {
419 # Append -B$specdir so that we find libgcj.spec before it
421 lappend args "compiler=$GCJ_UNDER_TEST -B$specdir"
424 # Avoid libtool wrapper scripts when possible.
425 # but not if libtool warnings results in FAILs
426 if {$mode == "link"} {
427 if {! [istarget "*-*-cygwin*"] && ! [istarget "*-*-mingw*"]
428 && ! [istarget "*-*-darwin*"] } {
429 lappend args "additional_flags=-no-install"
431 if { [istarget "*-*-darwin*"] } {
432 lappend args "additional_flags=-bind_at_load"
433 lappend args "additional_flags=-multiply_defined suppress"
435 if { [istarget "*-*-darwin9*"] || [istarget "*-*-darwin1*"] || [istarget "*-*-darwin2*"] } {
436 lappend args "additional_flags=-Wl,-allow_stack_execute"
444 # Link a bunch of objects into a program. MAIN is the name of the
445 # class holding `main'. Return 0 on failure.
446 proc gcj_link {program main files {options {}}} {
447 set arguments [libjava_arguments link]
448 if {[llength $options]} {
449 eval lappend arguments $options
451 lappend arguments "additional_flags=--main=$main"
452 set x [libjava_prune_warnings \
453 [libjava_tcompile $files $program executable $arguments]]
455 verbose "link failure: $x" 2
456 fail "linking $program"
458 fail "running $program"
462 pass "linking $program"
466 # Invoke the program and see what happens. Return 0 on failure.
467 proc gcj_invoke {program expectFile ld_library_additions} {
469 global libjava_ld_library_path
470 global ld_library_path
472 set ld_library_path "$libjava_ld_library_path"
473 if {[llength $ld_library_additions] > 0} {
474 append ld_library_path :[join $ld_library_additions :]
477 set_ld_library_path_env_vars
478 if [info exists env(LD_LIBRARY_PATH)] {
479 verbose "LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
482 set result [libjava_load ./$program]
483 set status [lindex $result 0]
484 set output [lindex $result 1]
487 restore_ld_library_path_env_vars
489 if {$status != "pass"} {
490 verbose "got $output"
492 untested "$program output"
496 set id [open $expectFile r]
497 set expected [read $id]
500 if {! [string compare $output $expected]} {
501 pass "$program output"
504 fail "$program output"
509 proc exec_gij {jarfile expectFile {ld_library_additions {}} {addl_flags {}}} {
511 global libjava_ld_library_path
512 global ld_library_path
514 set ld_library_path "$libjava_ld_library_path"
515 if {[llength $ld_library_additions] > 0} {
516 append ld_library_path :[join $ld_library_additions :]
519 set_ld_library_path_env_vars
520 if [info exists env(LD_LIBRARY_PATH)] {
521 verbose "LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
524 set gij [libjava_find_gij]
525 set classname [file rootname [file tail $jarfile]]
527 puts "LD_LIBRARY_PATH=. $gij -cp $jarfile $addl_flags $classname"
529 set result [libjava_load $gij "-cp $jarfile $addl_flags $classname"]
530 set status [lindex $result 0]
531 set output [lindex $result 1]
533 restore_ld_library_path_env_vars
535 if {$status != "pass"} {
536 verbose "got $output"
537 fail "$classname run"
538 untested "$classname output"
542 set id [open $expectFile r]
543 set expected [read $id]
546 if {! [string compare $output $expected]} {
547 pass "$classname output"
550 fail "$classname output"
555 # Invoke a program and check its output. EXECUTABLE is the program;
556 # ARGS are the arguments to the program. Returns 1 if tests passed
557 # (or things were left untested), 0 otherwise.
558 proc libjava_invoke {errname testName optName executable inpfile resultfile
559 ld_library_additions args} {
561 global libjava_ld_library_path
562 global ld_library_path
564 set ld_library_path "$libjava_ld_library_path"
565 if {[llength $ld_library_additions] > 0} {
566 append ld_library_path :[join $ld_library_additions :]
569 set_ld_library_path_env_vars
570 if [info exists env(LD_LIBRARY_PATH)] {
571 verbose "LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
576 if {[info exists opts(no-exec)]} {
577 if {[info exists opts(need-threads)]} {
578 # This means we wanted to try to run it but we couldn't
579 # because threads aren't supported. So we have to
580 # generate an `untested'.
581 untested "$errname execution - $testName"
582 untested "$errname output - $testName"
587 send_log "invoke: $executable $args $inpfile\n"
589 set result [libjava_load $executable $args "$inpfile"]
590 set status [lindex $result 0]
591 set output [lindex $result 1]
593 # Restore LD_LIBRARY_PATH setting.
594 restore_ld_library_path_env_vars
596 if {[info exists opts(xfail-exec)]} then {
599 $status "$errname execution - $testName"
600 if { $status != "pass" } {
601 untested "$errname output - $testName"
605 verbose "resultfile is $resultfile"
606 set id [open $resultfile r]
608 append expected [read $id]
609 regsub -all "\r" "$output" "" output
610 regsub "\n*$" $expected "" expected
611 regsub "\n*$" $output "" output
612 regsub "^\n*" $expected "" expected
613 regsub "^\n*" $output "" output
614 regsub -all "\[ \t\]\[ \t\]*" $expected " " expected
615 regsub -all "\[ \t\]*\n\n*" $expected "\n" expected
616 regsub -all "\[ \t\]\[ \t\]*" $output " " output
617 regsub -all "\[ \t\]*\n\n*" $output "\n" output
618 verbose "expected is $expected"
619 verbose "actual is $output"
621 if {[info exists opts(regexp_match)]} {
622 if [regexp $expected $output] {
626 if { $expected == $output } {
630 if {[info exists opts(xfail-output)]} {
633 if { $passed == 1 } {
634 pass "$errname output - $testName"
636 fail "$errname output - $testName"
644 # Run the test specified by srcfile and resultfile. compile_args and
645 # exec_args are options telling this proc how to work.
647 proc test_libjava_from_source { options srcfile compile_args inpfile resultfile exec_args } {
649 global srcdir subdir objdir
651 global GCJ_UNDER_TEST
655 # Make opts into an array.
658 foreach item $exec_args {
662 # If we need threads and we don't have them then set the `no-exec'
663 # flag. This is case is also handled specially later.
664 if {[info exists opts(need-threads)]} {
665 global libjava_uses_threads
666 if {! $libjava_uses_threads} {
671 set errname [file rootname [file tail $srcfile]]
672 if {! [runtest_file_p $runtests $errname]} {
676 if {[info exists opts(no-link)]} {
681 set args [libjava_arguments $mode]
682 if {! [info exists opts(no-link)]} {
683 # Add the --main flag
684 lappend args "additional_flags=--main=[file rootname [file tail $srcfile]]"
685 if { $compile_args != "" } {
686 lappend args "additional_flags=$compile_args"
690 regsub "^.*/(\[^/.\]+)\[.\]\[^/]*$" "$srcfile" "\\1" out
691 set executable "${objdir}/$out"
692 if {[info exists opts(no-link)]} {
693 append executable ".o"
696 # DOS/win32 targets default to .exe if no suffix is given
697 # We then try to delete a file that doesn't exist. It is
698 # simpler to add the suffix everywhere.
699 append executable ".exe"
700 set target executable
702 if { $compile_args != "" } {
703 set errname "$errname $compile_args"
706 set removeList [list $executable]
708 set x [libjava_prune_warnings \
709 [libjava_tcompile $srcfile "$executable" $target $args]]
710 if {[info exists opts(xfail-gcj)]} {
714 verbose "target_compile failed: $x" 2
716 if {[info exists opts(shouldfail)]} {
717 pass "$errname compilation from source"
718 eval gcj_cleanup $removeList
722 fail "$errname compilation from source"
723 if {[info exists opts(xfail-gcj)]
724 || ! [info exists opts(no-exec)]
725 || [info exists opts(need-threads)]} {
726 untested "$errname execution from source compiled test"
727 untested "$errname output from source compiled test"
731 if {[info exists opts(shouldfail)]} {
732 fail "$errname compilation from source"
735 pass "$errname compilation from source"
737 # Set up the options the way they are expected by libjava_invoke.
738 if {[info exists opts(xfail-source-output)]} {
739 set opts(xfail-output) x
741 if {[libjava_invoke $errname "source compiled test" opts $executable \
742 $inpfile $resultfile ""]} {
743 # Everything ok, so clean up.
744 eval gcj_cleanup $removeList
749 # Run the test specified by srcfile and resultfile. compile_args and
750 # exec_args are options telling this proc how to work.
751 # `no-link' don't try to link the program
752 # `no-exec' don't try to run the test
753 # `xfail-gcj' compilation from source will fail
754 # `xfail-javac' compilation with javac will fail
755 # `xfail-gcjC' compilation with gcj -C will fail
756 # `shouldfail' compilation from source is supposed to fail
757 # This is different from xfail, which marks a known
758 # failure that we just haven't fixed.
759 # A compilation marked this way should fail with any
761 # `xfail-byte' compilation from bytecode will fail
762 # `xfail-exec' exec will fail
764 # output will be wrong
765 # `xfail-byte-output'
766 # output will be wrong when compiled from bytecode
767 # `xfail-source-output'
768 # output will be wrong when compiled from source code
770 # test relies on thread support
772 proc test_libjava { options srcfile compile_args inpfile resultfile exec_args } {
773 test_libjava_from_source $options $srcfile $compile_args $inpfile $resultfile $exec_args
775 # Test BC-ABI compilation.
776 set compile_args_bcabi $compile_args
777 lappend compile_args_bcabi "-findirect-dispatch"
778 test_libjava_from_source $options $srcfile $compile_args_bcabi $inpfile $resultfile $exec_args
782 # libjava_version -- extract and print the version number of libjavap
784 proc default_libjava_version {} {
787 proc default_libjava_start { } {