summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDario Freni <dariofreni@google.com>2020-11-06 16:25:19 +0000
committerDario Freni <dariofreni@google.com>2020-11-09 10:27:04 +0000
commit5f541cbb88809eed08993f38ab7023879dbaf42e (patch)
treea51ce307f7e7629c5cd2400f1de118a3e35e7e5c /tests
parent26b017aae2129dddee9fff881a22cf3813291eef (diff)
Add ability to stage multiple apexs.
Test: atest sharedlibs_hosts_test Change-Id: I9dfc6b783fd63c555622932d59712c0e0b9b073e
Diffstat (limited to 'tests')
-rw-r--r--tests/utils/hostutils/src/com/android/internal/util/test/SystemPreparer.java39
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/utils/hostutils/src/com/android/internal/util/test/SystemPreparer.java b/tests/utils/hostutils/src/com/android/internal/util/test/SystemPreparer.java
index 173338660113..1139fd6b811e 100644
--- a/tests/utils/hostutils/src/com/android/internal/util/test/SystemPreparer.java
+++ b/tests/utils/hostutils/src/com/android/internal/util/test/SystemPreparer.java
@@ -16,6 +16,7 @@
package com.android.internal.util.test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.android.tradefed.device.DeviceNotAvailableException;
@@ -114,6 +115,24 @@ public class SystemPreparer extends ExternalResource {
return this;
}
+ /** Stages multiple APEXs within the host test jar onto the device. */
+ public SystemPreparer stageMultiplePackages(String[] resourcePaths, String[] packageNames)
+ throws DeviceNotAvailableException, IOException {
+ assertEquals(resourcePaths.length, packageNames.length);
+ final ITestDevice device = mDeviceProvider.getDevice();
+ final String[] adbCommandLine = new String[resourcePaths.length + 2];
+ adbCommandLine[0] = "install-multi-package";
+ adbCommandLine[1] = "--staged";
+ for (int i = 0; i < resourcePaths.length; i++) {
+ final File tmpFile = copyResourceToTemp(resourcePaths[i]);
+ adbCommandLine[i + 2] = tmpFile.getAbsolutePath();
+ mInstalledPackages.add(packageNames[i]);
+ }
+ final String output = device.executeAdbCommand(adbCommandLine);
+ assertTrue(output.contains("Success. Reboot device to apply staged session"));
+ return this;
+ }
+
/** Sets the enable state of an overlay package. */
public SystemPreparer setOverlayEnabled(String packageName, boolean enabled)
throws DeviceNotAvailableException {
@@ -182,9 +201,27 @@ public class SystemPreparer extends ExternalResource {
return this;
}
+ private static @Nullable String getFileExtension(@Nullable String path) {
+ if (path == null) {
+ return null;
+ }
+ final int lastDot = path.lastIndexOf('.');
+ if (lastDot >= 0) {
+ return path.substring(lastDot + 1);
+ } else {
+ return null;
+ }
+ }
+
/** Copies a file within the host test jar to a temporary file on the host machine. */
private File copyResourceToTemp(String resourcePath) throws IOException {
- final File tempFile = mHostTempFolder.newFile();
+ final String ext = getFileExtension(resourcePath);
+ final File tempFile;
+ if (ext != null) {
+ tempFile = File.createTempFile("junit", "." + ext, mHostTempFolder.getRoot());
+ } else {
+ tempFile = mHostTempFolder.newFile();
+ }
final ClassLoader classLoader = getClass().getClassLoader();
try (InputStream assetIs = classLoader.getResourceAsStream(resourcePath);
FileOutputStream assetOs = new FileOutputStream(tempFile)) {