summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiakai Zhang <jiakaiz@google.com>2023-02-15 16:02:45 +0000
committerJiakai Zhang <jiakaiz@google.com>2023-03-15 16:23:01 +0000
commitd035dab3dd256fd6cc4684d6f94b2e925b6e8edb (patch)
treed8182edbbfbaadcf149efe7388cd0aaf13c26a25
parent3d927f06d730166746c671198195f2148f487fee (diff)
downloadart-d035dab3dd256fd6cc4684d6f94b2e925b6e8edb.tar.gz
Restore the test state before every test in OdrefreshHostTest.
To save time, we don't run odrefresh before every test to reset the test state. Therefore, the test state can leak from one test to another. This used to be fine because it used to be the case that all the tests ended in a clean state, where the artifacts all exist and are up-to-date. However, this is no longer true since aosp/2366494, which introduced a test that ends in the state where the artifacts are in "verify" rather than the normal "speed-profile" filter, causing any test the runs after it to fail. It's possible to fix that test, but the pitfall that every test has to end in a clean state will remain. Instead of doing this, this change added code to backup the artifacts and restore them before every test to make sure every test starts in a clean state. Bug: 269223220 Test: atest odsign_e2e_tests_full:OdrefreshHostTest Change-Id: I7ccd6ae56c7c802d9278fad89e196d640bae8c90 Merged-In: I7ccd6ae56c7c802d9278fad89e196d640bae8c90
-rw-r--r--test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java33
1 files changed, 17 insertions, 16 deletions
diff --git a/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java b/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java
index cf6c5ba773..60709f11a7 100644
--- a/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java
+++ b/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java
@@ -27,7 +27,6 @@ import com.android.tradefed.testtype.junit4.AfterClassWithInfo;
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
import com.android.tradefed.testtype.junit4.BeforeClassWithInfo;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,6 +46,8 @@ public class OdrefreshHostTest extends BaseHostJUnit4Test {
private static final String CACHE_INFO_FILE =
OdsignTestUtils.ART_APEX_DALVIK_CACHE_DIRNAME + "/cache-info.xml";
private static final String ODREFRESH_BIN = "odrefresh";
+ private static final String ART_APEX_DALVIK_CACHE_BACKUP_DIRNAME =
+ OdsignTestUtils.ART_APEX_DALVIK_CACHE_DIRNAME + ".bak";
private static final String TAG = "OdrefreshHostTest";
private static final String ZYGOTE_ARTIFACTS_KEY = TAG + ":ZYGOTE_ARTIFACTS";
@@ -70,10 +71,19 @@ public class OdrefreshHostTest extends BaseHostJUnit4Test {
testInfo.properties().put(ZYGOTE_ARTIFACTS_KEY, String.join(":", zygoteArtifacts));
testInfo.properties()
.put(SYSTEM_SERVER_ARTIFACTS_KEY, String.join(":", systemServerArtifacts));
+
+ // Backup the artifacts.
+ testInfo.getDevice().executeShellV2Command(
+ String.format("rm -rf '%s'", ART_APEX_DALVIK_CACHE_BACKUP_DIRNAME));
+ testUtils.assertCommandSucceeds(
+ String.format("cp -r '%s' '%s'", OdsignTestUtils.ART_APEX_DALVIK_CACHE_DIRNAME,
+ ART_APEX_DALVIK_CACHE_BACKUP_DIRNAME));
}
@AfterClassWithInfo
public static void afterClassWithDevice(TestInformation testInfo) throws Exception {
+ testInfo.getDevice().executeShellV2Command(
+ String.format("rm -rf '%s'", ART_APEX_DALVIK_CACHE_BACKUP_DIRNAME));
OdsignTestUtils testUtils = new OdsignTestUtils(testInfo);
testUtils.uninstallTestApex();
testUtils.reboot();
@@ -82,22 +92,13 @@ public class OdrefreshHostTest extends BaseHostJUnit4Test {
@Before
public void setUp() throws Exception {
mTestUtils = new OdsignTestUtils(getTestInformation());
- }
- @After
- public void tearDown() throws Exception {
- Set<String> artifacts = new HashSet<>();
- artifacts.addAll(getZygoteArtifacts());
- artifacts.addAll(getSystemServerArtifacts());
-
- for (String artifact : artifacts) {
- if (!getDevice().doesFileExist(artifact)) {
- // Things went wrong during the test. Run odrefresh to revert to a normal state.
- mTestUtils.removeCompilationLogToAvoidBackoff();
- runOdrefresh();
- break;
- }
- }
+ // Restore the artifacts to ensure a clean initial state.
+ getDevice().executeShellV2Command(
+ String.format("rm -rf '%s'", OdsignTestUtils.ART_APEX_DALVIK_CACHE_DIRNAME));
+ mTestUtils.assertCommandSucceeds(
+ String.format("cp -r '%s' '%s'", ART_APEX_DALVIK_CACHE_BACKUP_DIRNAME,
+ OdsignTestUtils.ART_APEX_DALVIK_CACHE_DIRNAME));
}
@Test