annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/TestHelper.java @ 16967:c5db657d93c1

Truffle-DSL: added test for source sections in @CreateCast methods.
author Christian Humer <christian.humer@gmail.com>
date Wed, 27 Aug 2014 11:35:59 +0200
parents 5148aab962af
children 62c43fcf5be2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.api.dsl.test;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
25 import static org.junit.Assert.*;
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
26
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
27 import java.util.*;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
28
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29 import com.oracle.truffle.api.*;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30 import com.oracle.truffle.api.dsl.*;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ArgumentNode;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ChildrenNode;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
34 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
35
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36 /**
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37 * Utility class to provide some test helper functions.
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38 */
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39 class TestHelper {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 private static ArgumentNode[] arguments(int count) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42 ArgumentNode[] nodes = new ArgumentNode[count];
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 for (int i = 0; i < nodes.length; i++) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44 nodes[i] = new ArgumentNode(i);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 return nodes;
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
49 static <E extends ValueNode> E createNode(NodeFactory<E> factory, boolean prefixConstants, Object... constants) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50 ArgumentNode[] argumentNodes = arguments(factory.getExecutionSignature().size());
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52 List<Object> argumentList = new ArrayList<>();
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
53 if (prefixConstants) {
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
54 argumentList.addAll(Arrays.asList(constants));
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
55 }
13528
5a0c694ef735 Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents: 12401
diff changeset
56 if (ChildrenNode.class.isAssignableFrom(factory.getNodeClass())) {
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57 argumentList.add(argumentNodes);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 } else {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 argumentList.addAll(Arrays.asList(argumentNodes));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
60 }
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
61 if (!prefixConstants) {
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
62 argumentList.addAll(Arrays.asList(constants));
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
63 }
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 return factory.createNode(argumentList.toArray(new Object[argumentList.size()]));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 static <E extends ValueNode> TestRootNode<E> createRoot(NodeFactory<E> factory, Object... constants) {
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
68 TestRootNode<E> rootNode = new TestRootNode<>(createNode(factory, false, constants));
14632
5f5e2711dc24 fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents: 14042
diff changeset
69 rootNode.adoptChildren();
5f5e2711dc24 fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents: 14042
diff changeset
70 return rootNode;
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72
16967
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
73 static <E extends ValueNode> TestRootNode<E> createRootPrefix(NodeFactory<E> factory, boolean prefixConstants, Object... constants) {
c5db657d93c1 Truffle-DSL: added test for source sections in @CreateCast methods.
Christian Humer <christian.humer@gmail.com>
parents: 16756
diff changeset
74 TestRootNode<E> rootNode = new TestRootNode<>(createNode(factory, prefixConstants, constants));
14632
5f5e2711dc24 fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents: 14042
diff changeset
75 rootNode.adoptChildren();
5f5e2711dc24 fix TruffleDSL tests
Andreas Woess <andreas.woess@jku.at>
parents: 14042
diff changeset
76 return rootNode;
12401
85dcc7f59c34 Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents: 11473
diff changeset
77 }
85dcc7f59c34 Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents: 11473
diff changeset
78
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79 static CallTarget createCallTarget(ValueNode node) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 return createCallTarget(new TestRootNode<>(node));
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
81 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
82
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83 static CallTarget createCallTarget(TestRootNode<? extends ValueNode> node) {
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84 return Truffle.getRuntime().createCallTarget(node);
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
87 static <E> Object executeWith(TestRootNode<? extends ValueNode> node, Object... values) {
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 14632
diff changeset
88 return createCallTarget(node).call(values);
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
91 static Object[] array(Object... val) {
11464
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
92 return val;
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
93 }
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
94
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
95 static <E> List<List<E>> permutations(List<E> list) {
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
96 return permutations(new ArrayList<E>(), list, new ArrayList<List<E>>());
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
97 }
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
98
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
99 static Object[][] permutations(Object... list) {
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
100 List<List<Object>> permutations = permutations(Arrays.asList(list));
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
101
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
102 Object[][] a = new Object[permutations.size()][];
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
103 int index = 0;
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
104 for (List<Object> p : permutations) {
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
105 a[index] = p.toArray(new Object[p.size()]);
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
106 index++;
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
107 }
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
108
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
109 return a;
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
110 }
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
111
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
112 static <E> List<List<E>> permutations(List<E> prefix, List<E> suffix, List<List<E>> output) {
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
113 if (suffix.size() == 1) {
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
114 ArrayList<E> newElement = new ArrayList<>(prefix);
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
115 newElement.addAll(suffix);
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
116 output.add(newElement);
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
117 return output;
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
118 }
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
119
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
120 for (int i = 0; i < suffix.size(); i++) {
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
121 List<E> newPrefix = new ArrayList<>(prefix);
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
122 newPrefix.add(suffix.get(i));
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
123 List<E> newSuffix = new ArrayList<>(suffix);
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
124 newSuffix.remove(i);
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
125 permutations(newPrefix, newSuffix, output);
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
126 }
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
127
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
128 return output;
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
129 }
e55e24cc3e7b Truffle-DSL: added permutation util functions to the TestHelper.
Christian Humer <christian.humer@gmail.com>
parents: 11191
diff changeset
130
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
131 static void assertRuns(NodeFactory<? extends ValueNode> factory, Object[] testValues, Object[] result) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
132 assertRuns(factory, testValues, result, null);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
133 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
134
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
135 /* Methods tests all test values in combinational order. */
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
136 static void assertRuns(NodeFactory<? extends ValueNode> factory, Object[] testValues, Object[] result, ExecutionListener listener) {
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
137 // test each run by its own.
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
138 for (int i = 0; i < testValues.length; i++) {
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
139 assertValue(createRoot(factory), 0, testValues[i], result[i], listener, true);
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
140 }
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
141
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
142 // test all combinations of the test values
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
143 List<Object> testValuesList = Arrays.asList(testValues);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
144 List<List<Object>> permuts = permutations(testValuesList);
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
145 for (List<Object> list : permuts) {
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
146 TestRootNode<?> root = createRoot(factory);
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
147 int index = 0;
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
148 for (Object object : list) {
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
149 assertValue(root, index, object, result[testValuesList.indexOf(object)], listener, index == list.size() - 1);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
150 index++;
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
151 }
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
152 }
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
153 }
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
154
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
155 static void assertValue(TestRootNode<? extends ValueNode> root, int index, Object value, Object result, ExecutionListener listener, boolean last) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
156 Object actualResult = null;
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
157 if (result instanceof Class && Throwable.class.isAssignableFrom((Class<?>) result)) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
158 try {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
159 if (value instanceof Object[]) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
160 actualResult = executeWith(root, (Object[]) value);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
161 } else {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
162 actualResult = executeWith(root, value);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
163 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
164 fail(String.format("Exception %s expected but not occured.", result.getClass()));
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
165 } catch (Throwable e) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
166 actualResult = e;
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
167 if (!e.getClass().isAssignableFrom(((Class<?>) result))) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
168 e.printStackTrace();
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
169 fail(String.format("Incompatible exception class thrown. Expected %s but was %s.", result.toString(), e.getClass()));
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
170 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
171 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
172 } else if (value instanceof Object[]) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
173 actualResult = executeWith(root, (Object[]) value);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
174 assertEquals(result, actualResult);
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
175 } else {
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
176 actualResult = executeWith(root, value);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
177 assertEquals(result, actualResult);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
178 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
179 if (listener != null) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
180 listener.afterExecution(root, index, value, result, actualResult, last);
11469
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
181 }
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
182 }
88316d1c4644 Truffle-DSL: preparations for implicit casts
Christian Humer <christian.humer@gmail.com>
parents: 11464
diff changeset
183
16756
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
184 public static final class LogListener implements ExecutionListener {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
185
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
186 public void afterExecution(TestRootNode<? extends ValueNode> node, int index, Object value, Object expectedResult, Object actualResult, boolean last) {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
187 System.out.printf("Run %3d Node:%-20s Parameters: %10s Expected: %10s Result %10s%n", index, node.getNode().getClass().getSimpleName(), value, expectedResult, actualResult);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
188 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
189
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
190 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
191
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
192 interface ExecutionListener {
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
193
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
194 void afterExecution(TestRootNode<? extends ValueNode> node, int index, Object value, Object expectedResult, Object actualResult, boolean last);
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
195
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
196 }
5148aab962af Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
197
10597
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
198 }