From cde1a0fce0c07970d24123916bafb072f19edeb4 Mon Sep 17 00:00:00 2001 From: JW Wang Date: Wed, 14 Oct 2020 16:29:57 +0800 Subject: [PATCH] Don't fail #getSnapshotDirectories siliently (2/n) Let's verify the theory in b/170689774#comment4 where the 'after' list is incorrectly calculated because the 1st #getSnapshotDirectories fails. Bug: 170689774 Test: atest StagedRollbackTest Change-Id: I0570df4642e923d69092bd66125520cb30253863 --- .../rollback/host/StagedRollbackTest.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java b/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java index 9bf6b6f2aaa4d..6662b0e199fb0 100644 --- a/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +++ b/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java @@ -27,6 +27,7 @@ import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper; +import com.android.ddmlib.Log; import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.device.IFileEntry; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; @@ -53,6 +54,7 @@ import java.util.stream.Collectors; */ @RunWith(DeviceJUnit4ClassRunner.class) public class StagedRollbackTest extends BaseHostJUnit4Test { + private static final String TAG = "StagedRollbackTest"; private static final int NATIVE_CRASHES_THRESHOLD = 5; /** @@ -556,16 +558,18 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { return String.format("/data/user_de/%d/%s", userId, apexName); } - private List getSnapshotDirectories(String baseDir) { - try { - return getDevice().getFileEntry(baseDir).getChildren(false) - .stream().filter(entry -> entry.getName().matches("\\d+(-prerestore)?")) - .map(entry -> entry.getFullPath()) - .collect(Collectors.toList()); - } catch (Exception e) { - // Return an empty list if any error + private List getSnapshotDirectories(String baseDir) throws Exception { + IFileEntry f = getDevice().getFileEntry(baseDir); + if (f == null) { + Log.d(TAG, "baseDir doesn't exist: " + baseDir); return Collections.EMPTY_LIST; } + List list = f.getChildren(false) + .stream().filter(entry -> entry.getName().matches("\\d+(-prerestore)?")) + .map(entry -> entry.getFullPath()) + .collect(Collectors.toList()); + Log.d(TAG, "getSnapshotDirectories=" + list); + return list; } private void assertDirectoryIsEmpty(String path) {