changeset 9111:0298d8a0caf5

added JUnit 4.11 support to ProfilingInfoTest
author Christian Haeubl <haeubl@ssw.jku.at>
date Thu, 04 Apr 2013 11:57:04 +0200
parents 00a548fdf821
children 79b098d44d20
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ProfilingInfoTest.java
diffstat 1 files changed, 54 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ProfilingInfoTest.java	Thu Apr 04 10:04:49 2013 +0200
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ProfilingInfoTest.java	Thu Apr 04 11:57:04 2013 +0200
@@ -22,8 +22,6 @@
  */
 package com.oracle.graal.compiler.test;
 
-import static org.junit.Assert.*;
-
 import java.io.*;
 import java.lang.reflect.*;
 
@@ -35,38 +33,39 @@
 public class ProfilingInfoTest extends GraalCompilerTest {
 
     private static final int N = 100;
+    private static final double DELTA = 1d / Integer.MAX_VALUE;
 
     @Test
     public void testBranchTakenProbability() {
         ProfilingInfo info = profile("branchProbabilitySnippet", 0);
-        assertEquals(0.0, info.getBranchTakenProbability(1));
-        assertEquals(N, info.getExecutionCount(1));
-        assertEquals(-1.0, info.getBranchTakenProbability(8));
-        assertEquals(0, info.getExecutionCount(8));
+        Assert.assertEquals(0.0, info.getBranchTakenProbability(1), DELTA);
+        Assert.assertEquals(N, info.getExecutionCount(1));
+        Assert.assertEquals(-1.0, info.getBranchTakenProbability(8), DELTA);
+        Assert.assertEquals(0, info.getExecutionCount(8));
 
         info = profile("branchProbabilitySnippet", 1);
-        assertEquals(1.0, info.getBranchTakenProbability(1));
-        assertEquals(N, info.getExecutionCount(1));
-        assertEquals(0.0, info.getBranchTakenProbability(8));
-        assertEquals(N, info.getExecutionCount(8));
+        Assert.assertEquals(1.0, info.getBranchTakenProbability(1), DELTA);
+        Assert.assertEquals(N, info.getExecutionCount(1));
+        Assert.assertEquals(0.0, info.getBranchTakenProbability(8), DELTA);
+        Assert.assertEquals(N, info.getExecutionCount(8));
 
         info = profile("branchProbabilitySnippet", 2);
-        assertEquals(1.0, info.getBranchTakenProbability(1));
-        assertEquals(N, info.getExecutionCount(1));
-        assertEquals(1.0, info.getBranchTakenProbability(8));
-        assertEquals(N, info.getExecutionCount(8));
+        Assert.assertEquals(1.0, info.getBranchTakenProbability(1), DELTA);
+        Assert.assertEquals(N, info.getExecutionCount(1));
+        Assert.assertEquals(1.0, info.getBranchTakenProbability(8), DELTA);
+        Assert.assertEquals(N, info.getExecutionCount(8));
 
         continueProfiling(3 * N, "branchProbabilitySnippet", 0);
-        assertEquals(0.25, info.getBranchTakenProbability(1));
-        assertEquals(4 * N, info.getExecutionCount(1));
-        assertEquals(1.0, info.getBranchTakenProbability(8));
-        assertEquals(N, info.getExecutionCount(8));
+        Assert.assertEquals(0.25, info.getBranchTakenProbability(1), DELTA);
+        Assert.assertEquals(4 * N, info.getExecutionCount(1));
+        Assert.assertEquals(1.0, info.getBranchTakenProbability(8), DELTA);
+        Assert.assertEquals(N, info.getExecutionCount(8));
 
         resetProfile("branchProbabilitySnippet");
-        assertEquals(-1.0, info.getBranchTakenProbability(1));
-        assertEquals(0, info.getExecutionCount(1));
-        assertEquals(-1.0, info.getBranchTakenProbability(8));
-        assertEquals(0, info.getExecutionCount(8));
+        Assert.assertEquals(-1.0, info.getBranchTakenProbability(1), DELTA);
+        Assert.assertEquals(0, info.getExecutionCount(1));
+        Assert.assertEquals(-1.0, info.getBranchTakenProbability(8), DELTA);
+        Assert.assertEquals(0, info.getExecutionCount(8));
     }
 
     public static int branchProbabilitySnippet(int value) {
@@ -82,16 +81,16 @@
     @Test
     public void testSwitchProbabilities() {
         ProfilingInfo info = profile("switchProbabilitySnippet", 0);
-        assertEquals(new double[]{1.0, 0.0, 0.0}, info.getSwitchProbabilities(1));
+        Assert.assertArrayEquals(new double[]{1.0, 0.0, 0.0}, info.getSwitchProbabilities(1), DELTA);
 
         info = profile("switchProbabilitySnippet", 1);
-        assertEquals(new double[]{0.0, 1.0, 0.0}, info.getSwitchProbabilities(1));
+        Assert.assertArrayEquals(new double[]{0.0, 1.0, 0.0}, info.getSwitchProbabilities(1), DELTA);
 
         info = profile("switchProbabilitySnippet", 2);
-        assertEquals(new double[]{0.0, 0.0, 1.0}, info.getSwitchProbabilities(1));
+        Assert.assertArrayEquals(new double[]{0.0, 0.0, 1.0}, info.getSwitchProbabilities(1), DELTA);
 
         resetProfile("switchProbabilitySnippet");
-        assertNull(info.getSwitchProbabilities(1));
+        Assert.assertNull(info.getSwitchProbabilities(1));
     }
 
     public static int switchProbabilitySnippet(int value) {
@@ -147,66 +146,66 @@
 
         ProfilingInfo info = profile(methodName, "ABC");
         JavaTypeProfile typeProfile = info.getTypeProfile(bci);
-        assertEquals(0.0, typeProfile.getNotRecordedProbability());
-        assertEquals(1, typeProfile.getTypes().length);
-        assertEquals(stringType, typeProfile.getTypes()[0].getType());
-        assertEquals(1.0, typeProfile.getTypes()[0].getProbability());
+        Assert.assertEquals(0.0, typeProfile.getNotRecordedProbability(), DELTA);
+        Assert.assertEquals(1, typeProfile.getTypes().length);
+        Assert.assertEquals(stringType, typeProfile.getTypes()[0].getType());
+        Assert.assertEquals(1.0, typeProfile.getTypes()[0].getProbability(), DELTA);
 
         continueProfiling(methodName, new StringBuilder());
         typeProfile = info.getTypeProfile(bci);
-        assertEquals(0.0, typeProfile.getNotRecordedProbability());
-        assertEquals(2, typeProfile.getTypes().length);
-        assertEquals(stringType, typeProfile.getTypes()[0].getType());
-        assertEquals(stringBuilderType, typeProfile.getTypes()[1].getType());
-        assertEquals(0.5, typeProfile.getTypes()[0].getProbability());
-        assertEquals(0.5, typeProfile.getTypes()[1].getProbability());
+        Assert.assertEquals(0.0, typeProfile.getNotRecordedProbability(), DELTA);
+        Assert.assertEquals(2, typeProfile.getTypes().length);
+        Assert.assertEquals(stringType, typeProfile.getTypes()[0].getType());
+        Assert.assertEquals(stringBuilderType, typeProfile.getTypes()[1].getType());
+        Assert.assertEquals(0.5, typeProfile.getTypes()[0].getProbability(), DELTA);
+        Assert.assertEquals(0.5, typeProfile.getTypes()[1].getProbability(), DELTA);
 
         resetProfile(methodName);
         typeProfile = info.getTypeProfile(bci);
-        assertNull(typeProfile);
+        Assert.assertNull(typeProfile);
     }
 
     @Test
     public void testExceptionSeen() {
         // NullPointerException
         ProfilingInfo info = profile("nullPointerExceptionSnippet", 5);
-        assertEquals(TriState.FALSE, info.getExceptionSeen(1));
+        Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(1));
 
         info = profile("nullPointerExceptionSnippet", (Object) null);
-        assertEquals(TriState.TRUE, info.getExceptionSeen(1));
+        Assert.assertEquals(TriState.TRUE, info.getExceptionSeen(1));
 
         resetProfile("nullPointerExceptionSnippet");
-        assertEquals(TriState.FALSE, info.getExceptionSeen(1));
+        Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(1));
 
         // ArrayOutOfBoundsException
         info = profile("arrayIndexOutOfBoundsExceptionSnippet", new int[1]);
-        assertEquals(TriState.FALSE, info.getExceptionSeen(2));
+        Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(2));
 
         info = profile("arrayIndexOutOfBoundsExceptionSnippet", new int[0]);
