diff options
author | JW Wang <wangchun@google.com> | 2020-02-13 18:47:22 +0800 |
---|---|---|
committer | JW Wang <wangchun@google.com> | 2020-02-17 22:08:39 +0800 |
commit | 99c5b20bbdac368852b93514e9844798f7646cfa (patch) | |
tree | b7df53eb7c8c4455bb669193f6c4767f6a382c75 /tests/RollbackTest | |
parent | 80288de910c82d95506f624e236cd840383693a1 (diff) |
Speed up tests
Don't reboot the device when there is no file to delete. This saves us a
significant amount of time since each reboot takes 1 min and there are
dozens of reboot during the whole test case.
Bug: 149528114
Test: atest StagedRollbackTest
Change-Id: If3b06a304d9c87680c7cc5b7498d3b2ecf11cdfa
Diffstat (limited to 'tests/RollbackTest')
-rw-r--r-- | tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java | 51 |
1 files changed, 32 insertions, 19 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 8104d1dbb8ac..43759cf4b761 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,8 @@ import static org.testng.Assert.assertThrows; import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import com.android.tradefed.util.CommandResult; +import com.android.tradefed.util.CommandStatus; import org.junit.After; import org.junit.Before; @@ -83,14 +85,8 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { @Before public void setUp() throws Exception { - if (!getDevice().isAdbRoot()) { - getDevice().enableAdbRoot(); - } - getDevice().remountSystemWritable(); - getDevice().executeShellCommand( - "rm -f /system/apex/" + APK_IN_APEX_TESTAPEX_NAME + "*.apex " - + "/data/apex/active/" + APK_IN_APEX_TESTAPEX_NAME + "*.apex"); - getDevice().reboot(); + deleteFiles("/system/apex/" + APK_IN_APEX_TESTAPEX_NAME + "*.apex", + "/data/apex/active/" + APK_IN_APEX_TESTAPEX_NAME + "*.apex"); runPhase("testCleanUp"); mLogger.start(getDevice()); } @@ -99,19 +95,36 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { public void tearDown() throws Exception { mLogger.stop(); runPhase("testCleanUp"); + deleteFiles("/system/apex/" + APK_IN_APEX_TESTAPEX_NAME + "*.apex", + "/data/apex/active/" + APK_IN_APEX_TESTAPEX_NAME + "*.apex", + apexDataDirDeSys(APK_IN_APEX_TESTAPEX_NAME) + "*", + apexDataDirCe(APK_IN_APEX_TESTAPEX_NAME, 0) + "*"); + } - if (!getDevice().isAdbRoot()) { - getDevice().enableAdbRoot(); + /** + * Deletes files and reboots the device if necessary. + * @param files the paths of files which might contain wildcards + */ + private void deleteFiles(String... files) throws Exception { + boolean found = false; + for (String file : files) { + CommandResult result = getDevice().executeShellV2Command("ls " + file); + if (result.getStatus() == CommandStatus.SUCCESS) { + found = true; + break; + } + } + + if (found) { + if (!getDevice().isAdbRoot()) { + getDevice().enableAdbRoot(); + } + getDevice().remountSystemWritable(); + for (String file : files) { + getDevice().executeShellCommand("rm -rf " + file); + } + getDevice().reboot(); } - getDevice().remountSystemWritable(); - getDevice().executeShellCommand( - "rm -f /system/apex/" + APK_IN_APEX_TESTAPEX_NAME + "*.apex " - + "/data/apex/active/" + APK_IN_APEX_TESTAPEX_NAME + "*.apex"); - getDevice().executeShellCommand( - "rm -rf " + apexDataDirDeSys(APK_IN_APEX_TESTAPEX_NAME) + "*"); - getDevice().executeShellCommand( - "rm -rf " + apexDataDirCe(APK_IN_APEX_TESTAPEX_NAME, 0) + "*"); - getDevice().reboot(); } /** |