aboutsummaryrefslogtreecommitdiff
path: root/libjava/testsuite/lib/libjava.exp
blob: 3cb6140438d8d7fb144efcf0e17d9ccf315d6ef2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
# Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation

load_lib "libgloss.exp"

# GCJ_UNDER_TEST is the compiler under test.

global tmpdir

if ![info exists tmpdir] {
    set tmpdir "/tmp"
}

# This is like `target_compile' but it does some surgery to work
# around stupid DejaGNU bugs.  In particular DejaGNU has very poor
# quoting, so for instance a `$' will be re-evaluated at spawn time.
# We don't want that.
proc libjava_tcompile {source destfile type options} {
    # This strange-looking expression really does quote the `$'.
    regsub -all -- {\$} $source {\$} source
    regsub -all -- {\$} $destfile {\$} destfile
    return [target_compile $source $destfile $type $options]
}

# Read an `xfail' file if it exists.  Returns a list of xfail tokens.
proc libjava_read_xfail {file} {
    if {! [file exists $file]} {
	return ""
    }
    set fd [open $file r]
    set tokens [string trim [read $fd]]
    close $fd
    return $tokens
}

# Find a particular executable.  FIXME: this relies on DejaGnu
# internals.  These should probably be exposed in a better way.
proc libjava_find_program {prog} {
    global tool_root_dir

    set file [lookfor_file $tool_root_dir $prog]
    if { $file == "" } {
	set file [lookfor_file $tool_root_dir gcc/$prog];
    }
    if {$file == ""} {
	set file $prog
    }
    return $file
}

# Find `jv-scan'.
proc find_jvscan {} {
    return [libjava_find_program jv-scan]
}

# Find `gcjh'.
proc find_gcjh {} {
    return [libjava_find_program gcjh]
}

proc find_javac {} {
    global SUN_JAVAC GCJ_UNDER_TEST env
    # If JDK doesn't run on your platform but some other
    # JDK-compatible javac does, you may set SUN_JAVAC to point to it.
    # One of the most important properties of a SUN_JAVAC is that it
    # must create class-files even for classes that have not been
    # specified in the command line, but that were needed to compile
    # those that have.  For example, Pizza won't do it, but you can
    # use `kaffe sun.tools.javac.Main', if you have Sun's classes.zip
    # in the kaffe's default search path.
    if {![info exists SUN_JAVAC]} {
	if {[info exists env(SUN_JAVAC)]} {
	    set SUN_JAVAC $env(SUN_JAVAC)
	} else {
	    set SUN_JAVAC "$GCJ_UNDER_TEST -C"
	}
    }
    return $SUN_JAVAC
}

proc bytecompile_file { file objdir {classpath {}} } {
    global env
    set dirname [file dirname $file]

    set javac [find_javac]
    if {$classpath != ""} then {
        set env(CLASSPATH) $classpath
    }
    set here [pwd]
    cd $dirname
    if {[catch {
	set q [eval exec "$javac [list $file] -d $objdir 2>@ stdout"]
    } msg]} then {
	verbose "couldn't compile $file: $msg"
	set r 0
    } else {
	set r 1
    }
    cd $here
    return $r
}

set libjava_initialized 0

