aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/com/android/tradefed/device/TestDeviceOptions.java1
-rw-r--r--src/com/android/tradefed/targetprep/DeviceCleaner.java3
-rw-r--r--src/com/android/tradefed/targetprep/DeviceWiper.java7
-rw-r--r--src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java23
-rw-r--r--tests/src/com/android/tradefed/targetprep/FastbootDeviceFlasherTest.java37
5 files changed, 63 insertions, 8 deletions
diff --git a/src/com/android/tradefed/device/TestDeviceOptions.java b/src/com/android/tradefed/device/TestDeviceOptions.java
index 851c70b79..ffb2cb064 100644
--- a/src/com/android/tradefed/device/TestDeviceOptions.java
+++ b/src/com/android/tradefed/device/TestDeviceOptions.java
@@ -16,7 +16,6 @@
package com.android.tradefed.device;
import com.android.tradefed.config.Option;
-import com.android.tradefed.log.LogUtil.CLog;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/com/android/tradefed/targetprep/DeviceCleaner.java b/src/com/android/tradefed/targetprep/DeviceCleaner.java
index e2d1c184d..60024f26a 100644
--- a/src/com/android/tradefed/targetprep/DeviceCleaner.java
+++ b/src/com/android/tradefed/targetprep/DeviceCleaner.java
@@ -104,8 +104,7 @@ public class DeviceCleaner implements ITargetCleaner {
break;
case FORMAT:
device.rebootIntoBootloader();
- device.executeLongFastbootCommand("format", "cache");
- device.executeLongFastbootCommand("format", "userdata");
+ device.executeLongFastbootCommand("-w");
device.executeFastbootCommand("reboot");
device.waitForDeviceAvailable();
break;
diff --git a/src/com/android/tradefed/targetprep/DeviceWiper.java b/src/com/android/tradefed/targetprep/DeviceWiper.java
index b3e1663c8..d916c364d 100644
--- a/src/com/android/tradefed/targetprep/DeviceWiper.java
+++ b/src/com/android/tradefed/targetprep/DeviceWiper.java
@@ -56,8 +56,11 @@ public class DeviceWiper implements ITargetPreparer {
}
private void doFormat(ITestDevice device) throws DeviceNotAvailableException, TargetSetupError {
- performFastbootOp(device, "format", "cache");
- performFastbootOp(device, "format", "userdata");
+ CLog.d("Attempting fastboot wiping");
+ CommandResult r = device.executeLongFastbootCommand("-w");
+ if (r.getStatus() != CommandStatus.SUCCESS) {
+ throw new TargetSetupError(String.format("fastboot wiping failed: %s", r.getStderr()));
+ }
}
private void doErase(ITestDevice device) throws DeviceNotAvailableException, TargetSetupError {
diff --git a/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java b/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java
index 75c7e5ee1..88575d2e2 100644
--- a/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java
+++ b/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java
@@ -119,15 +119,32 @@ public class FastbootDeviceFlasher implements IDeviceFlasher {
device.rebootIntoBootloader();
downloadFlashingResources(device, deviceBuild);
-
+ handleUserDataFlashing(device, deviceBuild);
checkAndFlashBootloader(device, deviceBuild);
checkAndFlashBaseband(device, deviceBuild);
- flashUserData(device, deviceBuild);
- wipeCache(device);
checkAndFlashSystem(device, systemBuildId, systemBuildFlavor, deviceBuild);
}
/**
+ * Handle flashing of userdata/cache partition
+ * @param device the {@link ITestDevice} to flash
+ * @param deviceBuild the {@link IDeviceBuildInfo} that contains the files to flash
+ * @throws DeviceNotAvailableException
+ * @throws TargetSetupError
+ */
+ protected void handleUserDataFlashing(ITestDevice device, IDeviceBuildInfo deviceBuild)
+ throws DeviceNotAvailableException, TargetSetupError {
+ if (UserDataFlashOption.FORCE_WIPE.equals(mUserDataFlashOption) ||
+ UserDataFlashOption.WIPE.equals(mUserDataFlashOption)) {
+ CommandResult result = device.executeFastbootCommand("-w");
+ handleFastbootResult(device, result, "-w");
+ } else {
+ flashUserData(device, deviceBuild);
+ wipeCache(device);
+ }
+ }
+
+ /**
* Flash an individual partition of a device
*
* @param device the {@link ITestDevice} to flash
diff --git a/tests/src/com/android/tradefed/targetprep/FastbootDeviceFlasherTest.java b/tests/src/com/android/tradefed/targetprep/FastbootDeviceFlasherTest.java
index c60eb826d..609fc7fec 100644
--- a/tests/src/com/android/tradefed/targetprep/FastbootDeviceFlasherTest.java
+++ b/tests/src/com/android/tradefed/targetprep/FastbootDeviceFlasherTest.java
@@ -199,6 +199,43 @@ public class FastbootDeviceFlasherTest extends TestCase {
}
/**
+ * Verify that correct fastboot command is called with WIPE data option
+ * @throws DeviceNotAvailableException
+ * @throws TargetSetupError
+ */
+ public void testFlashUserData_wipe() throws DeviceNotAvailableException, TargetSetupError {
+ mFlasher.setUserDataFlashOption(UserDataFlashOption.WIPE);
+ doTestFlashWithWipe();
+ }
+
+ /**
+ * Verify that correct fastboot command is called with FORCE_WIPE data option
+ * @throws DeviceNotAvailableException
+ * @throws TargetSetupError
+ */
+ public void testFlashUserData_forceWipe() throws DeviceNotAvailableException, TargetSetupError {
+ mFlasher.setUserDataFlashOption(UserDataFlashOption.FORCE_WIPE);
+ doTestFlashWithWipe();
+ }
+
+ /**
+ * Convenience function to set expectations for `fastboot -w` and execute test
+ * @throws DeviceNotAvailableException
+ * @throws TargetSetupError
+ */
+ private void doTestFlashWithWipe() throws DeviceNotAvailableException, TargetSetupError {
+ CommandResult result = new CommandResult();
+ result.setStatus(CommandStatus.SUCCESS);
+ result.setStderr("");
+ result.setStdout("");
+ EasyMock.expect(mMockDevice.executeFastbootCommand("-w")).andReturn(result);
+
+ EasyMock.replay(mMockDevice);
+ mFlasher.handleUserDataFlashing(mMockDevice, mMockBuildInfo);
+ EasyMock.verify(mMockDevice);
+ }
+
+ /**
* Test doing a user data with with rm
*
* @throws TargetSetupError