OSDN Git Service

a807c4c8d60d0ac4d6e78f7e5f3163ce925a66e8
[pf3gnuchains/gcc-fork.git] / libjava / testsuite / lib / libjava.exp
1 # Copyright (C) 1998, 1999, 2000, 2001, 2002 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 `prune_warnings', but it also prunes away a warning
14 # from the bytecode front end that we don't care about.
15 proc libjava_prune_warnings {text} {
16     set text [prune_warnings $text]
17     set tlist [split $text \n]
18     set len [llength $tlist]
19     for {set i [expr {$len - 1}]} {$i >= 2} {incr i -1} {
20         if {[string match "*unreachable bytecode*" [lindex $tlist $i]]} {
21             # Delete this line and the previous two lines.
22             set tlist [lreplace $tlist [expr {$i - 2}] $i]
23             incr i -2
24         }
25     }
26     return [join $tlist \n]
27 }
28
29 # This is like `target_compile' but it does some surgery to work
30 # around stupid DejaGNU bugs.  In particular DejaGNU has very poor
31 # quoting, so for instance a `$' will be re-evaluated at spawn time.
32 # We don't want that.
33 proc libjava_tcompile {source destfile type options} {
34     # This strange-looking expression really does quote the `$'.
35     regsub -all -- {\$} $source {\$} source
36     regsub -all -- {\$} $destfile {\$} destfile
37     return [target_compile $source $destfile $type $options]
38 }
39
40 # Read an `xfail' file if it exists.  Returns a list of xfail tokens.
41 proc libjava_read_xfail {file} {
42     if {! [file exists $file]} {
43         return ""
44     }
45     set fd [open $file r]
46     set tokens [string trim [read $fd]]
47     close $fd
48     return $tokens
49 }
50
51 # Find a particular executable.  FIXME: this relies on DejaGnu
52 # internals.  These should probably be exposed in a better way.
53 proc libjava_find_program {prog} {
54     global tool_root_dir
55
56     set file [lookfor_file $tool_root_dir $prog]
57     if { $file == "" } {
58         set file [lookfor_file $tool_root_dir gcc/$prog];
59     }
60     if {$file == ""} {
61         set file $prog
62     }
63     return $file
64 }
65
66 # Find `jv-scan'.
67 proc find_jvscan {} {
68     return [libjava_find_program jv-scan]
69 }
70
71 # Find `gcjh'.
72 proc find_gcjh {} {
73     return [libjava_find_program gcjh]
74 }
75
76 proc find_javac {} {
77     global SUN_JAVAC GCJ_UNDER_TEST env
78     # If JDK doesn't run on your platform but some other
79     # JDK-compatible javac does, you may set SUN_JAVAC to point to it.
80     # One of the most important properties of a SUN_JAVAC is that it
81     # must create class-files even for classes that have not been
82     # specified in the command line, but that were needed to compile
83     # those that have.  For example, Pizza won't do it, but you can
84     # use `kaffe sun.tools.javac.Main', if you have Sun's classes.zip
85     # in the kaffe's default search path.
86     if {![info exists SUN_JAVAC]} {
87         if {[info exists env(SUN_JAVAC)]} {
88             set SUN_JAVAC $env(SUN_JAVAC)
89         } else {
90             set SUN_JAVAC "$GCJ_UNDER_TEST -C"
91         }
92     }
93     return $SUN_JAVAC
94 }
95
96 proc bytecompile_file { file objdir {classpath {}} } {
97     global env
98     set dirname [file dirname $file]
99
100     set javac [find_javac]
101     if {$classpath != ""} then {
102         set env(CLASSPATH) $classpath
103     }
104     set here [pwd]
105     cd $dirname
106     if {[catch {
107         set q [eval exec "$javac [list $file] -d $objdir 2>@ stdout"]
108     } msg]} then {
109         verbose "couldn't compile $file: $msg"
110         set r 0
111     } else {
112         set r 1
113     }
114     cd $here
115     return $r
116 }
117
118 set libjava_initialized 0
119
120 #
121 # Build the status wrapper library as needed.
122 #
123 proc libjava_init { args } {
124     global wrapper_file;
125     global wrap_compile_flags;
126     global libjava_initialized libjava_uses_threads
127     global GCJ_UNDER_TEST
128     global TOOL_EXECUTABLE
129     global original_ld_library_path
130     global env objdir
131     global env libgcj_jar
132     global tool_root_dir
133     global libjava_libgcc_s_path
134
135     if { $libjava_initialized == 1 } { return; }
136
137     if ![info exists GCJ_UNDER_TEST] {
138         if [info exists TOOL_EXECUTABLE] {
139             set GCJ_UNDER_TEST $TOOL_EXECUTABLE;
140         } else {
141             if [info exists env(GCJ)] {
142                 set GCJ_UNDER_TEST $env(GCJ)
143             } else {
144                 set GCJ_UNDER_TEST "[find_gcj]"
145             }
146         }
147     }
148
149     # Find the libgcj jar file.
150     set libgcj_jar [glob $objdir/../libgcj-*.jar]
151     verbose "jar file is $libgcj_jar"
152
153     # FIXME: This finds libgcj.spec for the default multilib.
154     # If thread models differ between multilibs, this has to be moved
155     # to libjava_arguments
156     set specdir [libjava_find_spec]
157
158     # The -B is so we find libgcj.spec.
159     set text [eval exec "$GCJ_UNDER_TEST -B$specdir -v 2>@ stdout"]
160     regexp -- "Thread model: (\[^\n\]+)\n" $text ignore model
161     set libjava_uses_threads [expr {! ($model == "no"
162                                        || $model == "none"
163                                        || $model == "single")}]
164
165     # Always set encoding used by gcj.
166     append GCJ_UNDER_TEST " --encoding=UTF-8"
167
168     if [info exists env(LD_LIBRARY_PATH)] {
169         set original_ld_library_path $env(LD_LIBRARY_PATH)
170     } else {
171         if [info exists env(SHLIB_PATH)] {
172             set original_ld_library_path $env(SHLIB_PATH)
173         } else {
174             set original_ld_library_path ""
175         }
176     }
177
178     set wrapper_file "";
179     set wrap_compile_flags "";
180     if [target_info exists needs_status_wrapper] {
181         set result [build_wrapper "testglue.o"];
182         if { $result != "" } {
183             set wrapper_file [lindex $result 0];
184             set wrap_compile_flags [lindex $result 1];
185         } else {
186             warning "Status wrapper failed to build."
187         }
188     }
189
190     # Finally, add the gcc build directory so that we can find the
191     # shared libgcc.  This, like much of dejagnu, is hideous.
192     set libjava_libgcc_s_path {}
193     set gccdir [lookfor_file $tool_root_dir gcc/libgcc_s.so]
194     if {$gccdir != ""} {
195         set gccdir [file dirname $gccdir]
196         lappend libjava_libgcc_s_path $gccdir
197         set compiler ${gccdir}/xgcc
198         if { [is_remote host] == 0 && [which $compiler] != 0 } {
199             foreach i "[exec $compiler --print-multi-lib]" {
200                 set mldir ""
201                 regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
202                 set mldir [string trimright $mldir "\;@"]
203                 if { "$mldir" == "." } {
204                     continue
205                 }
206                 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] == 1 } {
207                     lappend libjava_libgcc_s_path "${gccdir}/${mldir}"
208                 }
209             }
210         }
211     }
212
213     set libjava_initialized 1
214 }
215
216 # Find a library.  We know where libtool puts the actual libraries,
217 # and we look there.  The implementation is fairly hacky.  We can't
218 # compile with -nodefaultlibs, because that will also eliminate the
219 # system libraries we need.  In order to have gcj still work, it must
220 # find the appropriate libraries so we must add -L options for their
221 # paths.  However we can't simply use those libraries; we still need
222 # libtool for linking.
223 # Don't return the the lib${name}.la files here, since this causes the
224 # libraries to be linked twice: once as lib${name}.so and another time
225 # via gcj's implicit -l${name}.  This is both unnecessary and causes the
226 # Solaris ld to warn: attempted multiple inclusion of file.  This warning
227 # is not ignored by the dejagnu framework and cannot be disabled.
228 proc libjava_find_lib {dir name} {
229     global base_dir
230     set gp [get_multilibs]
231     foreach sub {.libs _libs} {
232         if {$gp != ""} {
233             if {[file exists $gp/$dir/$sub/lib${name}.a]} then {
234                 # Just return the `-L' option.  The library itself
235                 # will be picked up via the spec file.
236                 return "-L$gp/$dir/$sub"
237             }
238         }
239         # Just return the `-L' option.  The library itself will be
240         # picked up via the spec file.
241         set lib [findfile $base_dir/../../$dir/$sub/lib${name}.a \
242                    "-L$base_dir/../../$dir/$sub" \
243                    ""]
244         if {$lib != ""} {
245             return $lib
246         }
247     }
248     return ""
249 }
250
251 # Find libgcj.spec.  We need to use the file corresponding to the multilib
252 # under test since they might differ.  Append a trailing slash since this
253 # is used with -B.
254 proc libjava_find_spec {} {
255     global objdir
256     set gp [get_multilibs]
257
258     if {[file exists $gp/libjava/libgcj.spec]} then {
259         return "$gp/libjava/"
260     }
261     return "$objdir/../"
262 }
263
264 # Find `gij'.
265 proc libjava_find_gij {} {
266     global base_dir
267     set gp [get_multilibs]
268     if {$gp != ""} {
269         set file $gp/libjava/gij
270     } else {
271         set file $base_dir/../gij
272     }
273
274     if {[file exists $file]} {
275         return $file
276     }
277     return gij
278 }
279
280 # Remove a bunch of files.
281 proc gcj_cleanup {args} {
282     foreach file $args {
283         if {[string match *.o $file]} {
284             verbose "removing [file rootname $file].lo"
285             file delete -force [file rootname $file].lo
286         }
287         file delete -force -- $file
288         verbose "removing $file"
289     }
290     # It is simplest to do this instead of trying to figure out what
291     # bits in .libs ought to be removed.
292     catch {system "rm -rf .libs"}
293 }
294
295 # Compute arguments needed for compiler.  MODE is a libtool mode:
296 # either compile or link.
297 proc libjava_arguments {{mode compile}} {
298     global base_dir
299     global LIBJAVA
300     global LIBGC
301     global LIBQTHREADS
302     global LIBZ
303     global srcdir subdir objdir
304     global TOOL_OPTIONS
305     global GCJ_UNDER_TEST
306     global tmpdir
307     global runtests
308     global env
309     global tool_root_dir
310     global libgcj_jar
311     global libjava_libgcc_s_path
312
313     if [info exists LIBJAVA] {
314         set libjava $LIBJAVA;
315     } else {
316         set libjava [libjava_find_lib libjava gcj]
317     }
318
319     if [info exists LIBGC] {
320         set libgc $LIBGC;
321     } else {
322         set libgc [libjava_find_lib boehm-gc gcjgc]
323     }
324
325     if [info exists LIBQTHREADS] {
326         set libqthreads $LIBQTHREADS
327     } else {
328         set libqthreads [libjava_find_lib qthreads gcjcoop]
329     }
330
331     if [info exists LIBZ] {
332         set libz $LIBZ
333     } else {
334         set libz [libjava_find_lib zlib zgcj]
335     }
336
337     # FIXME: there's no way to determine whether -lpthread is
338     # required.  We should get this info from configure, or it should
339     # just be in the compiler driver.
340
341     verbose "using LIBJAVA = $libjava" 2
342     verbose "using LIBGC = $libgc" 2
343     verbose "using LIBQTHREADS = $libqthreads" 2
344     verbose "using LIBZ = $libz" 2
345     set args ""
346
347     # Basically we want to build up a colon separated path list from
348     # the value of $libjava.
349
350     set lpath {}
351     foreach dir [list $libjava $libgc $libz] {
352         foreach item [split $dir " "] {
353             switch -glob -- $item {
354                 "-L*" {
355                     lappend lpath [string range $item 2 end]
356                 }
357             }
358         }
359     }
360
361     set lpath [concat $lpath $libjava_libgcc_s_path]
362     set ld_library_path [join $lpath :]
363
364     # That's enough to make things work for the normal case.
365     # If we wanted to handle an arbitrary value of libjava,
366     # then we'd have to do a lot more work.
367
368     # Set variables the dynamic linker looks at.
369     global original_ld_library_path
370     setenv LD_LIBRARY_PATH "$ld_library_path:$original_ld_library_path"
371     setenv SHLIB_PATH "$ld_library_path:$original_ld_library_path"
372
373     verbose "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
374
375     # Set the CLASSPATH environment variable
376     verbose "CLASSPATH is .:$srcdir/$subdir:$objdir:$libgcj_jar"
377     global env
378     set env(CLASSPATH) ".:$srcdir/$subdir:$objdir:$libgcj_jar"
379
380     if {$mode == "link"} {
381         global wrapper_file wrap_compile_flags;
382         lappend args "additional_flags=$wrap_compile_flags";
383         lappend args "libs=$wrapper_file";
384         lappend args "libs=$libjava";
385         lappend args "libs=$libgc";
386         lappend args "libs=$libqthreads"
387         lappend args "libs=$libz"
388         lappend args debug
389     }
390
391     if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
392         lappend args "libs=${gluefile}"
393         lappend args "ldflags=$wrap_flags"
394     }
395
396     if [info exists TOOL_OPTIONS] {
397         lappend args "additional_flags=$TOOL_OPTIONS"
398     }
399
400     # Determine libgcj.spec corresponding to multilib under test.
401     set specdir [libjava_find_spec]
402
403     # Search for libtool.  We need it to link.
404     set found_compiler 0
405     set d [absolute $objdir]
406     foreach x {. .. ../.. ../../..} {
407         if {[file exists $d/$x/libtool]} then {
408             # We have to run silently to avoid DejaGNU lossage.
409             lappend args \
410               "compiler=$d/$x/libtool --silent --tag=GCJ --mode=$mode $GCJ_UNDER_TEST -B$specdir"
411             set found_compiler 1
412             break
413         }
414     }
415     if {! $found_compiler} {
416         # Append -B$specdir so that we find libgcj.spec before it
417         # is installed.
418         lappend args "compiler=$GCJ_UNDER_TEST -B$specdir"
419     }
420
421     # Avoid libtool wrapper scripts when possible.
422     # but not if libtool warnings results in FAILs
423     if {$mode == "link"} {
424         if {! [istarget "*-*-cygwin*"] && ! [istarget "*-*-mingw*"] } {
425             lappend args "additional_flags=-no-install"
426         }
427     }
428
429     return $args
430 }
431
432 # Link a bunch of objects into a program.  MAIN is the name of the
433 # class holding `main'.  Return 0 on failure.
434 proc gcj_link {program main files {options {}}} {
435     set arguments [libjava_arguments link]
436     if {[llength $options]} {
437         eval lappend arguments $options
438     }
439     lappend arguments "additional_flags=--main=$main"
440     set x [libjava_prune_warnings \
441              [libjava_tcompile $files $program executable $arguments]]
442     if {$x != ""} {
443         verbose "link failure: $x" 2
444         fail "linking $program"
445         setup_xfail "*-*-*"
446         fail "running $program"
447         return 0
448     }
449
450     pass "linking $program"
451     return 1
452 }
453
454 # Invoke a program and check its output.  EXECUTABLE is the program;
455 # ARGS are the arguments to the program.  Returns 1 if tests passed
456 # (or things were left untested), 0 otherwise.
457 proc libjava_invoke {errname testName optName executable inpfile resultfile args} {
458     upvar $optName opts
459
460     if {[info exists opts(no-exec)]} {
461         if {[info exists opts(need-threads)]} {
462             # This means we wanted to try to run it but we couldn't
463             # because threads aren't supported.  So we have to
464             # generate an `untested'.
465             untested "$errname execution - $testName"
466             untested "$errname output - $testName"
467         }
468         return 1
469     }
470
471     set result [libjava_load $executable $args "$inpfile"]
472     set status [lindex $result 0]
473     set output [lindex $result 1]
474     if {[info exists opts(xfail-exec)]} then {
475         setup_xfail *-*-*
476     }
477     $status "$errname execution - $testName"
478     if { $status != "pass" } {
479         untested "$errname output - $testName"
480         return 0
481     }
482
483     verbose "resultfile is $resultfile"
484     set id [open $resultfile r]
485     set expected ""
486     append expected [read $id]
487     regsub -all "\r" "$output" "" output
488     regsub "\n*$" $expected "" expected
489     regsub "\n*$" $output "" output
490     regsub "^\n*" $expected "" expected
491     regsub "^\n*" $output "" output
492     regsub -all "\[ \t\]\[ \t\]*" $expected " " expected
493     regsub -all "\[ \t\]*\n\n*" $expected "\n" expected
494     regsub -all "\[ \t\]\[ \t\]*" $output " " output
495     regsub -all "\[ \t\]*\n\n*" $output "\n" output
496     verbose "expected is $expected"
497     verbose "actual is $output"
498     set passed 0
499     if {[info exists opts(regexp_match)]} {
500         if [regexp $expected $output] {
501             set passed 1
502         }
503     } else {
504         if { $expected == $output } {
505             set passed 1
506         }
507     }
508     if {[info exists opts(xfail-output)]} {
509         setup_xfail *-*-*
510     }
511     if { $passed == 1 } {
512         pass "$errname output - $testName"
513     } else {
514         fail "$errname output - $testName"
515     }
516     close $id
517
518     return $passed
519 }
520
521 #
522 # Run the test specified by srcfile and resultfile. compile_args and
523 # exec_args are options telling this proc how to work.
524 #
525 proc test_libjava_from_source { options srcfile compile_args inpfile resultfile exec_args } {
526     global base_dir
527     global LIBJAVA
528     global LIBGC
529     global srcdir subdir objdir
530     global TOOL_OPTIONS
531     global GCJ_UNDER_TEST
532     global tmpdir
533     global runtests
534
535     # Make opts into an array.
536     set opts(_) x
537     unset opts(_)
538     foreach item $exec_args {
539         set opts($item) x
540     }
541
542     # If we need threads and we don't have them then set the `no-exec'
543     # flag.  This is case is also handled specially later.
544     if {[info exists opts(need-threads)]} {
545         global libjava_uses_threads
546         if {! $libjava_uses_threads} {
547             set opts(no-exec) x
548         }
549     }
550
551     set errname [file rootname [file tail $srcfile]]
552     if {! [runtest_file_p $runtests $errname]} {
553         return
554     }
555
556     if {[info exists opts(no-link)]} {
557         set mode compile
558     } else {
559         set mode link
560     }
561     set args [libjava_arguments $mode]
562     if {! [info exists opts(no-link)]} {
563         # Add the --main flag
564         lappend args "additional_flags=--main=[file rootname [file tail $srcfile]]"
565         if { $compile_args != "" } {
566             lappend args "additional_flags=$compile_args"
567         }
568     }
569
570     regsub "^.*/(\[^/.\]+)\[.\]\[^/]*$" "$srcfile" "\\1" out
571     set executable "${objdir}/$out"
572     if {[info exists opts(no-link)]} {
573         append executable ".o"
574         set target object
575     } else {
576         # DOS/win32 targets default to .exe if no suffix is given
577         # We then try to delete a file that doesn't exist.  It is
578         # simpler to add the suffix everywhere.
579         append executable ".exe"
580         set target executable
581     }
582     if { $compile_args != "" } {
583         set errname "$errname $compile_args"
584     }
585
586     set removeList [list $executable]
587
588     set x [libjava_prune_warnings \
589              [libjava_tcompile $srcfile "$executable" $target $args]]
590     if {[info exists opts(xfail-gcj)]} {
591         setup_xfail *-*-*
592     }
593     if { $x != "" } {
594         verbose "target_compile failed: $x" 2
595
596         if {[info exists opts(shouldfail)]} {
597             pass "$errname compilation from source"
598             eval gcj_cleanup $removeList
599             return
600         }
601
602         fail "$errname compilation from source"
603         if {[info exists opts(xfail-gcj)]
604             || ! [info exists opts(no-exec)]
605             || [info exists opts(need-threads)]} {
606             untested "$errname execution from source compiled test"
607             untested "$errname output from source compiled test"
608         }
609         return
610     }
611     if {[info exists opts(shouldfail)]} {
612         fail "$errname compilation from source"
613         return
614     }
615     pass "$errname compilation from source"
616
617     # Set up the options the way they are expected by libjava_invoke.
618     if {[info exists opts(xfail-source-output)]} {
619         set opts(xfail-output) x
620     }
621     if {[libjava_invoke $errname "source compiled test" opts $executable \
622            $inpfile $resultfile]} {
623         # Everything ok, so clean up.
624         eval gcj_cleanup $removeList
625     }
626 }
627
628 #
629 # Run the test specified by srcfile and resultfile. compile_args and
630 # exec_args are options telling this proc how to work.
631 #
632 proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile exec_args } {
633     global base_dir
634     global LIBJAVA
635     global LIBGC
636     global srcdir subdir objdir
637     global TOOL_OPTIONS
638     global GCJ_UNDER_TEST
639     global tmpdir
640     global runtests
641     global INTERPRETER
642
643     # Make opts into an array.
644     set opts(_) x
645     unset opts(_)
646     foreach item $exec_args {
647         set opts($item) x
648     }
649
650     # If we need threads and we don't have them then set the `no-exec'
651     # flag.  This is case is also handled specially later.
652     if {[info exists opts(need-threads)]} {
653         global libjava_uses_threads
654         if {! $libjava_uses_threads} {
655             set opts(no-exec) x
656         }
657     }
658     set errname [file rootname [file tail $srcfile]]
659     if {! [runtest_file_p $runtests $errname]} {
660         return
661     }
662
663     # bytecompile files with Sun's compiler for now.
664     set bc_ok [bytecompile_file $srcfile $objdir]
665
666     set javac [find_javac]
667     # This is an ugly heuristic but it will have to do.
668     if {[string match *gcj* $javac]} {
669         set tag gcjC
670     } else {
671         set tag javac
672     }
673     if {[info exists opts(xfail-$tag)]} {
674         setup_xfail *-*-*
675     }
676     if {! $bc_ok} then {
677         if {[info exists opts(shouldfail)]} {
678             pass "$errname byte compilation"
679             return
680         }
681         fail "$errname byte compilation"
682         untested "$errname compilation from bytecode"
683         if {! [info exists opts(no-exec)]
684             || [info exists opts(need-threads)]} {
685             untested "$errname execution from bytecode->native test"
686             untested "$errname output from bytecode->native test"
687         }
688         return
689     }
690     if {[info exists opts(shouldfail)]} {
691         fail "$errname byte compilation"
692         return
693     }
694     pass "$errname byte compilation"
695
696     set removeList {}
697
698     # Find name to use for --main, and name of all class files.
699     set jvscan [find_jvscan]
700     verbose "jvscan is $jvscan"
701     set main_name [string trim \
702                      [libjava_prune_warnings \
703                         [lindex [local_exec "$jvscan --encoding=UTF-8 $srcfile --print-main" "" "" 300] 1]]]
704     verbose "main name is $main_name"
705     set class_out [string trim \
706                      [libjava_prune_warnings \
707                         [lindex [local_exec "$jvscan --encoding=UTF-8 $srcfile --list-class" "" "" 300] 1]]]
708     verbose "class list is $class_out"
709
710     if {[string match "*parse error*" $main_name]
711         || [string match "*parse error*" $class_out]} {
712         untested "$errname compilation from bytecode"
713         if {! [info exists opts(no-exec)]
714             || [info exists opts(need-threads)]} {
715             untested "$errname execution from bytecode->native test"
716             untested "$errname output from bytecode->native test"
717         }
718         return
719     }
720
721     # Turn "a b" into "a.class b.class".
722     # Also, turn "foo.bar" into "foo/bar.class".
723     set class_files {}
724     foreach file [split [string trim $class_out]] {
725         set file [join [split $file .] /]
726         lappend class_files $objdir/$file.class
727     }
728
729     eval lappend removeList $class_files
730
731     # Usually it is an error for a test program not to have a `main'
732     # method.  However, for no-exec tests it is ok.  Treat no-link
733     # like no-exec here.
734     if {[info exists opts(no-link)]} {
735         set opts(no-exec) x
736     }
737     set largs {}
738
739     if {[info exists opts(no-exec)]} {
740         set type object
741         set mode compile
742     } elseif {$main_name == ""} {
743         perror "No `main' given in program $errname"
744         return
745     } else {
746         set type executable
747         lappend largs "additional_flags=--main=$main_name"
748         # DOS/win32 targets default to .exe if no suffix is given
749         # We then try to delete a file that doesn't exist.  It is
750         # simpler to add the suffix everywhere.
751         set executable "${objdir}/${main_name}.exe"
752         set mode link
753     }
754
755     # We purposely ignore errors here; we still want to run the other
756     # appropriate tests.
757     set gij [libjava_find_gij]
758     # libjava_find_gij will return `gij' if it couldn't find the
759     # program; in this case we want to skip the test.
760     if {$INTERPRETER == "yes" && $gij != "gij"} {
761         libjava_invoke $errname "gij test" opts $gij \
762           $inpfile $resultfile $main_name
763     }
764
765     # Initial arguments.
766     set args [libjava_arguments $mode]
767     eval lappend args $largs
768
769     if { $compile_args != "" } {
770         lappend args "additional_flags=$compile_args"
771     }
772
773     if { $compile_args != "" } {
774         set errname "$errname $compile_args"
775     }
776
777     verbose "compilation command = $args" 2
778     # When compiling and not linking, we have to build each .o
779     # separately.  We do this because DejaGNU's target_compile won't
780     # accept an empty "destfile" argument when the mode is "compile".
781     if {$mode == "compile"} {
782         foreach c_file $class_files {
783             set executable [file rootname [file tail $c_file]].o
784             set x [libjava_prune_warnings \
785                      [libjava_tcompile $c_file "$executable" $type $args]]
786             lappend removeList $executable
787             if {$x != ""} {
788                 break
789             }
790         }
791     } else {
792         # This is so evil: we de-listify CLASS_FILES so that we can
793         # turn around and quote the `$' in it for the shell.  I really
794         # hate DejaGNU.  It is so !@#$!@# unpredictable.
795         set hack ""
796         foreach stupid $class_files {
797             set hack "$hack $stupid"
798         }
799         lappend removeList $executable
800         set x [libjava_prune_warnings \
801                  [libjava_tcompile $hack "$executable" $type $args]]
802     }
803     if {[info exists opts(xfail-byte)]} {
804         setup_xfail *-*-*
805     }
806     if { $x != "" } {
807         verbose "target_compile failed: $x" 2
808         fail "$errname compilation from bytecode"
809         if {! [info exists opts(no-exec)]
810             || [info exists opts(need-threads)]} {
811             untested "$errname execution from bytecode->native test"
812             untested "$errname output from bytecode->native test"
813         }
814         return;
815     }
816     pass "$errname compilation from bytecode"
817
818     # Set up the options the way they are expected by libjava_invoke.
819     if {[info exists opts(xfail-byte-output)]} {
820         set opts(xfail-output) x
821     }
822     if {[libjava_invoke $errname "bytecode->native test" opts $executable \
823            $inpfile $resultfile]} {
824         # Everything ok, so clean up.
825         eval gcj_cleanup $removeList
826     }
827 }
828
829 #
830 # Run the test specified by srcfile and resultfile. compile_args and
831 # exec_args are options telling this proc how to work.
832 #   `no-link'     don't try to link the program
833 #   `no-exec'     don't try to run the test
834 #   `xfail-gcj'   compilation from source will fail
835 #   `xfail-javac' compilation with javac will fail
836 #   `xfail-gcjC'  compilation with gcj -C will fail
837 #   `shouldfail'  compilation from source is supposed to fail
838 #                 This is different from xfail, which marks a known
839 #                 failure that we just haven't fixed.
840 #                 A compilation marked this way should fail with any
841 #                 front end.
842 #   `xfail-byte'  compilation from bytecode will fail
843 #   `xfail-exec'  exec will fail
844 #   `xfail-output'
845 #                 output will be wrong
846 #   `xfail-byte-output'
847 #                 output will be wrong when compiled from bytecode
848 #   `xfail-source-output'
849 #                 output will be wrong when compiled from source code
850 #   `need-threads'
851 #                 test relies on thread support
852 #
853 proc test_libjava { options srcfile compile_args inpfile resultfile exec_args } {
854     test_libjava_from_source $options $srcfile $compile_args $inpfile $resultfile $exec_args
855     test_libjava_from_javac $options $srcfile $compile_args $inpfile $resultfile $exec_args
856  }
857
858 #
859 # libjava_version -- extract and print the version number of libjavap
860 #
861 proc default_libjava_version {} {
862 }
863
864 proc default_libjava_start { } {
865 }
866
867 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
868 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
869 # (for the 64-bit ABI).  The right way to do this would be to modify
870 # unix.exp -- but that's not an option since it's part of DejaGNU
871 # proper, so we do it here, by trickery.  We really only need to do 
872 # this on IRIX, but it shouldn't hurt to do it anywhere else.
873
874 proc ${tool}_set_ld_library_path { name element op } {
875   setenv LD_LIBRARYN32_PATH [getenv LD_LIBRARY_PATH]
876   setenv LD_LIBRARY64_PATH [getenv LD_LIBRARY_PATH]
877 }
878
879 trace variable env(LD_LIBRARY_PATH) w ${tool}_set_ld_library_path
880
881 # Local Variables:
882 # tcl-indent-level:4
883 # End: