diff options
author | fitzsim <fitzsim@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-02-23 17:36:26 +0000 |
---|---|---|
committer | fitzsim <fitzsim@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-02-23 17:36:26 +0000 |
commit | a504c2c16828e174902675d71a2cd5348f42147e (patch) | |
tree | 9b2cca6c033589c537e103cd0b5bbf64f75f3359 /libjava/testsuite/libjava.jni | |
parent | b82a5135037408ded1ea901f3de3e23e2eefd895 (diff) | |
download | gcc-a504c2c16828e174902675d71a2cd5348f42147e.tar.gz |
2005-02-23 Thomas Fitzsimmons <fitzsim@redhat.com>
PR libgcj/16923
* gcj.texi (Invocation): Add descriptions of JvVMInitArgs and
JvVMOption.
2005-02-23 Thomas Fitzsimmons <fitzsim@redhat.com>
PR libgcj/16923
* jni.cc (JNI_CreateJavaVM): Check JNI version. Cast args to
JvVMInitArgs. Pass args to _Jv_CreateJavaVM and check return
value. Move argument parsing code to prims.cc.
* prims.cc (no_properties): Remove.
(_Jv_Compiler_Properties): Initialize to NULL.
(_Jv_Properties_Count): Initialize to 0.
(parse_verbose_args): New function.
(parse_init_args): New function.
(_Jv_CreateJavaVM): Call parse_init_args.
(_Jv_RunMain): Check return value of _Jv_CreateJavaVM.
* gcj/cni.h (JvVMOption): New struct.
(JvVMInitArgs): Likewise.
(JvCreateJavaVM): Declare vm_args as JvVMInitArgs* rather than
void*.
* libjava/gcj/javaprims.h (_Jv_VMOption): New struct.
(_Jv_VMInitArgs): Likewise.
* include/java-props.h (_Jv_Properties_Count): Declare.
* java/lang/natRuntime.cc (insertSystemProperties): Use
_Jv_Properties_Count in for loop exit condition.
* testsuite/libjava.jni/jni.exp
(gcj_invocation_compile_c_to_binary): New procedure.
(gcj_invocation_test_one): Likewise.
(gcj_jni_run): Run JNI invocation API tests.
* testsuite/libjava.jni/invocation/PR16923.c,
testsuite/libjava.jni/invocation/PR16923.java,
testsuite/libjava.jni/invocation/PR16923.out: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@95459 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/testsuite/libjava.jni')
-rw-r--r-- | libjava/testsuite/libjava.jni/invocation/PR16923.c | 43 | ||||
-rw-r--r-- | libjava/testsuite/libjava.jni/invocation/PR16923.java | 7 | ||||
-rw-r--r-- | libjava/testsuite/libjava.jni/invocation/PR16923.out | 1 | ||||
-rw-r--r-- | libjava/testsuite/libjava.jni/jni.exp | 86 |
4 files changed, 137 insertions, 0 deletions
diff --git a/libjava/testsuite/libjava.jni/invocation/PR16923.c b/libjava/testsuite/libjava.jni/invocation/PR16923.c new file mode 100644 index 00000000000..881738b61ca --- /dev/null +++ b/libjava/testsuite/libjava.jni/invocation/PR16923.c @@ -0,0 +1,43 @@ +#include <assert.h> +#include <jni.h> + +union env_union +{ + void *void_env; + JNIEnv *jni_env; +}; + +int +main (int argc, const char** argv) +{ + union env_union tmp; + JNIEnv* env; + JavaVM* jvm; + JavaVMInitArgs vm_args; + JavaVMOption options[1]; + jclass class_id; + jmethodID method_id; + jint result; + + options[0].optionString = "-DPR16923=optionReceived"; + + vm_args.version = JNI_VERSION_1_2; + vm_args.ignoreUnrecognized = JNI_TRUE; + vm_args.options = options; + vm_args.nOptions = 1; + + result = JNI_CreateJavaVM (&jvm, &tmp.void_env, &vm_args); + assert (result >= 0); + + env = tmp.jni_env; + + class_id = (*env)->FindClass (env, "PR16923"); + assert (class_id); + + method_id = (*env)->GetStaticMethodID (env, class_id, "printIt", "()V"); + assert (method_id); + + (*env)->CallStaticVoidMethod (env, class_id, method_id, NULL); + + return 0; +} diff --git a/libjava/testsuite/libjava.jni/invocation/PR16923.java b/libjava/testsuite/libjava.jni/invocation/PR16923.java new file mode 100644 index 00000000000..efda4bd755a --- /dev/null +++ b/libjava/testsuite/libjava.jni/invocation/PR16923.java @@ -0,0 +1,7 @@ +public class PR16923 +{ + public static void printIt () + { + System.out.println (System.getProperty ("PR16923")); + } +} diff --git a/libjava/testsuite/libjava.jni/invocation/PR16923.out b/libjava/testsuite/libjava.jni/invocation/PR16923.out new file mode 100644 index 00000000000..58bf3fe1982 --- /dev/null +++ b/libjava/testsuite/libjava.jni/invocation/PR16923.out @@ -0,0 +1 @@ +optionReceived diff --git a/libjava/testsuite/libjava.jni/jni.exp b/libjava/testsuite/libjava.jni/jni.exp index cbd90ca28cb..d736b8690d6 100644 --- a/libjava/testsuite/libjava.jni/jni.exp +++ b/libjava/testsuite/libjava.jni/jni.exp @@ -181,6 +181,85 @@ proc gcj_jni_test_one {file} { return 1 } +# 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 {}}} { + global srcdir + global host_triplet + verbose "options: $options" + set options_cxx $options + set options "" + + set filename [file tail $file] + set name [file rootname $filename] + + # Find jni.h. + lappend options "additional_flags=-I$srcdir/../include" + + # 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 +} + +# Do all the work for a single invocation API test. Return 0 on +# failure. +proc gcj_jni_invocation_test_one {file} { + 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 + } + + 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 cfile [file rootname $file].c + set cxxflags "-lgcj" + + if {! [gcj_jni_invocation_compile_c_to_binary $cfile $cxxflags]} { + # FIXME + return 0 + } + + set resultfile [file rootname $file].out + + if {! [gcj_invoke $main $resultfile ""]} { + # FIXME + return 0 + } + + # 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 +} + # Run the JNI tests. proc gcj_jni_run {} { global srcdir subdir @@ -193,6 +272,13 @@ proc gcj_jni_run {} { foreach x $srcfiles { gcj_jni_test_one $x } + + # Run JNI invocation API tests + catch { lsort [glob -nocomplain ${srcdir}/${subdir}/invocation/*.java] } srcfiles + + foreach x $srcfiles { + gcj_jni_invocation_test_one $x + } } else { verbose "JNI tests not run in cross-compilation environment" } |