summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Onea <andreionea@google.com>2022-01-14 17:27:53 +0000
committerAndrei Onea <andreionea@google.com>2022-03-31 18:06:36 +0100
commit3e218097497cd38cea29ff16dd59868a9d5a4b35 (patch)
tree0fe9bb4bbfd6328e736208531cdd546ebfb77e97
parent79817ffd8774a8806b246ddb0ba005558e6b3005 (diff)
downloadcts-3e218097497cd38cea29ff16dd59868a9d5a4b35.tar.gz
Use @BeforeClassWithInfo for SJP test
This replaces the previous @Before method that would cause the first test method to stall until the classpath data is gathered. Test: atest StrictJavaPackagesTest Bug: 207497139 Change-Id: I37d7f210de22c3567898a85e897a11f9259adca7 Merged-In: I37d7f210de22c3567898a85e897a11f9259adca7
-rw-r--r--hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java96
1 files changed, 49 insertions, 47 deletions
diff --git a/hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java b/hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java
index 5ac8f32f498..9f9c681ecd1 100644
--- a/hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java
+++ b/hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java
@@ -28,8 +28,11 @@ import android.compat.testing.SharedLibraryInfo;
import com.android.modules.utils.build.testing.DeviceSdkLevel;
import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.invoker.TestInformation;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
+import com.android.tradefed.testtype.junit4.BeforeClassWithInfo;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableCollection;
@@ -62,7 +65,6 @@ public class StrictJavaPackagesTest extends BaseHostJUnit4Test {
private static final String ANDROID_TEST_MOCK_JAR = "/system/framework/android.test.mock.jar";
- private static final Object sLock = new Object();
private static ImmutableList<String> sBootclasspathJars;
private static ImmutableList<String> sSystemserverclasspathJars;
private static ImmutableList<String> sSharedLibJars;
@@ -318,53 +320,53 @@ public class StrictJavaPackagesTest extends BaseHostJUnit4Test {
* <p>This method cannot be static, as there are no static equivalents for {@link #getDevice()}
* and {@link #getBuild()}.
*/
- @Before
- public void setupOnce() throws IOException, DeviceNotAvailableException {
- if (getDevice() == null || getBuild() == null) {
+ @BeforeClassWithInfo
+ public static void setupOnce(TestInformation testInfo) throws Exception {
+ if (testInfo.getDevice() == null || testInfo.getBuildInfo() == null) {
throw new RuntimeException("No device and/or build type specified!");
}
- mDeviceSdkLevel = new DeviceSdkLevel(getDevice());
-
- synchronized (sLock) {
- if (sJarsToClasses != null) {
- return;
- }
- sBootclasspathJars = Classpaths.getJarsOnClasspath(getDevice(), BOOTCLASSPATH);
- sSystemserverclasspathJars =
- Classpaths.getJarsOnClasspath(getDevice(), SYSTEMSERVERCLASSPATH);
- sSharedLibs = mDeviceSdkLevel.isDeviceAtLeastS()
- ? Classpaths.getSharedLibraryInfos(getDevice(), getBuild())
- : ImmutableList.of();
- sSharedLibJars = sSharedLibs.stream()
- .map(sharedLibraryInfo -> sharedLibraryInfo.paths)
- .flatMap(ImmutableCollection::stream)
- .filter(this::doesFileExist)
- .collect(ImmutableList.toImmutableList());
-
- final ImmutableSetMultimap.Builder<String, String> jarsToClasses =
- ImmutableSetMultimap.builder();
- Stream.of(sBootclasspathJars.stream(),
- sSystemserverclasspathJars.stream(),
- sSharedLibJars.stream())
- .reduce(Stream::concat).orElseGet(Stream::empty)
- .parallel()
- .forEach(jar -> {
- try {
- ImmutableSet<String> classes =
- Classpaths.getClassDefsFromJar(getDevice(), jar).stream()
- .map(ClassDef::getType)
- // Inner classes always go with their parent.
- .filter(className -> !className.contains("$"))
- .collect(ImmutableSet.toImmutableSet());
- synchronized (jarsToClasses) {
- jarsToClasses.putAll(jar, classes);
- }
- } catch (DeviceNotAvailableException | IOException e) {
- throw new RuntimeException(e);
+ DeviceSdkLevel deviceSdkLevel = new DeviceSdkLevel(testInfo.getDevice());
+
+ sBootclasspathJars = Classpaths.getJarsOnClasspath(testInfo.getDevice(), BOOTCLASSPATH);
+ sSystemserverclasspathJars =
+ Classpaths.getJarsOnClasspath(testInfo.getDevice(), SYSTEMSERVERCLASSPATH);
+ sSharedLibs = deviceSdkLevel.isDeviceAtLeastS()
+ ? Classpaths.getSharedLibraryInfos(testInfo.getDevice(), testInfo.getBuildInfo())
+ : ImmutableList.of();
+ sSharedLibJars = sSharedLibs.stream()
+ .map(sharedLibraryInfo -> sharedLibraryInfo.paths)
+ .flatMap(ImmutableCollection::stream)
+ .filter(file -> doesFileExist(file, testInfo.getDevice()))
+ .collect(ImmutableList.toImmutableList());
+
+ final ImmutableSetMultimap.Builder<String, String> jarsToClasses =
+ ImmutableSetMultimap.builder();
+ Stream.of(sBootclasspathJars.stream(),
+ sSystemserverclasspathJars.stream(),
+ sSharedLibJars.stream())
+ .reduce(Stream::concat).orElseGet(Stream::empty)
+ .parallel()
+ .forEach(jar -> {
+ try {
+ ImmutableSet<String> classes =
+ Classpaths.getClassDefsFromJar(testInfo.getDevice(), jar).stream()
+ .map(ClassDef::getType)
+ // Inner classes always go with their parent.
+ .filter(className -> !className.contains("$"))
+ .collect(ImmutableSet.toImmutableSet());
+ synchronized (jarsToClasses) {
+ jarsToClasses.putAll(jar, classes);
}
- });
- sJarsToClasses = jarsToClasses.build();
- }
+ } catch (DeviceNotAvailableException | IOException e) {
+ throw new RuntimeException(e);
+ }
+ });
+ sJarsToClasses = jarsToClasses.build();
+ }
+
+ @Before
+ public void setup() {
+ mDeviceSdkLevel = new DeviceSdkLevel(getDevice());
}
/**
@@ -523,10 +525,10 @@ public class StrictJavaPackagesTest extends BaseHostJUnit4Test {
return Multimaps.filterKeys(allClasses, key -> allClasses.get(key).size() > 1);
}
- private boolean doesFileExist(String path) {
+ private static boolean doesFileExist(String path, ITestDevice device) {
assertThat(path).isNotNull();
try {
- return getDevice().doesFileExist(path);
+ return device.doesFileExist(path);
} catch (DeviceNotAvailableException e) {
throw new RuntimeException("Could not check whether " + path + " exists on device", e);
}