-        assertEquals(TriState.TRUE, info.getExceptionSeen(2));
+        Assert.assertEquals(TriState.TRUE, info.getExceptionSeen(2));
 
         resetProfile("arrayIndexOutOfBoundsExceptionSnippet");
-        assertEquals(TriState.FALSE, info.getExceptionSeen(2));
+        Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(2));
 
         // CheckCastException
         info = profile("checkCastExceptionSnippet", "ABC");
-        assertEquals(TriState.FALSE, info.getExceptionSeen(1));
+        Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(1));
 
         info = profile("checkCastExceptionSnippet", 5);
-        assertEquals(TriState.TRUE, info.getExceptionSeen(1));
+        Assert.assertEquals(TriState.TRUE, info.getExceptionSeen(1));
 
         resetProfile("checkCastExceptionSnippet");
-        assertEquals(TriState.FALSE, info.getExceptionSeen(1));
+        Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(1));
 
         // Invoke with exception
         info = profile("invokeWithExceptionSnippet", false);
-        assertEquals(TriState.FALSE, info.getExceptionSeen(1));
+        Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(1));
 
         info = profile("invokeWithExceptionSnippet", true);
-        assertEquals(TriState.TRUE, info.getExceptionSeen(1));
+        Assert.assertEquals(TriState.TRUE, info.getExceptionSeen(1));
 
         resetProfile("invokeWithExceptionSnippet");
