summaryrefslogtreecommitdiffstats
path: root/jack-tests
diff options
context:
space:
mode:
authorJean-Marie Henaff <jmhenaff@google.com>2014-12-17 16:34:03 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-12-17 16:34:03 +0000
commit48a28485a6a7eee3df3cba19cedea4954407e095 (patch)
treec9eadf86fe84c853d23f9289188abff2555bdf36 /jack-tests
parent09b72859dc18177a8db2c7f73f2dbd7d3327da0e (diff)
parent36117dc78b13c259ddaf48a9117a944924d26cfc (diff)
downloadtoolchain_jack-48a28485a6a7eee3df3cba19cedea4954407e095.zip
toolchain_jack-48a28485a6a7eee3df3cba19cedea4954407e095.tar.gz
toolchain_jack-48a28485a6a7eee3df3cba19cedea4954407e095.tar.bz2
Merge "Remove PrintStream wrapper for Runners output redirection" into ub-jack
Diffstat (limited to 'jack-tests')
-rw-r--r--jack-tests/src/com/android/jack/test/runner/AbstractRuntimeRunner.java25
-rw-r--r--jack-tests/src/com/android/jack/test/runner/DeviceRunner.java42
2 files changed, 30 insertions, 37 deletions
diff --git a/jack-tests/src/com/android/jack/test/runner/AbstractRuntimeRunner.java b/jack-tests/src/com/android/jack/test/runner/AbstractRuntimeRunner.java
index a20ff93..4530dbf 100644
--- a/jack-tests/src/com/android/jack/test/runner/AbstractRuntimeRunner.java
+++ b/jack-tests/src/com/android/jack/test/runner/AbstractRuntimeRunner.java
@@ -19,7 +19,6 @@ package com.android.jack.test.runner;
import java.io.File;
import java.io.OutputStream;
-import java.io.PrintStream;
import javax.annotation.Nonnull;
@@ -30,9 +29,9 @@ import javax.annotation.Nonnull;
public abstract class AbstractRuntimeRunner extends RuntimeRunner {
@Nonnull
- protected PrintStream outRedirectStream = System.out;
+ protected OutputStream outRedirectStream = System.out;
@Nonnull
- protected PrintStream errRedirectStream = System.err;
+ protected OutputStream errRedirectStream = System.err;
protected AbstractRuntimeRunner(@Nonnull File rtEnvRootDir) {
super(rtEnvRootDir);
@@ -44,30 +43,14 @@ public abstract class AbstractRuntimeRunner extends RuntimeRunner {
@Nonnull
public final AbstractRuntimeRunner setOutputStream(@Nonnull OutputStream outputStream) {
- if (outRedirectStream != null) {
- outRedirectStream.close();
- }
- outRedirectStream = new PrintStream(outputStream);
+ outRedirectStream = outputStream;
return this;
}
@Nonnull
public final AbstractRuntimeRunner setErrorStream(@Nonnull OutputStream errorStream) {
- if (errRedirectStream != null) {
- errRedirectStream.close();
- }
- errRedirectStream = new PrintStream(errorStream);
+ errRedirectStream = errorStream;
return this;
}
- @Nonnull
- public PrintStream getOutStream() {
- return outRedirectStream;
- }
-
- @Nonnull
- public PrintStream getErrStream() {
- return errRedirectStream;
- }
-
}
diff --git a/jack-tests/src/com/android/jack/test/runner/DeviceRunner.java b/jack-tests/src/com/android/jack/test/runner/DeviceRunner.java
index 973df5b..3f20db5 100644
--- a/jack-tests/src/com/android/jack/test/runner/DeviceRunner.java
+++ b/jack-tests/src/com/android/jack/test/runner/DeviceRunner.java
@@ -34,6 +34,7 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
+import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;
@@ -49,21 +50,30 @@ public abstract class DeviceRunner extends AbstractRuntimeRunner {
@Nonnull
public static final File ANDROID_DATA_DIR = new File("/data");
+ @Nonnull
private static final long ADB_CONNECTION_TIMEOUT = 5000;
+ @Nonnull
private static final long ADB_WAIT_STEP = ADB_CONNECTION_TIMEOUT / 10;
+ @Nonnull
private static final String TEST_SCRIPT_NAME = "test-exit-status.sh";
+ @Nonnull
private static final File TEST_SCRIPT_FILE =
new File(AbstractTestTools.getJackRootDir(), "etc/" + TEST_SCRIPT_NAME);
@Nonnull
+ private PrintStream out = new PrintStream(outRedirectStream);
+ @Nonnull
+ private PrintStream err = new PrintStream(errRedirectStream);
+
+ @Nonnull
private MyShellOuputReceiver shellOutput = new MyShellOuputReceiver();
private class MyShellOuputReceiver implements IShellOutputReceiver {
@Override
public void addOutput(@Nonnull byte[] data, int offset, int length) {
- outRedirectStream.println(new String(Arrays.copyOfRange(data, offset, offset + length)));
+ out.println(new String(Arrays.copyOfRange(data, offset, offset + length)));
}
@Override
@@ -88,11 +98,11 @@ public abstract class DeviceRunner extends AbstractRuntimeRunner {
private class ShellOutputToStringReceiver implements IShellOutputReceiver {
@Nonnull
- StringBuffer out = new StringBuffer();
+ StringBuffer outBuffer = new StringBuffer();
@Override
public void addOutput(@Nonnull byte[] data, int offset, int length) {
- out.append(new String(Arrays.copyOfRange(data, offset, offset + length)));
+ outBuffer.append(new String(Arrays.copyOfRange(data, offset, offset + length)));
}
@Override
@@ -106,7 +116,7 @@ public abstract class DeviceRunner extends AbstractRuntimeRunner {
@Nonnull
public String getOutput() {
- return out.toString();
+ return outBuffer.toString();
}
}
@@ -120,7 +130,7 @@ public abstract class DeviceRunner extends AbstractRuntimeRunner {
long start = System.currentTimeMillis();
if (isVerbose) {
- outRedirectStream.println("Initializing adb...");
+ out.println("Initializing adb...");
}
while (!isAdbInitialized(adb)) {
@@ -139,7 +149,7 @@ public abstract class DeviceRunner extends AbstractRuntimeRunner {
}
if (isVerbose) {
- outRedirectStream.println("Done");
+ out.println("Done");
}
IDevice[] connectedDevices = adb.getDevices();
@@ -154,7 +164,7 @@ public abstract class DeviceRunner extends AbstractRuntimeRunner {
checkDeviceRuntime(device);
if (isVerbose) {
- outRedirectStream.println("Running on device: " + device.getName());
+ out.println("Running on device: " + device.getName());
}
ensureAdbRoot(device);
@@ -163,13 +173,13 @@ public abstract class DeviceRunner extends AbstractRuntimeRunner {
File[] desFilePaths = new File[classpathFiles.length];
try {
if (isVerbose) {
- outRedirectStream.println("adb shell -s " + device.getSerialNumber() + " mkdir "
+ out.println("adb shell -s " + device.getSerialNumber() + " mkdir "
+ testsRootDir.getAbsolutePath());
}
device.executeShellCommand("mkdir " + testsRootDir.getAbsolutePath(), shellOutput);
if (isVerbose) {
- outRedirectStream.println("adb -s " + device.getSerialNumber() + " push "
+ out.println("adb -s " + device.getSerialNumber() + " push "
+ TEST_SCRIPT_FILE.getAbsolutePath() + " "
+ testsRootDir.getAbsolutePath() + '/' + TEST_SCRIPT_NAME);
}
@@ -177,7 +187,7 @@ public abstract class DeviceRunner extends AbstractRuntimeRunner {
testsRootDir.getAbsolutePath() + '/' + TEST_SCRIPT_NAME);
if (isVerbose) {
- outRedirectStream.println("adb -s " + device.getSerialNumber() + " shell chmod 777 "
+ out.println("adb -s " + device.getSerialNumber() + " shell chmod 777 "
+ testsRootDir.getAbsolutePath() + '/' + TEST_SCRIPT_NAME);
}
device.executeShellCommand(
@@ -188,7 +198,7 @@ public abstract class DeviceRunner extends AbstractRuntimeRunner {
desFilePaths[i] = new File(testsRootDir, "f" + i + "_" + f.getName());
if (isVerbose) {
- outRedirectStream.println("adb -s " + device.getSerialNumber() + " push "
+ out.println("adb -s " + device.getSerialNumber() + " push "
+ f.getAbsolutePath() + " " + desFilePaths[i].getAbsolutePath());
}
device.pushFile(f.getAbsolutePath(), desFilePaths[i].getAbsolutePath());
@@ -215,7 +225,7 @@ public abstract class DeviceRunner extends AbstractRuntimeRunner {
// https://code.google.com/p/go/source/browse/misc/arm/a
if (isVerbose) {
- outRedirectStream.println("adb -s " + device.getSerialNumber() + " shell "
+ out.println("adb -s " + device.getSerialNumber() + " shell "
+ testsRootDir.getAbsolutePath() + '/' + TEST_SCRIPT_NAME + ' ' + args);
}
device.executeShellCommand(
@@ -224,7 +234,7 @@ public abstract class DeviceRunner extends AbstractRuntimeRunner {
File exitStatusFile = AbstractTestTools.createTempFile("exitStatus", "");
if (isVerbose) {
- outRedirectStream.println("adb -s " + device.getSerialNumber() + " pull "
+ out.println("adb -s " + device.getSerialNumber() + " pull "
+ testsRootDir.getAbsolutePath() + "/exitStatus " + exitStatusFile.getAbsolutePath());
}
device.pullFile(testsRootDir.getAbsolutePath() + "/exitStatus",
@@ -242,19 +252,19 @@ public abstract class DeviceRunner extends AbstractRuntimeRunner {
}
if (isVerbose) {
- outRedirectStream.println("Exit status: " + exitStatus);
+ out.println("Exit status: " + exitStatus);
}
for (File pushedFile : desFilePaths) {
if (isVerbose) {
- outRedirectStream.println(
+ out.println(
"adb -s " + device.getSerialNumber() + "rm " + pushedFile.getAbsolutePath());
}
device.executeShellCommand("rm " + pushedFile.getAbsolutePath(), shellOutput);
}
if (exitStatus != 0) {
- errRedirectStream.println("Execution failed on device '" + device.getName() + "'");
+ err.println("Execution failed on device '" + device.getName() + "'");
break;
}