diff options
author | Guang Zhu <guangzhu@google.com> | 2016-10-03 14:58:25 -0700 |
---|---|---|
committer | Guang Zhu <guangzhu@google.com> | 2016-10-05 16:22:21 +0000 |
commit | d87d69d4f7e8053bb357eeb1667734eb7f7a0b6b (patch) | |
tree | a99767ed5907b1ad833e1aa492506e204ba1d9ed /src/com/android/tradefed | |
parent | 1f9b9dea429d0ad1dcd367fb8a0d58cf940f3c8a (diff) | |
download | tradefederation-d87d69d4f7e8053bb357eeb1667734eb7f7a0b6b.tar.gz |
check existence for cache before wiping
We have devices without cache partition, and certain code path
triggers #wipeCache() instead of using 'fastboot -w', so we need
to check partition existence before proceeding.
Bug: 30478349
Test: added unit test passes
$ tradefed.sh run google/util/flash --product-type ### \
--branch git_master --build-flavor ###-userdebug_asan \
--userdata-flash FLASH_IMG_ZIP
# above command ends in tool failure without the change
Change-Id: I82dc93d975a48536524fce5b75a9d04d80b648f1
Diffstat (limited to 'src/com/android/tradefed')
-rw-r--r-- | src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java b/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java index ce0aa7019..b0c20c396 100644 --- a/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java +++ b/src/com/android/tradefed/targetprep/FastbootDeviceFlasher.java @@ -176,6 +176,25 @@ public class FastbootDeviceFlasher implements IDeviceFlasher { } /** + * Checks with the bootloader if the specified partition exists or not + * + * @param device the {@link ITestDevice} to operate on + * @param partition the name of the partition to be checked + */ + protected boolean hasPartition(ITestDevice device, String partition) + throws DeviceNotAvailableException { + String partitionType = String.format("partition-type:%s", partition); + CommandResult result = device.executeFastbootCommand("getvar", partitionType); + if (!CommandStatus.SUCCESS.equals(result.getStatus()) + || result.getStderr().contains("FAILED")) { + return false; + } + Pattern regex = Pattern.compile(String.format("^%s:\\s*\\S+$", partitionType), + Pattern.MULTILINE); + return regex.matcher(result.getStderr()).find(); + } + + /** * Downloads extra flashing image files needed * * @param device the {@link ITestDevice} to download resources for @@ -398,7 +417,10 @@ public class FastbootDeviceFlasher implements IDeviceFlasher { // only wipe cache if user data is being wiped if (!mUserDataFlashOption.equals(UserDataFlashOption.RETAIN)) { CLog.i("Wiping cache on %s", device.getSerialNumber()); - wipePartition(device, "cache"); + String partition = "cache"; + if (hasPartition(device, partition)) { + wipePartition(device, partition); + } } else { CLog.d("Skipping cache wipe on %s", device.getSerialNumber()); } |