#
# Build the status wrapper library as needed.
#
proc libjava_init { args } {
    global wrapper_file;
    global wrap_compile_flags;
    global libjava_initialized libjava_uses_threads
    global GCJ_UNDER_TEST
    global TOOL_EXECUTABLE
    global original_ld_library_path
    global env objdir
    global env libgcj_jar
    global tool_root_dir
    global libjava_libgcc_s_path

    if { $libjava_initialized == 1 } { return; }

    if ![info exists GCJ_UNDER_TEST] {
	if [info exists TOOL_EXECUTABLE] {
	    set GCJ_UNDER_TEST $TOOL_EXECUTABLE;
	} else {
	    if [info exists env(GCJ)] {
		set GCJ_UNDER_TEST $env(GCJ)
	    } else {
		set GCJ_UNDER_TEST "[find_gcj]"
	    }
	}
    }

    # Find the libgcj jar file.
    set libgcj_jar [glob $objdir/../libgcj-*.jar]
    verbose "jar file is $libgcj_jar"

    # FIXME: This finds libgcj.spec for the default multilib.
    # If thread models differ between multilibs, this has to be moved
    # to libjava_arguments
    set specdir [libjava_find_spec]

    # The -B is so we find libgcj.spec.
    set text [eval exec "$GCJ_UNDER_TEST -B$specdir -v 2>@ stdout"]
    regexp -- "Thread model: (\[^\n\]+)\n" $text ignore model
    set libjava_uses_threads [expr {! ($model == "no"
				       || $model == "none"
				       || $model == "single")}]

    # Always set encoding used by gcj.
    append GCJ_UNDER_TEST " --encoding=UTF-8"

    if [info exists env(LD_LIBRARY_PATH)] {
	set original_ld_library_path $env(LD_LIBRARY_PATH)
    } else {
	if [info exists env(SHLIB_PATH)] {
	    set original_ld_library_path $env(SHLIB_PATH)
	} else {
	    set original_ld_library_path ""
	}
    }

    set wrapper_file "";
    set wrap_compile_flags "";
    if [target_info exists needs_status_wrapper] {
	set result [build_wrapper "testglue.o"];
	if { $result != "" } {
	    set wrapper_file [lindex $result 0];
	    set wrap_compile_flags [lindex $result 1];
	} else {
	    warning "Status wrapper failed to build."
	}
    }

    # Finally, add the gcc build directory so that we can find the
    # shared libgcc.  This, like much of dejagnu, is hideous.
    set libjava_libgcc_s_path {}
    set gccdir [lookfor_file $tool_root_dir gcc/libgcc_s.so]
    if {$gccdir != ""} {
	set gccdir [file dirname $gccdir]
	lappend libjava_libgcc_s_path $gccdir
	set compiler ${gccdir}/xgcc
	if { [is_remote host] == 0 && [which $compiler] != 0 } {
	    foreach i "[exec $compiler --print-multi-lib]" {
		set mldir ""
		regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
		set mldir [string trimright $mldir "\;@"]
		if { "$mldir" == "." } {
		    continue
		}
		if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] == 1 } {
		    lappend libjava_libgcc_s_path "${gccdir}/${mldir}"
		}
	    }
	}
    }

    set libjava_initialized 1
}

# Find a library.  We know where libtool puts the actual libraries,
# and we look there.  The implementation is fairly hacky.  We can't
# compile with -nodefaultlibs, because that will also eliminate the
# system libraries we need.  In order to have gcj still work, it must
# find the appropriate libraries so we must add -L options for their
# paths.  However we can't simply use those libraries; we still need
# libtool for linking.
# Don't return the the lib${name}.la files here, since this causes the
# libraries to be linked twice: once as lib${name}.so and another time
# via gcj's implicit -l${name}.  This is both unnecessary and causes the
# Solaris ld to warn: attempted multiple inclusion of file.  This warning
# is not ignored by the dejagnu framework and cannot be disabled.
proc libjava_find_lib {dir name} {
    global base_dir
    set gp [get_multilibs]
    foreach sub {.libs _libs} {
	if {$gp != ""} {
	    if {[file exists $gp/$dir/$sub/lib${name}.a]} then {
		# Just return the `-L' option.  The library itself
		# will be picked up via the spec file.
		return "-L$gp/$dir/$sub"
	    }
	}
	# Just return the `-L' option.  The library itself will be
	# picked up via the spec file.
	set lib [findfile $base_dir/../../$dir/$sub/lib${name}.a \
		   "-L$base_dir/../../$dir/$sub" \
		   ""]
	if {$lib != ""} {
	    return $lib
	}
    }
    return ""
}

