aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJinhui Wang <jinhuiw@google.com>2016-06-21 23:02:56 -0700
committerJinhui Wang <jinhuiw@google.com>2016-06-21 23:05:50 -0700
commit50e07e715726f2d0ab330b2ba3432fd397d3fa1f (patch)
tree72027e9653979a23e5b07ad61c3faa27d1f9d707
parent8c28a9831d53a17178c4f3acd96ff992eef2eb77 (diff)
downloadAfwTestHarness-50e07e715726f2d0ab330b2ba3432fd397d3fa1f.tar.gz
Update a few target preparers
- Move a few methods to AfwTestTargetPreparer - Don't throw exception while trying to connect wifi Change-Id: Icec5358fe6b2d9aa10fdbd5ba0b5f40341530e0a
-rw-r--r--tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestFactoryReset.java35
-rw-r--r--tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestTargetPreparer.java43
-rw-r--r--tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestWifiPreparer.java9
3 files changed, 50 insertions, 37 deletions
diff --git a/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestFactoryReset.java b/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestFactoryReset.java
index 4c849f2..5ee82fa 100644
--- a/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestFactoryReset.java
+++ b/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestFactoryReset.java
@@ -25,8 +25,6 @@ import com.android.tradefed.device.ITestDevice;
import com.android.tradefed.log.LogUtil.CLog;
import com.android.tradefed.targetprep.ITargetPreparer;
import com.android.tradefed.targetprep.TargetSetupError;
-import com.android.tradefed.util.CommandResult;
-import com.android.tradefed.util.CommandStatus;
import java.util.concurrent.TimeUnit;
@@ -177,38 +175,5 @@ public class AfwTestFactoryReset extends AfwTestTargetPreparer implements ITarge
}
return result;
}
-
- /**
- * Wipes device via fastboot.
- *
- * @param device test device
- */
- private void wipeDevice(ITestDevice device)
- throws DeviceNotAvailableException, TargetSetupError {
-
- CLog.i(String.format("Wiping device %s".format(device.getSerialNumber())));
-
- device.rebootIntoBootloader();
- fastbootFormat(device, "cache");
- fastbootFormat(device, "userdata");
- device.executeFastbootCommand("reboot");
- }
-
- /**
- * Performs fastboot erase/format operation on certain partition
- *
- * @param device test device
- * @param partition android partition, e.g. userdata, cache, system
- */
- private void fastbootFormat(ITestDevice device, String partition)
- throws DeviceNotAvailableException, TargetSetupError {
-
- CLog.i("Attempting: fastboot format %s", partition);
- CommandResult r = device.executeLongFastbootCommand("format", partition);
- if (r.getStatus() != CommandStatus.SUCCESS) {
- throw new TargetSetupError(
- String.format("format %s failed: %s", partition, r.getStderr()));
- }
- }
}
diff --git a/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestTargetPreparer.java b/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestTargetPreparer.java
index b066374..3316e6b 100644
--- a/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestTargetPreparer.java
+++ b/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestTargetPreparer.java
@@ -22,18 +22,23 @@ import com.android.tradefed.build.IBuildInfo;
import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.device.ITestDevice;
import com.android.tradefed.device.PackageInfo;
+import com.android.tradefed.log.LogUtil.CLog;
import com.android.tradefed.targetprep.TargetSetupError;
+import com.android.tradefed.util.CommandResult;
+import com.android.tradefed.util.CommandStatus;
import com.android.tradefed.util.RunUtil;
import java.io.File;
import java.util.concurrent.TimeUnit;
+
/**
* Abstract class to keep common functionality.
*/
public abstract class AfwTestTargetPreparer {
private CtsBuildHelper mBuildHelper;
+ private Long mTimeoutSecs = TimeUnit.MINUTES.toSeconds(5);
/**
* Gets an instance of {@link CtsBuildHelper}.
@@ -135,5 +140,43 @@ public abstract class AfwTestTargetPreparer {
return TestConfig.getInstance().getTimeoutSize();
}
+
+ /**
+ * Wipes device via fastboot.
+ *
+ * <p>
+ * Refers to com.android.tradefed.targetprep.DeviceWiper
+ * </p>
+ *
+ * @param device test device
+ */
+ protected void wipeDevice(ITestDevice device)
+ throws DeviceNotAvailableException, TargetSetupError {
+
+ CLog.i(String.format("Wiping device %s".format(device.getSerialNumber())));
+
+ device.rebootIntoBootloader();
+ fastbootFormat(device, "cache");
+ fastbootFormat(device, "userdata");
+ device.executeFastbootCommand("reboot");
+ }
+
+
+ /**
+ * Performs fastboot erase/format operation on certain partition
+ *
+ * @param device test device
+ * @param partition android partition, e.g. userdata, cache, system
+ */
+ protected void fastbootFormat(ITestDevice device, String partition)
+ throws DeviceNotAvailableException, TargetSetupError {
+
+ CLog.i("Attempting: fastboot format %s", partition);
+ CommandResult r = device.executeLongFastbootCommand("format", partition);
+ if (r.getStatus() != CommandStatus.SUCCESS) {
+ throw new TargetSetupError(
+ String.format("format %s failed: %s", partition, r.getStderr()));
+ }
+ }
}
diff --git a/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestWifiPreparer.java b/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestWifiPreparer.java
index 1a039a4..ffa9def 100644
--- a/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestWifiPreparer.java
+++ b/tools/tradefed-host/src/com/android/afwtest/tradefed/targetprep/AfwTestWifiPreparer.java
@@ -91,8 +91,13 @@ public final class AfwTestWifiPreparer extends AfwTestTargetPreparer implements
// Implement retry.
for (int i = 0; i < mWifiAttempts; ++i) {
- if (device.connectToWifiNetworkIfNeeded(wifiSsid, wifiPassword)) {
- return;
+ try {
+
+ if (device.connectToWifiNetworkIfNeeded(wifiSsid, wifiPassword)) {
+ return;
+ }
+ } catch(Exception e) {
+ CLog.e("Error trying to connect to Wifi:", e);
}
boolean lastAttempt = (i + 1) == mWifiAttempts;
if (!lastAttempt) {