PR target/61794
[official-gcc.git] / libjava / testsuite / libjava.cni / cni.exp
blobaec16b9330b9f616877380d5f2c600305534b39d
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 subdir
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.. -I$srcdir/$subdir -fdollars-in-identifiers"
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 global libgcj_jar
33 set gcjh [find_gcjh]
35 # Currently we only build a header file for the main class from the
36 # .java file, and then others on an ad hoc basis.
37 set list {}
38 set main [file rootname [file tail $file]]
39 lappend list $main
40 # ... for instance, an obvious hack.
41 if {$main == "shortfield"} {
42 lappend list shortfieldbase
45 foreach file $list {
46 set cmd "$gcjh -cni -force -classpath .:$libgcj_jar $file"
47 verbose $cmd
48 set x [string trim [libjava_prune_warnings \
49 [lindex [local_exec $cmd "" "" 300] 1]]]
50 if {$x != ""} {
51 verbose "local_exec failed: $x" 2
52 fail "$main header generation"
53 return 0
57 pass "$main header generation"
58 return 1
61 # Do all the work for a single CNI test. Return 0 on failure.
62 proc gcj_cni_test_one {file} {
63 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
72 # if {! [bytecompile_file $file [pwd]]} {
73 # fail "bytecompile $file"
74 # # FIXME - should use `untested' on all remaining tests.
75 # # But that is hard.
76 # return 0
77 # }
78 # pass "bytecompile $file"
80 # if {! [gcj_cni_build_headers $file]} {
81 # # FIXME
82 # return 0
83 # }
85 set cfile [file join [file dirname $file] nat$main.cc]
86 if {! [gcj_cni_compile_cxx_to_o $cfile]} {
87 # FIXME
88 return 0
91 if {! [gcj_link $main $main [list $file nat$main.o]]} {
92 # FIXME
93 return 0
96 if {! [gcj_invoke $main [file rootname $file].out {}]} {
97 # FIXME
98 return 0
101 # When we succeed we remove all our clutter.
102 eval gcj_cleanup [glob -nocomplain -- ${main}.*] [list $main nat$main.o]
104 return 1
107 # Run the CNI tests.
108 proc gcj_cni_run {} {
109 global srcdir subdir
110 global build_triplet host_triplet
112 # For now we only test CNI on native builds.
113 if {$build_triplet == $host_triplet} {
114 catch { lsort [glob -nocomplain ${srcdir}/${subdir}/*.jar] } srcfiles
116 foreach x $srcfiles {
117 gcj_cni_test_one $x
119 } else {
120 verbose "CNI tests not run in cross-compilation environment"
124 gcj_cni_run