mauve.exp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. # Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation.
  2. # Written by Tom Tromey <tromey@cygnus.com>.
  3. # Incorporate Mauve into libjava's DejaGNU test suite framework.
  4. # FIXME: should be able to compile from source as well as from .class.
  5. # Compute list of files to compile. Returns list of all files
  6. # representing classes that must be tested. Result parameter `uses'
  7. # maps source file names onto list of objects required for link.
  8. proc mauve_compute_uses {aName} {
  9. upvar $aName uses
  10. global env runtests
  11. set fd [open classes r]
  12. set line [read $fd]
  13. close $fd
  14. foreach item [split $line] {
  15. if {$item == ""} then {
  16. continue
  17. }
  18. set item [join [split $item .] /].java
  19. # User might have specified "mauve.exp=something.java".
  20. if {! [runtest_file_p $runtests $item]} {
  21. continue
  22. }
  23. # Look for Uses line in source file.
  24. set fd [open $env(MAUVEDIR)/$item r]
  25. set ufiles [list $item]
  26. set dir [file dirname $item]
  27. while {[gets $fd sline] != -1} {
  28. if {[regsub -- {^// Uses:} $sline {} sline]} then {
  29. foreach uf [split $sline] {
  30. if {$uf != ""} then {
  31. lappend ufiles $dir/$uf
  32. }
  33. }
  34. }
  35. }
  36. close $fd
  37. set uses($item) {}
  38. foreach file $ufiles {
  39. set file [file rootname $file].o
  40. lappend uses($item) $file
  41. # Now add all inner classes
  42. foreach inner [glob -nocomplain [file rootname $file]$*.class] {
  43. # Prevent excessive escaping by replacing $ with a ^ in the .o name
  44. set inner [file rootname $inner].o
  45. regsub -all "\\$" $inner "\^" inner
  46. lappend uses($item) $inner
  47. }
  48. }
  49. }
  50. return [lsort [array names uses]]
  51. }
  52. # Find Mauve sources. At end, env(MAUVEDIR) points to sources.
  53. # Returns 0 if sources not found, 1 otherwise.
  54. proc find_mauve_sources {} {
  55. global env srcdir
  56. if {[info exists env(MAUVEDIR)]} {
  57. return 1
  58. } elseif {[file isdirectory $srcdir/libjava.mauve/mauve]} {
  59. set env(MAUVEDIR) $srcdir/libjava.mauve/mauve
  60. return 1
  61. }
  62. return 0
  63. }
  64. # Find all the harness files and return a list of them, with no
  65. # suffix.
  66. proc mauve_find_harness_files {} {
  67. set result {}
  68. foreach file [glob -nocomplain -- *.class gnu/testlet/*.class] {
  69. lappend result [file root $file]
  70. }
  71. return $result
  72. }
  73. # Run all the Mauve tests. Return 1 on success, 0 on any failure. If
  74. # the tests are skipped, that is treated like success.
  75. proc test_mauve {} {
  76. global srcdir objdir subdir env
  77. if {! [find_mauve_sources]} then {
  78. verbose "MAUVEDIR not set; not running Mauve tests"
  79. return 1
  80. }
  81. # Run in subdir so we don't overwrite our own Makefile.
  82. catch {system "rm -rf mauve-build"}
  83. file mkdir mauve-build
  84. # Some weirdness to set srcdir correctly.
  85. set here [pwd]
  86. cd $srcdir
  87. set full_srcdir [pwd]
  88. cd $here/mauve-build
  89. global env libgcj_jar
  90. global GCJ_UNDER_TEST
  91. global TOOL_EXECUTABLE
  92. if ![info exists GCJ_UNDER_TEST] {
  93. if [info exists TOOL_EXECUTABLE] {
  94. set GCJ_UNDER_TEST $TOOL_EXECUTABLE;
  95. } else {
  96. if [info exists env(GCJ)] {
  97. set GCJ_UNDER_TEST env(GCJ)
  98. } else {
  99. set GCJ_UNDER_TEST "[find_gcj]"
  100. }
  101. }
  102. }
  103. # Append -B and -I so that libgcj.spec and libgcj.jar are found
  104. # before they're installed.
  105. # Append -Wno-deprecated since Mauve tests lots of deprecated stuff.
  106. set env(GCJ) "$GCJ_UNDER_TEST -Wno-deprecated -B$objdir/../ -I$libgcj_jar"
  107. if {[catch {
  108. system "$env(MAUVEDIR)/configure --with-gcj 2>&1"
  109. } msg]} then {
  110. fail "Mauve configure"
  111. verbose "configure failed with $msg"
  112. return 0
  113. }
  114. pass "Mauve configure"
  115. # Copy appropriate tags file locally.
  116. set fd [open $full_srcdir/../mauve-libgcj r]
  117. set c [read $fd]
  118. close $fd
  119. set fd [open mauve-libgcj w]
  120. puts -nonewline $fd $c
  121. close $fd
  122. catch {system "ln -s $full_srcdir/libjava.mauve/xfails xfails"}
  123. if {[catch {
  124. system "make KEYS=libgcj classes.stamp 2>&1"
  125. } msg]} then {
  126. fail "Mauve build"
  127. verbose "build failed with $msg"
  128. return 0
  129. }
  130. pass "Mauve build"
  131. set srcfile $full_srcdir/$subdir/DejaGNUTestHarness.java
  132. if {! [bytecompile_file $srcfile [pwd] $env(MAUVEDIR):[pwd]]} then {
  133. fail "Compile DejaGNUTestHarness.java"
  134. return 0
  135. }
  136. pass "Compile DejaGNUTestHarness.java"
  137. # Compute list of files to test, and also all files to build.
  138. set choices [mauve_compute_uses uses]
  139. # Compute flags to use to do the build.
  140. set compile_args [libjava_arguments]
  141. set link_args [concat [libjava_arguments link] \
  142. [list "additional_flags=--main=DejaGNUTestHarness"]]
  143. if {[string match "*libtool*" $compile_args]} {
  144. set objext lo
  145. } else {
  146. set objext o
  147. }
  148. set ok 1
  149. set objlist {}
  150. foreach base [mauve_find_harness_files] {
  151. set file $base.class
  152. set obj $base.$objext
  153. set x [libjava_prune_warnings \
  154. [target_compile [pwd]/$file $obj object $compile_args]]
  155. if {$x != ""} then {
  156. fail "Compile $obj"
  157. set ok 0
  158. } else {
  159. pass "Compile $obj"
  160. }
  161. lappend objlist $obj
  162. }
  163. if {! $ok} then {
  164. return 0
  165. }
  166. set proc_ok 1
  167. set Executable DejaGNUTestHarness
  168. foreach file $choices {
  169. # Turn `java/lang/Foo.java' into `java.lang.Foo'.
  170. set class [file rootname $file]
  171. regsub -all -- / $class . class
  172. set ok 1
  173. set this_olist {}
  174. foreach obj $uses($file) {
  175. set obj [file rootname $obj].$objext
  176. lappend this_olist $obj
  177. if {! [file exists $obj]} then {
  178. verbose "compiling $obj for test of $class"
  179. # The .class file does contain a $, but we can quote it between "'"s.
  180. set srcfile [file rootname $obj].class
  181. regsub -all "\\^" $srcfile "\$" srcfile
  182. set x [libjava_prune_warnings \
  183. [libjava_tcompile '[pwd]/$srcfile' $obj object $compile_args]]
  184. if {$x != ""} then {
  185. fail "Compile $obj for $class"
  186. set ok 0
  187. break
  188. }
  189. pass "Compile $obj for $class"
  190. }
  191. }
  192. if {! $ok} then {
  193. set proc_ok 0
  194. continue
  195. }
  196. set x [libjava_prune_warnings \
  197. [libjava_tcompile [concat $this_olist $objlist] \
  198. $Executable executable $link_args]]
  199. if {$x != ""} then {
  200. set proc_ok 0
  201. fail "Link for $class"
  202. continue
  203. }
  204. pass "Link for $class"
  205. set result [libjava_load [pwd]/DejaGNUTestHarness \
  206. "$env(MAUVEDIR) $class" ""]
  207. # Extract pass/failure info from output.
  208. foreach line [split [lindex $result 1] \n] {
  209. if {[regexp -- {^(PASS|FAIL|XFAIL|XPASS): (.*)$} $line ignore what msg]} then {
  210. if {$what == "XFAIL" || $what == "XPASS"} then {
  211. setup_xfail *-*-*
  212. }
  213. if {$what == "PASS" || $what == "XPASS"} then {
  214. pass $msg
  215. } else {
  216. set proc_ok 0
  217. fail $msg
  218. }
  219. }
  220. }
  221. }
  222. return $proc_ok
  223. }
  224. # Run all the Mauve tests in a sim environment. In this case, the
  225. # program cannot use argv[] because there's no way to pass in the
  226. # command line, so tha name of the class to test is substituted by
  227. # patching the source of the DejaGNUTestHarness. Return 1 on success,
  228. # 0 on any failure. If the tests are skipped, that is treated like
  229. # success.
  230. proc test_mauve_sim {} {
  231. global srcdir subdir env
  232. if {! [find_mauve_sources]} then {
  233. verbose "MAUVEDIR not set; not running Mauve tests"
  234. return 1
  235. }
  236. # Run in subdir so we don't overwrite our own Makefile.
  237. catch {system "rm -rf mauve-build"}
  238. file mkdir mauve-build
  239. # Some weirdness to set srcdir correctly.
  240. set here [pwd]
  241. cd $srcdir
  242. set full_srcdir [pwd]
  243. cd $here/mauve-build
  244. if {[catch {
  245. system "$env(MAUVEDIR)/configure --with-gcj 2>&1"
  246. } msg]} then {
  247. fail "Mauve configure"
  248. verbose "configure failed with $msg"
  249. return 0
  250. }
  251. pass "Mauve configure"
  252. # Copy appropriate tags file locally.
  253. set fd [open $full_srcdir/../mauve-libgcj r]
  254. set c [read $fd]
  255. close $fd
  256. set fd [open mauve-libgcj w]
  257. puts -nonewline $fd $c
  258. close $fd
  259. catch {system "ln -s $full_srcdir/libjava.mauve/xfails xfails"}
  260. if {[catch {
  261. system "make KEYS=libgcj classes.stamp 2>&1"
  262. } msg]} then {
  263. fail "Mauve build"
  264. verbose "build failed with $msg"
  265. return 0
  266. }
  267. pass "Mauve build"
  268. # Compute list of files to test, and also all files to build.
  269. set choices [mauve_compute_uses uses]
  270. # Compute flags to use to do the build.
  271. set compile_args [libjava_arguments]
  272. set link_args [concat [libjava_arguments link] \
  273. [list "additional_flags=--main=DejaGNUTestHarness"]]
  274. set ok 1
  275. set objlist {}
  276. foreach base [mauve_find_harness_files] {
  277. set file $base.class
  278. set obj $base.o
  279. set x [libjava_prune_warnings \
  280. [target_compile [pwd]/$file $obj object $compile_args]]
  281. if {$x != ""} then {
  282. fail "Compile $obj"
  283. set ok 0
  284. } else {
  285. pass "Compile $obj"
  286. }
  287. lappend objlist $obj
  288. }
  289. if {! $ok} then {
  290. return 0
  291. }
  292. set proc_ok 1
  293. set Executable DejaGNUTestHarness
  294. foreach file $choices {
  295. # Turn `java/lang/Foo.java' into `java.lang.Foo'.
  296. set class [file rootname $file]
  297. regsub -all -- / $class . class
  298. set ok 1
  299. foreach obj $uses($file) {
  300. if {! [file exists $obj]} then {
  301. verbose "compiling $obj for test of $class"
  302. set srcfile [file rootname $obj].class
  303. set x [libjava_prune_warnings \
  304. [target_compile [pwd]/$srcfile $obj object $compile_args]]
  305. if {$x != ""} then {
  306. fail "Compile $obj for $class"
  307. set ok 0
  308. break
  309. }
  310. pass "Compile $obj for $class"
  311. }
  312. }
  313. if {! $ok} then {
  314. set proc_ok 0
  315. continue
  316. }
  317. set infile $full_srcdir/$subdir/DejaGNUTestHarness.java
  318. set srcfile DejaGNUTestHarness.java
  319. set f [open $infile r]
  320. set d [open gnu/testlet/$srcfile w]
  321. while {[gets $f line] >= 0} {
  322. if [regexp {harness\.runtest \(args\[1\]\)} $line] then {
  323. regsub {args\[1\]} $line "\"$class\"" out
  324. } else {
  325. set out $line
  326. }
  327. puts $d $out
  328. }
  329. close $f
  330. close $d
  331. if {! [bytecompile_file [pwd]/gnu/testlet/$srcfile [pwd]/gnu/testlet \
  332. $env(MAUVEDIR):[pwd]]} then {
  333. fail "Compile DejaGNUTestHarness.java"
  334. return 0
  335. }
  336. set x [libjava_prune_warnings \
  337. [target_compile DejaGNUTestHarness.class \
  338. DejaGNUTestHarness.o object $compile_args]]
  339. if {$x != ""} then {
  340. fail "Compile DejaGNUTestHarness.java"
  341. set proc_ok 0
  342. continue
  343. }
  344. set x [libjava_prune_warnings \
  345. [target_compile [concat $uses($file) $objlist] \
  346. $Executable executable $link_args]]
  347. if {$x != ""} then {
  348. set proc_ok 0
  349. fail "Link for $class"
  350. continue
  351. }
  352. pass "Link for $class"
  353. set result [libjava_load [pwd]/DejaGNUTestHarness \
  354. "$env(MAUVEDIR) $class" ""]
  355. # Extract pass/failure info from output.
  356. foreach line [split [lindex $result 1] \n] {
  357. if {[regexp -- {^(PASS|FAIL|XFAIL|XPASS): (.*)$} $line ignore what msg]} then {
  358. if {$what == "XFAIL" || $what == "XPASS"} then {
  359. setup_xfail *-*-*
  360. }
  361. if {$what == "PASS" || $what == "XPASS"} then {
  362. pass $msg
  363. } else {
  364. set proc_ok 0
  365. fail $msg
  366. }
  367. }
  368. }
  369. }
  370. return $proc_ok
  371. }
  372. proc gcj_run_mauve_tests {} {
  373. # The test_mauve* procs will change the current directory. It's
  374. # simpler to fix this up here than to keep track of this in the
  375. # procs.
  376. set here [pwd]
  377. if { [board_info target exists is_simulator] } {
  378. set r [test_mauve_sim]
  379. } else {
  380. set r [test_mauve]
  381. }
  382. cd $here
  383. if {$r} {
  384. # No need to keep the build around. FIXME: this knows how the
  385. # tests work. This whole file could use a rewrite.
  386. system "rm -rf mauve-build"
  387. }
  388. }
  389. gcj_run_mauve_tests