Fix OnDeviceSigningHostTest to correctly get mapped artifacts.

We use `pidof` to get the pid of a process, in order to get the mapped
files of the process from `/proc/<pid>/maps`. However, `pidof` may
output multiple pids in some cases, separated by spaces, which leads to
weird errors because the test cannot handle such output. After this
change, only the first pid is taken.

Bug: 189467174
Test: atest odsign_e2e_tests
Change-Id: I6e137819fa032611636f92fdd2b6c9faf58acd25
diff --git a/test/odsign/test-src/com/android/tests/odsign/OnDeviceSigningHostTest.java b/test/odsign/test-src/com/android/tests/odsign/OnDeviceSigningHostTest.java
index d5ea545..bc9712b 100644
--- a/test/odsign/test-src/com/android/tests/odsign/OnDeviceSigningHostTest.java
+++ b/test/odsign/test-src/com/android/tests/odsign/OnDeviceSigningHostTest.java
@@ -136,19 +136,32 @@
      * process does not exist.
      */
     private Optional<Set<String>> getZygoteLoadedArtifacts(String zygoteName) throws Exception {
-        final CommandResult pgrepResult = getDevice().executeShellV2Command("pidof " + zygoteName);
-        if (pgrepResult.getExitCode() != 0) {
+        final CommandResult result =
+                getDevice().executeShellV2Command("pidof " + zygoteName);
+        if (result.getExitCode() != 0) {
             return Optional.empty();
         }
-        final String zygotePid = pgrepResult.getStdout();
+        // There may be multiple Zygote processes when Zygote just forks and has not executed any
+        // app binary. We can take any of the pids.
+        // We can't use the "-s" flag when calling `pidof` because the Toybox's `pidof`
+        // implementation is wrong and it outputs multiple pids regardless of the "-s" flag, so we
+        // split the output and take the first pid ourselves.
+        final String zygotePid = result.getStdout().trim().split("\\s+")[0];
+        assertTrue(!zygotePid.isEmpty());
 
         final String grepPattern = ART_APEX_DALVIK_CACHE_DIRNAME + ".*boot-framework";
         return Optional.of(getMappedArtifacts(zygotePid, grepPattern));
     }
 
     private Set<String> getSystemServerLoadedArtifacts() throws Exception {
-        String systemServerPid = getDevice().executeShellCommand("pidof system_server");
-        assertTrue(systemServerPid != null);
+        final CommandResult result =
+                getDevice().executeShellV2Command("pidof system_server");
+        assertTrue(result.toString(), result.getExitCode() == 0);
+        final String systemServerPid = result.getStdout().trim();
+        assertTrue(!systemServerPid.isEmpty());
+        assertTrue(
+                "There should be exactly one `system_server` process",
+                systemServerPid.matches("\\d+"));
 
         // system_server artifacts are in the APEX data dalvik cache and names all contain
         // the word "@classes". Look for mapped files that match this pattern in the proc map for