|
1 | 1 | /* |
2 | | - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
24 | 24 | */ |
25 | 25 | package com.oracle.truffle.api.impl; |
26 | 26 |
|
| 27 | +import com.oracle.truffle.api.CallTarget; |
27 | 28 | import com.oracle.truffle.api.TruffleLanguage; |
28 | 29 | import com.oracle.truffle.api.frame.FrameDescriptor; |
29 | 30 | import com.oracle.truffle.api.impl.Accessor.InstrumentSupport; |
|
37 | 38 | * @since 0.12 |
38 | 39 | */ |
39 | 40 | public abstract class TVMCI { |
| 41 | + |
| 42 | + /** |
| 43 | + * An interface between the Truffle test runner and hosting virtual machine. |
| 44 | + * |
| 45 | + * @param <T> the {@link CallTarget} subclass of the hosting virtual machine |
| 46 | + * |
| 47 | + * @since 0.25 |
| 48 | + */ |
| 49 | + public abstract static class Test<T extends CallTarget> { |
| 50 | + |
| 51 | + /** |
| 52 | + * Create a call target for the purpose of running a unit test. |
| 53 | + * |
| 54 | + * @param testName the name of the unit test |
| 55 | + * @param testNode the root node containing the test code |
| 56 | + * @return a call target |
| 57 | + * |
| 58 | + * @since 0.25 |
| 59 | + */ |
| 60 | + protected abstract T createTestCallTarget(String testName, RootNode testNode); |
| 61 | + |
| 62 | + /** |
| 63 | + * Notify the VM that the warmup is finished, and it should now compile the test code. |
| 64 | + * |
| 65 | + * @param callTarget a call target that was created with {@link #createTestCallTarget} |
| 66 | + * |
| 67 | + * @since 0.25 |
| 68 | + */ |
| 69 | + protected abstract void finishWarmup(T callTarget); |
| 70 | + } |
| 71 | + |
40 | 72 | /** |
41 | 73 | * Only useful for virtual machine implementors. |
42 | 74 | * |
@@ -132,4 +164,31 @@ protected boolean isCloneUninitializedSupported(RootNode root) { |
132 | 164 | protected RootNode cloneUninitialized(RootNode root) { |
133 | 165 | return Accessor.nodesAccess().cloneUninitialized(root); |
134 | 166 | } |
| 167 | + |
| 168 | + /** |
| 169 | + * Accessor for {@link TVMCI#Test} class. |
| 170 | + * |
| 171 | + * @param <T> |
| 172 | + * |
| 173 | + * @since 0.25 |
| 174 | + */ |
| 175 | + public static class TestAccessor<T extends CallTarget> { |
| 176 | + |
| 177 | + private final TVMCI.Test<T> testTvmci; |
| 178 | + |
| 179 | + protected TestAccessor(TVMCI.Test<T> testTvmci) { |
| 180 | + if (!this.getClass().getPackage().getName().equals("com.oracle.truffle.tck")) { |
| 181 | + throw new IllegalStateException(); |
| 182 | + } |
| 183 | + this.testTvmci = testTvmci; |
| 184 | + } |
| 185 | + |
| 186 | + protected final T createTestCallTarget(String testName, RootNode testNode) { |
| 187 | + return testTvmci.createTestCallTarget(testName, testNode); |
| 188 | + } |
| 189 | + |
| 190 | + protected final void finishWarmup(T callTarget) { |
| 191 | + testTvmci.finishWarmup(callTarget); |
| 192 | + } |
| 193 | + } |
135 | 194 | } |
0 commit comments