aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tradefed/targetprep
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/tradefed/targetprep')
-rw-r--r--src/com/android/tradefed/targetprep/CrashCollector.java14
-rw-r--r--src/com/android/tradefed/targetprep/NativeLeakCollector.java15
-rw-r--r--src/com/android/tradefed/targetprep/RunCommandTargetPreparer.java20
3 files changed, 36 insertions, 13 deletions
diff --git a/src/com/android/tradefed/targetprep/CrashCollector.java b/src/com/android/tradefed/targetprep/CrashCollector.java
index 3c17023e1..297b578a3 100644
--- a/src/com/android/tradefed/targetprep/CrashCollector.java
+++ b/src/com/android/tradefed/targetprep/CrashCollector.java
@@ -49,6 +49,10 @@ public class CrashCollector extends TestFilePushSetup
description = "Path to crashcollector binary in test artifact bundle.")
private String mCrashCollectorPath = "local/tmp/crashcollector";
+ @Option(name = "crash-collector-binary",
+ description = "The name of crashcollector binary in test artifact bundle.")
+ private String mCrashCollectorBinary = "crashcollector";
+
@Option(name = "disable", description = "If this preparer should be disabled.")
private boolean mDisable = false;
@@ -63,10 +67,11 @@ public class CrashCollector extends TestFilePushSetup
// first get pseudo API level to check for platform support
String codeName = device.getProperty("ro.build.version.codename").trim();
int apiLevel = device.getApiLevel();
- if ("!REL".equals(codeName)) {
+ if (!"REL".equals(codeName)) {
apiLevel++;
}
if (apiLevel < 24) {
+ CLog.i("API Level too low: %s.", apiLevel);
return true;
}
if (!(buildInfo instanceof IDeviceBuildInfo)) {
@@ -85,6 +90,7 @@ public class CrashCollector extends TestFilePushSetup
throws TargetSetupError, BuildError, DeviceNotAvailableException {
mDisable = shouldDisable(device, buildInfo);
if (mDisable) {
+ CLog.i("Crash collector disabled.");
return;
}
// clear all existing test file names, since we may receive that from the parameter defined
@@ -93,10 +99,12 @@ public class CrashCollector extends TestFilePushSetup
clearTestFileName();
addTestFileName(mCrashCollectorPath);
super.setUp(device, buildInfo);
+ String crashCollectorPath = String.format("/data/%s/%s",
+ mCrashCollectorPath, mCrashCollectorBinary);
+ device.executeShellCommand("chmod 755 " + crashCollectorPath);
mCrashReceiver = new LargeOutputReceiver("crash-collector",
device.getSerialNumber(), mMaxCrashLogSize);
- mCrashCollector = new BackgroundDeviceAction(
- "/data/local/tmp/crashcollector/crashcollector", "crash-collector",
+ mCrashCollector = new BackgroundDeviceAction(crashCollectorPath, "crash-collector",
device, mCrashReceiver, 0);
mCrashCollector.start();
}
diff --git a/src/com/android/tradefed/targetprep/NativeLeakCollector.java b/src/com/android/tradefed/targetprep/NativeLeakCollector.java
index 1659181ad..9c5db4d2e 100644
--- a/src/com/android/tradefed/targetprep/NativeLeakCollector.java
+++ b/src/com/android/tradefed/targetprep/NativeLeakCollector.java
@@ -16,18 +16,13 @@
package com.android.tradefed.targetprep;
import com.android.tradefed.build.IBuildInfo;
-import com.android.tradefed.build.IDeviceBuildInfo;
import com.android.tradefed.config.Option;
import com.android.tradefed.config.OptionClass;
-import com.android.tradefed.device.BackgroundDeviceAction;
import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.device.ITestDevice;
-import com.android.tradefed.device.LargeOutputReceiver;
import com.android.tradefed.log.ITestLogger;
-import com.android.tradefed.log.LogUtil.CLog;
import com.android.tradefed.result.ByteArrayInputStreamSource;
import com.android.tradefed.result.ITestLoggerReceiver;
-import com.android.tradefed.result.InputStreamSource;
import com.android.tradefed.result.LogDataType;
import com.android.tradefed.util.StreamUtil;
@@ -40,13 +35,18 @@ import com.android.tradefed.util.StreamUtil;
@OptionClass(alias = "native-leak-collector")
public class NativeLeakCollector implements ITestLoggerReceiver, ITargetCleaner {
private static final String UNREACHABLE_MEMINFO_CMD =
- "dumpsys -t 60 meminfo --unreachable -a";
+ "dumpsys -t %d meminfo --unreachable -a";
private ITestLogger mTestLogger;
@Option(name = "disable", description = "If this preparer should be disabled.")
private boolean mDisable = false;
+ @Option(name = "dump-timeout", description = "Timeout limit in for dumping unreachable native "
+ + "memory allocation information. Can be in any valid duration format, e.g. 5m, 1h",
+ isTimeVal = true)
+ private long mDumpTimeout = 5 * 60 * 1000; // defaults to 5m
+
@Option(name = "log-filename", description = "The filename to give this log.")
private String mLogFilename = "unreachable-meminfo";
@@ -69,7 +69,8 @@ public class NativeLeakCollector implements ITestLoggerReceiver, ITargetCleaner
return;
}
- String output = device.executeShellCommand(UNREACHABLE_MEMINFO_CMD);
+ String output = device.executeShellCommand(String.format(
+ UNREACHABLE_MEMINFO_CMD, mDumpTimeout / 1000));
if (output != null && !output.isEmpty()) {
ByteArrayInputStreamSource byteOutput =
new ByteArrayInputStreamSource(output.getBytes());
diff --git a/src/com/android/tradefed/targetprep/RunCommandTargetPreparer.java b/src/com/android/tradefed/targetprep/RunCommandTargetPreparer.java
index 5b1131d70..1caf5d3bf 100644
--- a/src/com/android/tradefed/targetprep/RunCommandTargetPreparer.java
+++ b/src/com/android/tradefed/targetprep/RunCommandTargetPreparer.java
@@ -19,13 +19,14 @@ package com.android.tradefed.targetprep;
import com.android.tradefed.build.IBuildInfo;
import com.android.tradefed.config.Option;
import com.android.tradefed.config.OptionClass;
+import com.android.tradefed.device.CollectingOutputReceiver;
import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.device.ITestDevice;
import com.android.tradefed.log.LogUtil.CLog;
import com.android.tradefed.util.RunUtil;
-
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
@OptionClass(alias = "run-command")
public class RunCommandTargetPreparer implements ITargetCleaner {
@@ -42,18 +43,31 @@ public class RunCommandTargetPreparer implements ITargetCleaner {
description = "Time to delay after running commands, in msecs")
private long mDelayMsecs = 0;
+ @Option(name = "run-command-timeout",
+ description = "Timeout for execute shell command",
+ isTimeVal = true)
+ private long mRunCmdTimeout = 0;
+
+
/**
* {@inheritDoc}
*/
@Override
public void setUp(ITestDevice device, IBuildInfo buildInfo) throws TargetSetupError,
DeviceNotAvailableException {
- if (mDisable) return;
+ if (mDisable)
+ return;
for (String cmd : mCommands) {
// If the command had any output, the executeShellCommand method will log it at the
// VERBOSE level; so no need to do any logging from here.
CLog.d("About to run setup command on device %s: %s", device.getSerialNumber(), cmd);
- device.executeShellCommand(cmd);
+ if (mRunCmdTimeout > 0) {
+ CollectingOutputReceiver receiver = new CollectingOutputReceiver();
+ device.executeShellCommand(cmd, receiver, mRunCmdTimeout, TimeUnit.MILLISECONDS, 0);
+ CLog.v("%s returned %s", cmd, receiver.getOutput());
+ } else {
+ device.executeShellCommand(cmd);
+ }
}
CLog.d("Sleeping %d msecs on device %s", mDelayMsecs, device.getSerialNumber());