Use a better approach to simulate OTAs.
Silimar to the previous change, use bind-mount instead of mutating
cache-info.xml.
Bug: 272245228
Test: atest odsign_e2e_tests_full:OdrefreshHostTest
Change-Id: If42071dba47e551fb0919e2555c67e5d52e5ad33
diff --git a/test/odsign/Android.bp b/test/odsign/Android.bp
index 511f5a1..eb09587 100644
--- a/test/odsign/Android.bp
+++ b/test/odsign/Android.bp
@@ -50,6 +50,9 @@
data: [
":odsign_e2e_test_app",
],
+ java_resources: [
+ ":art-gtest-jars-Main",
+ ],
test_config: "odsign-e2e-tests-full.xml",
test_suites: [
"general-tests",
diff --git a/test/odsign/test-src/com/android/tests/odsign/DeviceState.java b/test/odsign/test-src/com/android/tests/odsign/DeviceState.java
index fb21656..771623a 100644
--- a/test/odsign/test-src/com/android/tests/odsign/DeviceState.java
+++ b/test/odsign/test-src/com/android/tests/odsign/DeviceState.java
@@ -39,6 +39,7 @@
/** A helper class that can mutate the device state and restore it afterwards. */
public class DeviceState {
private static final String APEX_INFO_FILE = "/apex/apex-info-list.xml";
+ private static final String TEST_JAR_RESOURCE_NAME = "/art-gtest-jars-Main.jar";
private final TestInformation mTestInfo;
private final OdsignTestUtils mTestUtils;
@@ -95,6 +96,18 @@
}
}
+ /** Simulates that there is an OTA that updates a boot classpath jar. */
+ public void simulateBootClasspathOta() throws Exception {
+ File localFile = mTestUtils.copyResourceToFile(TEST_JAR_RESOURCE_NAME);
+ pushAndBindMount(localFile, "/system/framework/framework.jar");
+ }
+
+ /** Simulates that there is an OTA that updates a system server jar. */
+ public void simulateSystemServerOta() throws Exception {
+ File localFile = mTestUtils.copyResourceToFile(TEST_JAR_RESOURCE_NAME);
+ pushAndBindMount(localFile, "/system/framework/services.jar");
+ }
+
/**
* Pushes the file to a temporary location and bind-mount it at the given path. This is useful
* when the path is readonly.
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 cf2365e..3091527 100644
--- a/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java
+++ b/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java
@@ -35,8 +35,6 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* Test to check end-to-end odrefresh invocations, but without odsign, fs-verity, and ART runtime
@@ -131,7 +129,7 @@
@Test
public void verifyBootClasspathOtaTriggersCompilation() throws Exception {
- simulateBootClasspathOta();
+ mDeviceState.simulateBootClasspathOta();
long timeMs = mTestUtils.getCurrentTimeMs();
runOdrefresh();
@@ -141,7 +139,7 @@
@Test
public void verifySystemServerOtaTriggersCompilation() throws Exception {
- simulateSystemServerOta();
+ mDeviceState.simulateSystemServerOta();
long timeMs = mTestUtils.getCurrentTimeMs();
runOdrefresh();
@@ -435,51 +433,6 @@
assertArtifactsModifiedAfter(getZygoteArtifacts(), timeMs);
}
- /**
- * Checks the input line by line and replaces all lines that match the regex with the given
- * replacement.
- */
- private String replaceLine(String input, String regex, String replacement) {
- StringBuffer output = new StringBuffer();
- Pattern p = Pattern.compile(regex);
- for (String line : input.split("\n")) {
- Matcher m = p.matcher(line);
- if (m.matches()) {
- m.appendReplacement(output, replacement);
- output.append("\n");
- } else {
- output.append(line + "\n");
- }
- }
- return output.toString();
- }
-
- /**
- * Simulates that there is an OTA that updates a boot classpath jar.
- */
- private void simulateBootClasspathOta() throws Exception {
- String cacheInfo = getDevice().pullFileContents(CACHE_INFO_FILE);
- // Replace the cached checksum of /system/framework/framework.jar with "aaaaaaaa".
- cacheInfo = replaceLine(
- cacheInfo,
- "(.*/system/framework/framework\\.jar.*checksums=\").*?(\".*)",
- "$1aaaaaaaa$2");
- getDevice().pushString(cacheInfo, CACHE_INFO_FILE);
- }
-
- /**
- * Simulates that there is an OTA that updates a system server jar.
- */
- private void simulateSystemServerOta() throws Exception {
- String cacheInfo = getDevice().pullFileContents(CACHE_INFO_FILE);
- // Replace the cached checksum of /system/framework/services.jar with "aaaaaaaa".
- cacheInfo = replaceLine(
- cacheInfo,
- "(.*/system/framework/services\\.jar.*checksums=\").*?(\".*)",
- "$1aaaaaaaa$2");
- getDevice().pushString(cacheInfo, CACHE_INFO_FILE);
- }
-
private Set<String> simulateMissingArtifacts() throws Exception {
Set<String> missingArtifacts = new HashSet<>();
String sample = getSystemServerArtifacts().iterator().next();
diff --git a/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java b/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java
index 5951600..a11139e 100644
--- a/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java
+++ b/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java
@@ -18,6 +18,7 @@
import static com.android.tradefed.testtype.DeviceJUnit4ClassRunner.TestLogData;
+import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.assertNotNull;
@@ -36,7 +37,13 @@
import com.android.tradefed.result.LogDataType;
import com.android.tradefed.util.CommandResult;
+import com.google.common.io.ByteStreams;
+
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.time.Duration;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@@ -364,4 +371,13 @@
}
}
+ public File copyResourceToFile(String resourceName) throws Exception {
+ File file = File.createTempFile("odsign_e2e_tests", ".tmp");
+ file.deleteOnExit();
+ try (OutputStream outputStream = new FileOutputStream(file);
+ InputStream inputStream = getClass().getResourceAsStream(resourceName)) {
+ assertThat(ByteStreams.copy(inputStream, outputStream)).isGreaterThan(0);
+ }
+ return file;
+ }
}