summaryrefslogtreecommitdiffstats
path: root/debian/tests/ps
blob: e9cc83b396e92574154bc3f84d1f49416aa1377d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh

exec 2>&1

test_no_arguments() {
    ( ps >"${stdoutF}" 2>"${stderrF}" )
    rtrn=$?

    assertEquals "ps exit value" "0" "${rtrn}"
    grep -E '^[[:space:]]+PID[[:space:]]+TTY[[:space:]]+TIME[[:space:]]+CMD' "${stdoutF}" > /dev/null
    assertTrue 'header line' $?
}

test_pid() {
    ( ps -o pid "${myPID}" >"${stdoutF}" 2>"${stderrF}" )
    rtrn=$?

    assertEquals "ps exit value" "0" "${rtrn}"
    grep -E '^[[:space:]]+PID$' "${stdoutF}" > /dev/null
    assertTrue 'header line' $?
    grep -E "^[[:space:]]+${myPID}$" "${stdoutF}" > /dev/null
    assertTrue 'pid line' $?
}

test_exe() {
    ( ps -o exe "${myPID}" >"${stdoutF}" 2>"${stderrF}" )
    rtrn=$?

    assertEquals "ps exit value" "0" "${rtrn}"

    myEXE=$(readlink "/proc/${myPID}/exe" 2>/dev/null)
    [ -z "${myEXE:-}" ] && startSkipping
    grep -E "^${myEXE}$" "${stdoutF}" > /dev/null
    assertTrue 'exe line' $?
}

oneTimeSetUp() {
  # Define global variables for command output.
  stdoutF="${AUTOPKGTEST_TMP}/stdout"
  stderrF="${AUTOPKGTEST_TMP}/stderr"
  myPID=$$
}

setUp() {
  # Truncate the output files.
  cp /dev/null "${stdoutF}"
  cp /dev/null "${stderrF}"
}


# shellcheck disable=SC1091
. shunit2