| 1 | #!/bin/sh |
| 2 | |
| 3 | exec 2>&1 |
| 4 | |
| 5 | test_no_arguments() { |
| 6 | ( vmstat >"${stdoutF}" 2>"${stderrF}" ) |
| 7 | rtrn=$? |
| 8 | |
| 9 | assertEquals "vmstat exit value" "0" "${rtrn}" |
| 10 | |
| 11 | grep -E '^procs[ -]+memory[ -]+swap[ -]+io[ -]+system[ -]+cpu[ -]+$' "${stdoutF}" > /dev/null |
| 12 | assertTrue 'header line' $? |
| 13 | grep -E '^ +r +b +swpd +free +buff +cache +si +so +bi +bo +in +cs us sy id wa st gu$' "${stdoutF}" >/dev/null |
| 14 | assertTrue 'header second line' $? |
| 15 | grep -E '^[[:space:]]?[[:digit:]]+([[:space:]]+[[:digit:]]+){17}$' "${stdoutF}" >/dev/null |
| 16 | assertTrue 'value line' $? |
| 17 | } |
| 18 | |
| 19 | test_forks() { |
| 20 | ( vmstat -f >"${stdoutF}" 2>"${stderrF}" ) |
| 21 | rtrn=$? |
| 22 | |
| 23 | assertEquals "vmstat -f exit value" "0" "${rtrn}" |
| 24 | |
| 25 | grep -E '^[[:space:]]+[[:digit:]]+ forks$' "${stdoutF}" > /dev/null |
| 26 | assertTrue 'fork output' $? |
| 27 | } |
| 28 | |
| 29 | test_disk() { |
| 30 | ( vmstat -d >"${stdoutF}" 2>"${stderrF}" ) |
| 31 | rtrn=$? |
| 32 | |
| 33 | assertEquals "vmstat -d exit value" "0" "${rtrn}" |
| 34 | |
| 35 | grep -E '^disk[ -]+reads[ -]+writes[ -]+IO[ -]+$' "${stdoutF}" > /dev/null |
| 36 | assertTrue 'header line' $? |
| 37 | grep -E '^ +total +merged +sectors +ms +total +merged +sectors +ms +cur +sec$' "${stdoutF}" >/dev/null |
| 38 | assertTrue 'header second line' $? |
| 39 | grep -E '^[[:alnum:]]+([[:space:]]+[[:digit:]]+){10}$' "${stdoutF}" >/dev/null |
| 40 | assertTrue 'value line' $? |
| 41 | } |
| 42 | |
| 43 | oneTimeSetUp() { |
| 44 | # Define global variables for command output. |
| 45 | stdoutF="${AUTOPKGTEST_TMP}/stdout" |
| 46 | stderrF="${AUTOPKGTEST_TMP}/stderr" |
| 47 | } |
| 48 | |
| 49 | setUp() { |
| 50 | # Truncate the output files. |
| 51 | cp /dev/null "${stdoutF}" |
| 52 | cp /dev/null "${stderrF}" |
| 53 | } |
| 54 | |
| 55 | |
| 56 | # shellcheck disable=SC1091 |
| 57 | . shunit2 |
| 58 |