1 # Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation.
2 # Written by Tom Tromey <tromey@cygnus.com>.
3 # Incorporate Mauve into libjava's DejaGNU test suite framework.
5 # FIXME: should be able to compile from source as well as from .class.
8 # Compute list of files to compile. Returns list of all files
9 # representing classes that must be tested. Result parameter `uses'
10 # maps source file names onto list of objects required for link.
11 proc mauve_compute_uses {aName} {
15 set fd [open classes r]
19 foreach item [split $line] {
20 if {$item == ""} then {
23 set item [join [split $item .] /].java
25 # User might have specified "mauve.exp=something.java".
26 if {! [runtest_file_p $runtests $item]} {
30 # Look for Uses line in source file.
31 set fd [open $env(MAUVEDIR)/$item r]
32 set ufiles [list $item]
33 set dir [file dirname $item]
34 while {[gets $fd sline] != -1} {
35 if {[regsub -- {^// Uses:} $sline {} sline]} then {
36 foreach uf [split $sline] {
38 lappend ufiles $dir/$uf
46 foreach file $ufiles {
47 set file [file rootname $file].o
48 lappend uses($item) $file
52 return [lsort [array names uses]]
55 # Find Mauve sources. At end, env(MAUVEDIR) points to sources.
56 # Returns 0 if sources not found, 1 otherwise.
57 proc find_mauve_sources {} {
60 if {[info exists env(MAUVEDIR)]} {
62 } elseif {[file isdirectory $srcdir/libjava.mauve/mauve]} {
63 set env(MAUVEDIR) $srcdir/libjava.mauve/mauve
70 # Run all the Mauve tests. Return 1 on success, 0 on any failure. If
71 # the tests are skipped, that is treated like success.
73 global srcdir objdir subdir env
75 if {! [find_mauve_sources]} then {
76 verbose "MAUVEDIR not set; not running Mauve tests"
80 # Run in subdir so we don't overwrite our own Makefile.
81 catch {system "rm -rf mauve-build"}
82 file mkdir mauve-build
83 # Some weirdness to set srcdir correctly.
91 global TOOL_EXECUTABLE
93 if ![info exists GCJ_UNDER_TEST] {
94 if [info exists TOOL_EXECUTABLE] {
95 set GCJ_UNDER_TEST $TOOL_EXECUTABLE;
97 if [info exists env(GCJ)] {
98 set GCJ_UNDER_TEST env(GCJ)
100 set GCJ_UNDER_TEST "[find_gcj]"
105 # Append -B and -I so that libgcj.spec and libgcj.zip are found
106 # before they're installed.
107 set env(GCJ) "$GCJ_UNDER_TEST -B$objdir/../ -I$objdir/../libgcj.jar"
110 system "$env(MAUVEDIR)/configure --with-gcj 2>&1"
112 fail "Mauve configure"
113 verbose "configure failed with $msg"
116 pass "Mauve configure"
118 # Copy appropriate tags file locally.
119 set fd [open $full_srcdir/../mauve-libgcj r]
122 set fd [open mauve-libgcj w]
123 puts -nonewline $fd $c
126 catch {system "ln -s $full_srcdir/libjava.mauve/xfails xfails"}
129 system "make KEYS=libgcj classes.stamp 2>&1"
132 verbose "build failed with $msg"
137 set srcfile $full_srcdir/$subdir/DejaGNUTestHarness.java
138 if {! [bytecompile_file $srcfile [pwd] $env(MAUVEDIR):[pwd]]} then {
139 fail "Compile DejaGNUTestHarness.java"
142 pass "Compile DejaGNUTestHarness.java"
144 # Compute list of files to test, and also all files to build.
145 set choices [mauve_compute_uses uses]
147 # Compute flags to use to do the build.
148 set compile_args [libjava_arguments]
149 set link_args [concat [libjava_arguments link] \
150 [list "additional_flags=--main=DejaGNUTestHarness"]]
154 foreach base {DejaGNUTestHarness gnu/testlet/SimpleTestHarness gnu/testlet/TestHarness gnu/testlet/Testlet gnu/testlet/ResourceNotFoundException gnu/testlet/config} {
157 set x [libjava_prune_warnings \
158 [target_compile [pwd]/$file $obj object $compile_args]]
172 set Executable DejaGNUTestHarness
173 foreach file $choices {
174 # Turn `java/lang/Foo.java' into `java.lang.Foo'.
175 set class [file rootname $file]
176 regsub -all -- / $class . class
179 foreach obj $uses($file) {
180 if {! [file exists $obj]} then {
181 verbose "compiling $obj for test of $class"
182 set srcfile [file rootname $obj].class
183 set x [libjava_prune_warnings \
184 [target_compile [pwd]/$srcfile $obj object $compile_args]]
186 fail "Compile $obj for $class"
190 pass "Compile $obj for $class"
198 set x [libjava_prune_warnings \
199 [target_compile [concat $uses($file) $objlist] \
200 $Executable executable $link_args]]
203 fail "Link for $class"
206 pass "Link for $class"
208 set result [libjava_load [pwd]/DejaGNUTestHarness \
209 "$env(MAUVEDIR) $class" ""]
211 # Extract pass/failure info from output.
212 foreach line [split [lindex $result 1] \n] {
213 if {[regexp -- {^(PASS|FAIL|XFAIL|XPASS): (.*)$} $line ignore what msg]} then {
214 if {$what == "XFAIL" || $what == "XPASS"} then {
217 if {$what == "PASS" || $what == "XPASS"} then {
230 # Run all the Mauve tests in a sim environment. In this case, the
231 # program cannot use argv[] because there's no way to pass in the
232 # command line, so tha name of the class to test is substituted by
233 # patching the source of the DejaGNUTestHarness. Return 1 on success,
234 # 0 on any failure. If the tests are skipped, that is treated like
236 proc test_mauve_sim {} {
237 global srcdir subdir env
239 if {! [find_mauve_sources]} then {
240 verbose "MAUVEDIR not set; not running Mauve tests"
244 # Run in subdir so we don't overwrite our own Makefile.
245 catch {system "rm -rf mauve-build"}
246 file mkdir mauve-build
247 # Some weirdness to set srcdir correctly.
250 set full_srcdir [pwd]
254 system "$env(MAUVEDIR)/configure --with-gcj 2>&1"
256 fail "Mauve configure"
257 verbose "configure failed with $msg"
260 pass "Mauve configure"
262 # Copy appropriate tags file locally.
263 set fd [open $full_srcdir/../mauve-libgcj r]
266 set fd [open mauve-libgcj w]
267 puts -nonewline $fd $c
270 catch {system "ln -s $full_srcdir/libjava.mauve/xfails xfails"}
273 system "make KEYS=libgcj classes.stamp 2>&1"
276 verbose "build failed with $msg"
281 # Compute list of files to test, and also all files to build.
282 set choices [mauve_compute_uses uses]
284 # Compute flags to use to do the build.
285 set compile_args [libjava_arguments]
286 set link_args [concat [libjava_arguments link] \
287 [list "additional_flags=--main=DejaGNUTestHarness"]]
291 foreach base {gnu/testlet/SimpleTestHarness gnu/testlet/TestHarness \
292 gnu/testlet/Testlet gnu/testlet/ResourceNotFoundException \
293 gnu/testlet/config} {
296 set x [libjava_prune_warnings \
297 [target_compile [pwd]/$file $obj object $compile_args]]
310 lappend objlist gnu/testlet/DejaGNUTestHarness.o
313 set Executable DejaGNUTestHarness
314 foreach file $choices {
315 # Turn `java/lang/Foo.java' into `java.lang.Foo'.
317 set class [file rootname $file]
318 regsub -all -- / $class . class
321 foreach obj $uses($file) {
322 if {! [file exists $obj]} then {
323 verbose "compiling $obj for test of $class"
324 set srcfile [file rootname $obj].class
325 set x [libjava_prune_warnings \
326 [target_compile [pwd]/$srcfile $obj object $compile_args]]
328 fail "Compile $obj for $class"
332 pass "Compile $obj for $class"
340 set infile $full_srcdir/$subdir/DejaGNUTestHarness.java
341 set srcfile DejaGNUTestHarness.java
342 set f [open $infile r]
343 set d [open gnu/testlet/$srcfile w]
344 while {[gets $f line] >= 0} {
345 if [regexp {harness\.runtest \(args\[1\]\)} $line] then {
346 regsub {args\[1\]} $line "\"$class\"" out
355 if {! [bytecompile_file [pwd]/gnu/testlet/$srcfile [pwd]/gnu/testlet \
356 $env(MAUVEDIR):[pwd]]} then {
357 fail "Compile DejaGNUTestHarness.java"
361 set x [libjava_prune_warnings \
362 [target_compile gnu/testlet/DejaGNUTestHarness.class \
363 gnu/testlet/DejaGNUTestHarness.o object $compile_args]]
365 fail "Compile DejaGNUTestHarness.java"
370 set x [libjava_prune_warnings \
371 [target_compile [concat $uses($file) $objlist] \
372 $Executable executable $link_args]]
375 fail "Link for $class"
378 pass "Link for $class"
380 set result [libjava_load [pwd]/DejaGNUTestHarness \
381 "$env(MAUVEDIR) $class" ""]
383 # Extract pass/failure info from output.
384 foreach line [split [lindex $result 1] \n] {
385 if {[regexp -- {^(PASS|FAIL|XFAIL|XPASS): (.*)$} $line ignore what msg]} then {
386 if {$what == "XFAIL" || $what == "XPASS"} then {
389 if {$what == "PASS" || $what == "XPASS"} then {
402 proc gcj_run_mauve_tests {} {
403 # The test_mauve* procs will change the current directory. It's
404 # simpler to fix this up here than to keep track of this in the
407 if { [board_info target exists is_simulator] } {
408 set r [test_mauve_sim]
415 # No need to keep the build around. FIXME: this knows how the
416 # tests work. This whole file could use a rewrite.
417 system "rm -rf mauve-build"