OSDN Git Service

* testsuite/libjava.jvmti/jvmti.exp: New file.
[pf3gnuchains/gcc-fork.git] / libjava / testsuite / libjava.jvmti / jvmti.exp
1 # Tests for JVMTI code.
2
3 # Compile a single C++ file and produce a .o file.  OPTIONS is a list
4 # of options to pass to the compiler.  Returns 0 on failure, 1 on
5 # success.
6 proc gcj_jvmti_compile_cxx_to_o {file {options {}}} {
7   global srcdir
8   global objdir
9
10   set name [file rootname [file tail $file]]
11   set oname ${name}.o
12
13   # Find the generated header.
14   lappend options "additional_flags=-g -I. -I.."
15   # Find libgcj headers.
16   lappend options "additional_flags=-I$srcdir/.."
17   # Find jvmti.h, jvmti_md.h, jvmti-int.h, jvm.h requirements
18   lappend options "additional_flags=-I$srcdir/../include -I$srcdir/../classpath/include -I$objdir/../include -I$objdir/../../boehm-gc/include"
19
20   set x [libjava_prune_warnings \
21            [target_compile $file $oname object $options]]
22   if {$x != ""} {
23     verbose "target_compile failed: $x" 2
24     fail "[file tail $file] compilation"
25     return 0
26   }
27
28   pass "[file tail $file] compilation"
29   return 1
30 }
31
32 # Build header files given name of .java file.  Return 0 on failure.
33 proc gcj_jvmti_build_headers {file} {
34   set gcjh [find_gcjh]
35   set jvscan [find_jvscan]
36
37   set class_out [string trim \
38                    [libjava_prune_warnings \
39                       [lindex [local_exec "$jvscan --encoding=UTF-8 $file --list-class" "" "" 300] 1]]]
40   if {[string match "*parse error*" $class_out]} {
41     fail "$file header generation"
42     return 0
43   }
44
45   foreach file [split $class_out] {
46     set x [string trim [libjava_prune_warnings \
47                           [lindex [local_exec "$gcjh $file" "" "" 300] 1]]]
48     if {$x != ""} {
49       verbose "local_exec failed: $x" 2
50       fail "$file header generation"
51       return 0
52     }
53   }
54
55   pass "$file header generation"
56   return 1
57 }
58
59 # Do all the work for a single JVMTI test.  Return 0 on failure.
60 proc gcj_jvmti_test_one {file} {
61   global runtests
62
63   # The base name.  We use it for several purposes.
64   set main [file rootname [file tail $file]]
65   if {! [runtest_file_p $runtests $main]} {
66     # Simply skip it.
67     return 1
68   }
69
70   if {! [bytecompile_file $file [pwd]]} {
71     fail "bytecompile $file"
72     # FIXME - should use `untested' on all remaining tests.
73     # But that is hard.
74     return 0
75   }
76   pass "bytecompile $file"
77
78   if {! [gcj_jvmti_build_headers $file]} {
79     # FIXME
80     return 0
81   }
82
83   set cfile [file join [file dirname $file] nat$main.cc]
84   if {! [gcj_jvmti_compile_cxx_to_o $cfile]} {
85     # FIXME
86     return 0
87   }
88
89   if {! [gcj_link $main $main [list $file nat$main.o]]} {
90     # FIXME
91     return 0
92   }
93
94   if {! [gcj_invoke $main [file rootname $file].out {}]} {
95     # FIXME
96     return 0
97   }
98
99   # When we succeed we remove all our clutter.
100   eval gcj_cleanup [glob -nocomplain -- ${main}.*] [list $main nat$main.o]
101
102   return 1
103 }
104
105 # Run the JVMTI tests.
106 proc gcj_jvmti_run {} {
107   global srcdir subdir
108   global build_triplet host_triplet
109
110   # For now we only test JVMTI on native builds.
111   if {$build_triplet == $host_triplet} {
112     catch { lsort [glob -nocomplain ${srcdir}/${subdir}/*.java] } srcfiles
113
114     foreach x $srcfiles {
115       gcj_jvmti_test_one $x
116     }
117   } else {
118     verbose "JVMTI tests not run in cross-compilation environment"
119   }
120 }
121
122 gcj_jvmti_run