# Find libgcj.spec.  We need to use the file corresponding to the multilib
# under test since they might differ.  Append a trailing slash since this
# is used with -B.
proc libjava_find_spec {} {
    global objdir
    set gp [get_multilibs]

    if {[file exists $gp/libjava/libgcj.spec]} then {
	return "$gp/libjava/"
    }
    return "$objdir/../"
}

# Find `gij'.
proc libjava_find_gij {} {
    global base_dir
    set gp [get_multilibs]
    if {$gp != ""} {
	set file $gp/libjava/gij
    } else {
	set file $base_dir/../gij
    }

    if {[file exists $file]} {
	return $file
    }
    return gij
}

# Remove a bunch of files.
proc gcj_cleanup {args} {
    foreach file $args {
	if {[string match *.o $file]} {
	    verbose "removing [file rootname $file].lo"
	    file delete -force [file rootname $file].lo
	}
	file delete -force -- $file
	verbose "removing $file"
    }
    # It is simplest to do this instead of trying to figure out what
    # bits in .libs ought to be removed.
    catch {system "rm -rf .libs"}
}

# Compute arguments needed for compiler.  MODE is a libtool mode:
# either compile or link.
proc libjava_arguments {{mode compile}} {
    global base_dir
    global LIBJAVA
    global LIBGC
    global LIBQTHREADS
    global LIBZ
    global srcdir subdir objdir
    global TOOL_OPTIONS
    global GCJ_UNDER_TEST
    global tmpdir
    global runtests
    global env
    global tool_root_dir
    global libgcj_jar
    global libjava_libgcc_s_path

    if [info exists LIBJAVA] {
	set libjava $LIBJAVA;
    } else {
	set libjava [libjava_find_lib libjava gcj]
    }

    if [info exists LIBGC] {
	set libgc $LIBGC;
    } else {
	set libgc [libjava_find_lib boehm-gc gcjgc]
    }

    if [info exists LIBQTHREADS] {
	set libqthreads $LIBQTHREADS
    } else {
	set libqthreads [libjava_find_lib qthreads gcjcoop]
    }

    if [info exists LIBZ] {
	set libz $LIBZ
    } else {
	set libz [libjava_find_lib zlib zgcj]
    }

    # FIXME: there's no way to determine whether -lpthread is
    # required.  We should get this info from configure, or it should
    # just be in the compiler driver.

    verbose "using LIBJAVA = $libjava" 2
    verbose "using LIBGC = $libgc" 2
    verbose "using LIBQTHREADS = $libqthreads" 2
    verbose "using LIBZ = $libz" 2
    set args ""

    # Basically we want to build up a colon separated path list from
    # the value of $libjava.

    set lpath {}
    foreach dir [list $libjava $libgc $libz] {
	foreach item [split $dir " "] {
	    switch -glob -- $item {
		"-L*" {
		    lappend lpath [string range $item 2 end]
		}
	    }
	}
    }

    set lpath [concat $lpath $libjava_libgcc_s_path]
    set ld_library_path [join $lpath :]

    # That's enough to make things work for the normal case.
    # If we wanted to handle an arbitrary value of libjava,
    # then we'd have to do a lot more work.

    # Set variables the dynamic linker looks at.
    global original_ld_library_path
    setenv LD_LIBRARY_PATH "$ld_library_path:$original_ld_library_path"
    setenv SHLIB_PATH "$ld_library_path:$original_ld_library_path"

    verbose "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"

    # Set the CLASSPATH environment variable
    verbose "CLASSPATH is .:$srcdir/$subdir:$objdir:$libgcj_jar"
    global env
    set env(CLASSPATH) ".:$srcdir/$subdir:$objdir:$libgcj_jar"

    if {$mode == "link"} {
	global wrapper_file wrap_compile_flags;
	lappend args "additional_flags=$wrap_compile_flags";
	lappend args "libs=$wrapper_file";
	lappend args "libs=$libjava";
	lappend args "libs=$libgc";
	lappend args "libs=$libqthreads"
	lappend args "libs=$libz"
	lappend args debug
    }

    if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
	lappend args "libs=${gluefile}"
	lappend args "ldflags=$wrap_flags"
    }

    if [info exists TOOL_OPTIONS] {
	lappend args "additional_flags=$TOOL_OPTIONS"
    }

    # Determine libgcj.spec corresponding to multilib under test.
    set specdir [libjava_find_spec]

    # Search for libtool.  We need it to link.
    set found_compiler 0
    set d [absolute $objdir]
    foreach x {. .. ../.. ../../..} {
	if {[file exists $d/$x/libtool]} then {
	    # We have to run silently to avoid DejaGNU lossage.
	    lappend args \
	      "compiler=$d/$x/libtool --silent --tag=GCJ --mode=$mode $GCJ_UNDER_TEST -B$specdir"
	    set found_compiler 1
	    break
	}
    }
    if {! $found_compiler} {
	# Append -B$specdir so that we find libgcj.spec before it
	# is installed.
	lappend args "compiler=$GCJ_UNDER_TEST -B$specdir"
    }

    # Avoid libtool wrapper scripts when possible.
    # but not if libtool warnings results in FAILs
    if {$mode == "link"} {
        if {! [istarget "*-*-cygwin*"] && ! [istarget "*-*-mingw*"] } {
            lappend args "additional_flags=-no-install"
        }
    }

    return $args
}

