comparison graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/TruffleTCK.java @ 21557:31fc2fce38f3

Merge.
author Doug Simon <doug.simon@oracle.com>
date Wed, 27 May 2015 13:32:18 +0200
parents b1530a6cce8c 3286fb5fea4a
children ed234a3178af
comparison
equal deleted inserted replaced
21556:48c1ebd24120 21557:31fc2fce38f3
22 */ 22 */
23 package com.oracle.truffle.api.test.vm; 23 package com.oracle.truffle.api.test.vm;
24 24
25 import java.util.*; 25 import java.util.*;
26 26
27 import org.junit.*;
28
27 import com.oracle.truffle.api.vm.*; 29 import com.oracle.truffle.api.vm.*;
28 30
29 /** 31 /**
30 * A collection of tests that can certify language implementaiton to be complient with most recent 32 * A collection of tests that can certify language implementaiton to be complient with most recent
31 * requirements of the Truffle infrastructure and tooling. Subclass, implement abstract methods and 33 * requirements of the Truffle infrastructure and tooling. Subclass, implement abstract methods and
32 * include in your test suite. 34 * include in your test suite.
33 */ 35 */
34 public abstract class TruffleTCK { 36 public class TruffleTCK { // abstract
35 private TruffleVM vm; 37 private TruffleVM tckVM;
36 38
37 protected TruffleTCK() { 39 public TruffleTCK() { // protected
38 } 40 }
39 41
40 /** 42 /**
41 * This methods is called before first test is executed. It's purpose is to set a TruffleVM with 43 * This methods is called before first test is executed. It's purpose is to set a TruffleVM with
42 * your language up, so it is ready for testing. 44 * your language up, so it is ready for testing.
44 * prepare global symbols with proper names. The symbols will then be looked up by the 46 * prepare global symbols with proper names. The symbols will then be looked up by the
45 * infastructure (using the names provided by you from methods like {@link #plusInt()}) and used 47 * infastructure (using the names provided by you from methods like {@link #plusInt()}) and used
46 * for internal testing. 48 * for internal testing.
47 * 49 *
48 * @return initialized Truffle virtual machine 50 * @return initialized Truffle virtual machine
51 * @throws java.lang.Exception thrown when the VM preparation fails
49 */ 52 */
50 protected abstract TruffleVM prepareVM() throws Exception; 53 protected TruffleVM prepareVM() throws Exception { // abstract
54 return null;
55 }
51 56
52 /** 57 /**
53 * Name of function which will return value 42 as a number. The return value of the method 58 * Name of function which will return value 42 as a number. The return value of the method
54 * should be instance of {@link Number} and its {@link Number#intValue()} should return 59 * should be instance of {@link Number} and its {@link Number#intValue()} should return
55 * <code>42</code>. 60 * <code>42</code>.
56 * 61 *
57 * @return name of globally exported symbol 62 * @return name of globally exported symbol
58 */ 63 */
59 protected abstract String fourtyTwo(); 64 protected String fourtyTwo() { // abstract
65 return null;
66 }
60 67
61 /** 68 /**
62 * Name of function to add two integer values together. The symbol will be invoked with two 69 * Name of function to add two integer values together. The symbol will be invoked with two
63 * parameters of type {@link Integer} and expects result of type {@link Number} which's 70 * parameters of type {@link Integer} and expects result of type {@link Number} which's
64 * {@link Number#intValue()} is equivalent of <code>param1 + param2</code>. 71 * {@link Number#intValue()} is equivalent of <code>param1 + param2</code>.
65 * 72 *
66 * @return name of globally exported symbol 73 * @return name of globally exported symbol
67 */ 74 */
68 protected abstract String plusInt(); 75 protected String plusInt() { // abstract
76 return null;
77 }
69 78
70 private TruffleVM vm() throws Exception { 79 private TruffleVM vm() throws Exception {
71 if (vm == null) { 80 if (tckVM == null) {
72 vm = prepareVM(); 81 tckVM = prepareVM();
73 } 82 }
74 return vm; 83 return tckVM;
75 } 84 }
76 85
77 // 86 //
78 // The tests 87 // The tests
79 // 88 //
80 89
90 @Test
81 public void testFortyTwo() throws Exception { 91 public void testFortyTwo() throws Exception {
92 if (getClass() == TruffleTCK.class) {
93 return;
94 }
82 TruffleVM.Symbol fourtyTwo = findGlobalSymbol(fourtyTwo()); 95 TruffleVM.Symbol fourtyTwo = findGlobalSymbol(fourtyTwo());
83 96
84 Object res = fourtyTwo.invoke(null); 97 Object res = fourtyTwo.invoke(null);
85 98
86 assert res instanceof Number : "should yield a number, but was: " + res; 99 assert res instanceof Number : "should yield a number, but was: " + res;
88 Number n = (Number) res; 101 Number n = (Number) res;
89 102
90 assert 42 == n.intValue() : "The value is 42 = " + n.intValue(); 103 assert 42 == n.intValue() : "The value is 42 = " + n.intValue();
91 } 104 }
92 105
106 @Test
93 public void testPlusWithInts() throws Exception { 107 public void testPlusWithInts() throws Exception {
108 if (getClass() == TruffleTCK.class) {
109 return;
110 }
94 Random r = new Random(); 111 Random r = new Random();
95 int a = r.nextInt(100); 112 int a = r.nextInt(100);
96 int b = r.nextInt(100); 113 int b = r.nextInt(100);
97 114
98 TruffleVM.Symbol plus = findGlobalSymbol(plusInt()); 115 TruffleVM.Symbol plus = findGlobalSymbol(plusInt());