Patch: ClassLoader tests

Anthony Green green@redhat.com
Sun Nov 3 17:20:00 GMT 2002


Here are some classloader tests.  I've put them in a new directory for now.
I suppose they could go back into libjava.lang, but I envision writing more
class loader tests and libjava.lang is getting crowded.  I also thought about 
putting these in Mauve, but I want to test gcj specific features here.

Ok?


2002-11-04  Anthony Green  <green@redhat.com>

	* libjava.loader/dummy.java, libjava.loader/loader.exp, 
	libjava.loader/MyLoader.java, libjava.loader/TestLeak.java,
	libjava.loader/TestLeak.out, libjava.loader/TestMultiple.java, 
	libjava.loader/TestMultiple.out: New files.
  
Index: libjava/testsuite/libjava.loader/MyLoader.java
===================================================================
RCS file: libjava/testsuite/libjava.loader/MyLoader.java
diff -N libjava/testsuite/libjava.loader/MyLoader.java
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- libjava/testsuite/libjava.loader/MyLoader.java	4 Nov 2002 01:16:14 -0000
***************
*** 0 ****
--- 1,9 ----
+ import java.net.*;
+ 
+ public class MyLoader extends URLClassLoader
+ {
+   public MyLoader (URL urls[])
+   {
+     super (urls);
+   }
+ }
Index: libjava/testsuite/libjava.loader/TestLeak.java
===================================================================
RCS file: libjava/testsuite/libjava.loader/TestLeak.java
diff -N libjava/testsuite/libjava.loader/TestLeak.java
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- libjava/testsuite/libjava.loader/TestLeak.java	4 Nov 2002 01:16:14 -0000
***************
*** 0 ****
--- 1,33 ----
+ import java.net.*;
+ import java.lang.reflect.*;
+ 
+ public class TestLeak
+ {
+   class MyLoader extends URLClassLoader
+   {
+     public MyLoader (URL urls[])
+     {
+       super (urls);
+     }
+   }
+ 
+   public static void main (String[] args)
+   {
+     URLClassLoader ucl = 
+       (URLClassLoader) ClassLoader.getSystemClassLoader();
+     URL urls[] = ucl.getURLs ();
+     Class ifaces[] = new Class[1];
+     ifaces[0] = java.lang.Comparable.class;
+ 
+     try {
+       for (int i = 0; i < 100; i++)
+ 	{
+ 	  Proxy.getProxyClass (new MyLoader (urls), ifaces);
+ 	} 
+     } catch (Exception e) {
+       e.printStackTrace ();
+     }
+   }
+ }
+ 
+ 
Index: libjava/testsuite/libjava.loader/TestLeak.out
===================================================================
RCS file: libjava/testsuite/libjava.loader/TestLeak.out
diff -N libjava/testsuite/libjava.loader/TestLeak.out
Index: libjava/testsuite/libjava.loader/TestMultiple.java
===================================================================
RCS file: libjava/testsuite/libjava.loader/TestMultiple.java
diff -N libjava/testsuite/libjava.loader/TestMultiple.java
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- libjava/testsuite/libjava.loader/TestMultiple.java	4 Nov 2002 01:16:14 -0000
***************
*** 0 ****
--- 1,28 ----
+ import java.net.*;
+ 
+ public class TestMultiple
+ {
+   public static void main (String[] args)
+   {
+     URLClassLoader ucl = 
+       (URLClassLoader) ClassLoader.getSystemClassLoader();
+     URL urls[] = ucl.getURLs ();
+ 
+     MyLoader t1 = new MyLoader (urls);
+     MyLoader t2 = new MyLoader (urls);
+ 
+     Class c1, c2;
+ 
+     try {
+ 
+       c1 = t1.loadClass ("dummy");
+       c2 = t2.loadClass ("dummy");
+ 
+     } 
+     catch (Exception e) {
+ 	e.printStackTrace ();
+     }
+   }
+ }
+ 
+ 
Index: libjava/testsuite/libjava.loader/TestMultiple.out
===================================================================
RCS file: libjava/testsuite/libjava.loader/TestMultiple.out
diff -N libjava/testsuite/libjava.loader/TestMultiple.out
Index: libjava/testsuite/libjava.loader/dummy.java
===================================================================
RCS file: libjava/testsuite/libjava.loader/dummy.java
diff -N libjava/testsuite/libjava.loader/dummy.java
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- libjava/testsuite/libjava.loader/dummy.java	4 Nov 2002 01:16:14 -0000
***************
*** 0 ****
--- 1,6 ----
+ // A dummy class
+ 
+ public class dummy
+ {
+ }
+ 
Index: libjava/testsuite/libjava.loader/loader.exp
===================================================================
RCS file: libjava/testsuite/libjava.loader/loader.exp
diff -N libjava/testsuite/libjava.loader/loader.exp
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- libjava/testsuite/libjava.loader/loader.exp	4 Nov 2002 01:16:14 -0000
***************
*** 0 ****
--- 1,64 ----
+ # Tests for ClassLoader and native library loader code.
+ 
+ # Do all the work for a single JNI test.  Return 0 on failure.
+ proc gcj_loader_test_one {srcfile} {
+   global objdir srcdir subdir
+ 
+   set resfile $srcdir/$subdir/[file rootname [file tail $srcfile]].out
+ 
+   regsub "^.*/(\[^/.\]+)\[.\]\[^/]*$" "$srcfile" "\\1" out
+   set executable "${objdir}/$out.exe"
+ 
+     set errname [file rootname [file tail $srcfile]]
+     set args [libjava_arguments link]
+     lappend args "additional_flags=--main=[file rootname [file tail $srcfile]] $srcdir/$subdir/MyLoader.java $objdir/dummy.o"
+   set x [prune_warnings \
+ 	     [libjava_tcompile $srcfile "$executable" "$executable" $args]]
+ 
+     if { $x != "" } {
+ 	verbose "target_compile failed: $x" 2
+ 
+ 	fail "$errname compilation from source"
+ 	untested "$errname execution from source compiled test"
+ 	return
+     }
+     pass "$errname compilation from source"
+ 
+     libjava_invoke $executable $executable "" $executable "" $resfile ""
+ 
+   return 1
+ }
+ 
+ # Run the bytecode loader tests.
+ proc gcj_loader_run {} {
+   global srcdir subdir objdir
+   global build_triplet host_triplet
+   global GCJ_UNDER_TEST
+ 
+   set file "${srcdir}/${subdir}/dummy.java"
+   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 x [prune_warnings \
+ 	     [eval exec "$GCJ_UNDER_TEST --resource $objdir/dummy.class -c $objdir/dummy.class -o $objdir/dummy.o"]]
+     if { $x != "" } {
+ 	verbose "resource compilation failed: $x" 2
+ 
+ 	fail "resource compilation dummy.class"
+ 	return 0;
+     }
+   pass "resource compilation: dummy.class"
+ 
+   catch { lsort [glob -nocomplain ${srcdir}/${subdir}/Test*.java] } srcfiles
+ 
+   foreach x $srcfiles {
+     gcj_loader_test_one $x
+   }
+ }
+ 
+ gcj_loader_run





More information about the Java-patches mailing list