# Link a bunch of objects into a program.  MAIN is the name of the
# class holding `main'.  Return 0 on failure.
proc gcj_link {program main files {options {}}} {
    set arguments [libjava_arguments link]
    if {[llength $options]} {
	eval lappend arguments $options
    }
    lappend arguments "additional_flags=--main=$main"
    set x [prune_warnings [libjava_tcompile $files $program executable \
			     $arguments]]
    if {$x != ""} {
	verbose "link failure: $x" 2
	fail "linking $program"
	setup_xfail "*-*-*"
	fail "running $program"
	return 0
    }

    pass "linking $program"
    return 1
}

# Invoke a program and check its output.  EXECUTABLE is the program;
# ARGS are the arguments to the program.  Returns 1 if tests passed
# (or things were left untested), 0 otherwise.
proc libjava_invoke {errname testName optName executable inpfile resultfile args} {
    upvar $optName opts

    if {[info exists opts(no-exec)]} {
	if {[info exists opts(need-threads)]} {
	    # This means we wanted to try to run it but we couldn't
	    # because threads aren't supported.  So we have to
	    # generate an `untested'.
	    untested "$errname execution - $testName"
	    untested "$errname output - $testName"
	}
	return 1
    }

    set result [libjava_load $executable $args "$inpfile"]
    set status [lindex $result 0]
    set output [lindex $result 1]
    if {[info exists opts(xfail-exec)]} then {
	setup_xfail *-*-*
    }
    $status "$errname execution - $testName"
    if { $status != "pass" } {
	untested "$errname output - $testName"
	return 0
    }

    verbose "resultfile is $resultfile"
    set id [open $resultfile r]
    set expected ""
    append expected [read $id]
    regsub -all "\r" "$output" "" output
    regsub "\n*$" $expected "" expected
    regsub "\n*$" $output "" output
    regsub "^\n*" $expected "" expected
    regsub "^\n*" $output "" output
    regsub -all "\[ \t\]\[ \t\]*" $expected " " expected
    regsub -all "\[ \t\]*\n\n*" $expected "\n" expected
    regsub -all "\[ \t\]\[ \t\]*" $output " " output
    regsub -all "\[ \t\]*\n\n*" $output "\n" output
    verbose "expected is $expected"
    verbose "actual is $output"
    set passed 0
    if {[info exists opts(regexp_match)]} {
	if [regexp $expected $output] {
	    set passed 1
	}
    } else {
	if { $expected == $output } {
	    set passed 1
	}
    }
    if {[info exists opts(xfail-output)]} {
	setup_xfail *-*-*
    }
    if { $passed == 1 } {
	pass "$errname output - $testName"
    } else {
	fail "$errname output - $testName"
    }
    close $id

    return $passed
}

