OSDN Git Service

* libjava.loader/loader.exp (gcj_loader_test_one): Use
[pf3gnuchains/gcc-fork.git] / libjava / testsuite / libjava.mauve / mauve.exp
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.
4
5 # FIXME: should be able to compile from source as well as from .class.
6
7
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} {
12   upvar $aName uses
13   global env runtests
14
15   set fd [open classes r]
16   set line [read $fd]
17   close $fd
18
19   foreach item [split $line] {
20     if {$item == ""} then {
21       continue
22     }
23     set item [join [split $item .] /].java
24
25     # User might have specified "mauve.exp=something.java".
26     if {! [runtest_file_p $runtests $item]} {
27       continue
28     }
29
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] {
37           if {$uf != ""} then {
38             lappend ufiles $dir/$uf
39           }
40         }
41       }
42     }
43     close $fd
44
45     set uses($item) {}
46     foreach file $ufiles {
47       set file [file rootname $file].o
48       lappend uses($item) $file
49     }
50   }
51
52   return [lsort [array names uses]]
53 }
54
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 {} {
58   global env srcdir
59
60   if {[info exists env(MAUVEDIR)]} {
61     return 1
62   } elseif {[file isdirectory $srcdir/libjava.mauve/mauve]} {
63     set env(MAUVEDIR) $srcdir/libjava.mauve/mauve
64     return 1
65   }
66
67   return 0
68 }
69
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.
72 proc test_mauve {} {
73   global srcdir objdir subdir env
74
75   if {! [find_mauve_sources]} then {
76     verbose "MAUVEDIR not set; not running Mauve tests"
77     return 1
78   }
79
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.
84   set here [pwd]
85   cd $srcdir
86   set full_srcdir [pwd]
87   cd $here/mauve-build
88
89     global env
90     global GCJ_UNDER_TEST
91     global TOOL_EXECUTABLE
92
93     if ![info exists GCJ_UNDER_TEST] {
94         if [info exists TOOL_EXECUTABLE] {
95             set GCJ_UNDER_TEST $TOOL_EXECUTABLE;
96         } else {
97             if [info exists env(GCJ)] {
98                 set GCJ_UNDER_TEST env(GCJ)
99             } else {
100                 set GCJ_UNDER_TEST "[find_gcj]"
101             }
102         }
103     }
104
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"
108
109   if {[catch {
110     system "$env(MAUVEDIR)/configure --with-gcj 2>&1"
111   } msg]} then {
112     fail "Mauve configure"
113     verbose "configure failed with $msg"
114     return 0
115   }
116   pass "Mauve configure"
117
118   # Copy appropriate tags file locally.
119   set fd [open $full_srcdir/../mauve-libgcj r]
120   set c [read $fd]
121   close $fd
122   set fd [open mauve-libgcj w]
123   puts -nonewline $fd $c
124   close $fd
125
126   catch {system "ln -s $full_srcdir/libjava.mauve/xfails xfails"}
127
128   if {[catch {
129     system "make KEYS=libgcj classes.stamp 2>&1"
130   } msg]} then {
131     fail "Mauve build"
132     verbose "build failed with $msg"
133     return 0
134   }
135   pass "Mauve build"
136
137   set srcfile $full_srcdir/$subdir/DejaGNUTestHarness.java
138   if {! [bytecompile_file $srcfile [pwd] $env(MAUVEDIR):[pwd]]} then {
139     fail "Compile DejaGNUTestHarness.java"
140     return 0
141   }
142   pass "Compile DejaGNUTestHarness.java"
143
144   # Compute list of files to test, and also all files to build.
145   set choices [mauve_compute_uses uses]
146
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"]]
151
152   set ok 1
153   set objlist {}
154   foreach base {DejaGNUTestHarness gnu/testlet/SimpleTestHarness gnu/testlet/TestHarness gnu/testlet/Testlet gnu/testlet/ResourceNotFoundException gnu/testlet/config} {
155     set file $base.class
156     set obj $base.o
157     set x [libjava_prune_warnings \
158              [target_compile [pwd]/$file $obj object $compile_args]]
159     if {$x != ""} then {
160       fail "Compile $obj"
161       set ok 0
162     } else {
163       pass "Compile $obj"
164     }
165     lappend objlist $obj
166   }
167   if {! $ok} then {
168     return 0
169   }
170
171   set proc_ok 1
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
177
178     set ok 1
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]]
185         if {$x != ""} then {
186           fail "Compile $obj for $class"
187           set ok 0
188           break
189         }
190         pass "Compile $obj for $class"
191       }
192     }
193     if {! $ok} then {
194       set proc_ok 0
195       continue
196     }
197
198     set x [libjava_prune_warnings \
199              [target_compile [concat $uses($file) $objlist] \
200                 $Executable executable $link_args]]
201     if {$x != ""} then {
202       set proc_ok 0
203       fail "Link for $class"
204       continue
205     }
206     pass "Link for $class"
207
208     set result [libjava_load [pwd]/DejaGNUTestHarness \
209                   "$env(MAUVEDIR) $class" ""]
210
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 {
215           setup_xfail *-*-*
216         }
217         if {$what == "PASS" || $what == "XPASS"} then {
218           pass $msg
219         } else {
220           set proc_ok 0
221           fail $msg
222         }
223       }
224     }
225   }
226
227   return $proc_ok
228 }
229
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
235 # success.
236 proc test_mauve_sim {} {
237   global srcdir subdir env
238
239   if {! [find_mauve_sources]} then {
240     verbose "MAUVEDIR not set; not running Mauve tests"
241     return 1
242   }
243
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.
248   set here [pwd]
249   cd $srcdir
250   set full_srcdir [pwd]
251   cd $here/mauve-build
252
253   if {[catch {
254     system "$env(MAUVEDIR)/configure --with-gcj 2>&1"
255   } msg]} then {
256     fail "Mauve configure"
257     verbose "configure failed with $msg"
258     return 0
259   }
260   pass "Mauve configure"
261
262   # Copy appropriate tags file locally.
263   set fd [open $full_srcdir/../mauve-libgcj r]
264   set c [read $fd]
265   close $fd
266   set fd [open mauve-libgcj w]
267   puts -nonewline $fd $c
268   close $fd
269
270   catch {system "ln -s $full_srcdir/libjava.mauve/xfails xfails"}
271
272   if {[catch {
273     system "make KEYS=libgcj classes.stamp 2>&1"
274   } msg]} then {
275     fail "Mauve build"
276     verbose "build failed with $msg"
277     return 0
278   }
279   pass "Mauve build"
280
281   # Compute list of files to test, and also all files to build.
282   set choices [mauve_compute_uses uses]
283
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"]]
288
289   set ok 1
290   set objlist {}
291   foreach base {gnu/testlet/SimpleTestHarness gnu/testlet/TestHarness \
292                   gnu/testlet/Testlet gnu/testlet/ResourceNotFoundException \
293                   gnu/testlet/config} {
294     set file $base.class
295     set obj $base.o
296     set x [libjava_prune_warnings \
297              [target_compile [pwd]/$file $obj object $compile_args]]
298     if {$x != ""} then {
299       fail "Compile $obj"
300       set ok 0
301     } else {
302       pass "Compile $obj"
303     }
304     lappend objlist $obj
305   }
306   if {! $ok} then {
307     return 0
308   }
309
310   lappend objlist gnu/testlet/DejaGNUTestHarness.o
311
312   set proc_ok 1
313   set Executable DejaGNUTestHarness
314   foreach file $choices {
315     # Turn `java/lang/Foo.java' into `java.lang.Foo'.
316     
317     set class [file rootname $file]
318     regsub -all -- / $class . class
319
320     set ok 1
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]]
327         if {$x != ""} then {
328           fail "Compile $obj for $class"
329           set ok 0
330           break
331         }
332         pass "Compile $obj for $class"
333       }
334     }
335     if {! $ok} then {
336       set proc_ok 0
337       continue
338     }
339
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
347         } else {
348             set out $line
349         }
350         puts $d $out
351     }
352     close $f
353     close $d
354
355     if {! [bytecompile_file [pwd]/gnu/testlet/$srcfile [pwd]/gnu/testlet \
356                $env(MAUVEDIR):[pwd]]} then {
357         fail "Compile DejaGNUTestHarness.java"
358         return 0
359     }
360
361     set x [libjava_prune_warnings \
362              [target_compile gnu/testlet/DejaGNUTestHarness.class \
363                 gnu/testlet/DejaGNUTestHarness.o object $compile_args]]
364     if {$x != ""} then {
365         fail "Compile DejaGNUTestHarness.java"
366         set proc_ok 0
367         continue
368     }
369
370     set x [libjava_prune_warnings \
371              [target_compile [concat $uses($file) $objlist] \
372                 $Executable executable $link_args]]
373     if {$x != ""} then {
374       set proc_ok 0
375       fail "Link for $class"
376       continue
377     }
378     pass "Link for $class"
379
380     set result [libjava_load [pwd]/DejaGNUTestHarness \
381                   "$env(MAUVEDIR) $class" ""]
382
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 {
387           setup_xfail *-*-*
388         }
389         if {$what == "PASS" || $what == "XPASS"} then {
390           pass $msg
391         } else {
392           set proc_ok 0
393           fail $msg
394         }
395       }
396     }
397   }
398
399   return $proc_ok
400 }
401
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
405   # procs.
406   set here [pwd]
407   if { [board_info target exists is_simulator] } {
408     set r [test_mauve_sim]
409   } else {
410     set r [test_mauve]
411   }
412   cd $here
413
414   if {$r} {
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"
418   }
419 }
420
421 gcj_run_mauve_tests