From d87d69d4f7e8053bb357eeb1667734eb7f7a0b6b Mon Sep 17 00:00:00 2001 From: Guang Zhu Date: Mon, 3 Oct 2016 14:58:25 -0700 Subject: 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 --- .../tradefed/targetprep/FastbootDeviceFlasher.java | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/com/android/tradefed') 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 @@ -175,6 +175,25 @@ public class FastbootDeviceFlasher implements IDeviceFlasher { handleFastbootResult(device, result, wipeMethod, partition); } + /** + * 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 * @@ -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()); } -- cgit v1.2.3