1 # Copyright (C) 1998, 1999 Cygnus Solutions
3 load_lib "libgloss.exp"
5 # GCJ_UNDER_TEST is the compiler under test.
9 if ![info exists tmpdir] {
13 # Read an `xfail' file if it exists. Returns a list of xfail tokens.
14 proc libjava_read_xfail {file} {
15 if {! [file exists $file]} {
19 set tokens [string trim [read $fd]]
24 # Find `jv-scan'. FIXME: this relies on DejaGnu internals. These
25 # should probably be exposed in a better way.
29 set file [lookfor_file $tool_root_dir jv-scan]
31 set file [lookfor_file $tool_root_dir gcc/jv-scan];
39 proc bytecompile_file { file objdir {classpath {}} } {
41 set dirname [file dirname $file];
43 catch {unset env(CLASSPATH)}
44 if {$classpath != ""} then {
45 set env(CLASSPATH) $classpath
47 if {[catch {system "cd $dirname; javac $file -d $objdir"} msg]} then {
48 verbose "couldn't compile $file: $msg"
56 set libjava_initialized 0
59 # Build the status wrapper library as needed.
61 proc libjava_init { args } {
63 global wrap_compile_flags;
64 global libjava_initialized
66 global TOOL_EXECUTABLE
68 if { $libjava_initialized == 1 } { return; }
70 if ![info exists GCJ_UNDER_TEST] {
71 if [info exists TOOL_EXECUTABLE] {
72 set GCJ_UNDER_TEST $TOOL_EXECUTABLE;
74 set GCJ_UNDER_TEST "[find_gcj]"
79 set wrap_compile_flags "";
80 if [target_info exists needs_status_wrapper] {
81 set result [build_wrapper "testglue.o"];
82 if { $result != "" } {
83 set wrapper_file [lindex $result 0];
84 set wrap_compile_flags [lindex $result 1];
86 warning "Status wrapper failed to build."
90 set libjava_initialized 1
93 # Find a library. We know where libtool puts the actual libraries,
94 # and we look there. The implementation is fairly hacky. We can't
95 # compile with -nodefaultlibs, because that will also eliminate the
96 # system libraries we need. In order to have gcj still work, it must
97 # find the appropriate libraries so we must add -L options for their
98 # paths. However we can't simply use those libraries; we still need
99 # libtool for linking.
100 proc libjava_find_lib {dir name} {
102 set gp [get_multilibs]
103 foreach sub {.libs _libs} {
105 if {[file exists $gp/$dir/$sub/lib${name}.a]} then {
106 return "$gp/$dir/lib${name}.la -L$gp/$dir/$sub"
109 set lib [findfile $base_dir/../../$dir/$sub/lib${name}.a \
110 "$base_dir/../../$dir/lib${name}.la -L$base_dir/../../$dir/$sub" \
119 # Compute arguments needed for compiler. MODE is a libtool mode:
120 # either compile or link.
121 proc libjava_arguments {{mode compile}} {
127 global srcdir subdir objdir
129 global GCJ_UNDER_TEST
133 if [info exists LIBJAVA] {
134 set libjava $LIBJAVA;
136 set libjava [libjava_find_lib libjava gcj]
139 if [info exists LIBGC] {
142 set libgc [libjava_find_lib boehm-gc gcjgc]
145 if [info exists LIBQTHREADS] {
146 set libqthreads $LIBQTHREADS
148 set libqthreads [libjava_find_lib qthreads gcjcoop]
151 if [info exists LIBZ] {
154 set libz [libjava_find_lib zlib zgcj]
157 # FIXME: there's no way to determine whether -lpthread is
158 # required. We should get this info from configure, or it should
159 # just be in the compiler driver.
161 verbose "using LIBJAVA = $libjava" 2
162 verbose "using LIBGC = $libgc" 2
163 verbose "using LIBQTHREADS = $libqthreads" 2
164 verbose "using LIBZ = $libz" 2
167 # Basically we want to build up a colon separated path list from
168 # the value of $libjava.
170 # First strip away any -L arguments.
171 regsub -all -- "-L" $libjava "" ld_library_path
173 # Then remove any -lgcj argument.
174 regsub -all -- " -lgcj.*" $ld_library_path "" ld_library_path
176 # First strip away any -L arguments.
177 regsub -all -- "-L" $libgc $ld_library_path ld_library_path
179 # Then remove any -lgcjgc argument.
180 regsub -all -- " -lgcjgc.*" $ld_library_path "" ld_library_path
182 # That's enough to make things work for the normal case.
183 # If we wanted to handle an arbitrary value of libjava,
184 # then we'd have to do a lot more work.
186 # Set variables the dynamic linker looks at.
187 setenv LD_LIBRARY_PATH $ld_library_path
188 setenv SHLIB_PATH $ld_library_path
190 # Set the CLASSPATH environment variable
191 verbose "CLASSPATH is $objdir/.."
193 set env(CLASSPATH) "$objdir/.."
195 global wrapper_file wrap_compile_flags;
196 lappend args "additional_flags=$wrap_compile_flags";
197 lappend args "libs=$wrapper_file";
198 lappend args "libs=$libjava";
199 lappend args "libs=$libgc";
200 lappend args "libs=$libqthreads"
201 lappend args "libs=$libz"
204 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
205 lappend args "libs=${gluefile}"
206 lappend args "ldflags=$wrap_flags"
209 if [info exists TOOL_OPTIONS] {
210 lappend args "additional_flags=$TOOL_OPTIONS"
213 # Search for libtool. We need it to link.
215 set d [absolute $objdir]
216 foreach x {. .. ../.. ../../..} {
217 if {[file exists $d/$x/libtool]} then {
218 # We have to run silently to avoid DejaGNU lossage.
220 "compiler=$d/$x/libtool --silent --mode=$mode $GCJ_UNDER_TEST"
225 if {! $found_compiler} {
226 lappend args "compiler=$GCJ_UNDER_TEST"
234 # Run the test specified by srcfile and resultfile. compile_args and
235 # exec_args are options telling this proc how to work.
236 # `no-exec' don't try to run the test
237 # `xfail-gcj' compilation from source will fail
238 # `xfail-javac' compilation with javac will fail
239 # `xfail-gcjC' compilation with gcj -C will fail
240 # `xfail-byte' compilation from bytecode will fail
241 # `xfail-exec' exec will fail
242 # `xfail-output' output will be wrong
245 proc test_libjava_from_source { options srcfile compile_args inpfile resultfile exec_args } {
249 global srcdir subdir objdir
251 global GCJ_UNDER_TEST
255 # Make opts into an array.
258 foreach item $exec_args {
262 set errname [file rootname [file tail $srcfile]]
263 if {! [runtest_file_p $runtests $errname]} {
267 set args [libjava_arguments link]
268 # Add the --main flag
269 lappend args "additional_flags=--main=[file rootname [file tail $srcfile]]"
270 if { $compile_args != "" } {
271 lappend args "additional_flags=$compile_args"
274 regsub "^.*/(\[^/.\]+)\[.\]\[^/]*$" "$srcfile" "\\1" out
275 set executable "${objdir}/$out"
276 if { $compile_args != "" } {
277 set errname "$errname $compile_args"
280 set x [target_compile $srcfile "$executable" executable $args]
281 if {[info exists opts(xfail-gcj)]} {
285 verbose "target_compile failed: $x" 2
286 fail "$errname compilation from source"
287 if {[info exists opts(xfail-gcj)] || ! [info exists opts(no-exec)]} {
289 fail "$errname execution from source compiled test"
291 fail "$errname output from source compiled test"
295 pass "$errname compilation from source"
297 if {[info exists opts(no-exec)]} {
301 set result [libjava_load $executable "" "$inpfile"];
302 set status [lindex $result 0];
303 set output [lindex $result 1];
304 if {[info exists opts(xfail-exec)]} then {
307 $status "$errname execution from source compiled test"
308 if { $status != "pass" } {
310 fail "$errname execution from source compiled test"
314 verbose "resultfile is $resultfile"
315 set id [open $resultfile r];
317 append expected [read $id];
318 regsub -all "\r" "$output" "" output;
319 regsub "\n*$" $expected "" expected
320 regsub "\n*$" $output "" output
321 regsub "^\n*" $expected "" expected
322 regsub "^\n*" $output "" output
323 regsub -all "\[ \t\]\[ \t\]*" $expected " " expected
324 regsub -all "\[ \t\]*\n\n*" $expected "\n" expected
325 regsub -all "\[ \t\]\[ \t\]*" $output " " output
326 regsub -all "\[ \t\]*\n\n*" $output "\n" output
327 verbose "expected is $expected"
328 verbose "actual is $output"
330 if {$options == "regexp_match"} {
331 if [regexp $expected $output] {
335 if { $expected == $output } {
339 if {[info exists opts(xfail-output)]} {
342 if { $passed == 1 } {
343 pass "$errname output from source compiled test"
345 clone_output "expected was $expected"
346 clone_output "output was $output"
347 fail "$errname output from source compiled test"
353 # Run the test specified by srcfile and resultfile. compile_args and
354 # exec_args are options telling this proc how to work.
355 # `no-exec' don't try to run the test
356 # `xfail-gcj' compilation from source will fail
357 # `xfail-javac' compilation with javac will fail
358 # `xfail-gcjC' compilation with gcj -C will fail
359 # `xfail-byte' compilation from bytecode will fail
360 # `xfail-exec' exec will fail
361 # `xfail-output' output will be wrong
363 proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile exec_args } {
367 global srcdir subdir objdir
369 global GCJ_UNDER_TEST
373 # Make opts into an array.
376 foreach item $exec_args {
380 set errname [file rootname [file tail $srcfile]]
381 if {! [runtest_file_p $runtests $errname]} {
385 # bytecompile files with Sun's compiler for now.
386 set bc_ok [bytecompile_file $srcfile $objdir]
387 # FIXME: assumes we are using javac to compile to bytecode.
388 # This is not always the case.
389 if {[info exists opts(xfail-javac)]} {
393 fail "$errname byte compilation"
395 fail "$errname compilation from bytecode"
396 if {! [info exists opts(no-exec)]} {
398 fail "$errname execution from bytecode->native test"
400 fail "$errname output from bytecode->native test"
404 pass "$errname byte compilation"
406 # Find name to use for --main, and name of all class files.
407 set jvscan [find_jvscan]
408 verbose "jvscan is $jvscan"
409 set main_name [string trim \
410 [target_compile $srcfile "" none \
411 "compiler=$jvscan additional_flags=--print-main"]]
412 verbose "main name is $main_name"
413 set class_out [string trim \
414 [target_compile $srcfile "" none \
415 "compiler=$jvscan additional_flags=--list-class"]]
416 verbose "class list is $class_out"
417 # FIXME: As of Wed Feb 24 1999, `jv-scan --list-class' prints
418 # nothing if the file contains an interface and not a class. I
419 # believe this is a jv-scan bug.
420 if {$class_out == ""} then {
422 [list $objdir/[file rootname [file tail $srcfile]].class]
424 # Turn "a b" into "a.class b.class".
426 foreach file [split [string trim $class_out]] {
427 lappend class_files $objdir/$file.class
431 # Usually it is an error for a test program not to have a `main'
432 # method. However, for no-exec tests it is ok.
434 if {$main_name == ""} {
435 if {! [info exists opts(no-exec)]} {
436 perror "No `main' given in program $errname"
440 set executable [file rootname [file tail $srcfile]].o
445 lappend largs "additional_flags=--main=$main_name"
446 set executable "${objdir}/$main_name"
451 set args [libjava_arguments $mode]
452 eval lappend args $largs
454 if { $compile_args != "" } {
455 lappend args "additional_flags=$compile_args"
458 if { $compile_args != "" } {
459 set errname "$errname $compile_args"
462 verbose "compilation command = $args" 2
463 set x [target_compile $class_files "$executable" $type $args]
464 if {[info exists opts(xfail-byte)]} {
468 verbose "target_compile failed: $x" 2
469 fail "$errname compilation from bytecode"
471 if {! [info exists opts(no-exec)]} {
472 fail "$errname execution from bytecode->native test"
474 fail "$errname output from bytecode->native test"
478 pass "$errname compilation from bytecode"
480 if {[info exists opts(no-exec)]} {
484 set result [libjava_load $executable "" "$inpfile"];
485 set status [lindex $result 0];
486 set output [lindex $result 1];
487 if {[info exists opts(xfail-exec)]} {
490 $status "$errname execution from bytecode->native test"
491 if { $status != "pass" } {
493 fail "$errname output from bytecode->native test"
497 verbose "resultfile is $resultfile"
498 set id [open $resultfile r];
500 append expected [read $id];
501 regsub -all "\r" "$output" "" output;
502 regsub "\n*$" $expected "" expected
503 regsub "\n*$" $output "" output
504 regsub "^\n*" $expected "" expected
505 regsub "^\n*" $output "" output
506 regsub -all "\[ \t\]\[ \t\]*" $expected " " expected
507 regsub -all "\[ \t\]*\n\n*" $expected "\n" expected
508 regsub -all "\[ \t\]\[ \t\]*" $output " " output
509 regsub -all "\[ \t\]*\n\n*" $output "\n" output
510 verbose "expected is $expected"
511 verbose "actual is $output"
513 if {[info exists opts(xfail-output)]} {
516 if {$options == "regexp_match"} {
517 if [regexp $expected $output] {
521 if { $expected == $output } {
525 if { $passed == 1 } {
526 pass "$errname output from bytecode->native test"
528 clone_output "expected was $expected"
529 clone_output "output was $output"
530 fail "$errname output from bytecode->native test"
536 # Run the test specified by srcfile and resultfile. compile_args and
537 # exec_args are options telling this proc how to work.
538 # `no-exec' don't try to run the test
539 # `xfail-gcj' compilation from source will fail
540 # `xfail-javac' compilation with javac will fail
541 # `xfail-gcjC' compilation with gcj -C will fail
542 # `xfail-byte' compilation from bytecode will fail
543 # `xfail-exec' exec will fail
544 # `xfail-output' output will be wrong
546 proc test_libjava { options srcfile compile_args inpfile resultfile exec_args } {
547 test_libjava_from_source $options $srcfile $compile_args $inpfile $resultfile $exec_args
548 test_libjava_from_javac $options $srcfile $compile_args $inpfile $resultfile $exec_args
552 # libjava_version -- extract and print the version number of libjavap
554 proc default_libjava_version {} {
557 proc default_libjava_start { } {