#
# Run the test specified by srcfile and resultfile. compile_args and
# exec_args are options telling this proc how to work.
#
proc test_libjava_from_source { options srcfile compile_args inpfile resultfile exec_args } {
    global base_dir
    global LIBJAVA
    global LIBGC
    global srcdir subdir objdir
    global TOOL_OPTIONS
    global GCJ_UNDER_TEST
    global tmpdir
    global runtests

    # Make opts into an array.
    set opts(_) x
    unset opts(_)
    foreach item $exec_args {
	set opts($item) x
    }

    # If we need threads and we don't have them then set the `no-exec'
    # flag.  This is case is also handled specially later.
    if {[info exists opts(need-threads)]} {
	global libjava_uses_threads
	if {! $libjava_uses_threads} {
	    set opts(no-exec) x
	}
    }

    set errname [file rootname [file tail $srcfile]]
    if {! [runtest_file_p $runtests $errname]} {
        return
    }

    if {[info exists opts(no-link)]} {
	set mode compile
    } else {
	set mode link
    }
    set args [libjava_arguments $mode]
    if {! [info exists opts(no-link)]} {
	# Add the --main flag
	lappend args "additional_flags=--main=[file rootname [file tail $srcfile]]"
	if { $compile_args != "" } {
	    lappend args "additional_flags=$compile_args"
	}
    }

    regsub "^.*/(\[^/.\]+)\[.\]\[^/]*$" "$srcfile" "\\1" out
    set executable "${objdir}/$out"
    if {[info exists opts(no-link)]} {
	append executable ".o"
	set target object
    } else {
        # DOS/win32 targets default to .exe if no suffix is given
        # We then try to delete a file that doesn't exist.  It is
        # simpler to add the suffix everywhere.
        append executable ".exe"
	set target executable
    }
    if { $compile_args != "" } {
	set errname "$errname $compile_args"
    }

    set removeList [list $executable]

    set x [prune_warnings \
	     [libjava_tcompile $srcfile "$executable" $target $args]]
    if {[info exists opts(xfail-gcj)]} {
	setup_xfail *-*-*
    }
    if { $x != "" } {
	verbose "target_compile failed: $x" 2

	if {[info exists opts(shouldfail)]} {
	    pass "$errname compilation from source"
	    eval gcj_cleanup $removeList
	    return
	}

	fail "$errname compilation from source"
	if {[info exists opts(xfail-gcj)]
	    || ! [info exists opts(no-exec)]
	    || [info exists opts(need-threads)]} {
	    untested "$errname execution from source compiled test"
	    untested "$errname output from source compiled test"
	}
	return
    }
    if {[info exists opts(shouldfail)]} {
	fail "$errname compilation from source"
	return
    }
    pass "$errname compilation from source"

    # Set up the options the way they are expected by libjava_invoke.
    if {[info exists opts(xfail-source-output)]} {
	set opts(xfail-output) x
    }
    if {[libjava_invoke $errname "source compiled test" opts $executable \
	   $inpfile $resultfile]} {
	# Everything ok, so clean up.
	eval gcj_cleanup $removeList
    }
}

