Make odsign_e2e_tests in CTS agnostic to ART implementation.
This change adds a new test `verifyArtUpgradeGeneratesAnyArtifacts`,
which checks if there is any file that exists in ART dalvik-cache,
instead of checking particular files. The original test,
`verifyArtUpgradeGeneratesRequiredArtifacts`, is now skipped in CTS.
Bug: 224760042
Test: atest odsign_e2e_tests
Change-Id: Ie26369153efad68fc44b534f13ef0f2315e6f33f
diff --git a/test/odsign/Android.bp b/test/odsign/Android.bp
index 39b8021..40676d5 100644
--- a/test/odsign/Android.bp
+++ b/test/odsign/Android.bp
@@ -63,6 +63,7 @@
"junit",
],
static_libs: [
+ "androidx.test.ext.truth",
"androidx.test.runner",
"ctstestrunner-axt",
],
diff --git a/test/odsign/src/com/android/tests/odsign/ArtifactsSignedTest.java b/test/odsign/src/com/android/tests/odsign/ArtifactsSignedTest.java
index f29baa7..563c64b 100644
--- a/test/odsign/src/com/android/tests/odsign/ArtifactsSignedTest.java
+++ b/test/odsign/src/com/android/tests/odsign/ArtifactsSignedTest.java
@@ -16,11 +16,10 @@
package com.android.tests.odsign;
-import static org.junit.Assert.assertTrue;
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assume.assumeTrue;
-import android.util.Log;
-
import androidx.annotation.NonNull;
import org.junit.Test;
@@ -30,9 +29,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.List;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
public class ArtifactsSignedTest {
private static final String TAG = "VerifyArtArtifactsSignedTest";
@@ -51,8 +49,6 @@
"system@framework@services.jar@classes.art",
};
- private static final ArrayList<String> mFoundArtifactNames = new ArrayList<>();
-
static {
System.loadLibrary("OdsignTestAppJni");
}
@@ -66,36 +62,26 @@
@Test
public void testArtArtifactsHaveFsverity() throws Exception {
assumeTrue("fs-verity is not supported on this device.", isFsVeritySupported());
- List<File> files = Files.walk(Paths.get(ARTIFACTS_DIR), Integer.MAX_VALUE).
- map(Path::toFile)
- .collect(Collectors.toList());
-
- for (File file : files) {
- if (file.isFile()) {
- assertTrue(file.getPath() + " is not in fs-verity",
- hasFsverityNative(file.getPath()));
- Log.i(TAG, file.getPath() + " is in fs-verity");
- mFoundArtifactNames.add(file.getName());
- }
- }
- for (String artifact : REQUIRED_ARTIFACT_NAMES) {
- assertTrue("Missing artifact " + artifact, mFoundArtifactNames.contains(artifact));
- }
+ assertWithMessage("Found artifacts not in fs-verity")
+ .that(getArtifacts().map(File::getPath).filter((path) -> !hasFsverityNative(path))
+ .collect(Collectors.toList()))
+ .isEmpty();
}
@Test
public void testGeneratesRequiredArtArtifacts() throws Exception {
- List<File> files = Files.walk(Paths.get(ARTIFACTS_DIR), Integer.MAX_VALUE).
- map(Path::toFile)
- .collect(Collectors.toList());
+ assertThat(getArtifacts().map(File::getName).collect(Collectors.toList()))
+ .containsAtLeastElementsIn(REQUIRED_ARTIFACT_NAMES);
+ }
- for (File file : files) {
- if (file.isFile()) {
- mFoundArtifactNames.add(file.getName());
- }
- }
- for (String artifact : REQUIRED_ARTIFACT_NAMES) {
- assertTrue("Missing artifact " + artifact, mFoundArtifactNames.contains(artifact));
- }
+ @Test
+ public void testGeneratesAnyArtArtifacts() throws Exception {
+ assertThat(getArtifacts().collect(Collectors.toList())).isNotEmpty();
+ }
+
+ private Stream<File> getArtifacts() throws Exception {
+ return Files.walk(Paths.get(ARTIFACTS_DIR), Integer.MAX_VALUE)
+ .map(Path::toFile)
+ .filter(File::isFile);
}
}
diff --git a/test/odsign/test-src/com/android/tests/odsign/ActivationTest.java b/test/odsign/test-src/com/android/tests/odsign/ActivationTest.java
index 41a2972..b5101ae 100644
--- a/test/odsign/test-src/com/android/tests/odsign/ActivationTest.java
+++ b/test/odsign/test-src/com/android/tests/odsign/ActivationTest.java
@@ -55,7 +55,21 @@
}
@Test
+ public void verifyArtUpgradeGeneratesAnyArtifacts() throws Exception {
+ installPackage(TEST_APP_APK);
+ DeviceTestRunOptions options = new DeviceTestRunOptions(TEST_APP_PACKAGE_NAME);
+ options.setTestClassName(TEST_APP_PACKAGE_NAME + ".ArtifactsSignedTest");
+ options.setTestMethodName("testGeneratesAnyArtArtifacts");
+ runDeviceTests(options);
+ }
+
+ @Test
public void verifyArtUpgradeGeneratesRequiredArtifacts() throws Exception {
+ // This test does not actually require root access, but we use `enableAdbRootOrSkipTest` as
+ // a way to skip the test in CTS. This test should not run in CTS because it has assumptions
+ // on the ART module's behavior.
+ mTestUtils.enableAdbRootOrSkipTest();
+
installPackage(TEST_APP_APK);
DeviceTestRunOptions options = new DeviceTestRunOptions(TEST_APP_PACKAGE_NAME);
options.setTestClassName(TEST_APP_PACKAGE_NAME + ".ArtifactsSignedTest");