summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Dombroski <cdombroski@google.com>2023-08-25 01:28:17 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-08-25 01:28:17 +0000
commitb289f18c248851d166735c3d4664224f50c1a39c (patch)
treee94cf649de05be1c726bd3a3fcf0d0d049b44454
parent886504bd4527328d129bd6b148f1d4f810fa6f06 (diff)
parent6fa12f9f25938c8bb68d2532fce81812743d2e7c (diff)
downloadplatform_testing-b289f18c248851d166735c3d4664224f50c1a39c.tar.gz
findFileByProcess no exception on missing match am: b936b11b23 am: 0d748bafa2 am: 53b1c1ea25 am: e9e990af5c am: 6fa12f9f25
Original change: https://googleplex-android-review.googlesource.com/c/platform/platform_testing/+/24540930 Change-Id: I1ebff58e6659726ba7e363c633ff53e6719de7ec Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--libraries/sts-common-util/host-side/src/com/android/sts/common/ProcessUtil.java1
-rw-r--r--libraries/sts-common-util/host-side/tests/src/com/android/sts/common/ProcessUtilTest.java28
2 files changed, 25 insertions, 4 deletions
diff --git a/libraries/sts-common-util/host-side/src/com/android/sts/common/ProcessUtil.java b/libraries/sts-common-util/host-side/src/com/android/sts/common/ProcessUtil.java
index 8c8c7a331..d8fd05fda 100644
--- a/libraries/sts-common-util/host-side/src/com/android/sts/common/ProcessUtil.java
+++ b/libraries/sts-common-util/host-side/src/com/android/sts/common/ProcessUtil.java
@@ -447,7 +447,6 @@ public final class ProcessUtil {
return Optional.of(device.getFileEntry(f.trim()));
}
}
- throw new IllegalStateException(java.util.Arrays.toString(openFiles));
}
return Optional.empty();
}
diff --git a/libraries/sts-common-util/host-side/tests/src/com/android/sts/common/ProcessUtilTest.java b/libraries/sts-common-util/host-side/tests/src/com/android/sts/common/ProcessUtilTest.java
index c7201534a..c6f4c6963 100644
--- a/libraries/sts-common-util/host-side/tests/src/com/android/sts/common/ProcessUtilTest.java
+++ b/libraries/sts-common-util/host-side/tests/src/com/android/sts/common/ProcessUtilTest.java
@@ -24,6 +24,8 @@ import com.android.tradefed.device.IFileEntry;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -34,9 +36,18 @@ import java.util.regex.Pattern;
@RunWith(DeviceJUnit4ClassRunner.class)
public class ProcessUtilTest extends BaseHostJUnit4Test {
+ @Before
+ public void setUp() throws Exception {
+ assertTrue("could not unroot", getDevice().disableAdbRoot());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ assertTrue("could not unroot", getDevice().disableAdbRoot());
+ }
+
@Test(expected = IllegalStateException.class)
public void testFindLoadedByProcessNonRoot() throws Exception {
- assertTrue(getDevice().disableAdbRoot());
// expect failure because the shell user has no permission to read process info of other
// users
ProcessUtil.findFileLoadedByProcess(
@@ -45,7 +56,6 @@ public class ProcessUtilTest extends BaseHostJUnit4Test {
@Test(expected = IllegalArgumentException.class)
public void testFindLoadedByProcessMultipleProcesses() throws Exception {
- assertTrue(getDevice().disableAdbRoot());
// pattern 'android' has multiple (android.hardware.drm, android.hardware.gnss, etc)
ProcessUtil.findFileLoadedByProcess(getDevice(), "android", null);
}
@@ -63,6 +73,18 @@ public class ProcessUtilTest extends BaseHostJUnit4Test {
assertWithMessage("file entry should be a path to libc.so")
.that(fileEntry.getFullPath())
.contains("libc.so");
- assertTrue(getDevice().disableAdbRoot());
+ }
+
+ @Test
+ public void testFindLoadedByProcessUtilNoMatch() throws Exception {
+ assertTrue("must test with rootable device", getDevice().enableAdbRoot());
+ Optional<IFileEntry> fileEntryOptional =
+ ProcessUtil.findFileLoadedByProcess(
+ getDevice(),
+ "system_server",
+ Pattern.compile(Pattern.quote("doesnotexist.foobar")));
+ assertWithMessage("file entry should be empty if no matches")
+ .that(fileEntryOptional.isPresent())
+ .isFalse();
}
}