1 # Copyright
(C
) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2011
2 # Free Software Foundation
4 proc load_gcc_lib
{ filename
} {
5 global srcdir loaded_libs
7 load_file $srcdir
/..
/..
/gcc
/testsuite
/lib
/$filename
8 set loaded_libs
($filename
) ""
13 load_gcc_lib target
-libpath.exp
15 # GCJ_UNDER_TEST is the compiler under test.
19 if ![info exists tmpdir
] {
23 # This is like `prune_warnings
', but it also prunes away a warning
24 # from the bytecode front end that we don't care about.
25 proc libjava_prune_warnings
{text} {
26 set text [prune_warnings $
text]
27 set tlist
[split $
text \n]
28 set len
[llength $tlist
]
29 for {set i
[expr
{$len
- 1}]} {$i
>= 2} {incr i
-1} {
30 if {[string match
"*unreachable bytecode*" [lindex $tlist $i]]} {
31 #
Delete this line
, all other unreachable warnings and the previous
32 # two lines containing the method and class.
34 while {[string match
"*unreachable bytecode*" [lindex $tlist $j]]} {
38 set tlist
[lreplace $tlist $j $i
]
42 return [join $tlist
\n]
45 # This is like `target_compile
' but it does some surgery to work
46 # around stupid DejaGNU bugs. In particular DejaGNU has very poor
47 # quoting, so for instance a `$' will be re
-evaluated at spawn time.
49 proc libjava_tcompile {source destfile type options} {
50 # This strange-looking expression really does quote the `$'.
51 regsub
-all
-- {\$
} $source
{\$
} source
52 regsub
-all
-- {\$
} $destfile
{\$
} destfile
53 return [target_compile $source $destfile $type $options
]
56 # Read an `xfail
' file if it exists. Returns a list of xfail tokens.
57 proc libjava_read_xfail {file} {
58 if {! [file exists $file]} {
62 set tokens [string trim [read $fd]]
67 # Find a particular executable. FIXME: this relies on DejaGnu
68 # internals. These should probably be exposed in a better way.
69 proc libjava_find_program {prog} {
72 set file [lookfor_file $tool_root_dir $prog]
74 set file [lookfor_file $tool_root_dir gcc/$prog];
84 return [libjava_find_program gjavah
]
88 global SUN_JAVAC GCJ_UNDER_TEST env libgcj_jar
89 #
If JDK doesn
't run on your platform but some other
90 # JDK-compatible javac does, you may set SUN_JAVAC to point to it.
91 # One of the most important properties of a SUN_JAVAC is that it
92 # must create class-files even for classes that have not been
93 # specified in the command line, but that were needed to compile
94 # those that have. For example, Pizza won't
do it
, but you can
95 # use `kaffe sun.tools.javac.Main
', if you have Sun's classes.zip
96 # in the kaffe
's default search path.
97 if {![info exists SUN_JAVAC]} {
98 if {[info exists env(SUN_JAVAC)]} {
99 set SUN_JAVAC $env(SUN_JAVAC)
101 set SUN_JAVAC "$GCJ_UNDER_TEST -C -I$libgcj_jar"
107 proc bytecompile_file { file objdir {classpath {}} } {
109 set dirname [file dirname $file]
111 set javac [find_javac]
112 if {$classpath != ""} then {
113 set env(CLASSPATH) $classpath
117 send_log "byte compile: $javac -g [list $file] -d $objdir 2>@ stdout\n"
119 set q [eval exec "$javac -g [list $file] -d $objdir 2>@ stdout"]
121 send_log "couldn't
compile $file
: $msg
\n"
130 set libjava_initialized
0
133 # Build the
status wrapper library as needed.
135 proc libjava_init
{ args } {
137 global wrap_compile_flags
;
138 global libjava_initialized libjava_uses_threads
139 global GCJ_UNDER_TEST
140 global TOOL_EXECUTABLE
142 global env libgcj_jar
144 global libjava_libgcc_s_path
145 global target_triplet
146 global libjava_version
148 # We
set LC_ALL and LANG to C so that we
get the same error messages as expected.
152 # Many hosts now default to a non
-ASCII C locale
, however
, so
153 # they can
set a
charset encoding here
if they need.
154 if { [ishost
"*-*-cygwin*"] } {
155 setenv LC_ALL C.ASCII
159 if { $libjava_initialized
== 1 } { return; }
161 if ![info exists GCJ_UNDER_TEST
] {
162 if [info exists TOOL_EXECUTABLE
] {
163 set GCJ_UNDER_TEST $TOOL_EXECUTABLE
;
165 if [info exists env
(GCJ
)] {
166 set GCJ_UNDER_TEST $env
(GCJ
)
168 set GCJ_UNDER_TEST
"[find_gcj]"
173 # Find the libgcj jar file.
175 # FIXME
: This finds libgcj.spec
for the default multilib.
176 #
If thread models differ between multilibs
, this has to be moved
177 # to libjava_arguments
178 set specdir
[libjava_find_spec
]
180 set text [eval exec
"$GCJ_UNDER_TEST -B$specdir -v 2>@ stdout"]
181 regexp
" version \[^\n\r\]*" $text version
182 set libjava_version
[lindex $version
1]
184 verbose
"version: $libjava_version"
186 set libgcj_jar
[glob $objdir
/..
/libgcj
-$libjava_version.jar
]
187 verbose
"jar file is $libgcj_jar"
189 # The
-B is so we find libgcj.spec.
190 regexp
-- "Thread model: (\[^\n\]+)\n" $text ignore model
191 set libjava_uses_threads
[expr
{! ($
model == "no"
193 || $
model == "single")}]
195 # Always
set encoding used by gcj.
196 append GCJ_UNDER_TEST
" --encoding=UTF-8"
199 set wrap_compile_flags
"";
200 if [target_info
exists needs_status_wrapper
] {
201 set result
[build_wrapper
"testglue.o"];
202 if { $result
!= "" } {
203 set wrapper_file
[lindex $result
0];
204 set wrap_compile_flags
[lindex $result
1];
206 warning
"Status wrapper failed to build."
210 # Finally
, add the gcc build directory so that we can find the
211 # shared libgcc. This
, like much of dejagnu
, is hideous.
212 set libjava_libgcc_s_path
{}
214 if { [istarget
"*-*-darwin*"] } {
215 set so_extension
"dylib"
216 } elseif
{ [istarget
"*-*-cygwin*"] || [istarget "*-*-mingw*"] } {
217 set so_extension
"dll"
219 set so_extension
"so"
221 set gccdir
[lookfor_file $tool_root_dir gcc
/libgcc_s.$
{so_extension
}]
223 set gccdir
[file dirname $gccdir
]
224 lappend libjava_libgcc_s_path $gccdir
225 verbose
"libjava_libgcc_s_path = $libjava_libgcc_s_path"
226 set compiler $
{gccdir
}/xgcc
227 if { [is_remote host
] == 0 && [which $compiler
] != 0 } {
228 foreach i
"[exec $compiler --print-multi-lib]" {
230 regexp
-- "\[a-z0-9=_/\.-\]*;" $i mldir
231 set mldir
[string trimright $mldir
"\;@"]
232 if { "$mldir" == "." } {
235 if { [llength
[glob
-nocomplain $
{gccdir
}/$
{mldir
}/libgcc_s
*.$
{so_extension
}.
*]] >= 1 } {
236 lappend libjava_libgcc_s_path
"${gccdir}/${mldir}"
242 set libjava_initialized
1
245 # Find a library. We know where libtool puts the actual libraries
,
246 # and we look there. The implementation is fairly hacky. We can
't
247 # compile with -nodefaultlibs, because that will also eliminate the
248 # system libraries we need. In order to have gcj still work, it must
249 # find the appropriate libraries so we must add -L options for their
250 # paths. However we can't simply use those libraries
; we still need
251 # libtool
for linking.
252 # Don
't return the the lib${name}.la files here, since this causes the
253 # libraries to be linked twice: once as lib${name}.so/dylib and another time
254 # via gcj's implicit
-l$
{name}. This is both unnecessary and causes the
255 # Solaris
ld to warn
: attempted multiple inclusion of file. This warning
256 # is not ignored by the dejagnu framework and cannot be disabled.
257 proc libjava_find_lib
{dir name} {
259 set gp
[get_multilibs
]
260 foreach extension
{so dll dylib sl a
} {
261 foreach sub
{.libs _libs
} {
263 if {[file
exists $gp
/$
dir/$sub
/lib$
{name}.$
{extension
}]} then {
264 # Just
return the `
-L
' option. The library itself
265 # will be picked up via the spec file.
266 return "-L$gp/$dir/$sub"
269 # Just return the `-L' option. The library itself will be
270 # picked up via the spec file.
272 $base_dir
/..
/..
/$
dir/$sub
/lib$
{name}.$
{extension
} \
273 "-L$base_dir/../../$dir/$sub" \
283 # Find libgcj.spec. We need to use the file corresponding to the multilib
284 # under test since they might differ. Append a trailing slash since this
286 proc libjava_find_spec
{} {
291 # Find `gij
'. Return empty string if not found.
292 proc libjava_find_gij {} {
293 global base_dir objdir
295 set gijdir [lookfor_file [get_multilibs] libjava];
296 # Fall back if get_multilibs fails.
298 set gijdir "$objdir/.."
300 if {! [file exists $gijdir/gij]} {
306 # Remove a bunch of files.
307 proc gcj_cleanup {args} {
309 if {[string match *.o $file]} {
310 verbose "removing [file rootname $file].lo"
311 file delete -force [file rootname $file].lo
313 file delete -force -- $file
314 verbose "removing $file"
316 # It is simplest to do this instead of trying to figure out what
317 # bits in .libs ought to be removed.
318 catch {system "rm -rf .libs"}
321 # Compute arguments needed for compiler. MODE is a libtool mode:
322 # either compile or link.
323 proc libjava_arguments {{mode compile}} {
326 global srcdir subdir objdir
328 global GCJ_UNDER_TEST
334 global libjava_libgcc_s_path
335 global libjava_ld_library_path
336 global ld_library_path
337 global target_triplet
339 if [info exists LIBJAVA] {
340 set libjava $LIBJAVA;
342 set libjava [libjava_find_lib libjava gcj]
345 verbose "using LIBJAVA = $libjava" 2
348 # Basically we want to build up a colon separated path list from
349 # the value of $libjava.
352 foreach dir [list $libjava] {
353 foreach item [split $dir " "] {
354 switch -glob -- $item {
356 lappend lpath [string range $item 2 end]
362 set lpath [concat $lpath $libjava_libgcc_s_path]
363 verbose "lpath = $lpath ; libgcc_s_path = $libjava_libgcc_s_path"
364 set ld_library_path [join $lpath :]
365 set libjava_ld_library_path "$ld_library_path"
367 # That's enough to make things work
for the
normal case.
368 #
If we wanted to handle an arbitrary value of libjava
,
369 #
then we
'd have to do a lot more work.
371 set_ld_library_path_env_vars
372 if [info exists env(LD_LIBRARY_PATH)] {
373 verbose "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
376 # Determine CLASSPATH separator
377 if { [string match "i?86-pc-mingw32*" $target_triplet] } {
383 # Set the CLASSPATH environment variable
386 [join [list . $srcdir/$subdir $objdir $libgcj_jar] $sep]
387 verbose "CLASSPATH is $env(CLASSPATH)"
389 # Disable all warnings, as ecj is rather chatty.
390 lappend args "additional_flags=-w"
392 if {$mode == "link"} {
393 global wrapper_file wrap_compile_flags
394 lappend args "additional_flags=$wrap_compile_flags"
396 if { [regexp "linux" $target_triplet] } {
397 lappend args "additional_flags=-specs=libgcj-test.spec"
400 lappend args "libs=$wrapper_file"
401 lappend args "libs=$libjava"
405 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
406 lappend args "libs=${gluefile}"
407 lappend args "ldflags=$wrap_flags"
410 if [info exists TOOL_OPTIONS] {
411 lappend args "additional_flags=$TOOL_OPTIONS"
414 # Determine libgcj.spec corresponding to multilib under test.
415 set specdir [libjava_find_spec]
417 # Search for libtool. We need it to link.
419 set d [file normalize $objdir]
420 foreach x {. .. ../.. ../../..} {
421 if {[file exists $d/$x/libtool]} then {
422 # We have to run silently to avoid DejaGNU lossage.
424 "compiler=$d/$x/libtool --silent --tag=GCJ --mode=$mode $GCJ_UNDER_TEST -B$specdir"
429 if {! $found_compiler} {
430 # Append -B$specdir so that we find libgcj.spec before it
432 lappend args "compiler=$GCJ_UNDER_TEST -B$specdir"
435 # Avoid libtool wrapper scripts when possible.
436 # but not if libtool warnings results in FAILs
437 if {$mode == "link"} {
438 if {! [istarget "*-*-cygwin*"] && ! [istarget "*-*-mingw*"]
439 && ! [istarget "*-*-darwin*"] } {
440 lappend args "additional_flags=-no-install"
442 if { [istarget "*-*-darwin*"] } {
443 lappend args "additional_flags=-bind_at_load"
444 lappend args "additional_flags=-multiply_defined suppress"
446 if { [istarget "*-*-darwin9*"] || [istarget "*-*-darwin1*"] || [istarget "*-*-darwin2*"] } {
447 lappend args "additional_flags=-Wl,-allow_stack_execute"
455 # Link a bunch of objects into a program. MAIN is the name of the
456 # class holding `main'.
Return 0 on failure.
457 proc gcj_link
{program main files
{options
{}}} {
458 set arguments
[libjava_arguments link
]
459 if {[llength $options
]} {
460 eval lappend arguments $options
462 lappend arguments
"additional_flags=--main=$main"
463 set x
[libjava_prune_warnings \
464 [libjava_tcompile $files $
program executable $arguments
]]
466 verbose
"link failure: $x" 2
467 fail
"linking $program"
469 fail
"running $program"
473 pass
"linking $program"
477 # Invoke the
program and see what happens.
Return 0 on failure.
478 proc gcj_invoke
{program expectFile ld_library_additions
} {
480 global libjava_ld_library_path
481 global ld_library_path
483 set ld_library_path
"$libjava_ld_library_path"
484 if {[llength $ld_library_additions
] > 0} {
485 append ld_library_path
:[join $ld_library_additions
:]
488 set_ld_library_path_env_vars
489 if [info exists env
(LD_LIBRARY_PATH
)] {
490 verbose
"LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
493 set result
[libjava_load .
/$
program]
494 set status [lindex $result
0]
495 set output
[lindex $result
1]
498 restore_ld_library_path_env_vars
500 if {$
status != "pass"} {
501 verbose
"got $output"
503 untested
"$program output"
507 set id
[open $expectFile r
]
508 set expected
[read $id
]
511 if {! [string compare $output $expected
]} {
512 pass
"$program output"
515 fail
"$program output"
520 proc exec_gij
{jarfile expectFile
{ld_library_additions
{}} {addl_flags
{}}} {
522 global libjava_ld_library_path
523 global ld_library_path
525 set ld_library_path
"$libjava_ld_library_path"
526 if {[llength $ld_library_additions
] > 0} {
527 append ld_library_path
:[join $ld_library_additions
:]
530 set_ld_library_path_env_vars
531 if [info exists env
(LD_LIBRARY_PATH
)] {
532 verbose
"LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
535 set gij
[libjava_find_gij
]
536 set classname
[file rootname
[file tail $jarfile
]]
538 puts
"LD_LIBRARY_PATH=. $gij -cp $jarfile $addl_flags $classname"
540 set result
[libjava_load $gij
"-cp $jarfile $addl_flags $classname"]
541 set status [lindex $result
0]
542 set output
[lindex $result
1]
544 restore_ld_library_path_env_vars
546 if {$
status != "pass"} {
547 verbose
"got $output"
548 fail
"$classname run"
549 untested
"$classname output"
553 set id
[open $expectFile r
]
554 set expected
[read $id
]
557 if {! [string compare $output $expected
]} {
558 pass
"$classname output"
561 fail
"$classname output"
566 # Invoke a
program and check its output. EXECUTABLE is the
program;
567 #
ARGS are the arguments to the
program. Returns
1 if tests passed
568 #
(or things were left untested
), 0 otherwise.
569 proc libjava_invoke
{errname testName optName executable inpfile resultfile
570 ld_library_additions
args} {
572 global libjava_ld_library_path
573 global ld_library_path
575 set ld_library_path
"$libjava_ld_library_path"
576 if {[llength $ld_library_additions
] > 0} {
577 append ld_library_path
:[join $ld_library_additions
:]
580 set_ld_library_path_env_vars
581 if [info exists env
(LD_LIBRARY_PATH
)] {
582 verbose
"LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
587 if {[info exists opts
(no
-exec
)]} {
588 if {[info exists opts
(need
-threads
)]} {
589 # This means we wanted to try to run it but we couldn
't
590 # because threads aren't supported. So we have to
591 # generate an `untested
'.
592 untested "$errname execution - $testName"
593 untested "$errname output - $testName"
598 send_log "invoke: $executable $args $inpfile\n"
600 set result [libjava_load $executable $args "$inpfile"]
601 set status [lindex $result 0]
602 set output [lindex $result 1]
604 # Restore LD_LIBRARY_PATH setting.
605 restore_ld_library_path_env_vars
607 if {[info exists opts(xfail-exec)]} then {
610 $status "$errname execution - $testName"
611 if { $status != "pass" } {
612 untested "$errname output - $testName"
616 verbose "resultfile is $resultfile"
617 set id [open $resultfile r]
619 append expected [read $id]
620 regsub -all "\r" "$output" "" output
621 regsub "\n*$" $expected "" expected
622 regsub "\n*$" $output "" output
623 regsub "^\n*" $expected "" expected
624 regsub "^\n*" $output "" output
625 regsub -all "\[ \t\]\[ \t\]*" $expected " " expected
626 regsub -all "\[ \t\]*\n\n*" $expected "\n" expected
627 regsub -all "\[ \t\]\[ \t\]*" $output " " output
628 regsub -all "\[ \t\]*\n\n*" $output "\n" output
629 verbose "expected is $expected"
630 verbose "actual is $output"
632 if {[info exists opts(regexp_match)]} {
633 if [regexp $expected $output] {
637 if { $expected == $output } {
641 if {[info exists opts(xfail-output)]} {
644 if { $passed == 1 } {
645 pass "$errname output - $testName"
647 fail "$errname output - $testName"
655 # Run the test specified by srcfile and resultfile. compile_args and
656 # exec_args are options telling this proc how to work.
658 proc test_libjava_from_source { options srcfile compile_args inpfile resultfile exec_args } {
660 global srcdir subdir objdir
662 global GCJ_UNDER_TEST
666 # Make opts into an array.
669 foreach item $exec_args {
673 # If we need threads and we don't have them
then set the `no
-exec
'
674 # flag. This is case is also handled specially later.
675 if {[info exists opts(need-threads)]} {
676 global libjava_uses_threads
677 if {! $libjava_uses_threads} {
682 set errname [file rootname [file tail $srcfile]]
683 if {! [runtest_file_p $runtests $errname]} {
687 if {[info exists opts(no-link)]} {
692 set args [libjava_arguments $mode]
693 if {! [info exists opts(no-link)]} {
694 # Add the --main flag
695 lappend args "additional_flags=--main=[file rootname [file tail $srcfile]]"
696 if { $compile_args != "" } {
697 lappend args "additional_flags=$compile_args"
701 regsub "^.*/(\[^/.\]+)\[.\]\[^/]*$" "$srcfile" "\\1" out
702 set executable "${objdir}/$out"
703 if {[info exists opts(no-link)]} {
704 append executable ".o"
707 # DOS/win32 targets default to .exe if no suffix is given
708 # We then try to delete a file that doesn't exist. It is
709 # simpler to add the suffix everywhere.
710 append executable
".exe"
711 set target executable
713 if { $compile_args
!= "" } {
714 set errname
"$errname $compile_args"
717 set removeList
[list $executable
]
719 set x
[libjava_prune_warnings \
720 [libjava_tcompile $srcfile
"$executable" $target $args]]
721 if {[info exists opts
(xfail
-gcj
)]} {
725 verbose
"target_compile failed: $x" 2
727 if {[info exists opts
(shouldfail
)]} {
728 pass
"$errname compilation from source"
729 eval gcj_cleanup $removeList
733 fail
"$errname compilation from source"
734 if {[info exists opts
(xfail
-gcj
)]
735 ||
! [info exists opts
(no
-exec
)]
736 ||
[info exists opts
(need
-threads
)]} {
737 untested
"$errname execution from source compiled test"
738 untested
"$errname output from source compiled test"
742 if {[info exists opts
(shouldfail
)]} {
743 fail
"$errname compilation from source"
746 pass
"$errname compilation from source"
748 #
Set up the options the way they are expected by libjava_invoke.
749 if {[info exists opts
(xfail
-source
-output
)]} {
750 set opts
(xfail
-output
) x
752 if {[libjava_invoke $errname
"source compiled test" opts $executable \
753 $inpfile $resultfile
""]} {
754 # Everything ok
, so clean up.
755 eval gcj_cleanup $removeList
760 # Run the test specified by srcfile and resultfile. compile_args and
761 # exec_args are options telling this proc how to work.
762 # `no
-link
' don't try to link the
program
763 # `no
-exec
' don't try to run the test
764 # `xfail
-gcj
' compilation from source will fail
765 # `xfail-javac' compilation with javac will fail
766 # `xfail
-gcjC
' compilation with gcj -C will fail
767 # `shouldfail' compilation from source is supposed to fail
768 # This is different from xfail
, which marks a known
769 # failure that we just haven
't fixed.
770 # A compilation marked this way should fail with any
772 # `xfail-byte' compilation from bytecode will fail
773 # `xfail
-exec
' exec will fail
775 # output will be wrong
776 # `xfail
-byte
-output
'
777 # output will be wrong when compiled from bytecode
778 # `xfail-source-output'
779 # output will be wrong when compiled from source code
781 # test relies on thread support
783 proc test_libjava { options srcfile compile_args inpfile resultfile exec_args } {
784 test_libjava_from_source $options $srcfile $compile_args $inpfile $resultfile $exec_args
786 # Test BC-ABI compilation.
787 set compile_args_bcabi $compile_args
788 lappend compile_args_bcabi "-findirect-dispatch"
789 test_libjava_from_source $options $srcfile $compile_args_bcabi $inpfile $resultfile $exec_args
793 # libjava_version -- extract and print the version number of libjavap
795 proc default_libjava_version {} {
798 proc default_libjava_start { } {