#
# Run the test specified by srcfile and resultfile. compile_args and
# exec_args are options telling this proc how to work.
#
proc test_libjava_from_javac { options srcfile compile_args inpfile resultfile exec_args } {
    global base_dir
    global LIBJAVA
    global LIBGC
    global srcdir subdir objdir
    global TOOL_OPTIONS
    global GCJ_UNDER_TEST
    global tmpdir
    global runtests
    global INTERPRETER

    # Make opts into an array.
    set opts(_) x
    unset opts(_)
    foreach item $exec_args {
	set opts($item) x
    }

    # If we need threads and we don't have them then set the `no-exec'
    # flag.  This is case is also handled specially later.
    if {[info exists opts(need-threads)]} {
	global libjava_uses_threads
	if {! $libjava_uses_threads} {
	    set opts(no-exec) x
	}
    }
    set errname [file rootname [file tail $srcfile]]
    if {! [runtest_file_p $runtests $errname]} {
        return
    }

    # bytecompile files with Sun's compiler for now.
    set bc_ok [bytecompile_file $srcfile $objdir]

    set javac [find_javac]
    # This is an ugly heuristic but it will have to do.
    if {[string match *gcj* $javac]} {
	set tag gcjC
    } else {
	set tag javac
    }
    if {[info exists opts(xfail-$tag)]} {
	setup_xfail *-*-*
    }
    if {! $bc_ok} then {
	if {[info exists opts(shouldfail)]} {
	    pass "$errname byte compilation"
	    return
	}
	fail "$errname byte compilation"
	untested "$errname compilation from bytecode"
	if {! [info exists opts(no-exec)]
	    || [info exists opts(need-threads)]} {
	    untested "$errname execution from bytecode->native test"
	    untested "$errname output from bytecode->native test"
	}
	return
    }
    if {[info exists opts(shouldfail)]} {
	fail "$errname byte compilation"
	return
    }
    pass "$errname byte compilation"

    set removeList {}

    # Find name to use for --main, and name of all class files.
    set jvscan [find_jvscan]
    verbose "jvscan is $jvscan"
    set main_name [string trim \
		     [prune_warnings \
			[lindex [local_exec "$jvscan --encoding=UTF-8 $srcfile --print-main" "" "" 300] 1]]]
    verbose "main name is $main_name"
    set class_out [string trim \
		     [prune_warnings \
			[lindex [local_exec "$jvscan --encoding=UTF-8 $srcfile --list-class" "" "" 300] 1]]]
    verbose "class list is $class_out"

    if {[string match "*parse error*" $main_name]
	|| [string match "*parse error*" $class_out]} {
	untested "$errname compilation from bytecode"
	if {! [info exists opts(no-exec)]
	    || [info exists opts(need-threads)]} {
	    untested "$errname execution from bytecode->native test"
	    untested "$errname output from bytecode->native test"
	}
	return
    }

    # Turn "a b" into "a.class b.class".
    # Also, turn "foo.bar" into "foo/bar.class".
    set class_files {}
    foreach file [split [string trim $class_out]] {
	set file [join [split $file .] /]
	lappend class_files $objdir/$file.class
    }

    eval lappend removeList $class_files

    # Usually it is an error for a test program not to have a `main'
    # method.  However, for no-exec tests it is ok.  Treat no-link
    # like no-exec here.
    if {[info exists opts(no-link)]} {
	set opts(no-exec) x
    }
    set largs {}

    if {[info exists opts(no-exec)]} {
	set type object
	set mode compile
    } elseif {$main_name == ""} {
	perror "No `main' given in program $errname"
	return
    } else {
	set type executable
	lappend largs "additional_flags=--main=$main_name"
	# DOS/win32 targets default to .exe if no suffix is given
        # We then try to delete a file that doesn't exist.  It is
	# simpler to add the suffix everywhere.
	set executable "${objdir}/${main_name}.exe"
	set mode link
    }

    # We purposely ignore errors here; we still want to run the other
    # appropriate tests.
    set gij [libjava_find_gij]
    # libjava_find_gij will return `gij' if it couldn't find the
    # program; in this case we want to skip the test.
    if {$INTERPRETER == "yes" && $gij != "gij"} {
	libjava_invoke $errname "gij test" opts $gij \
	  $inpfile $resultfile $main_name
    }

    # Initial arguments.
    set args [libjava_arguments $mode]
    eval lappend args $largs

    if { $compile_args != "" } {
	lappend args "additional_flags=$compile_args"
    }

    if { $compile_args != "" } {
	set errname "$errname $compile_args"
    }

    verbose "compilation command = $args" 2
    # When compiling and not linking, we have to build each .o
    # separately.  We do this because DejaGNU's target_compile won't
    # accept an empty "destfile" argument when the mode is "compile".
    if {$mode == "compile"} {
	foreach c_file $class_files {
	    set executable [file rootname [file tail $c_file]].o
	    set x [prune_warnings \
		     [libjava_tcompile $c_file "$executable" $type $args]]
	    lappend removeList $executable
	    if {$x != ""} {
		break
	    }
	}
    } else {
	# This is so evil: we de-listify CLASS_FILES so that we can
	# turn around and quote the `$' in it for the shell.  I really
	# hate DejaGNU.  It is so !@#$!@# unpredictable.
	set hack ""
	foreach stupid $class_files {
	    set hack "$hack $stupid"
	}
	lappend removeList $executable
	set x [prune_warnings \
		 [libjava_tcompile $hack "$executable" $type $args]]
    }
    if {[info exists opts(xfail-byte)]} {
	setup_xfail *-*-*
    }
    if { $x != "" } {
	verbose "target_compile failed: $x" 2
	fail "$errname compilation from bytecode"
	if {! [info exists opts(no-exec)]
	    || [info exists opts(need-threads)]} {
	    untested "$errname execution from bytecode->native test"
	    untested "$errname output from bytecode->native test"
	}
	return;
    }
    pass "$errname compilation from bytecode"

    # Set up the options the way they are expected by libjava_invoke.
    if {[info exists opts(xfail-byte-output)]} {
	set opts(xfail-output) x
    }
    if {[libjava_invoke $errname "bytecode->native test" opts $executable \
	   $inpfile $resultfile]} {
	# Everything ok, so clean up.
	eval gcj_cleanup $removeList
    }
}

