OSDN Git Service

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