diff options
author | Richard Uhler <ruhler@google.com> | 2018-10-22 11:48:19 +0100 |
---|---|---|
committer | Richard Uhler <ruhler@google.com> | 2018-10-22 11:48:19 +0100 |
commit | d64bdbccf4b8dd9d0cc7084a18ee9ff546386ec7 (patch) | |
tree | c25a11bdf5bd0a36283f5f7b931dd38248040dd3 | |
parent | c070f7588be4c2a663a5b66592b655c3c817a54f (diff) |
Use existing getProcessPid method to get pid of system_server.
Rather than using custom logic for it.
Test: atest -v system-memory-test
Bug: 111830582
Change-Id: I94cb856fbedbdf2b653f448857024f7f79f3de6f
3 files changed, 9 insertions, 26 deletions
diff --git a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java index 6500428253f6..18cdf96c7131 100644 --- a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java +++ b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java @@ -34,7 +34,7 @@ public class Cujs { // Do an explicit GC in the system server process as part of the test // case to reduce GC-related sources of noise. // SIGUSR1 = 10 is the magic signal to trigger the GC. - int pid = mDevice.getPidForProcess("system_server"); + int pid = mDevice.getProcessPid("system_server"); mDevice.executeShellCommand("kill -10 " + pid); // Invoke the Device Cujs instrumentation to run the cujs. diff --git a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Device.java b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Device.java index 03503cec5fec..26146ca0ea6c 100644 --- a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Device.java +++ b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Device.java @@ -19,9 +19,6 @@ package com.android.tests.sysmem.host; import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.device.ITestDevice; -import java.util.InputMismatchException; -import java.util.Scanner; - /** * Wrapper around ITestDevice exposing useful device functions. */ @@ -58,29 +55,15 @@ class Device { /** * Returns the pid for the process with the given name. */ - public int getPidForProcess(String name) throws TestException { - String psout = executeShellCommand("ps -A -o PID,CMD"); - Scanner sc = new Scanner(psout); + public int getProcessPid(String name) throws TestException { try { - // ps output is of the form: - // PID CMD - // 1 init - // 2 kthreadd - // ... - // 9693 ps - sc.nextLine(); - while (sc.hasNextLine()) { - int pid = sc.nextInt(); - String cmd = sc.next(); - - if (name.equals(cmd)) { - return pid; - } + String pid = mDevice.getProcessPid(name); + if (pid == null) { + throw new TestException("failed to get pid for " + name); } - } catch (InputMismatchException e) { - throw new TestException("unexpected ps output format: " + psout, e); + return Integer.parseInt(pid); + } catch (DeviceNotAvailableException e) { + throw new TestException(e); } - - throw new TestException("failed to get pid for process " + name); } } diff --git a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java index b408a81d8f93..b46e642b5e92 100644 --- a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java +++ b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java @@ -79,7 +79,7 @@ class Metrics { // adb root access is required to get showmap mDevice.enableAdbRoot(); - int pid = mDevice.getPidForProcess("system_server"); + int pid = mDevice.getProcessPid("system_server"); // Read showmap for system server and add it as a test log String showmap = mDevice.executeShellCommand("showmap " + pid); |