# HG changeset patch # User Christian Haeubl # Date 1365069424 -7200 # Node ID 0298d8a0caf5e511cef383675dc2b4edbdcbec41 # Parent 00a548fdf821560249873f92544eeeea3e77d587 added JUnit 4.11 support to ProfilingInfoTest diff -r 00a548fdf821 -r 0298d8a0caf5 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ProfilingInfoTest.java --- 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()); } }