#
# Run the test specified by srcfile and resultfile. compile_args and
# exec_args are options telling this proc how to work.
#   `no-link'     don't try to link the program
#   `no-exec'     don't try to run the test
#   `xfail-gcj'   compilation from source will fail
#   `xfail-javac' compilation with javac will fail
#   `xfail-gcjC'  compilation with gcj -C will fail
#   `shouldfail'  compilation from source is supposed to fail
#                 This is different from xfail, which marks a known
#                 failure that we just haven't fixed.
#                 A compilation marked this way should fail with any
#                 front end.
#   `xfail-byte'  compilation from bytecode will fail
#   `xfail-exec'  exec will fail
#   `xfail-output'
#                 output will be wrong
#   `xfail-byte-output'
#                 output will be wrong when compiled from bytecode
#   `xfail-source-output'
#                 output will be wrong when compiled from source code
#   `need-threads'
#                 test relies on thread support
#
proc test_libjava { options srcfile compile_args inpfile resultfile exec_args } {
    test_libjava_from_source $options $srcfile $compile_args $inpfile $resultfile $exec_args
    test_libjava_from_javac $options $srcfile $compile_args $inpfile $resultfile $exec_args
 }

#
# libjava_version -- extract and print the version number of libjavap
#
proc default_libjava_version {} {
}

proc default_libjava_start { } {
}

# On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
# called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH
# (for the 64-bit ABI).  The right way to do this would be to modify
# unix.exp -- but that's not an option since it's part of DejaGNU
# proper, so we do it here, by trickery.  We really only need to do 
# this on IRIX, but it shouldn't hurt to do it anywhere else.

proc ${tool}_set_ld_library_path { name element op } {
  setenv LD_LIBRARYN32_PATH [getenv LD_LIBRARY_PATH]
  setenv LD_LIBRARY64_PATH [getenv LD_LIBRARY_PATH]
}

trace variable env(LD_LIBRARY_PATH) w ${tool}_set_ld_library_path

# Local Variables:
# tcl-indent-level:4
# End: