| 1 | #!/bin/sh |
| 2 | |
| 3 | exec 2>&1 |
| 4 | |
| 5 | test_no_arguments() { |
| 6 | ( ps >"${stdoutF}" 2>"${stderrF}" ) |
| 7 | rtrn=$? |
| 8 | |
| 9 | assertEquals "ps exit value" "0" "${rtrn}" |
| 10 | grep -E '^[[:space:]]+PID[[:space:]]+TTY[[:space:]]+TIME[[:space:]]+CMD' "${stdoutF}" > /dev/null |
| 11 | assertTrue 'header line' $? |
| 12 | } |
| 13 | |
| 14 | test_pid() { |
| 15 | ( ps -o pid "${myPID}" >"${stdoutF}" 2>"${stderrF}" ) |
| 16 | rtrn=$? |
| 17 | |
| 18 | assertEquals "ps exit value" "0" "${rtrn}" |
| 19 | grep -E '^[[:space:]]+PID$' "${stdoutF}" > /dev/null |
| 20 | assertTrue 'header line' $? |
| 21 | grep -E "^[[:space:]]*${myPID}$" "${stdoutF}" > /dev/null |
| 22 | assertTrue 'pid line' $? |
| 23 | } |
| 24 | |
| 25 | test_exe() { |
| 26 | ( ps -o exe "${myPID}" >"${stdoutF}" 2>"${stderrF}" ) |
| 27 | rtrn=$? |
| 28 | |
| 29 | assertEquals "ps exit value" "0" "${rtrn}" |
| 30 | |
| 31 | myEXE=$(readlink "/proc/${myPID}/exe" 2>/dev/null) |
| 32 | [ -z "${myEXE:-}" ] && startSkipping |
| 33 | grep -E "^${myEXE}$" "${stdoutF}" > /dev/null |
| 34 | assertTrue 'exe line' $? |
| 35 | } |
| 36 | |
| 37 | oneTimeSetUp() { |
| 38 | # Define global variables for command output. |
| 39 | stdoutF="${AUTOPKGTEST_TMP}/stdout" |
| 40 | stderrF="${AUTOPKGTEST_TMP}/stderr" |
| 41 | myPID=$$ |
| 42 | } |
| 43 | |
| 44 | setUp() { |
| 45 | # Truncate the output files. |
| 46 | cp /dev/null "${stdoutF}" |
| 47 | cp /dev/null "${stderrF}" |
| 48 | } |
| 49 | |
| 50 | |
| 51 | # shellcheck disable=SC1091 |
| 52 | . shunit2 |
| 53 |