Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/profiles/BinaryConditionProfileTest.java @ 22530:4ba1aa33fda4
Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 06 Jan 2016 13:52:35 +0100 |
parents | a63bda98cfdb |
children |
rev | line source |
---|---|
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
16854
fc6f12ee71e5
Truffle: fixed header dates.
Christian Humer <christian.humer@gmail.com>
parents:
16852
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
22501
a63bda98cfdb
Extract profiles into separate package. Add isProfilingEnabled in TruffleRuntime to disable profiling in the default runtime; Add low overhead profiles for primitives; Add LoopConditionProfile; Profile footprint/threadsafety improvements; Make toString implementations more consistent; Greatly enhanced javadoc documentation for profiles; Deprecate old profiles
Christian Humer <christian.humer@oracle.com>
parents:
22425
diff
changeset
|
23 package com.oracle.truffle.api.profiles; |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
25 import static org.hamcrest.CoreMatchers.is; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
26 import static org.junit.Assert.assertThat; |
22425
b39b603e2a1e
Organize imports after rename.
Christian Humer <christian.humer@oracle.com>
parents:
22424
diff
changeset
|
27 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
28 import org.junit.Before; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
29 import org.junit.Test; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
30 import org.junit.experimental.theories.DataPoints; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
31 import org.junit.experimental.theories.Theory; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
32 import org.junit.runner.RunWith; |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 |
22530
4ba1aa33fda4
Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22501
diff
changeset
|
34 @RunWith(SeparateClassloaderTestRunner.Theories.class) |
16860
fa5e62620593
Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
Christian Humer <christian.humer@gmail.com>
parents:
16854
diff
changeset
|
35 public class BinaryConditionProfileTest { |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 @DataPoints public static boolean[] data = new boolean[]{true, false}; |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 |
22501
a63bda98cfdb
Extract profiles into separate package. Add isProfilingEnabled in TruffleRuntime to disable profiling in the default runtime; Add low overhead profiles for primitives; Add LoopConditionProfile; Profile footprint/threadsafety improvements; Make toString implementations more consistent; Greatly enhanced javadoc documentation for profiles; Deprecate old profiles
Christian Humer <christian.humer@oracle.com>
parents:
22425
diff
changeset
|
39 private ConditionProfile.Binary profile; |
16910
c9437b07c26a
Truffle: changed return types of condition profile factory methods.
Christian Humer <christian.humer@gmail.com>
parents:
16860
diff
changeset
|
40 |
c9437b07c26a
Truffle: changed return types of condition profile factory methods.
Christian Humer <christian.humer@gmail.com>
parents:
16860
diff
changeset
|
41 @Before |
c9437b07c26a
Truffle: changed return types of condition profile factory methods.
Christian Humer <christian.humer@gmail.com>
parents:
16860
diff
changeset
|
42 public void create() { |
22501
a63bda98cfdb
Extract profiles into separate package. Add isProfilingEnabled in TruffleRuntime to disable profiling in the default runtime; Add low overhead profiles for primitives; Add LoopConditionProfile; Profile footprint/threadsafety improvements; Make toString implementations more consistent; Greatly enhanced javadoc documentation for profiles; Deprecate old profiles
Christian Humer <christian.humer@oracle.com>
parents:
22425
diff
changeset
|
43 profile = (ConditionProfile.Binary) ConditionProfile.Binary.create(); |
16910
c9437b07c26a
Truffle: changed return types of condition profile factory methods.
Christian Humer <christian.humer@gmail.com>
parents:
16860
diff
changeset
|
44 } |
c9437b07c26a
Truffle: changed return types of condition profile factory methods.
Christian Humer <christian.humer@gmail.com>
parents:
16860
diff
changeset
|
45 |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 @Test |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 public void testInitial() { |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 assertThat(profile.wasTrue(), is(false)); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 assertThat(profile.wasFalse(), is(false)); |
22501
a63bda98cfdb
Extract profiles into separate package. Add isProfilingEnabled in TruffleRuntime to disable profiling in the default runtime; Add low overhead profiles for primitives; Add LoopConditionProfile; Profile footprint/threadsafety improvements; Make toString implementations more consistent; Greatly enhanced javadoc documentation for profiles; Deprecate old profiles
Christian Humer <christian.humer@oracle.com>
parents:
22425
diff
changeset
|
50 profile.toString(); |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 } |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 @Theory |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 public void testProfileOne(boolean value) { |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 boolean result = profile.profile(value); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 assertThat(result, is(value)); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 assertThat(profile.wasTrue(), is(value)); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 assertThat(profile.wasFalse(), is(!value)); |
22501
a63bda98cfdb
Extract profiles into separate package. Add isProfilingEnabled in TruffleRuntime to disable profiling in the default runtime; Add low overhead profiles for primitives; Add LoopConditionProfile; Profile footprint/threadsafety improvements; Make toString implementations more consistent; Greatly enhanced javadoc documentation for profiles; Deprecate old profiles
Christian Humer <christian.humer@oracle.com>
parents:
22425
diff
changeset
|
60 profile.toString(); |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 } |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 @Theory |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 public void testProfileTwo(boolean value0, boolean value1) { |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 boolean result0 = profile.profile(value0); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 boolean result1 = profile.profile(value1); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 assertThat(result0, is(value0)); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 assertThat(result1, is(value1)); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 assertThat(profile.wasTrue(), is(value0 || value1)); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 assertThat(profile.wasFalse(), is(!value0 || !value1)); |
22501
a63bda98cfdb
Extract profiles into separate package. Add isProfilingEnabled in TruffleRuntime to disable profiling in the default runtime; Add low overhead profiles for primitives; Add LoopConditionProfile; Profile footprint/threadsafety improvements; Make toString implementations more consistent; Greatly enhanced javadoc documentation for profiles; Deprecate old profiles
Christian Humer <christian.humer@oracle.com>
parents:
22425
diff
changeset
|
72 profile.toString(); |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 } |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 @Theory |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 public void testProfileThree(boolean value0, boolean value1, boolean value2) { |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 boolean result0 = profile.profile(value0); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 boolean result1 = profile.profile(value1); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 boolean result2 = profile.profile(value2); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 assertThat(result0, is(value0)); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 assertThat(result1, is(value1)); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 assertThat(result2, is(value2)); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
84 assertThat(profile.wasTrue(), is(value0 || value1 || value2)); |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
85 assertThat(profile.wasFalse(), is(!value0 || !value1 || !value2)); |
22501
a63bda98cfdb
Extract profiles into separate package. Add isProfilingEnabled in TruffleRuntime to disable profiling in the default runtime; Add low overhead profiles for primitives; Add LoopConditionProfile; Profile footprint/threadsafety improvements; Make toString implementations more consistent; Greatly enhanced javadoc documentation for profiles; Deprecate old profiles
Christian Humer <christian.humer@oracle.com>
parents:
22425
diff
changeset
|
86 profile.toString(); |
16828
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
87 } |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 |
2834af86f398
Truffle: new condition profile primitives.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
89 } |