]> gcc.gnu.org Git - gcc.git/blob - libjava/testsuite/lib/libjava.exp
libjava.exp (libjava_arguments): Rewrote computation of LD_LIBRARY_PATH.
[gcc.git] / libjava / testsuite / lib / libjava.exp
1 # Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
2
3 load_lib "libgloss.exp"
4
5 # GCJ_UNDER_TEST is the compiler under test.
6
7 global tmpdir
8
9 if ![info exists tmpdir] {
10 set tmpdir "/tmp"
11 }
12
13 # This is like `target_compile' but it does some surgery to work
14 # around stupid DejaGNU bugs. In particular DejaGNU has very poor
15 # quoting, so for instance a `$' will be re-evaluated at spawn time.
16 # We don't want that.
17 proc libjava_tcompile {source destfile type options} {
18 # This strange-looking expression really does quote the `$'.
19 regsub -all -- {\$} $source {\$} source
20 regsub -all -- {\$} $destfile {\$} destfile
21 return [target_compile $source $destfile $type $options]
22 }
23
24 # Read an `xfail' file if it exists. Returns a list of xfail tokens.
25 proc libjava_read_xfail {file} {
26 if {! [file exists $file]} {
27 return ""
28 }
29 set fd [open $file r]
30 set tokens [string trim [read $fd]]
31 close $fd
32 return $tokens
33 }
34
35 # Find a particular executable. FIXME: this relies on DejaGnu
36 # internals. These should probably be exposed in a better way.
37 proc libjava_find_program {prog} {
38 global tool_root_dir
39
40 set file [lookfor_file $tool_root_dir $prog]
41 if { $file == "" } {
42 set file [lookfor_file $tool_root_dir gcc/$prog];
43 }
44 if {$file == ""} {
45 set file $prog
46 }
47 return $file
48 }
49
50 # Find `jv-scan'.
51 proc find_jvscan {} {
52 return [libjava_find_program jv-scan]
53 }
54
55 # Find `gcjh'.
56 proc find_gcjh {} {
57 return [libjava_find_program gcjh]
58 }
59
60 proc find_javac {} {
61 global SUN_JAVAC GCJ_UNDER_TEST env
62 # If JDK doesn't run on your platform but some other
63 # JDK-compatible javac does, you may set SUN_JAVAC to point to it.
64 # One of the most important properties of a SUN_JAVAC is that it
65 # must create class-files even for classes that have not been
66 # specified in the command line, but that were needed to compile
67 # those that have. For example, Pizza won't do it, but you can
68 # use `kaffe sun.tools.javac.Main', if you have Sun's classes.zip
69 # in the kaffe's default search path.
70 if {![info exists SUN_JAVAC]} {
71 if {[info exists env(SUN_JAVAC)]} {
72 set SUN_JAVAC $env(SUN_JAVAC)
73 } else {
74 set SUN_JAVAC "$GCJ_UNDER_TEST -C"
75 }
76 }
77 return $SUN_JAVAC
78 }
79
80 proc bytecompile_file { file objdir {classpath {}} } {
81 global env
82 set dirname [file dirname $file]
83
84 set javac [find_javac]
85 if {$classpath != ""} then {
86 set env(CLASSPATH) $classpath
87 }
88 set here [pwd]
89 cd $dirname
90 if {[catch {
91 set q [eval exec "$javac [list $file] -d $objdir 2>@ stdout"]
92 } msg]} then {
93 verbose "couldn't compile $file: $msg"
94 set r 0
95 } else {
96 set r 1
97 }
98 cd $here
99 return $r
100 }
101
102 set libjava_initialized 0
103
104 #
105 # Build the status wrapper library as needed.
106 #
107 proc libjava_init { args } {
108 global wrapper_file;
109 global wrap_compile_flags;
110 global libjava_initialized
111 global GCJ_UNDER_TEST
112 global TOOL_EXECUTABLE
113 global original_ld_library_path
114 global env
115
116 if { $libjava_initialized == 1 } { return; }
117
118 if ![info exists GCJ_UNDER_TEST] {
119 if [info exists TOOL_EXECUTABLE] {
120 set GCJ_UNDER_TEST $TOOL_EXECUTABLE;
121 } else {
122 if [info exists env(GCJ)] {
123 set GCJ_UNDER_TEST $env(GCJ)
124 } else {
125 set GCJ_UNDER_TEST "[find_gcj]"
126 }
127 }
128 }
129
130 if [info exists env(LD_LIBRARY_PATH)] {
131 set original_ld_library_path $env(LD_LIBRARY_PATH)
132 } else {
133 if [info exists env(SHLIB_PATH)] {
134 set original_ld_library_path $env(SHLIB_PATH)
135 } else {
136 set original_ld_library_path ""
137 }
138 }
139
140 set wrapper_file "";
141 set wrap_compile_flags "";
142 if [target_info exists needs_status_wrapper] {
143 set result [build_wrapper "testglue.o"];
144 if { $result != "" } {
145 set wrapper_file [lindex $result 0];
146 set wrap_compile_flags [lindex $result 1];
147 } else {
148 warning "Status wrapper failed to build."
149 }
150 }
151
152 set libjava_initialized 1
153 }
154
155 # Find a library. We know where libtool puts the actual libraries,
156 # and we look there. The implementation is fairly hacky. We can't
157 # compile with -nodefaultlibs, because that will also eliminate the
158 # system libraries we need. In order to have gcj still work, it must
159 # find the appropriate libraries so we must add -L options for their
160 # paths. However we can't simply use those libraries; we still need
161 # libtool for linking.
162 proc libjava_find_lib {dir name} {
163 global base_dir
164 set gp [get_multilibs]
165 foreach sub {.libs _libs} {
166 if {$gp != ""} {
167 if {[file exists $gp/$dir/$sub/lib${name}.a]} then {
168 return "$gp/$dir/lib${name}.la -L$gp/$dir/$sub"
169 }
170 }
171 set lib [findfile $base_dir/../../$dir/$sub/lib${name}.a \
172 "$base_dir/../../$dir/lib${name}.la -L$base_dir/../../$dir/$sub" \
173 ""]
174 if {$lib != ""} {
175 return $lib
176 }
177 }
178 return ""
179 }
180
181 # Compute arguments needed for compiler. MODE is a libtool mode:
182 # either compile or link.
183 proc libjava_arguments {{mode compile}} {
184 global base_dir
185 global LIBJAVA
186 global LIBGC
187 global LIBQTHREADS
188 global LIBZ
189 global srcdir subdir objdir
190 global TOOL_OPTIONS
191 global GCJ_UNDER_TEST
192 global tmpdir
193 global runtests
194 global env
195 global tool_root_dir
196
197 if [info exists LIBJAVA] {
198 set libjava $LIBJAVA;
199 } else {
200 set libjava [libjava_find_lib libjava gcj]
201 }
202
203 if [info exists LIBGC] {
204 set libgc $LIBGC;
205 } else {
206 set libgc [libjava_find_lib boehm-gc gcjgc]
207 }
208
209 if [info exists LIBQTHREADS] {
210 set libqthreads $LIBQTHREADS
211 } else {
212 set libqthreads [libjava_find_lib qthreads gcjcoop]
213 }
214
215 if [info exists LIBZ] {
216 set libz $LIBZ
217 } else {
218 set libz [libjava_find_lib zlib zgcj]
219 }
220
221 # FIXME: there's no way to determine whether -lpthread is
222 # required. We should get this info from configure, or it should
223 # just be in the compiler driver.
224
225 verbose "using LIBJAVA = $libjava" 2
226 verbose "using LIBGC = $libgc" 2
227 verbose "using LIBQTHREADS = $libqthreads" 2
228 verbose "using LIBZ = $libz" 2
229 set args ""
230
231 # Basically we want to build up a colon separated path list from
232 # the value of $libjava.
233
234 set lpath {}
235 foreach dir [list $libjava $libgc $libz] {
236 foreach item [split $dir " "] {
237 switch -glob -- $item {
238 "-L*" {
239 lappend lpath [string range $item 2 end]
240 }
241 }
242 }
243 }
244
245 # Finally, add the gcc build directory so that we can find the
246 # shared libgcc. This, like much of dejagnu, is hideous.
247 set gccdir [lookfor_file $tool_root_dir gcc/libgcc_s.so]
248 if {$gccdir != ""} {
249 lappend lpath [file dirname $gccdir]
250 }
251
252 set ld_library_path [join $lpath :]
253
254 # That's enough to make things work for the normal case.
255 # If we wanted to handle an arbitrary value of libjava,
256 # then we'd have to do a lot more work.
257
258 # Set variables the dynamic linker looks at.
259 global original_ld_library_path
260 setenv LD_LIBRARY_PATH "$ld_library_path:$original_ld_library_path"
261 setenv SHLIB_PATH "$ld_library_path:$original_ld_library_path"
262
263 verbose "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
264
265 # Set the CLASSPATH environment variable
266 verbose "CLASSPATH is .:$srcdir/$subdir:$objdir:$objdir/../libgcj.jar"
267 global env
268 set env(CLASSPATH) ".:$srcdir/$subdir:$objdir:$objdir/../libgcj.jar"
269
270 global wrapper_file wrap_compile_flags;
271 lappend args "additional_flags=$wrap_compile_flags";
272 lappend args "libs=$wrapper_file";
273 lappend args "libs=$libjava";
274 lappend args "libs=$libgc";
275 lappend args "libs=$libqthreads"
276 lappend args "libs=$libz"
277 lappend args debug
278
279 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
280 lappend args "libs=${gluefile}"
281 lappend args "ldflags=$wrap_flags"
282 }
283
284 if [info exists TOOL_OPTIONS] {
285 lappend args "additional_flags=$TOOL_OPTIONS"
286 }
287
288 # Search for libtool. We need it to link.
289 set found_compiler 0
290 set d [absolute $objdir]
291 foreach x {. .. ../.. ../../..} {
292 if {[file exists $d/$x/libtool]} then {
293 # We have to run silently to avoid DejaGNU lossage.
294 lappend args \
295 "compiler=$d/$x/libtool --silent --tag=GCJ --mode=$mode $GCJ_UNDER_TEST -B$objdir/../"
296 set found_compiler 1
297 break
298 }
299 }
300 if {! $found_compiler} {
301 # Append -B$objdir/../ so that we find libgcj.spec before it
302 # is installed.
303 lappend args "compiler=$GCJ_UNDER_TEST -B$objdir/../"
304 }
305
306 return $args
307 }
308
309
310 #
311 # Run the test specified by srcfile and resultfile. compile_args and
312 # exec_args are options telling this proc how to work.
313 #
314 proc test_libjava_from_source { options srcfile compile_args inpfile resultfile exec_args } {
315 global base_dir
316 global LIBJAVA
317 global LIBGC
318 global srcdir subdir objdir
319 global TOOL_OPTIONS
320 global GCJ_UNDER_TEST
321 global tmpdir
322 global runtests
323
324 # Make opts into an array.
325 set opts(_) x
326 unset opts(_)
327 foreach item $exec_args {
328 set opts($item) x
329 }
330
331 set errname [file rootname [file tail $srcfile]]
332 if {! [runtest_file_p $runtests $errname]} {
333 return
334 }
335
336 if {[info exists opts(no-link)]} {
337 set mode compile
338 } else {
339 set mode link
340 }
341 set args [libjava_arguments $mode]
342 if {! [info exists opts(no-link)]} {
343 # Add the --main flag
344 lappend args "additional_flags=--main=[file rootname [file tail $srcfile]]"
345 if { $compile_args != "" } {
346 lappend args "additional_flags=$compile_args"
347 }
348 }
349
350 regsub "^.*/(\[^/.\]+)\[.\]\[^/]*$" "$srcfile" "\\1" out
351 set executable "${objdir}/$out"
352 if {[info exists opts(no-link)]} {
353 append executable ".o"
354 set target object
355 } else {
356 set target executable
357 }
358 if { $compile_args != "" } {
359 set errname "$errname $compile_args"
360 }
361
362 set x [prune_warnings \
363 [libjava_tcompile $srcfile "$executable" $target $args]]
364 if {[info exists opts(xfail-gcj)]} {
365 setup_xfail *-*-*
366 }
367 if { $x != "" } {
368 verbose "target_compile failed: $x" 2
369
370 if {[info exists opts(shouldfail)]} {
371 pass "$errname compilation from source"
372 return
373 }
374
375 fail "$errname compilation from source"
376 if {[info exists opts(xfail-gcj)] || ! [info exists opts(no-exec)]} {
377 setup_xfail "*-*-*"
378 fail "$errname execution from source compiled test"
379 setup_xfail "*-*-*"
380 fail "$errname output from source compiled test"
381 }
382 return
383 }
384 if {[info exists opts(shouldfail)]} {
385 fail "$errname compilation from source"
386 return
387 }
388 pass "$errname compilation from source"
389
390 if {[info exists opts(no-exec)]
391 || [info exists opts(no-link)]} {
392 return
393 }
394
395 set result [libjava_load $executable "" "$inpfile"];
396 set status [lindex $result 0];
397 set output [lindex $result 1];
398 if {[info exists opts(xfail-exec)]} then {
399 setup_xfail *-*-*
400 }
401 $status "$errname execution from source compiled test"
402 if { $status != "pass" } {
403 setup_xfail "*-*-*"
404 fail "$errname execution from source compiled test"
405 return;
406 }
407
408 verbose "resultfile is $resultfile"
409 set id [open $resultfile r];
410 set expected ""
411 append expected [read $id];
412 regsub -all "\r" "$output" "" output;
413 regsub "\n*$" $expected "" expected
414 regsub "\n*$" $output "" output
415 regsub "^\n*" $expected "" expected
416 regsub "^\n*" $output "" output
417 regsub -all "\[ \t\]\[ \t\]*" $expected " " expected
418 regsub -all "\[ \t\]*\n\n*" $expected "\n" expected
419 regsub -all "\[ \t\]\[ \t\]*" $output " " output
420 regsub -all "\[ \t\]*\n\n*" $output "\n" output
421 verbose "expected is $expected"
422 verbose "actual is $output"
423 set passed 0;
424 if {$options == "regexp_match"} {
425 if [regexp $expected $output] {
426 set passed 1;
427 }
428 } else {
429 if { $expected == $output } {
430 set passed 1;
431 }
432 }
433 if {[info exists opts(xfail-output)]} {
434 setup_xfail *-*-*
435 }
436 if { $passed == 1 } {
437 pass "$errname output from source compiled test"
438 } else {
439 clone_output "expected was $expected"
440 clone_output "output was $output"
441 fail "$errname output from source compiled test"
442 }
443 close $id;
444 }
445
446 #
447 # Run the test specified by srcfile and resultfile. compile_args and
448 # exec_args are options telling this proc how to work.
449 #
450 proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile exec_args } {
451 global base_dir
452 global LIBJAVA
453 global LIBGC
454 global srcdir subdir objdir
455 global TOOL_OPTIONS
456 global GCJ_UNDER_TEST
457 global tmpdir
458 global runtests
459
460 # Make opts into an array.
461 set opts(_) x
462 unset opts(_)
463 foreach item $exec_args {
464 set opts($item) x
465 }
466
467 set errname [file rootname [file tail $srcfile]]
468 if {! [runtest_file_p $runtests $errname]} {
469 return
470 }
471
472 # bytecompile files with Sun's compiler for now.
473 set bc_ok [bytecompile_file $srcfile $objdir]
474
475 set javac [find_javac]
476 # This is an ugly heuristic but it will have to do.
477 if {[string match *gcj* $javac]} {
478 set tag gcjC
479 } else {
480 set tag javac
481 }
482 if {[info exists opts(xfail-$tag)]} {
483 setup_xfail *-*-*
484 }
485 if {! $bc_ok} then {
486 if {[info exists opts(shouldfail)]} {
487 pass "$errname byte compilation"
488 return
489 }
490 fail "$errname byte compilation"
491 setup_xfail "*-*-*"
492 fail "$errname compilation from bytecode"
493 if {! [info exists opts(no-exec)]} {
494 setup_xfail "*-*-*"
495 fail "$errname execution from bytecode->native test"
496 setup_xfail "*-*-*"
497 fail "$errname output from bytecode->native test"
498 }
499 return
500 }
501 if {[info exists opts(shouldfail)]} {
502 fail "$errname byte compilation"
503 return
504 }
505 pass "$errname byte compilation"
506
507 # Find name to use for --main, and name of all class files.
508 set jvscan [find_jvscan]
509 verbose "jvscan is $jvscan"
510 set main_name [string trim \
511 [prune_warnings \
512 [libjava_tcompile $srcfile "" none \
513 "compiler=$jvscan additional_flags=--print-main"]]]
514 verbose "main name is $main_name"
515 set class_out [string trim \
516 [prune_warnings \
517 [libjava_tcompile $srcfile "" none \
518 "compiler=$jvscan additional_flags=--list-class"]]]
519 verbose "class list is $class_out"
520
521 if {[string match "*parse error*" $main_name]
522 || [string match "*parse error*" $class_out]} {
523 # Do the remaining fails.
524 setup_xfail "*-*-*"
525 fail "$errname compilation from bytecode"
526 if {! [info exists opts(no-exec)]} {
527 setup_xfail "*-*-*"
528 fail "$errname execution from bytecode->native test"
529 setup_xfail "*-*-*"
530 fail "$errname output from bytecode->native test"
531 }
532 return
533 }
534
535 # Turn "a b" into "a.class b.class".
536 # Also, turn "foo.bar" into "foo/bar.class".
537 set class_files {}
538 foreach file [split [string trim $class_out]] {
539 set file [join [split $file .] /]
540 lappend class_files $objdir/$file.class
541 }
542
543 # Usually it is an error for a test program not to have a `main'
544 # method. However, for no-exec tests it is ok. Treat no-link
545 # like no-exec here.
546 if {[info exists opts(no-link)]} {
547 set opts(no-exec) x
548 }
549 set largs {}
550
551 if {[info exists opts(no-exec)]} {
552 set type object
553 set mode compile
554 } elseif {$main_name == ""} {
555 perror "No `main' given in program $errname"
556 return
557 } else {
558 set type executable
559 lappend largs "additional_flags=--main=$main_name"
560 set executable "${objdir}/$main_name"
561 set mode link
562 }
563
564 # Initial arguments.
565 set args [libjava_arguments $mode]
566 eval lappend args $largs
567
568 if { $compile_args != "" } {
569 lappend args "additional_flags=$compile_args"
570 }
571
572 if { $compile_args != "" } {
573 set errname "$errname $compile_args"
574 }
575
576 verbose "compilation command = $args" 2
577 # When compiling and not linking, we have to build each .o
578 # separately. We do this because DejaGNU's target_compile won't
579 # accept an empty "destfile" argument when the mode is "compile".
580 if {$mode == "compile"} {
581 foreach c_file $class_files {
582 set executable [file rootname [file tail $c_file]].o
583 set x [prune_warnings \
584 [libjava_tcompile $c_file "$executable" $type $args]]
585 if {$x != ""} {
586 break
587 }
588 }
589 } else {
590 # This is no evil: we de-listify CLASS_FILES so that we can
591 # turn around and quote the `$' in it for the shell. I really
592 # hate DejaGNU. It is so !@#$!@# unpredictable.
593 set hack ""
594 foreach stupid $class_files {
595 set hack "$hack $stupid"
596 }
597 set x [prune_warnings \
598 [libjava_tcompile $hack "$executable" $type $args]]
599 }
600 if {[info exists opts(xfail-byte)]} {
601 setup_xfail *-*-*
602 }
603 if { $x != "" } {
604 verbose "target_compile failed: $x" 2
605 fail "$errname compilation from bytecode"
606 setup_xfail "*-*-*"
607 if {! [info exists opts(no-exec)]} {
608 fail "$errname execution from bytecode->native test"
609 setup_xfail "*-*-*"
610 fail "$errname output from bytecode->native test"
611 }
612 return;
613 }
614 pass "$errname compilation from bytecode"
615
616 if {[info exists opts(no-exec)]} {
617 return
618 }
619
620 set result [libjava_load $executable "" "$inpfile"];
621 set status [lindex $result 0];
622 set output [lindex $result 1];
623 if {[info exists opts(xfail-exec)]} {
624 setup_xfail *-*-*
625 }
626 $status "$errname execution from bytecode->native test"
627 if { $status != "pass" } {
628 setup_xfail "*-*-*"
629 fail "$errname output from bytecode->native test"
630 return;
631 }
632
633 verbose "resultfile is $resultfile"
634 set id [open $resultfile r];
635 set expected ""
636 append expected [read $id];
637 regsub -all "\r" "$output" "" output;
638 regsub "\n*$" $expected "" expected
639 regsub "\n*$" $output "" output
640 regsub "^\n*" $expected "" expected
641 regsub "^\n*" $output "" output
642 regsub -all "\[ \t\]\[ \t\]*" $expected " " expected
643 regsub -all "\[ \t\]*\n\n*" $expected "\n" expected
644 regsub -all "\[ \t\]\[ \t\]*" $output " " output
645 regsub -all "\[ \t\]*\n\n*" $output "\n" output
646 verbose "expected is $expected"
647 verbose "actual is $output"
648 set passed 0;
649 if {[info exists opts(xfail-output)]} {
650 setup_xfail *-*-*
651 }
652 if {$options == "regexp_match"} {
653 if [regexp $expected $output] {
654 set passed 1;
655 }
656 } else {
657 if { $expected == $output } {
658 set passed 1;
659 }
660 }
661 if { $passed == 1 } {
662 pass "$errname output from bytecode->native test"
663 } else {
664 clone_output "expected was $expected"
665 clone_output "output was $output"
666 fail "$errname output from bytecode->native test"
667 }
668 close $id;
669 }
670
671 #
672 # Run the test specified by srcfile and resultfile. compile_args and
673 # exec_args are options telling this proc how to work.
674 # `no-link' don't try to link the program
675 # `no-exec' don't try to run the test
676 # `xfail-gcj' compilation from source will fail
677 # `xfail-javac' compilation with javac will fail
678 # `xfail-gcjC' compilation with gcj -C will fail
679 # `shouldfail' compilation from source is supposed to fail
680 # This is different from xfail, which marks a known
681 # failure that we just havne't fixed.
682 # A compilation marked this way should fail with any
683 # front end.
684 # `xfail-byte' compilation from bytecode will fail
685 # `xfail-exec' exec will fail
686 # `xfail-output' output will be wrong
687 #
688 proc test_libjava { options srcfile compile_args inpfile resultfile exec_args } {
689 test_libjava_from_source $options $srcfile $compile_args $inpfile $resultfile $exec_args
690 test_libjava_from_javac $options $srcfile $compile_args $inpfile $resultfile $exec_args
691 }
692
693 #
694 # libjava_version -- extract and print the version number of libjavap
695 #
696 proc default_libjava_version {} {
697 }
698
699 proc default_libjava_start { } {
700 }
701
702 # Local Variables:
703 # tcl-indent-level:4
704 # End:
This page took 0.066637 seconds and 5 git commands to generate.