-        assertEquals(TriState.FALSE, info.getExceptionSeen(1));
+        Assert.assertEquals(TriState.FALSE, info.getExceptionSeen(1));
     }
 
     public static int nullPointerExceptionSnippet(Object obj) {
@@ -252,19 +251,19 @@
     @Test
     public void testNullSeen() {
         ProfilingInfo info = profile("instanceOfSnippet", 1);
-        assertEquals(TriState.FALSE, info.getNullSeen(1));
+        Assert.assertEquals(TriState.FALSE, info.getNullSeen(1));
 
         continueProfiling("instanceOfSnippet", "ABC");
-        assertEquals(TriState.FALSE, info.getNullSeen(1));
+        Assert.assertEquals(TriState.FALSE, info.getNullSeen(1));
 
         continueProfiling("instanceOfSnippet", (Object) null);
-        assertEquals(TriState.TRUE, info.getNullSeen(1));
+        Assert.assertEquals(TriState.TRUE, info.getNullSeen(1));
 
         continueProfiling("instanceOfSnippet", 0.0);
-        assertEquals(TriState.TRUE, info.getNullSeen(1));
+        Assert.assertEquals(TriState.TRUE, info.getNullSeen(1));
 
         resetProfile("instanceOfSnippet");
-        assertEquals(TriState.FALSE, info.getNullSeen(1));
+        Assert.assertEquals(TriState.FALSE, info.getNullSeen(1));
     }
 
     private ProfilingInfo profile(String methodName, Object... args) {
@@ -292,7 +291,7 @@
             try {
                 method.invoke(null, args);
             } catch (Throwable e) {
-                fail("method should not throw an exception: " + e.toString());
+                Assert.fail("method should not throw an exception: " + e.toString());
             }
         }