Search in sources :

Example 6 with CaptureOutput

use of com.oracle.truffle.llvm.tests.pipe.CaptureOutput in project graal by oracle.

the class PolyglotToolchainTest method testCC.

@Test
public void testCC() throws IOException {
    try (CaptureOutput out = new CaptureNativeOutput()) {
        testLibrary.getMember("print_cc").execute();
        Assert.assertEquals(String.format("CC=%s\n", getToolchain().getToolPath("CC").toString()), out.getStdOut());
    }
}
Also used : CaptureOutput(com.oracle.truffle.llvm.tests.pipe.CaptureOutput) CaptureNativeOutput(com.oracle.truffle.llvm.tests.pipe.CaptureNativeOutput) Test(org.junit.Test)

Example 7 with CaptureOutput

use of com.oracle.truffle.llvm.tests.pipe.CaptureOutput in project graal by oracle.

the class ProcessUtil method executeSulongTestMainSameEngine.

public static ProcessResult executeSulongTestMainSameEngine(File bitcodeFile, String[] args, Map<String, String> options, Function<Context.Builder, CaptureOutput> captureOutput, Engine engine) throws IOException {
    if (TestOptions.TEST_AOT_IMAGE == null) {
        org.graalvm.polyglot.Source source = org.graalvm.polyglot.Source.newBuilder(LLVMLanguage.ID, bitcodeFile).build();
        Builder builder = Context.newBuilder();
        try (CaptureOutput out = captureOutput.apply(builder)) {
            int result;
            try (Context context = builder.engine(engine).arguments(LLVMLanguage.ID, args).options(options).allowAllAccess(true).build()) {
                Value main = context.eval(source);
                if (!main.canExecute()) {
                    throw new LLVMLinkerException("No main function found.");
                }
                result = main.execute().asInt();
            }
            return new ProcessResult(bitcodeFile.getName(), result, out.getStdErr(), out.getStdOut());
        }
    } else {
        String aotArgs = TestOptions.TEST_AOT_ARGS == null ? "" : TestOptions.TEST_AOT_ARGS + " ";
        String cmdline = TestOptions.TEST_AOT_IMAGE + " " + aotArgs + concatOptions(options) + bitcodeFile.getAbsolutePath() + " " + concatCommand(args);
        return executeNativeCommand(cmdline);
    }
}
Also used : CaptureOutput(com.oracle.truffle.llvm.tests.pipe.CaptureOutput) Context(org.graalvm.polyglot.Context) Builder(org.graalvm.polyglot.Context.Builder) Value(org.graalvm.polyglot.Value) LLVMLinkerException(com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)

Example 8 with CaptureOutput

use of com.oracle.truffle.llvm.tests.pipe.CaptureOutput in project graal by oracle.

the class PolyglotToolchainTest method testIdentifier.

@Test
public void testIdentifier() throws IOException {
    try (CaptureOutput out = new CaptureNativeOutput()) {
        testLibrary.getMember("print_id").execute();
        Assert.assertEquals(String.format("ID=%s\n", getToolchain().getIdentifier().toString()), out.getStdOut());
    }
}
Also used : CaptureOutput(com.oracle.truffle.llvm.tests.pipe.CaptureOutput) CaptureNativeOutput(com.oracle.truffle.llvm.tests.pipe.CaptureNativeOutput) Test(org.junit.Test)

Example 9 with CaptureOutput

use of com.oracle.truffle.llvm.tests.pipe.CaptureOutput in project graal by oracle.

the class CaptureOutputTest method testOutputCapturing2.

@Test
public void testOutputCapturing2() throws IOException {
    String string = "Does it work again?";
    String captured;
    try (CaptureOutput out = new CaptureNativeOutput()) {
        System.out.print(string);
        captured = out.getStdOut();
    }
    System.out.println("MUST NOT BE IN CAPTURE");
    assertEquals(string, captured);
}
Also used : CaptureOutput(com.oracle.truffle.llvm.tests.pipe.CaptureOutput) CaptureNativeOutput(com.oracle.truffle.llvm.tests.pipe.CaptureNativeOutput) Test(org.junit.Test)

Example 10 with CaptureOutput

use of com.oracle.truffle.llvm.tests.pipe.CaptureOutput in project graal by oracle.

the class CaptureOutputTest method testErrCapturing2.

@Test
public void testErrCapturing2() throws IOException {
    String string = "Does it work again?";
    String captured;
    try (CaptureOutput out = new CaptureNativeOutput()) {
        System.err.print(string);
        captured = out.getStdErr();
    }
    System.err.println("MUST NOT BE IN CAPTURE");
    assertEquals(string, captured);
}
Also used : CaptureOutput(com.oracle.truffle.llvm.tests.pipe.CaptureOutput) CaptureNativeOutput(com.oracle.truffle.llvm.tests.pipe.CaptureNativeOutput) Test(org.junit.Test)

Aggregations

CaptureOutput (com.oracle.truffle.llvm.tests.pipe.CaptureOutput)11 CaptureNativeOutput (com.oracle.truffle.llvm.tests.pipe.CaptureNativeOutput)10 Test (org.junit.Test)10 TruffleFile (com.oracle.truffle.api.TruffleFile)2 File (java.io.File)2 LLVMLinkerException (com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)1 Context (org.graalvm.polyglot.Context)1 Builder (org.graalvm.polyglot.Context.Builder)1 Value (org.graalvm.polyglot.Value)1