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