jvmti-interp.exp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. # Interpreted Tests for JVMTI code.
  2. # These tests are used to test JVMTI functions in a purley interpreted setting
  3. # This file compiles the JNI code into a shared object, then invokes gij to run
  4. # the test.
  5. # Compile a single C file and produce a .so file. OPTIONS is a list
  6. # of options to pass to the compiler. Returns 0 on failure, 1 on
  7. # success.
  8. proc gcj_jni_compile_c_to_so {file {options {}}} {
  9. global srcdir subdir
  10. global host_triplet
  11. verbose "options: $options"
  12. set options_cxx $options
  13. set options ""
  14. # Apple uses a different extension for shared/dynamic libraries
  15. # so we check against powerpc-apple-darwin and set them to
  16. # dylib.
  17. # HP-UX uses sl, so we check this too, otherwise we take so.
  18. if { [istarget "*-*-darwin*"] } {
  19. set so_extension "dylib"
  20. set so_flag "-dynamiclib"
  21. } elseif { [istarget "hppa*-hp-hpux*"] } {
  22. set so_extension "sl"
  23. set so_flag "-shared"
  24. } elseif { [istarget "*-*-cygwin*"] || [istarget "*-*-mingw*"] } {
  25. set so_extension "dll"
  26. set so_flag "-shared"
  27. } else {
  28. set so_extension "so"
  29. set so_flag "-shared"
  30. }
  31. # ARM C++ emits an ABI warning for varargs.
  32. if { [istarget "arm*"] } {
  33. lappend options "additional_flags=-Wno-abi"
  34. }
  35. set filename [file tail $file]
  36. set name [file rootname $filename]
  37. set soname lib${name}.${so_extension}
  38. lappend options "additional_flags=${so_flag} -fPIC"
  39. # Find the generated header.
  40. lappend options "additional_flags=-I. -I.. -I$srcdir/$subdir"
  41. # Ensure that the generated header has correct prototypes.
  42. set cfile [file rootname $file].c
  43. if { [file exists $cfile] } {
  44. # This option is only valid for C sources.
  45. lappend options "additional_flags=-Wmissing-prototypes"
  46. }
  47. # Find jni.h and jni_md.h.
  48. lappend options "additional_flags=-I$srcdir/../include \
  49. -I$srcdir/../classpath/include -fdollars-in-identifiers"
  50. # Append C++ options
  51. lappend options "additional_flags=$options_cxx"
  52. set x [libjava_prune_warnings \
  53. [target_compile $file $soname executable $options]]
  54. if {$x != ""} {
  55. verbose "target_compile failed: $x" 2
  56. fail "$filename compilation"
  57. return 0
  58. }
  59. pass "$filename compilation"
  60. return 1
  61. }
  62. # Do all the work for a single JVMTI test. Return 0 on failure.
  63. proc gij_jvmti_test_one {file} {
  64. global runtests
  65. # The base name. We use it for several purposes.
  66. set main [file rootname [file tail $file]]
  67. if {! [runtest_file_p $runtests $main] } {
  68. # Simply skip it.
  69. return 1
  70. }
  71. # if {! [bytecompile_file $file [pwd]] } {
  72. # fail "bytecompile $file"
  73. # # FIXME - should use `untested' on all remaining tests.
  74. # # But that is hard.
  75. # return 0
  76. # }
  77. # pass "bytecompile $file"
  78. # if {! [gcj_jvmti_build_headers $file] } {
  79. # # FIXME
  80. # return 0
  81. # }
  82. set cfile [file join [file dirname $file] nat$main.c]
  83. set cxxflags ""
  84. set cxxldlibflags {}
  85. # If there is no `.c' file, assume there is a `.cc' file.
  86. if {! [file exists $cfile] } {
  87. set cfile [file join [file dirname $file] nat$main.cc]
  88. set cxxflaglist {}
  89. foreach arg [split [libjava_find_lib libstdc++-v3/src stdc++] " "] {
  90. switch -glob -- $arg {
  91. "-L*" {
  92. set arg [string range $arg 2 end]
  93. lappend cxxldlibflags $arg
  94. # Strip the `.libs' directory; we link with libtool which
  95. # doesn't need it.
  96. set arg "-L[file dirname $arg]"
  97. }
  98. }
  99. lappend cxxflaglist $arg
  100. # In case the libstdc++ is not installed yet, we pass the build
  101. # directory of it to the cxxflaglist.
  102. lappend cxxflaglist "-L$cxxldlibflags"
  103. }
  104. # If you're building the compiler with --prefix set to a place
  105. # where it's not yet installed, then the linker won't be able to
  106. # find the libgcc used by libgcj.dylib/libstdc++.dylib. We could pass
  107. # the -dylib_file option, but that's complicated, and it's much easier
  108. # to just make the linker find libgcc using -L options.
  109. if { [istarget "*-*-darwin*"] } {
  110. lappend cxxflaglist "-shared-libgcc -lstdc++"
  111. } else {
  112. lappend cxxflaglist "-lstdc++"
  113. }
  114. set cxxflags [join $cxxflaglist]
  115. }
  116. if {! [gcj_jni_compile_c_to_so $cfile $cxxflags] } {
  117. # FIXME
  118. return 0
  119. }
  120. libjava_arguments
  121. set jarfile [file join [file dirname $file] $main.jar]
  122. set gij_flags {-agentlib:dummyagent}
  123. if {! [exec_gij $jarfile [file rootname $file].out $cxxldlibflags $gij_flags] } {
  124. return 0
  125. }
  126. # When we succeed we remove all our clutter.
  127. eval gcj_cleanup [glob -nocomplain -- ${main}.*] \
  128. [list $main.class libnat$main.so]
  129. return 1
  130. }
  131. # Run the JVMTI tests.
  132. proc gij_jvmti_run {} {
  133. global srcdir subdir
  134. global build_triplet host_triplet
  135. # For now we only test JVMTI on native builds.
  136. if {$build_triplet == $host_triplet} {
  137. # Build our dummy JVMTI agent library
  138. if {![gcj_jni_compile_c_to_so [file join $srcdir $subdir dummyagent.c]]} {
  139. fail "compiling dummy JVMTI agent"
  140. } else {
  141. pass "compiling dummy JVMTI agent"
  142. catch {lsort [glob -nocomplain ${srcdir}/${subdir}/interp/*.jar]} \
  143. srcfiles
  144. foreach x $srcfiles {
  145. gij_jvmti_test_one $x
  146. }
  147. gcj_cleanup libdummyagent.so
  148. }
  149. } else {
  150. verbose "JVMTI tests not run in cross-compilation environment"
  151. }
  152. }
  153. gij_jvmti_run