Regression test driver now can read different expected output files
[cacao.git] / tests / regression / extest.java
index e98e77b91b3cb1adb5887335550275c290f446e7..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();
@@ -159,19 +114,7 @@ public class extest {
        }
 
         try {
-            p("ClassCastException:");
-            Object o = new Object();
-            Integer i = null;
-            i = (Integer) o;
-            failed();
-        } catch (ClassCastException e) {
-           ok();
-           pstacktrace(e);
-       }
-
-
-        try {
-            p("NegativeArraySizeException:");
+            p("NegativeArraySizeException (newarray):");
             int[] ia = new int[-1];
             failed();
         } catch (NegativeArraySizeException e) {
@@ -180,39 +123,18 @@ public class extest {
        }
 
         try {
-            p("NegativeArraySizeException:");
-            int[] ia = new int[-1];
+            p("NegativeArraySizeException (multianewarray):");
+            int[][] ia = new int[1][-1];
             failed();
         } catch (NegativeArraySizeException 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("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();
@@ -220,9 +142,8 @@ public class extest {
        }
 
         try {
-            p("OutOfMemoryError:");
-           /* 100 MB should be enough */
-           byte[] ba = new byte[100 * 1024 * 1024];
+            p("OutOfMemoryError (multianewarray):");
+           byte[][] ba = new byte[maxmem][maxmem];
             failed();
         } catch (OutOfMemoryError e) {
            ok();
@@ -232,7 +153,7 @@ public class extest {
        pln();
 
 
-       pln("---------- exceptions in leaf functions ---------");
+       pheader("exceptions in leaf functions");
 
         try {
             p("ArithmeticException:");
@@ -278,48 +199,26 @@ public class extest {
             pstacktrace(e);
         }
 
-       pln();
-
-
-       pln("---------- some asmpart exceptions --------------");
-
         try {
-            p("NullPointerException in <clinit> (PUTSTATIC):");
-            extest_clinit_1.i = 1;
+            p("Exception in <clinit> triggered from a leaf method:");
+            extest_clinit_patcher.i = 1;
             failed();
         } catch (ExceptionInInitializerError e) {
-            if (e.getCause().getClass() != NullPointerException.class) {
-                failed();
-            } else {
-                ok();
-               pstacktrace(e);
-            }
-        }
-
-        try {
-            p("NullPointerException in <clinit> (GETSTATIC):");
-            int i = extest_clinit_2.i;
-            failed();
-        } catch (ExceptionInInitializerError e) {
-            if (e.getCause().getClass() != NullPointerException.class) {
-                failed();
-            } else {
-                ok();
-               pstacktrace(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);
@@ -328,31 +227,17 @@ public class extest {
         pln();
 
 
-       pln("---------- native stub exceptions ---------------");
-
-       try {
-            p("NullPointerException (native):");
-            System.arraycopy(null, 1, null, 1, 1);
-            failed();
-       } catch (Exception e) {
-           ok();
-            pstacktrace(e);
-       }
+       pheader("native stub exceptions");
 
         try {
             p("NullPointerException in <clinit>:");
-            extest_clinit_3.sub();
+            extest_clinit.sub();
             failed();
         } catch (ExceptionInInitializerError e) {
             ok();
             pstacktrace(e);
-        } catch (UnsatisfiedLinkError e) {
-            /* catch this one for staticvm and say it's ok */
-            ok();
-            pstacktrace(e);
         }
 
-        /*
         try {
             p("UnsatisfiedLinkError:");
             nsub();
@@ -361,12 +246,36 @@ public class extest {
             ok();
             pstacktrace(e);
         }
-        */
+
+       try {
+            p("NullPointerException (native):");
+            System.arraycopy(null, 1, null, 1, 1);
+            failed();
+       } catch (NullPointerException e) {
+           ok();
+            pstacktrace(e);
+       }
 
         pln();
 
 
-       pln("---------- no OK beyond this point --------------");
+       pheader("special exceptions");
+
+       try {
+            p("OutOfMemoryError (array clone):");
+            /* use half of the heap size */
+            byte[] ba1 = new byte[maxmem / 2];
+            byte[] ba2 = (byte[]) ba1.clone();
+            failed();
+       } catch (OutOfMemoryError e) {
+           ok();
+            pstacktrace(e);
+       }
+
+        pln();
+
+
+       pheader("exception thrown to command-line");
 
         pln("NullPointerException (without catch):");
         String s = null;
@@ -410,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,29 +357,20 @@ public class extest {
     }
 }
 
-public class extest_clinit_1 {
+class extest_clinit {
     static {
         String s = null;
         s.length();
     }
 
-    public static int i;
+    public static native void sub();
 }
 
-public class extest_clinit_2 {
-    static {
-        String s = null;
-        s.length();
-    }
-
-    public static int i;
-}
+class extest_clinit_patcher {
+    static int i;
 
-public class extest_clinit_3 {
     static {
-        String s = null;
-        s.length();
+        int[] ia = null;
+        int a = ia.length;
     }
-
-    public static native void sub();
 }