2003-03-22 08:14:53 +01:00
|
|
|
# Tests for CNI code.
|
|
|
|
|
|
|
|
# Compile a single C++ file and produce a .o file. OPTIONS is a list
|
|
|
|
# of options to pass to the compiler. Returns 0 on failure, 1 on
|
|
|
|
# success.
|
|
|
|
proc gcj_cni_compile_cxx_to_o {file {options {}}} {
|
2007-01-09 20:58:05 +01:00
|
|
|
global srcdir subdir
|
2003-03-22 08:14:53 +01:00
|
|
|
|
|
|
|
set name [file rootname [file tail $file]]
|
|
|
|
set oname ${name}.o
|
|
|
|
|
|
|
|
# Find the generated header.
|
2007-07-13 16:07:16 +02:00
|
|
|
lappend options "additional_flags=-I. -I.. -I$srcdir/$subdir -fdollars-in-identifiers"
|
2003-03-22 08:14:53 +01:00
|
|
|
# Find libgcj headers.
|
|
|
|
lappend options "additional_flags=-I$srcdir/.."
|
|
|
|
|
|
|
|
set x [libjava_prune_warnings \
|
|
|
|
[target_compile $file $oname object $options]]
|
|
|
|
if {$x != ""} {
|
|
|
|
verbose "target_compile failed: $x" 2
|
|
|
|
fail "[file tail $file] compilation"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
pass "[file tail $file] compilation"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Build header files given name of .java file. Return 0 on failure.
|
|
|
|
proc gcj_cni_build_headers {file} {
|
2007-01-09 20:58:05 +01:00
|
|
|
global libgcj_jar
|
|
|
|
|
2003-03-22 08:14:53 +01:00
|
|
|
set gcjh [find_gcjh]
|
|
|
|
|
2007-01-09 20:58:05 +01:00
|
|
|
# Currently we only build a header file for the main class from the
|
|
|
|
# .java file, and then others on an ad hoc basis.
|
|
|
|
set list {}
|
|
|
|
set main [file rootname [file tail $file]]
|
|
|
|
lappend list $main
|
|
|
|
# ... for instance, an obvious hack.
|
|
|
|
if {$main == "shortfield"} {
|
|
|
|
lappend list shortfieldbase
|
2003-03-22 08:14:53 +01:00
|
|
|
}
|
|
|
|
|
2007-01-09 20:58:05 +01:00
|
|
|
foreach file $list {
|
|
|
|
set cmd "$gcjh -cni -force -classpath .:$libgcj_jar $file"
|
|
|
|
verbose $cmd
|
2003-03-22 08:14:53 +01:00
|
|
|
set x [string trim [libjava_prune_warnings \
|
2007-01-09 20:58:05 +01:00
|
|
|
[lindex [local_exec $cmd "" "" 300] 1]]]
|
2003-03-22 08:14:53 +01:00
|
|
|
if {$x != ""} {
|
|
|
|
verbose "local_exec failed: $x" 2
|
2007-01-09 20:58:05 +01:00
|
|
|
fail "$main header generation"
|
2003-03-22 08:14:53 +01:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-09 20:58:05 +01:00
|
|
|
pass "$main header generation"
|
2003-03-22 08:14:53 +01:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Do all the work for a single CNI test. Return 0 on failure.
|
|
|
|
proc gcj_cni_test_one {file} {
|
|
|
|
global runtests
|
|
|
|
|
|
|
|
# The base name. We use it for several purposes.
|
|
|
|
set main [file rootname [file tail $file]]
|
|
|
|
if {! [runtest_file_p $runtests $main]} {
|
|
|
|
# Simply skip it.
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2007-01-09 20:58:05 +01:00
|
|
|
# if {! [bytecompile_file $file [pwd]]} {
|
|
|
|
# fail "bytecompile $file"
|
|
|
|
# # FIXME - should use `untested' on all remaining tests.
|
|
|
|
# # But that is hard.
|
|
|
|
# return 0
|
|
|
|
# }
|
|
|
|
# pass "bytecompile $file"
|
2003-03-22 08:14:53 +01:00
|
|
|
|
2007-01-09 20:58:05 +01:00
|
|
|
# if {! [gcj_cni_build_headers $file]} {
|
|
|
|
# # FIXME
|
|
|
|
# return 0
|
|
|
|
# }
|
2003-03-22 08:14:53 +01:00
|
|
|
|
|
|
|
set cfile [file join [file dirname $file] nat$main.cc]
|
|
|
|
if {! [gcj_cni_compile_cxx_to_o $cfile]} {
|
|
|
|
# FIXME
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if {! [gcj_link $main $main [list $file nat$main.o]]} {
|
|
|
|
# FIXME
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if {! [gcj_invoke $main [file rootname $file].out {}]} {
|
|
|
|
# FIXME
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# When we succeed we remove all our clutter.
|
|
|
|
eval gcj_cleanup [glob -nocomplain -- ${main}.*] [list $main nat$main.o]
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run the CNI tests.
|
|
|
|
proc gcj_cni_run {} {
|
|
|
|
global srcdir subdir
|
|
|
|
global build_triplet host_triplet
|
|
|
|
|
|
|
|
# For now we only test CNI on native builds.
|
|
|
|
if {$build_triplet == $host_triplet} {
|
2007-01-09 20:58:05 +01:00
|
|
|
catch { lsort [glob -nocomplain ${srcdir}/${subdir}/*.jar] } srcfiles
|
2003-03-22 08:14:53 +01:00
|
|
|
|
|
|
|
foreach x $srcfiles {
|
|
|
|
gcj_cni_test_one $x
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
verbose "CNI tests not run in cross-compilation environment"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gcj_cni_run
|