diff options
author | Christopher Dombroski <cdombroski@google.com> | 2023-08-25 00:04:19 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-08-25 00:04:19 +0000 |
commit | e9e990af5cf450a5f1aec770c9cf6bd38e17e012 (patch) | |
tree | 95f021d0293dea71d1e115c8cb01adebd56c72bd | |
parent | d0639601db9fbbe6c265e5d3031c6663d15f8408 (diff) | |
parent | 53b1c1ea25dc2e76e66ac5d7ab52893d4ddc2920 (diff) | |
download | platform_testing-e9e990af5cf450a5f1aec770c9cf6bd38e17e012.tar.gz |
findFileByProcess no exception on missing match am: b936b11b23 am: 0d748bafa2 am: 53b1c1ea25
Original change: https://googleplex-android-review.googlesource.com/c/platform/platform_testing/+/24540930
Change-Id: If910e470e4cabaf1ea543d1c016b31fe4f203a35
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.java | 1 | ||||
-rw-r--r-- | libraries/sts-common-util/host-side/tests/src/com/android/sts/common/ProcessUtilTest.java | 28 |
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(); } } |