Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d64bdbcc authored by Richard Uhler's avatar Richard Uhler
Browse files

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
parent c070f758
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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.
+7 −24
Original line number Diff line number Diff line
@@ -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);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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);