aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2003-03-22 07:14:53 +0000
committerTom Tromey <tromey@gcc.gnu.org>2003-03-22 07:14:53 +0000
commit6932a1994e035982ca387d7d66b32e53b8e3bce0 (patch)
tree173dacf5d424f802b24bc491f512bcdbaaeb8592
parent442c0874ea857deaed375a626f848ac97a4fbcaf (diff)
downloadgcc-6932a1994e035982ca387d7d66b32e53b8e3bce0.zip
gcc-6932a1994e035982ca387d7d66b32e53b8e3bce0.tar.gz
gcc-6932a1994e035982ca387d7d66b32e53b8e3bce0.tar.bz2
libjava.exp (gcj_invoke): Moved...
* lib/libjava.exp (gcj_invoke): Moved... * libjava.jni/jni.exp: ...from here. * libjava.cni/shortfield.out: New file. * libjava.cni/shortfield.java: New file. * libjava.cni/natshortfield.cc: New file. * libjava.cni/natlongfield.cc: New file. * libjava.cni/longfield.out: New file. * libjava.cni/longfield.java: New file. * libjava.cni/cni.exp: New file. From-SVN: r64702
-rw-r--r--libjava/testsuite/ChangeLog14
-rw-r--r--libjava/testsuite/lib/libjava.exp44
-rw-r--r--libjava/testsuite/libjava.cni/cni.exp119
-rw-r--r--libjava/testsuite/libjava.cni/longfield.java22
-rw-r--r--libjava/testsuite/libjava.cni/longfield.out6
-rw-r--r--libjava/testsuite/libjava.cni/natlongfield.cc15
-rw-r--r--libjava/testsuite/libjava.cni/natshortfield.cc10
-rw-r--r--libjava/testsuite/libjava.cni/shortfield.java21
-rw-r--r--libjava/testsuite/libjava.cni/shortfield.out1
-rw-r--r--libjava/testsuite/libjava.jni/jni.exp44
10 files changed, 252 insertions, 44 deletions
diff --git a/libjava/testsuite/ChangeLog b/libjava/testsuite/ChangeLog
index 59182eb..54a7365 100644
--- a/libjava/testsuite/ChangeLog
+++ b/libjava/testsuite/ChangeLog
@@ -1,3 +1,17 @@
+2003-03-22 Tom Tromey <tromey@redhat.com>
+
+ * lib/libjava.exp (gcj_invoke): Moved...
+ * libjava.jni/jni.exp: ...from here.
+
+ * libjava.cni/shortfield.out: New file.
+ * libjava.cni/shortfield.java: New file.
+ * libjava.cni/natshortfield.cc: New file.
+ * libjava.cni/natlongfield.cc: New file.
+ * libjava.cni/longfield.out: New file.
+ * libjava.cni/longfield.java: New file.
+
+ * libjava.cni/cni.exp: New file.
+
2003-03-11 Tom Tromey <tromey@redhat.com>
* libjava.lang/initfield.java: New file.
diff --git a/libjava/testsuite/lib/libjava.exp b/libjava/testsuite/lib/libjava.exp
index 6be5ec6..972b7be 100644
--- a/libjava/testsuite/lib/libjava.exp
+++ b/libjava/testsuite/lib/libjava.exp
@@ -457,6 +457,50 @@ proc gcj_link {program main files {options {}}} {
return 1
}
+# Invoke the program and see what happens. Return 0 on failure.
+proc gcj_invoke {program expectFile ld_library_additions} {
+ global env
+ set lib_path $env(LD_LIBRARY_PATH)
+
+ set newval .
+ if {[llength $ld_library_additions] > 0} {
+ append newval :[join $ld_library_additions :]
+ }
+ append newval :$lib_path
+
+ setenv LD_LIBRARY_PATH $newval
+ setenv SHLIB_PATH $newval
+
+ verbose "LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
+
+ set result [libjava_load ./$program]
+ set status [lindex $result 0]
+ set output [lindex $result 1]
+
+ # Restore setting
+ setenv LD_LIBRARY_PATH $lib_path
+ setenv SHLIB_PATH $lib_path
+
+ if {$status != "pass"} {
+ verbose "got $output"
+ fail "$program run"
+ untested "$program output"
+ return 0
+ }
+
+ set id [open $expectFile r]
+ set expected [read $id]
+ close $id
+
+ if {! [string compare $output $expected]} {
+ pass "$program output"
+ return 1
+ } else {
+ fail "$program output"
+ return 0
+ }
+}
+
# Invoke a program and check its output. EXECUTABLE is the program;
# ARGS are the arguments to the program. Returns 1 if tests passed
# (or things were left untested), 0 otherwise.
diff --git a/libjava/testsuite/libjava.cni/cni.exp b/libjava/testsuite/libjava.cni/cni.exp
new file mode 100644
index 0000000..22df146
--- /dev/null
+++ b/libjava/testsuite/libjava.cni/cni.exp
@@ -0,0 +1,119 @@
+# 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 {}}} {
+ global srcdir
+
+ set name [file rootname [file tail $file]]
+ set oname ${name}.o
+
+ # Find the generated header.
+ lappend options "additional_flags=-I. -I.."
+ # 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} {
+ set gcjh [find_gcjh]
+ set jvscan [find_jvscan]
+
+ set class_out [string trim \
+ [libjava_prune_warnings \
+ [lindex [local_exec "$jvscan --encoding=UTF-8 $file --list-class" "" "" 300] 1]]]
+ if {[string match "*parse error*" $class_out]} {
+ fail "$file header generation"
+ return 0
+ }
+
+ foreach file [split $class_out] {
+ set x [string trim [libjava_prune_warnings \
+ [lindex [local_exec "$gcjh $file" "" "" 300] 1]]]
+ if {$x != ""} {
+ verbose "local_exec failed: $x" 2
+ fail "$file header generation"
+ return 0
+ }
+ }
+
+ pass "$file header generation"
+ 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
+ }
+
+ 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"
+
+ if {! [gcj_cni_build_headers $file]} {
+ # FIXME
+ return 0
+ }
+
+ 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} {
+ catch { lsort [glob -nocomplain ${srcdir}/${subdir}/*.java] } srcfiles
+
+ foreach x $srcfiles {
+ gcj_cni_test_one $x
+ }
+ } else {
+ verbose "CNI tests not run in cross-compilation environment"
+ }
+}
+
+gcj_cni_run
diff --git a/libjava/testsuite/libjava.cni/longfield.java b/libjava/testsuite/libjava.cni/longfield.java
new file mode 100644
index 0000000..917bf95
--- /dev/null
+++ b/libjava/testsuite/libjava.cni/longfield.java
@@ -0,0 +1,22 @@
+public class longfield
+{
+ long lval = 232300;
+ boolean bval = true;
+ String sval = "maude";
+
+ public native void doitc ();
+
+ public void doitj()
+ {
+ System.out.println(lval);
+ System.out.println(bval);
+ System.out.println(sval);
+ }
+
+ public static void main(String[] args)
+ {
+ longfield f = new longfield();
+ f.doitc();
+ f.doitj();
+ }
+}
diff --git a/libjava/testsuite/libjava.cni/longfield.out b/libjava/testsuite/libjava.cni/longfield.out
new file mode 100644
index 0000000..d041bbb
--- /dev/null
+++ b/libjava/testsuite/libjava.cni/longfield.out
@@ -0,0 +1,6 @@
+232300
+true
+maude
+232300
+true
+maude
diff --git a/libjava/testsuite/libjava.cni/natlongfield.cc b/libjava/testsuite/libjava.cni/natlongfield.cc
new file mode 100644
index 0000000..c16a46c
--- /dev/null
+++ b/libjava/testsuite/libjava.cni/natlongfield.cc
@@ -0,0 +1,15 @@
+#include <gcj/cni.h>
+
+#include "longfield.h"
+#include <java/lang/System.h>
+#include <java/io/PrintStream.h>
+
+void
+longfield::doitc ()
+{
+ java::io::PrintStream *ps = java::lang::System::out;
+
+ ps->println(lval);
+ ps->println(bval);
+ ps->println(sval);
+}
diff --git a/libjava/testsuite/libjava.cni/natshortfield.cc b/libjava/testsuite/libjava.cni/natshortfield.cc
new file mode 100644
index 0000000..08a7d5c
--- /dev/null
+++ b/libjava/testsuite/libjava.cni/natshortfield.cc
@@ -0,0 +1,10 @@
+#include <stdio.h>
+#include "shortfield.h"
+
+void shortfield::ouch ()
+{
+ printf ("list: %d %d 0x%x\n",
+ modCount,
+ size__,
+ data);
+}
diff --git a/libjava/testsuite/libjava.cni/shortfield.java b/libjava/testsuite/libjava.cni/shortfield.java
new file mode 100644
index 0000000..68b6c5e
--- /dev/null
+++ b/libjava/testsuite/libjava.cni/shortfield.java
@@ -0,0 +1,21 @@
+class shortfieldbase
+{
+ short modCount;
+}
+
+public class shortfield extends shortfieldbase
+{
+ short size__;
+ int data;
+
+ native void ouch ();
+
+ public static void main (String[] s)
+ {
+ shortfield f = new shortfield();
+ f.modCount = 99;
+ f.size__ = 2;
+ f.data = 0x12345678;
+ f.ouch();
+ }
+}
diff --git a/libjava/testsuite/libjava.cni/shortfield.out b/libjava/testsuite/libjava.cni/shortfield.out
new file mode 100644
index 0000000..06485db
--- /dev/null
+++ b/libjava/testsuite/libjava.cni/shortfield.out
@@ -0,0 +1 @@
+list: 99 2 0x12345678
diff --git a/libjava/testsuite/libjava.jni/jni.exp b/libjava/testsuite/libjava.jni/jni.exp
index 2aec4c9..6d6c93d 100644
--- a/libjava/testsuite/libjava.jni/jni.exp
+++ b/libjava/testsuite/libjava.jni/jni.exp
@@ -43,50 +43,6 @@ proc gcj_jni_build_header {file} {
return 1
}
-# Invoke the program and see what happens. Return 0 on failure.
-proc gcj_invoke {program expectFile ld_library_additions} {
- global env
- set lib_path $env(LD_LIBRARY_PATH)
-
- set newval .
- if {[llength $ld_library_additions] > 0} {
- append newval :[join $ld_library_additions :]
- }
- append newval :$lib_path
-
- setenv LD_LIBRARY_PATH $newval
- setenv SHLIB_PATH $newval
-
- verbose "LD_LIBRARY_PATH=$env(LD_LIBRARY_PATH)"
-
- set result [libjava_load ./$program]
- set status [lindex $result 0]
- set output [lindex $result 1]
-
- # Restore setting
- setenv LD_LIBRARY_PATH $lib_path
- setenv SHLIB_PATH $lib_path
-
- if {$status != "pass"} {
- verbose "got $output"
- fail "$program run"
- untested "$program output"
- return 0
- }
-
- set id [open $expectFile r]
- set expected [read $id]
- close $id
-
- if {! [string compare $output $expected]} {
- pass "$program output"
- return 1
- } else {
- fail "$program output"
- return 0
- }
-}
-
# Do all the work for a single JNI test. Return 0 on failure.
proc gcj_jni_test_one {file} {
global runtests