Test Interface for Truffle: Good for PE tests?

Roland Schatz roland.schatz at oracle.com
Tue Apr 4 08:55:28 UTC 2017

Hi Stefan,

On 03/31/2017 01:16 PM, Stefan Marr wrote:
> Hi:
> I just saw that a recent commit [1] introduced a test interface for Truffle.
> What exactly is this good for? Can I use this to easily check for instance that specific operations properly constant fold?
Yes, the idea of that interface is that you can use it to unit-test the 
partial evaluation and compilation of individual nodes or small AST 
You can combine that with CompilerDirectives to explicitly test for 
constant folding.

> I looked a little at the documentation. Does the warmup annotation imply that after the given number of iterations, compilation is forced for me? This isn’t quite clear to me from the javadoc.
If there is a Truffle compiler in the system (i.e. you're running with 
Graal), then compilation is forced for the final execution of the test AST.
This is essentially saving you the need to write a manual warmup loop in 
the hope of eventually triggering compilation.

> If this can be used to build checks that code constant folds, I am also wondering how the tests can be ignored/skipped when unit tests are executed without Graal. Are there now facilities, to test explicitly that the TruffleRuntime supports compilation? There has been a long standing feature request for such an API [2].
CompilerDirectives.isCompilationConstant will return true if called from 
the interpreter, so if you're writing a test that's asserting that 
something is constant, it should at least not fail if there is no 
compiler available (but of course it also won't actually test anything).
You could also just put a big "if (CompilerDirectives.inCompiledCode())" 
around the code in the test root node, but that would of course also 
effectively disable your warmup (which may be totally fine, depending on 
how you build your test AST).

- Roland

> Thanks
> Stefan
> [1]: https://github.com/graalvm/truffle/commit/1dce7adb2833abc2aa3f3a4bcd0e0c288a472faf
> [2]: https://github.com/graalvm/truffle/issues/47

More information about the graal-dev mailing list