Regression test driver now can read different expected output files
[cacao.git] / tests / regression / extest.java
index e5b13630950b7e9a8b6608866bbdc9f26c44144f..7408c8ee1c657c925558b7e8acd9dc5d7e975756 100644 (file)
@@ -1,4 +1,6 @@
 public class extest {
+    final static int COLUMN = 55;
+
     final static int INDEX1 = 0xcafebabe;
     final static int INDEX2 = 0xbabecafe;
     final static int INDEX3 = 0xdeadbeef;
@@ -8,25 +10,27 @@ public class extest {
     public static void main(String[] argv) {
        printStackTrace = true;
 
+        Runtime r = Runtime.getRuntime();
+        int maxmem = (int) r.maxMemory();
+
 //     if (argv.length > 0) 
 //              if (argv[0].equals("stacktrace"))
 //                  printStackTrace = true;
 
-        boolean catched = false;
+        boolean caught = false;
 
-       pln("---------- normal exceptions --------------------");
+       pheader("normal exceptions");
 
        try {
             p("throw new Exception():");
            throw new Exception();
        } catch (Exception e) {
-            catched = true;
+            caught = true;
            ok();
            pstacktrace(e);
-
        } finally {
             /* check if catch block was executed */
-            if (!catched) {
+            if (!caught) {
                 failed();
             }
         }
@@ -53,8 +57,7 @@ public class extest {
        pln();
 
 
-       pln("---------- test soft inline exceptions ----------");
-       pln("/* thrown twice to check the inline jump code */");
+       pheader("exceptions thrown in JIT code");
 
         try {
             p("ArithmeticException (only w/ -softnull):");
@@ -72,23 +75,6 @@ public class extest {
             }
        }
 
-        try {
-            p("ArithmeticException (only w/ -softnull):");
-            long i = 1, j = 0, k = i / j;
-            failed();
-        } catch (ArithmeticException e) {
-           String msg = e.getMessage();
-
-           if (msg == null || !msg.equals("/ by zero")) {
-               pln("FAILED: wrong message: " + msg + ", should be: / by zero");
-
-           } else {
-                ok();
-                pstacktrace(e);
-            }
-       }
-
-
         try {
             p("ArrayIndexOutOfBoundsException:");
             int[] ia = new int[1];
@@ -106,25 +92,6 @@ public class extest {
            }
        }
 
-        try {
-            p("ArrayIndexOutOfBoundsException:");
-            int[] ia = new int[1];
-            ia[INDEX2] = 1;
-            failed();
-        } catch (ArrayIndexOutOfBoundsException e) {
-           String msg = e.getMessage();
-
-           if (msg == null || !msg.equals(String.valueOf(INDEX2))) {
-               pln("FAILED: wrong index: " + msg + ", should be: " + INDEX2);
-               pstacktrace(e);
-           } else {
-               ok();
-               pstacktrace(e);
-
-           }
-       }
-
-
         try {
             p("ArrayStoreException:");
            Integer[] ia = new Integer[1];
@@ -136,18 +103,6 @@ public class extest {
            pstacktrace(e);
        }
 
-        try {
-            p("ArrayStoreException:");
-           Integer[] ia = new Integer[1];
-            Object[] oa = (Object[]) ia;
-           oa[0] = new Object();
-            failed();
-        } catch (ArrayStoreException e) {
-           ok();
-           pstacktrace(e);
-       }
-
-
         try {
             p("ClassCastException:");
             Object o = new Object();
@@ -158,27 +113,6 @@ public class extest {
            pstacktrace(e);
        }
 
-        try {
-            p("ClassCastException:");
-            Object o = new Object();
-            Integer i = null;
-            i = (Integer) o;
-            failed();
-        } catch (ClassCastException e) {
-           ok();
-           pstacktrace(e);
-       }
-
-
-        try {
-            p("NegativeArraySizeException (newarray):");
-            int[] ia = new int[-1];
-            failed();
-        } catch (NegativeArraySizeException e) {
-           ok();
-           pstacktrace(e);
-       }
-
         try {
             p("NegativeArraySizeException (newarray):");
             int[] ia = new int[-1];
@@ -197,51 +131,19 @@ public class extest {
            pstacktrace(e);
        }
 
-        
-        try {
-            p("NullPointerException (only w/ -softnull):");
-            int[] ia = null;
-            int i = ia.length;
-            failed();
-        } catch (NullPointerException e) {
-           ok();
-           pstacktrace(e);
-       }
-
-        try {
-            p("NullPointerException (only w/ -softnull):");
-            int[] ia = null;
-            int i = ia.length;
-            failed();
-        } catch (NullPointerException e) {
-           ok();
-           pstacktrace(e);
-       }
-
         try {
             p("OutOfMemoryError:");
-           /* 100 MB should be enough */
-           byte[] ba = new byte[100 * 1024 * 1024];
+           /* maxmem + 1 should be enough and hopefully not overflow the int so it becomes negative */
+           byte[] ba = new byte[maxmem];
             failed();
         } catch (OutOfMemoryError e) {
            ok();
            pstacktrace(e);
        }
 
-        try {
-            p("OutOfMemoryError:");
-           /* 100 MB should be enough */
-           byte[] ba = new byte[100 * 1024 * 1024];
-            failed();
-        } catch (OutOfMemoryError e) {
-           ok();
-           pstacktrace(e);
-       }
-        
         try {
             p("OutOfMemoryError (multianewarray):");
-           /* 100 MB should be enough */
-           byte[][] ba = new byte[10 * 1024 * 1024][10 * 1024 * 1024];
+           byte[][] ba = new byte[maxmem][maxmem];
             failed();
         } catch (OutOfMemoryError e) {
            ok();
@@ -251,7 +153,7 @@ public class extest {
        pln();
 
 
-       pln("---------- exceptions in leaf functions ---------");
+       pheader("exceptions in leaf functions");
 
         try {
             p("ArithmeticException:");
@@ -297,17 +199,26 @@ public class extest {
             pstacktrace(e);
         }
 
+        try {
+            p("Exception in <clinit> triggered from a leaf method:");
+            extest_clinit_patcher.i = 1;
+            failed();
+        } catch (ExceptionInInitializerError e) {
+            ok();
+            pstacktrace(e);
+        }
+
        pln();
 
 
-       pln("---------- exception related things -------------");
+       pheader("exception related things");
 
         try {
             p("load/link an exception class in asmpart:");
             throw new Exception();
         } catch (UnknownError e) {
             /* this exception class MUST NOT be loaded before!!!
-               otherwise this test in useless */
+               otherwise this test is useless */
         } catch (Exception e) {
            ok();
            pstacktrace(e);
@@ -316,7 +227,7 @@ public class extest {
         pln();
 
 
-       pln("---------- native stub exceptions ---------------");
+       pheader("native stub exceptions");
 
         try {
             p("NullPointerException in <clinit>:");
@@ -325,10 +236,6 @@ public class extest {
         } catch (ExceptionInInitializerError e) {
             ok();
             pstacktrace(e);
-        } catch (UnsatisfiedLinkError e) {
-            /* catch this one for ENABLE_STATICVM and say it's ok */
-            ok();
-            pstacktrace(e);
         }
 
         try {
@@ -352,11 +259,12 @@ public class extest {
         pln();
 
 
-       pln("---------- special exceptions -------------------");
+       pheader("special exceptions");
 
        try {
             p("OutOfMemoryError (array clone):");
-            byte[] ba1 = new byte[40 * 1024 * 1024];
+            /* use half of the heap size */
+            byte[] ba1 = new byte[maxmem / 2];
             byte[] ba2 = (byte[]) ba1.clone();
             failed();
        } catch (OutOfMemoryError e) {
@@ -367,7 +275,7 @@ public class extest {
         pln();
 
 
-       pln("---------- no OK beyond this point --------------");
+       pheader("exception thrown to command-line");
 
         pln("NullPointerException (without catch):");
         String s = null;
@@ -411,11 +319,20 @@ public class extest {
 
     static void p(String s) {
        System.out.print(s);
-        for (int i = s.length(); i < 46; i++) {
+        for (int i = s.length(); i < COLUMN; i++) {
             System.out.print(" ");
         }
     }
 
+    static void pheader(String s) {
+       System.out.print(s);
+        for (int i = s.length(); i < COLUMN + 3; i++) {
+            System.out.print("-");
+        }
+        System.out.println();
+        System.out.println();
+    }
+
     static void pln() {
        System.out.println();
     }
@@ -439,3 +356,21 @@ public class extest {
        System.out.println();
     }
 }
+
+class extest_clinit {
+    static {
+        String s = null;
+        s.length();
+    }
+
+    public static native void sub();
+}
+
+class extest_clinit_patcher {
+    static int i;
+
+    static {
+        int[] ia = null;
+        int a = ia.length;
+    }
+}