2001-06-14 19:46:53 +02:00
|
|
|
# Tests for JNI code.
|
|
|
|
|
|
|
|
# Compile a single C file and produce a .so file. OPTIONS is a list
|
|
|
|
# of options to pass to the compiler. Returns 0 on failure, 1 on
|
|
|
|
# success.
|
|
|
|
proc gcj_jni_compile_c_to_so {file {options {}}} {
|
|
|
|
global srcdir
|
2003-03-22 11:45:04 +01:00
|
|
|
global host_triplet
|
|
|
|
verbose "options: $options"
|
|
|
|
set options_cxx $options
|
|
|
|
set options ""
|
|
|
|
|
|
|
|
# apple uses a different extension for shared/dynamic libraries
|
|
|
|
# so we check against powerpc-apple-darwin and set them to
|
|
|
|
# dylib, else we assume it's .so
|
|
|
|
|
|
|
|
if { [ regexp {powerpc-apple-darwin} $host_triplet] } {
|
|
|
|
set so_extension "dylib"
|
|
|
|
set so_flag "-dynamiclib"
|
|
|
|
} else {
|
|
|
|
set so_extension "so"
|
|
|
|
set so_flag "-shared"
|
|
|
|
}
|
2004-04-30 20:19:37 +02:00
|
|
|
set filename [file tail $file]
|
|
|
|
set name [file rootname $filename]
|
2003-03-22 11:45:04 +01:00
|
|
|
set soname lib${name}.${so_extension}
|
2001-06-14 19:46:53 +02:00
|
|
|
|
2003-03-22 11:45:04 +01:00
|
|
|
lappend options "additional_flags=${so_flag} -fPIC"
|
2001-06-14 19:46:53 +02:00
|
|
|
# Find the generated header.
|
2002-01-05 23:26:58 +01:00
|
|
|
lappend options "additional_flags=-I. -I.."
|
2004-04-30 20:19:37 +02:00
|
|
|
|
|
|
|
# Ensure that the generated header has correct prototypes.
|
|
|
|
set cfile [file rootname $file].c
|
|
|
|
if { [file exists $cfile]} {
|
|
|
|
# This option is only valid for C sources.
|
|
|
|
lappend options "additional_flags=-Wmissing-prototypes"
|
|
|
|
}
|
|
|
|
|
2001-06-14 19:46:53 +02:00
|
|
|
# Find jni.h.
|
2001-06-25 06:48:55 +02:00
|
|
|
lappend options "additional_flags=-I$srcdir/../include"
|
2001-06-14 19:46:53 +02:00
|
|
|
|
2002-12-13 06:00:15 +01:00
|
|
|
set x [libjava_prune_warnings \
|
|
|
|
[target_compile $file $soname executable $options]]
|
2001-06-14 19:46:53 +02:00
|
|
|
if {$x != ""} {
|
|
|
|
verbose "target_compile failed: $x" 2
|
2004-04-30 20:19:37 +02:00
|
|
|
fail "$filename compilation"
|
2001-06-14 19:46:53 +02:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2004-04-30 20:19:37 +02:00
|
|
|
pass "$filename compilation"
|
2001-06-14 19:46:53 +02:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Build a header file from a .class file. Return 0 on failure.
|
|
|
|
proc gcj_jni_build_header {file} {
|
|
|
|
set gcjh [find_gcjh]
|
|
|
|
set file [file rootname $file]
|
2002-12-13 06:00:15 +01:00
|
|
|
set x [string trim [libjava_prune_warnings \
|
2002-03-17 21:34:36 +01:00
|
|
|
[lindex [local_exec "$gcjh -jni $file" "" "" 300] 1]]]
|
2001-06-14 19:46:53 +02:00
|
|
|
if {$x != ""} {
|
2002-03-17 21:34:36 +01:00
|
|
|
verbose "local_exec failed: $x" 2
|
2001-06-14 19:46:53 +02:00
|
|
|
fail "$file header generation"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
pass "$file header generation"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Do all the work for a single JNI test. Return 0 on failure.
|
|
|
|
proc gcj_jni_test_one {file} {
|
|
|
|
global runtests
|
2003-03-22 11:45:04 +01:00
|
|
|
global host_triplet
|
|
|
|
|
|
|
|
# apple uses a different extension for shared/dynamic libraries
|
|
|
|
# so we check against powerpc-apple-darwin and set them to
|
|
|
|
# dylib, else we assume it's .so
|
|
|
|
|
|
|
|
if { [ regexp {powerpc-apple-darwin} $host_triplet] } {
|
|
|
|
set so_extension "dylib"
|
|
|
|
} else {
|
|
|
|
set so_extension "so"
|
|
|
|
}
|
2001-06-14 19:46:53 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
set bytefile [file rootname [file tail $file]].class
|
|
|
|
if {! [gcj_jni_build_header $bytefile]} {
|
|
|
|
# FIXME
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
set cfile [file rootname $file].c
|
2001-12-14 22:56:29 +01:00
|
|
|
set cxxflags ""
|
2002-03-18 22:39:09 +01:00
|
|
|
set cxxldlibflags {}
|
2001-12-14 22:56:29 +01:00
|
|
|
# If there is no `.c' file, assume there is a `.cc' file.
|
|
|
|
if {! [file exists $cfile]} {
|
|
|
|
set cfile [file rootname $file].cc
|
2002-03-18 22:39:09 +01:00
|
|
|
|
|
|
|
set cxxflaglist {}
|
|
|
|
foreach arg [split [libjava_find_lib libstdc++-v3/src stdc++] " "] {
|
|
|
|
switch -glob -- $arg {
|
|
|
|
"-L*" {
|
|
|
|
set arg [string range $arg 2 end]
|
|
|
|
lappend cxxldlibflags $arg
|
|
|
|
# Strip the `.libs' directory; we link with libtool which
|
|
|
|
# doesn't need it.
|
|
|
|
set arg "-L[file dirname $arg]"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lappend cxxflaglist $arg
|
|
|
|
}
|
|
|
|
|
|
|
|
lappend cxxflaglist "-lstdc++"
|
|
|
|
set cxxflags [join $cxxflaglist]
|
2001-12-14 22:56:29 +01:00
|
|
|
}
|
|
|
|
|
2001-06-14 19:46:53 +02:00
|
|
|
if {! [gcj_jni_compile_c_to_so $cfile]} {
|
|
|
|
# FIXME
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# We use -l$main because the .so is named the same as the main
|
|
|
|
# program.
|
2001-12-14 22:56:29 +01:00
|
|
|
set args [list "additional_flags=-fjni -L. -l$main $cxxflags"]
|
2001-06-14 19:46:53 +02:00
|
|
|
if {! [gcj_link $main $main $file $args]} {
|
|
|
|
# FIXME
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2002-03-18 22:39:09 +01:00
|
|
|
if {! [gcj_invoke $main [file rootname $file].out $cxxldlibflags]} {
|
2001-06-14 19:46:53 +02:00
|
|
|
# FIXME
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# When we succeed we remove all our clutter.
|
2003-03-22 11:45:04 +01:00
|
|
|
eval gcj_cleanup [glob -nocomplain -- ${main}.*] [list $main lib${main}.${so_extension}]
|
2001-06-14 19:46:53 +02:00
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run the JNI tests.
|
|
|
|
proc gcj_jni_run {} {
|
|
|
|
global srcdir subdir
|
2002-03-27 17:29:04 +01:00
|
|
|
global build_triplet host_triplet
|
2001-06-14 19:46:53 +02:00
|
|
|
|
|
|
|
# For now we only test JNI on native builds.
|
2002-03-27 17:29:04 +01:00
|
|
|
if {$build_triplet == $host_triplet} {
|
2002-07-18 19:42:31 +02:00
|
|
|
catch { lsort [glob -nocomplain ${srcdir}/${subdir}/*.java] } srcfiles
|
2001-06-14 19:46:53 +02:00
|
|
|
|
|
|
|
foreach x $srcfiles {
|
|
|
|
gcj_jni_test_one $x
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
verbose "JNI tests not run in cross-compilation environment"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gcj_jni_run
|