Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 Makefile                           |    1 +
 regression/jvm/ExceptionsTest.java |   25 ----------
 regression/jvm/StackTraceTest.java |   90 ++++++++++++++++++++++++++++++++++++
 regression/jvm/TestCase.java       |   18 +++++++
 regression/run-suite.sh            |    1 +
 5 files changed, 110 insertions(+), 25 deletions(-)
 create mode 100644 regression/jvm/StackTraceTest.java

diff --git a/Makefile b/Makefile
index 58ad9db..8beea06 100644
--- a/Makefile
+++ b/Makefile
@@ -255,6 +255,7 @@ REGRESSION_TEST_SUITE_CLASSES = \
        regression/jvm/PutstaticPatchingTest.class \
        regression/jvm/PutstaticTest.class \
        regression/jvm/RegisterAllocatorTortureTest.class \
+       regression/jvm/StackTraceTest.class \
        regression/jvm/StringTest.class \
        regression/jvm/SynchronizationExceptionsTest.class \
        regression/jvm/SynchronizationTest.class \
diff --git a/regression/jvm/ExceptionsTest.java 
b/regression/jvm/ExceptionsTest.java
index 1330281..b8aba54 100644
--- a/regression/jvm/ExceptionsTest.java
+++ b/regression/jvm/ExceptionsTest.java
@@ -140,30 +140,6 @@ public class ExceptionsTest extends TestCase {
         assertTrue(caught);
     }
 
-    public static void testGetStackTrace() {
-        StackTraceElement []e = new Exception().getStackTrace();
-
-        assertNotNull(e);
-
-        assertEquals(3, e.length);
-
-        assertEquals(144, e[0].getLineNumber());
-        assertObjectEquals("ExceptionsTest.java", e[0].getFileName());
-        assertObjectEquals("jvm.ExceptionsTest", e[0].getClassName());
-        assertObjectEquals("testGetStackTrace", e[0].getMethodName());
-        assertFalse(e[0].isNativeMethod());
-
-        assertEquals(164, e[1].getLineNumber());
-        assertObjectEquals("ExceptionsTest.java", e[1].getFileName());
-        assertObjectEquals("jvm.ExceptionsTest", e[1].getClassName());
-        assertObjectEquals("testStackTrace", e[1].getMethodName());
-        assertFalse(e[1].isNativeMethod());
-    }
-
-    public static void testStackTrace() {
-        testGetStackTrace();
-    }
-
     public static void main(String args[]) {
         testTryBlockDoesNotThrowAnything();
         testThrowAndCatchInTheSameMethod();
@@ -172,6 +148,5 @@ public class ExceptionsTest extends TestCase {
         testNestedTryCatch();
         testEmptyCatchBlock();
         testAthrow();
-        testStackTrace();
     }
 }
diff --git a/regression/jvm/StackTraceTest.java 
b/regression/jvm/StackTraceTest.java
new file mode 100644
index 0000000..dd364ca
--- /dev/null
+++ b/regression/jvm/StackTraceTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2009 Tomasz Grabiec
+ *
+ * This file is released under the GPL version 2 with the following
+ * clarification and special exception:
+ *
+ *     Linking this library statically or dynamically with other modules is
+ *     making a combined work based on this library. Thus, the terms and
+ *     conditions of the GNU General Public License cover the whole
+ *     combination.
+ *
+ *     As a special exception, the copyright holders of this library give you
+ *     permission to link this library with independent modules to produce an
+ *     executable, regardless of the license terms of these independent
+ *     modules, and to copy and distribute the resulting executable under terms
+ *     of your choice, provided that you also meet, for each linked independent
+ *     module, the terms and conditions of the license of that module. An
+ *     independent module is a module which is not derived from or based on
+ *     this library. If you modify this library, you may extend this exception
+ *     to your version of the library, but you are not obligated to do so. If
+ *     you do not wish to do so, delete this exception statement from your
+ *     version.
+ *
+ * Please refer to the file LICENSE for details.
+ */
+package jvm;
+
+import jato.internal.VM;
+
+/**
+ * @author Tomasz Grabiec
+ */
+public class StackTraceTest extends TestCase {
+
+    public static void doTestJITStackTrace() {
+        StackTraceElement []st = new Exception().getStackTrace();
+
+        assertNotNull(st);
+        assertEquals(3, st.length);
+
+        assertStackTraceElement(st[0], 36, "StackTraceTest.java",
+                "jvm.StackTraceTest",
+                "doTestJITStackTrace",
+                false);
+
+        assertStackTraceElement(st[1], 53, "StackTraceTest.java",
+                "jvm.StackTraceTest",
+                "testJITStackTrace",
+                false);
+    }
+
+    public static void testJITStackTrace() {
+        doTestJITStackTrace();
+    }
+
+    public static void doTestVMNativeInStackTrace() {
+        StackTraceElement []st = null;
+
+        try {
+            VM.println(null);
+        } catch (NullPointerException e) {
+            st = e.getStackTrace();
+        }
+
+        assertNotNull(st);
+        assertEquals(4, st.length);
+
+        assertStackTraceElement(st[0], -1, null, "jato.internal.VM",
+                "println", true);
+
+        assertStackTraceElement(st[1], 60, "StackTraceTest.java",
+                "jvm.StackTraceTest",
+                "doTestVMNativeInStackTrace",
+                false);
+
+        assertStackTraceElement(st[2], 83, "StackTraceTest.java",
+                "jvm.StackTraceTest",
+                "testVMNativeInStackTrace",
+                false);
+    }
+
+    public static void testVMNativeInStackTrace() {
+        doTestVMNativeInStackTrace();
+    }
+
+    public static void main(String []args) {
+        testJITStackTrace();
+        testVMNativeInStackTrace();
+    }
+}
\ No newline at end of file
diff --git a/regression/jvm/TestCase.java b/regression/jvm/TestCase.java
index 8ff0207..6ed621b 100644
--- a/regression/jvm/TestCase.java
+++ b/regression/jvm/TestCase.java
@@ -78,9 +78,27 @@ public class TestCase {
     }
 
     protected static void assertObjectEquals(String a, String b) {
+        if (a == null && b == null)
+            return;
+
         assertTrue(a.equals(b));
     }
 
+    protected static void assertStackTraceElement(StackTraceElement e,
+        int lineNumber, String fileName, String className,
+        String methodName, boolean isNative)
+    {
+        assertEquals(lineNumber, e.getLineNumber());
+        assertObjectEquals(fileName, e.getFileName());
+        assertObjectEquals(className, e.getClassName());
+        assertObjectEquals(methodName, e.getMethodName());
+
+        if (isNative)
+            assertTrue(e.isNativeMethod());
+        else
+            assertFalse(e.isNativeMethod());
+    }
+
     protected static void fail(String s) {
         throw new AssertionError(s);
     }
diff --git a/regression/run-suite.sh b/regression/run-suite.sh
index a3f3fe3..93a9e1b 100755
--- a/regression/run-suite.sh
+++ b/regression/run-suite.sh
@@ -79,6 +79,7 @@ if [ -z "$CLASS_LIST" ]; then
     run_java jvm.PutstaticPatchingTest 0
     run_java jvm.PutstaticTest 0
     run_java jvm.RegisterAllocatorTortureTest 0
+    run_java jvm.StackTraceTest 0
     run_java jvm.StringTest 0
     run_java jvm.SynchronizationExceptionsTest 0
     run_java jvm.SynchronizationTest 0
-- 
1.6.0.6


------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to