blob: 7505a835e6f61fa87502037b2368b54174768a4d [file] [log] [blame]
// Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8;
import com.android.tools.r8.TestBase.Backend;
import com.android.tools.r8.ToolHelper.ProcessResult;
import com.android.tools.r8.errors.Unreachable;
import com.android.tools.r8.utils.AndroidApp;
import com.android.tools.r8.utils.codeinspector.CodeInspector;
import java.io.IOException;
import java.nio.file.Path;
import java.util.concurrent.ExecutionException;
public abstract class TestCompileResult {
final TestState state;
final AndroidApp app;
TestCompileResult(TestState state, AndroidApp app) {
this.state = state;
this.app = app;
}
public abstract Backend getBackend();
public TestRunResult run(Class<?> mainClass) throws IOException {
return run(mainClass.getTypeName());
}
public TestRunResult run(String mainClass) throws IOException {
switch (getBackend()) {
case DEX:
return runArt(mainClass);
case CF:
return runJava(mainClass);
default:
throw new Unreachable();
}
}
public TestCompileResult writeToZip(Path file) throws IOException {
app.writeToZip(
file, getBackend() == Backend.DEX ? OutputMode.DexIndexed : OutputMode.ClassFile);
return this;
}
public CodeInspector inspector() throws IOException, ExecutionException {
return new CodeInspector(app);
}
private TestRunResult runJava(String mainClass) throws IOException {
Path out = state.getNewTempFolder().resolve("out.zip");
app.writeToZip(out, OutputMode.ClassFile);
ProcessResult result = ToolHelper.runJava(out, mainClass);
return new TestRunResult(app, result);
}
private TestRunResult runArt(String mainClass) throws IOException {
Path out = state.getNewTempFolder().resolve("out.zip");
app.writeToZip(out, OutputMode.DexIndexed);
ProcessResult result = ToolHelper.runArtRaw(out.toString(), mainClass);
return new TestRunResult(app, result);
}
}