Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java @ 22173:dcb70d90c11d
Merging in changes in default branch
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Mon, 21 Sep 2015 11:21:03 +0200 |
parents | b31dcacfc8ff dc83cc1f94f2 |
children | 7abcbeb12d08 |
comparison
equal
deleted
inserted
replaced
22172:b31dcacfc8ff | 22173:dcb70d90c11d |
---|---|
28 import com.oracle.truffle.api.interop.java.JavaInterop; | 28 import com.oracle.truffle.api.interop.java.JavaInterop; |
29 import com.oracle.truffle.api.source.Source; | 29 import com.oracle.truffle.api.source.Source; |
30 import com.oracle.truffle.api.vm.PolyglotEngine; | 30 import com.oracle.truffle.api.vm.PolyglotEngine; |
31 import java.io.IOException; | 31 import java.io.IOException; |
32 import java.util.Random; | 32 import java.util.Random; |
33 import java.util.logging.Level; | 33 import static org.junit.Assert.assertEquals; |
34 import java.util.logging.Logger; | 34 import static org.junit.Assert.assertNotNull; |
35 import static org.junit.Assert.*; | 35 import static org.junit.Assert.assertNotSame; |
36 import static org.junit.Assert.assertNull; | |
37 import static org.junit.Assert.assertSame; | |
38 import static org.junit.Assert.fail; | |
36 import org.junit.Test; | 39 import org.junit.Test; |
37 | 40 |
38 /** | 41 /** |
39 * A collection of tests that can certify language implementation to be compliant with most recent | 42 * A collection of tests that can certify language implementation to be compliant with most recent |
40 * requirements of the Truffle infrastructure and tooling. Subclass, implement abstract methods and | 43 * requirements of the Truffle infrastructure and tooling. Subclass, implement abstract methods and |
41 * include in your test suite. | 44 * include in your test suite. |
42 */ | 45 */ |
43 public abstract class TruffleTCK { | 46 public abstract class TruffleTCK { |
44 private static final Logger LOG = Logger.getLogger(TruffleTCK.class.getName()); | |
45 private static final Random RANDOM = new Random(); | 47 private static final Random RANDOM = new Random(); |
46 private PolyglotEngine tckVM; | 48 private PolyglotEngine tckVM; |
47 | 49 |
48 protected TruffleTCK() { | 50 protected TruffleTCK() { |
49 } | 51 } |
133 * identical output. | 135 * identical output. |
134 * | 136 * |
135 * @return name of globally exported symbol | 137 * @return name of globally exported symbol |
136 */ | 138 */ |
137 protected String identity() { | 139 protected String identity() { |
138 final long introduced = 1441894042844L; | 140 throw new UnsupportedOperationException("identity() method not implemented"); |
139 long wait = (System.currentTimeMillis() - introduced) / 3600; | |
140 if (wait < 100) { | |
141 wait = 100; | |
142 } | |
143 LOG.log(Level.SEVERE, "identity() method not overriden. Waiting for {0} ms", wait); | |
144 try { | |
145 Thread.sleep(wait); | |
146 } catch (InterruptedException ex) { | |
147 LOG.log(Level.SEVERE, null, ex); | |
148 } | |
149 return null; | |
150 } | 141 } |
151 | 142 |
152 /** | 143 /** |
153 * Name of a function that counts number of its invocations in current {@link PolyglotEngine} | 144 * Name of a function that counts number of its invocations in current {@link PolyglotEngine} |
154 * context. Your function should somehow keep a counter to remember number of its invocations | 145 * context. Your function should somehow keep a counter to remember number of its invocations |
191 * <b>returnsThis</b> that will return the object itself again. | 182 * <b>returnsThis</b> that will return the object itself again. |
192 * | 183 * |
193 * @return name of a function that returns such compound object | 184 * @return name of a function that returns such compound object |
194 */ | 185 */ |
195 protected String compoundObject() { | 186 protected String compoundObject() { |
196 return null; | 187 throw new UnsupportedOperationException("compoundObject() method not implemented"); |
197 } | 188 } |
198 | 189 |
199 private PolyglotEngine vm() throws Exception { | 190 private PolyglotEngine vm() throws Exception { |
200 if (tckVM == null) { | 191 if (tckVM == null) { |
201 tckVM = prepareVM(); | 192 tckVM = prepareVM(); |
220 assert 42 == n.intValue() : "The value is 42 = " + n.intValue(); | 211 assert 42 == n.intValue() : "The value is 42 = " + n.intValue(); |
221 } | 212 } |
222 | 213 |
223 @Test | 214 @Test |
224 public void testFortyTwoWithCompoundObject() throws Exception { | 215 public void testFortyTwoWithCompoundObject() throws Exception { |
225 CompoundObject obj = findCompoundSymbol("testFortyTwoWithCompoundObject"); | 216 CompoundObject obj = findCompoundSymbol(); |
226 if (obj == null) { | 217 if (obj == null) { |
227 return; | 218 return; |
228 } | 219 } |
229 Number res = obj.fourtyTwo(); | 220 Number res = obj.fourtyTwo(); |
230 assertEquals("Should be 42", 42, res.intValue()); | 221 assertEquals("Should be 42", 42, res.intValue()); |
239 assertNull("Should yield real Java null", res); | 230 assertNull("Should yield real Java null", res); |
240 } | 231 } |
241 | 232 |
242 @Test | 233 @Test |
243 public void testNullInCompoundObject() throws Exception { | 234 public void testNullInCompoundObject() throws Exception { |
244 CompoundObject obj = findCompoundSymbol("testNullInCompoundObject"); | 235 CompoundObject obj = findCompoundSymbol(); |
245 if (obj == null) { | 236 if (obj == null) { |
246 return; | 237 return; |
247 } | 238 } |
248 Object res = obj.returnsNull(); | 239 Object res = obj.returnsNull(); |
249 assertNull("Should yield real Java null", res); | 240 assertNull("Should yield real Java null", res); |
318 @Test | 309 @Test |
319 public void testPlusWithIntsOnCompoundObject() throws Exception { | 310 public void testPlusWithIntsOnCompoundObject() throws Exception { |
320 int a = RANDOM.nextInt(100); | 311 int a = RANDOM.nextInt(100); |
321 int b = RANDOM.nextInt(100); | 312 int b = RANDOM.nextInt(100); |
322 | 313 |
323 CompoundObject obj = findCompoundSymbol("testPlusWithIntsOnCompoundObject"); | 314 CompoundObject obj = findCompoundSymbol(); |
324 if (obj == null) { | 315 if (obj == null) { |
325 return; | 316 return; |
326 } | 317 } |
327 | 318 |
328 Number n = obj.plus(a, b); | 319 Number n = obj.plus(a, b); |
568 PolyglotEngine.Value s = vm().findGlobalSymbol(name); | 559 PolyglotEngine.Value s = vm().findGlobalSymbol(name); |
569 assert s != null : "Symbol " + name + " is not found!"; | 560 assert s != null : "Symbol " + name + " is not found!"; |
570 return s; | 561 return s; |
571 } | 562 } |
572 | 563 |
573 private CompoundObject findCompoundSymbol(String name) throws Exception { | 564 private CompoundObject findCompoundSymbol() throws Exception { |
574 final String compoundObjectName = compoundObject(); | 565 final String compoundObjectName = compoundObject(); |
575 if (compoundObjectName == null) { | |
576 final long introduced = 1441616302340L; | |
577 long wait = (System.currentTimeMillis() - introduced) / 36000; | |
578 if (wait < 100) { | |
579 wait = 100; | |
580 } | |
581 LOG.log(Level.SEVERE, "compoundObject() method not overriden! Skipping {1} test for now. But sleeping for {0} ms.", new Object[]{wait, name}); | |
582 Thread.sleep(wait); | |
583 return null; | |
584 } | |
585 PolyglotEngine.Value s = vm().findGlobalSymbol(compoundObjectName); | 566 PolyglotEngine.Value s = vm().findGlobalSymbol(compoundObjectName); |
586 assert s != null : "Symbol " + compoundObjectName + " is not found!"; | 567 assert s != null : "Symbol " + compoundObjectName + " is not found!"; |
587 CompoundObject obj = s.invoke(null).as(CompoundObject.class); | 568 final PolyglotEngine.Value value = s.invoke(null); |
569 CompoundObject obj = value.as(CompoundObject.class); | |
570 assertNotNull("Compound object for " + value + " found", obj); | |
588 int traverse = RANDOM.nextInt(10); | 571 int traverse = RANDOM.nextInt(10); |
589 while (traverse-- >= 0) { | 572 for (int i = 1; i <= traverse; i++) { |
590 obj = obj.returnsThis(); | 573 obj = obj.returnsThis(); |
574 assertNotNull("Remains non-null even after " + i + " iteration", obj); | |
591 } | 575 } |
592 return obj; | 576 return obj; |
593 } | 577 } |
594 | 578 |
595 interface CompoundObject { | 579 interface CompoundObject { |