2004-09-22 Kelley Cook <kcook@gcc.gnu.org>
[official-gcc.git] / libjava / testsuite / libjava.cni / cni.exp
blob22df1462c1df9716f641ec07b4aaf46df0cedf43
1 # Tests for CNI code.
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_cni_compile_cxx_to_o {file {options {}}} {
7 global srcdir
9 set name [file rootname [file tail $file]]
10 set oname ${name}.o
12 # Find the generated header.
13 lappend options "additional_flags=-I. -I.."
14 # Find libgcj headers.
15 lappend options "additional_flags=-I$srcdir/.."
17 set x [libjava_prune_warnings \
18 [target_compile $file $oname object $options]]
19 if {$x != ""} {
20 verbose "target_compile failed: $x" 2
21 fail "[file tail $file] compilation"
22 return 0
25 pass "[file tail $file] compilation"
26 return 1
29 # Build header files given name of .java file. Return 0 on failure.
30 proc gcj_cni_build_headers {file} {
31 set gcjh [find_gcjh]
32 set jvscan [find_jvscan]
34 set class_out [string trim \
35 [libjava_prune_warnings \
36 [lindex [local_exec "$jvscan --encoding=UTF-8 $file --list-class" "" "" 300] 1]]]
37 if {[string match "*parse error*" $class_out]} {
38 fail "$file header generation"
39 return 0
42 foreach file [split $class_out] {
43 set x [string trim [libjava_prune_warnings \
44 [lindex [local_exec "$gcjh $file" "" "" 300] 1]]]
45 if {$x != ""} {
46 verbose "local_exec failed: $x" 2
47 fail "$file header generation"
48 return 0
52 pass "$file header generation"
53 return 1
56 # Do all the work for a single CNI test. Return 0 on failure.
57 proc gcj_cni_test_one {file} {
58 global runtests
60 # The base name. We use it for several purposes.
61 set main [file rootname [file tail $file]]
62 if {! [runtest_file_p $runtests $main]} {
63 # Simply skip it.
64 return 1
67 if {! [bytecompile_file $file [pwd]]} {
68 fail "bytecompile $file"
69 # FIXME - should use `untested' on all remaining tests.
70 # But that is hard.
71 return 0
73 pass "bytecompile $file"
75 if {! [gcj_cni_build_headers $file]} {
76 # FIXME
77 return 0
80 set cfile [file join [file dirname $file] nat$main.cc]
81 if {! [gcj_cni_compile_cxx_to_o $cfile]} {
82 # FIXME
83 return 0
86 if {! [gcj_link $main $main [list $file nat$main.o]]} {
87 # FIXME
88 return 0
91 if {! [gcj_invoke $main [file rootname $file].out {}]} {
92 # FIXME
93 return 0
96 # When we succeed we remove all our clutter.
97 eval gcj_cleanup [glob -nocomplain -- ${main}.*] [list $main nat$main.o]
99 return 1
102 # Run the CNI tests.
103 proc gcj_cni_run {} {
104 global srcdir subdir
105 global build_triplet host_triplet
107 # For now we only test CNI on native builds.
108 if {$build_triplet == $host_triplet} {
109 catch { lsort [glob -nocomplain ${srcdir}/${subdir}/*.java] } srcfiles
111 foreach x $srcfiles {
112 gcj_cni_test_one $x
114 } else {
115 verbose "CNI tests not run in cross-compilation environment"
119 gcj_cni_run