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 {}}} {
|
2007-01-09 20:58:05 +01:00
|
|
|
global srcdir subdir
|
2003-03-22 11:45:04 +01:00
|
|
|
global host_triplet
|
|
|
|
verbose "options: $options"
|
|
|
|
set options_cxx $options
|
|
|
|
set options ""
|
|
|
|
|
2006-05-06 22:57:18 +02:00
|
|
|
# Apple uses a different extension for shared/dynamic libraries
|
2004-06-18 22:56:56 +02:00
|
|
|
# so we check against powerpc-apple-darwin and set them to
|
2006-05-06 22:57:18 +02:00
|
|
|
# dylib.
|
|
|
|
# HP-UX uses sl, so we check this too, otherwise we take so.
|
2003-03-22 11:45:04 +01:00
|
|
|
|
2005-03-11 22:33:56 +01:00
|
|
|
if { [istarget "*-*-darwin*"] } {
|
2003-03-22 11:45:04 +01:00
|
|
|
set so_extension "dylib"
|
|
|
|
set so_flag "-dynamiclib"
|
2006-05-06 22:57:18 +02:00
|
|
|
} elseif { [istarget "hppa*-hp-hpux*"] } {
|
|
|
|
set so_extension "sl"
|
|
|
|
set so_flag "-shared"
|
2003-03-22 11:45:04 +01:00
|
|
|
} 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.
|
2007-07-13 16:07:16 +02:00
|
|
|
lappend options "additional_flags=-I. -I.. -I$srcdir/$subdir -fdollars-in-identifiers"
|
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"
|
|
|
|
}
|
|
|
|
|
2005-07-16 03:27:14 +02:00
|
|
|
# Find jni.h and jni_md.h.
|
|
|
|
lappend options "additional_flags=-I$srcdir/../include -I$srcdir/../classpath/include"
|
2001-06-14 19:46:53 +02:00
|
|
|
|
2004-05-06 19:54:30 +02:00
|
|
|
# Append C++ options
|
|
|
|
lappend options "additional_flags=$options_cxx"
|
|
|
|
|
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} {
|
2007-01-09 20:58:05 +01:00
|
|
|
global libgcj_jar
|
|
|
|
|
2001-06-14 19:46:53 +02:00
|
|
|
set gcjh [find_gcjh]
|
|
|
|
set file [file rootname $file]
|
2007-01-09 20:58:05 +01:00
|
|
|
|
|
|
|
set cmd "$gcjh -jni -force -classpath .:$libgcj_jar $file"
|
|
|
|
verbose $cmd
|
|
|
|
|
2002-12-13 06:00:15 +01:00
|
|
|
set x [string trim [libjava_prune_warnings \
|
2007-01-09 20:58:05 +01:00
|
|
|
[lindex [local_exec $cmd "" "" 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
|
2004-05-06 19:54:30 +02:00
|
|
|
global INTERPRETER
|
2003-03-22 11:45:04 +01:00
|
|
|
|
2006-05-06 22:57:18 +02:00
|
|
|
# Apple uses a different extension for shared/dynamic libraries
|
2005-03-11 22:33:56 +01:00
|
|
|
# so we check against powerpc-apple-darwin and set them to
|
2006-05-06 22:57:18 +02:00
|
|
|
# dylib.
|
|
|
|
# HP-UX uses sl, so we check this too, otherwise we take so.
|
2003-03-22 11:45:04 +01:00
|
|
|
|
2005-03-11 22:33:56 +01:00
|
|
|
if { [istarget "*-*-darwin*"] } {
|
2003-03-22 11:45:04 +01:00
|
|
|
set so_extension "dylib"
|
2006-05-06 22:57:18 +02:00
|
|
|
} elseif { [istarget "hppa*-hp-hpux*"] } {
|
|
|
|
set so_extension "sl"
|
2003-03-22 11:45:04 +01:00
|
|
|
} 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]]
|
2007-01-23 00:04:16 +01:00
|
|
|
if {! [runtest_file_p $runtests $main]
|
|
|
|
|| $main == "pr29812" || $main == "pr29812_injar"} {
|
2001-06-14 19:46:53 +02:00
|
|
|
# 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"
|
2001-06-14 19:46:53 +02:00
|
|
|
|
2007-01-09 20:58:05 +01:00
|
|
|
# set bytefile [file rootname [file tail $file]].class
|
|
|
|
# if {! [gcj_jni_build_header $bytefile]} {
|
|
|
|
# # FIXME
|
|
|
|
# return 0
|
|
|
|
# }
|
2001-06-14 19:46:53 +02:00
|
|
|
|
|
|
|
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
|
2004-05-10 22:44:13 +02:00
|
|
|
# In case the libstdc++ is not installed yet, we pass the build
|
|
|
|
# directory of it to the cxxflaglist.
|
|
|
|
lappend cxxflaglist "-L$cxxldlibflags"
|
2002-03-18 22:39:09 +01:00
|
|
|
}
|
|
|
|
|
2005-10-02 23:40:55 +02:00
|
|
|
# If you're building the compiler with --prefix set to a place
|
|
|
|
# where it's not yet installed, then the linker won't be able to
|
|
|
|
# find the libgcc used by libffi.dylib. We could pass the
|
|
|
|
# -dylib_file option, but that's complicated, and it's much easier
|
|
|
|
# to just make the linker find libgcc using -L options.
|
2005-03-11 22:33:56 +01:00
|
|
|
if { [istarget "*-*-darwin*"] } {
|
2005-10-02 23:40:55 +02:00
|
|
|
lappend cxxflaglist "-shared-libgcc -lstdc++"
|
2004-06-18 22:56:56 +02:00
|
|
|
} else {
|
|
|
|
lappend cxxflaglist "-lstdc++"
|
|
|
|
}
|
2005-03-11 22:33:56 +01:00
|
|
|
|
2002-03-18 22:39:09 +01:00
|
|
|
set cxxflags [join $cxxflaglist]
|
2001-12-14 22:56:29 +01:00
|
|
|
}
|
|
|
|
|
2004-05-06 19:54:30 +02:00
|
|
|
if {! [gcj_jni_compile_c_to_so $cfile $cxxflags]} {
|
2001-06-14 19:46:53 +02:00
|
|
|
# FIXME
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2004-05-07 16:59:43 +02:00
|
|
|
set args [list "additional_flags=-fjni"]
|
2001-06-14 19:46:53 +02:00
|
|
|
if {! [gcj_link $main $main $file $args]} {
|
|
|
|
# FIXME
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2004-05-06 19:54:30 +02:00
|
|
|
set resultfile [file rootname $file].out
|
|
|
|
|
|
|
|
if {! [gcj_invoke $main $resultfile $cxxldlibflags]} {
|
2001-06-14 19:46:53 +02:00
|
|
|
# FIXME
|
|
|
|
return 0
|
|
|
|
}
|
2004-05-10 22:44:13 +02:00
|
|
|
|
2004-05-06 19:54:30 +02:00
|
|
|
# We purposely ignore errors here; we still want to run the other
|
|
|
|
# appropriate tests.
|
|
|
|
set errname [file rootname [file tail $file]]
|
|
|
|
set gij [libjava_find_gij]
|
2004-12-21 02:01:08 +01:00
|
|
|
# libjava_find_gij will return "" if it couldn't find the
|
2004-05-06 19:54:30 +02:00
|
|
|
# program; in this case we want to skip the test.
|
2004-05-10 22:44:13 +02:00
|
|
|
# If the libraries are not installed yet, we have to pass them via
|
|
|
|
# cxxldlibflags to libjava_invoke.
|
2004-12-21 02:01:08 +01:00
|
|
|
if {$INTERPRETER == "yes" && $gij != ""} {
|
|
|
|
libjava_invoke $errname "gij test" opts $gij \
|
2007-01-09 20:58:05 +01:00
|
|
|
"" $resultfile $cxxldlibflags \
|
|
|
|
-classpath $file $main
|
2004-05-10 22:44:13 +02:00
|
|
|
}
|
2001-06-14 19:46:53 +02:00
|
|
|
|
|
|
|
# When we succeed we remove all our clutter.
|
2004-12-21 02:01:08 +01:00
|
|
|
eval gcj_cleanup [glob -nocomplain -- ${main}.*] \
|
|
|
|
[list $main lib${main}.${so_extension}]
|
2001-06-14 19:46:53 +02:00
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2005-02-23 18:36:26 +01:00
|
|
|
# Compile a single C file and produce a binary. OPTIONS is a list of
|
|
|
|
# options to pass to the compiler. Returns 0 on failure, 1 on
|
|
|
|
# success.
|
|
|
|
proc gcj_jni_invocation_compile_c_to_binary {file {options {}}} {
|
2007-01-09 20:58:05 +01:00
|
|
|
global srcdir subdir
|
2005-02-23 18:36:26 +01:00
|
|
|
global host_triplet
|
|
|
|
verbose "options: $options"
|
|
|
|
set options_cxx $options
|
|
|
|
set options ""
|
|
|
|
|
|
|
|
set filename [file tail $file]
|
|
|
|
set name [file rootname $filename]
|
|
|
|
|
2005-03-11 22:33:56 +01:00
|
|
|
# Set some darwin specific options
|
|
|
|
if { [istarget "*-*-darwin*"] } {
|
2005-06-02 20:12:47 +02:00
|
|
|
lappend options "additional_flags= -bind_at_load -multiply_defined suppress"
|
2005-03-11 22:33:56 +01:00
|
|
|
}
|
2005-03-03 23:17:26 +01:00
|
|
|
# Find the generated header.
|
2007-01-09 20:58:05 +01:00
|
|
|
lappend options "additional_flags=-I. -I.. -I$srcdir/$subdir"
|
2005-03-03 23:17:26 +01:00
|
|
|
|
2005-07-16 03:27:14 +02:00
|
|
|
# Find jni.h and jni_md.h.
|
2007-07-13 16:07:16 +02:00
|
|
|
lappend options "additional_flags=-I$srcdir/../include -I$srcdir/../classpath/include -fdollars-in-identifiers"
|
2005-02-23 18:36:26 +01:00
|
|
|
|
|
|
|
# Append C++ options
|
|
|
|
lappend options "additional_flags=$options_cxx"
|
|
|
|
|
|
|
|
set x [libjava_prune_warnings \
|
|
|
|
[target_compile $file $name executable $options]]
|
|
|
|
if {$x != ""} {
|
|
|
|
verbose "target_compile failed: $x" 2
|
|
|
|
fail "$filename compilation"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
pass "$filename compilation"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2007-01-23 00:04:16 +01:00
|
|
|
proc gcj_jni_get_cxxflags_invocation {} {
|
|
|
|
# Darwin needs -liconv linked, otherwise we get some unresolved.
|
|
|
|
# If you're building the compiler with --prefix set to a place
|
|
|
|
# where it's not yet installed, then the linker won't be able to
|
|
|
|
# find the libgcc used by libffi.dylib. We could pass the
|
|
|
|
# -dylib_file option, but that's complicated, and it's much easier
|
|
|
|
# to just make the linker find libgcc using -L options.
|
|
|
|
# Similar logic applies to libgcj.
|
|
|
|
if { [istarget "*-*-darwin*"] } {
|
|
|
|
set cxxflags "-L../.libs -shared-libgcc -ljvm -lgcj -liconv"
|
|
|
|
} else {
|
|
|
|
global LIBJAVA
|
|
|
|
if [info exists LIBJAVA] {
|
|
|
|
set libjava $LIBJAVA;
|
|
|
|
} else {
|
|
|
|
set libjava [libjava_find_lib libjava gcj]
|
|
|
|
}
|
|
|
|
set cxxflags "$libjava -ljvm"
|
|
|
|
}
|
|
|
|
|
|
|
|
if { [istarget "*-*-solaris*"] } {
|
|
|
|
lappend cxxflags "-lsocket"
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cxxflags
|
|
|
|
}
|
|
|
|
|
2005-02-23 18:36:26 +01:00
|
|
|
# Do all the work for a single invocation API test. Return 0 on
|
|
|
|
# failure.
|
|
|
|
proc gcj_jni_invocation_test_one {file} {
|
2007-01-09 20:58:05 +01:00
|
|
|
global env
|
2005-02-23 18:36:26 +01:00
|
|
|
global runtests
|
|
|
|
global host_triplet
|
|
|
|
global INTERPRETER
|
|
|
|
|
|
|
|
# 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"
|
2005-02-23 18:36:26 +01:00
|
|
|
|
|
|
|
set cfile [file rootname $file].c
|
2005-03-28 14:08:28 +02:00
|
|
|
|
2007-01-23 00:04:16 +01:00
|
|
|
set cxxflags [gcj_jni_get_cxxflags_invocation]
|
2005-02-23 18:36:26 +01:00
|
|
|
if {! [gcj_jni_invocation_compile_c_to_binary $cfile $cxxflags]} {
|
|
|
|
# FIXME
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
set resultfile [file rootname $file].out
|
|
|
|
|
2007-01-09 20:58:05 +01:00
|
|
|
set env(CLASSPATH) $file
|
|
|
|
verbose "CLASSPATH = $env(CLASSPATH)"
|
2005-02-23 18:36:26 +01:00
|
|
|
if {! [gcj_invoke $main $resultfile ""]} {
|
2007-01-09 20:58:05 +01:00
|
|
|
unset env(CLASSPATH)
|
2005-02-23 18:36:26 +01:00
|
|
|
# FIXME
|
|
|
|
return 0
|
|
|
|
}
|
2007-01-09 20:58:05 +01:00
|
|
|
unset env(CLASSPATH)
|
2005-02-23 18:36:26 +01:00
|
|
|
|
|
|
|
# We purposely ignore errors here; we still want to run the other
|
|
|
|
# appropriate tests.
|
|
|
|
set errname [file rootname [file tail $file]]
|
|
|
|
|
|
|
|
# When we succeed we remove all our clutter.
|
|
|
|
eval gcj_cleanup [glob -nocomplain -- ${main}.*] \
|
|
|
|
[list $main]
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2007-01-23 00:04:16 +01:00
|
|
|
proc gcj_jni_pr29812 {} {
|
|
|
|
global srcdir subdir
|
|
|
|
global INTERPRETER runtests
|
|
|
|
|
|
|
|
# Set up a global we need.
|
|
|
|
libjava_arguments
|
|
|
|
|
|
|
|
set b ${srcdir}/${subdir}
|
|
|
|
|
|
|
|
if {! [runtest_file_p $runtests pr29812]} {
|
|
|
|
# Simply skip it.
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if {! [gcj_jni_compile_c_to_so $b/pr29812.c ""]} {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
if {! [gcj_jni_compile_c_to_so $b/pr29812_injar.c ""]} {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
set gij [libjava_find_gij]
|
|
|
|
if {$INTERPRETER == "yes" && $gij != ""} {
|
|
|
|
if {! [libjava_invoke pr29812 "gij test" opts $gij \
|
|
|
|
"" $b/pr29812.out "" \
|
|
|
|
-classpath $b/pr29812.jar pr29812 $b/pr29812_injar.jar]} {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# When we succeed we remove all our clutter.
|
|
|
|
eval gcj_cleanup [glob -nocomplain -- *pr29812*]
|
|
|
|
}
|
|
|
|
|
2001-06-14 19:46:53 +02:00
|
|
|
# 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} {
|
2007-01-09 20:58:05 +01:00
|
|
|
catch { lsort [glob -nocomplain ${srcdir}/${subdir}/*.jar] } srcfiles
|
2001-06-14 19:46:53 +02:00
|
|
|
|
|
|
|
foreach x $srcfiles {
|
|
|
|
gcj_jni_test_one $x
|
|
|
|
}
|
2005-02-23 18:36:26 +01:00
|
|
|
|
|
|
|
# Run JNI invocation API tests
|
2007-01-09 20:58:05 +01:00
|
|
|
catch { lsort [glob -nocomplain ${srcdir}/${subdir}/invocation/*.jar] } srcfiles
|
2005-02-23 18:36:26 +01:00
|
|
|
|
|
|
|
foreach x $srcfiles {
|
|
|
|
gcj_jni_invocation_test_one $x
|
|
|
|
}
|
2007-01-23 00:04:16 +01:00
|
|
|
|
|
|
|
gcj_jni_pr29812
|
2001-06-14 19:46:53 +02:00
|
|
|
} else {
|
|
|
|
verbose "JNI tests not run in cross-compilation environment"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gcj_jni_run
|