1 /* 2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.graph.test; 24 25 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_UNKNOWN; 26 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_UNKNOWN; 27 28 import org.junit.Assert; 29 import org.junit.Test; 30 31 import org.graalvm.compiler.graph.Graph; 32 import org.graalvm.compiler.graph.Node; 33 import org.graalvm.compiler.graph.NodeClass; 34 import org.graalvm.compiler.nodeinfo.NodeInfo; 35 36 public class NodeValidationChecksTest extends GraphTest { 37 38 @NodeInfo(cycles = CYCLES_UNKNOWN, size = SIZE_UNKNOWN) 39 static final class TestNode extends Node { 40 public static final NodeClass<TestNode> TYPE = NodeClass.create(TestNode.class); 41 42 @Input TestNode input; 43 @Successor TestNode successor; 44 45 protected TestNode(TestNode input, TestNode successor) { 46 super(TYPE); 47 this.input = input; 48 this.successor = successor; 49 } 50 } 51 52 @Test 53 public void testInputNotAlive() { 54 Graph graph = new Graph(getOptions()); 55 TestNode node = new TestNode(null, null); 56 try { 57 graph.add(new TestNode(node, null)); 58 Assert.fail("Exception expected."); 59 } catch (AssertionError e) { 60 Assert.assertTrue(e.getMessage().contains("Input")); 61 Assert.assertTrue(e.getMessage().contains("not alive")); 62 } 63 } 64 65 @Test 66 public void testSuccessorNotAlive() { 67 Graph graph = new Graph(getOptions()); 68 TestNode node = new TestNode(null, null); 69 try { 70 graph.add(new TestNode(null, node)); 71 Assert.fail("Exception expected."); 72 } catch (AssertionError e) { 73 Assert.assertTrue(e.getMessage().contains("Successor")); 74 Assert.assertTrue(e.getMessage().contains("not alive")); 75 } 76 } 77 }