| 1 |
#!/bin/sh |
| 2 |
# Verify that real disk I/O is detected and inactive processes |
| 3 |
# can be filtered. |
| 4 |
|
| 5 |
set -eu |
| 6 |
|
| 7 |
cleanup() { |
| 8 |
rm -f "$out" "$err" "$filter_stderr" "$file" |
| 9 |
} |
| 10 |
trap cleanup EXIT |
| 11 |
|
| 12 |
# Remove the known iotop-c warning about task_delayacct being disabled. |
| 13 |
# All other stderr output is preserved and should be treated as errors. |
| 14 |
filter_stderr() { |
| 15 |
sed '/task_delayacct is 0/d' |
| 16 |
} |
| 17 |
|
| 18 |
out=$(mktemp) |
| 19 |
err=$(mktemp) |
| 20 |
filter_stderr=$(mktemp) |
| 21 |
file=$(mktemp) |
| 22 |
|
| 23 |
iotop-c -d 0.2 -b -n 20 -o >"$out" 2>"$err" & |
| 24 |
iotop_pid=$! |
| 25 |
|
| 26 |
# Generate real I/O |
| 27 |
dd if=/dev/zero of="$file" bs=10M count=100 2>/dev/null & |
| 28 |
dd_pid=$! |
| 29 |
|
| 30 |
# Wait for iotop-c to finish |
| 31 |
wait $iotop_pid |
| 32 |
filter_stderr <"$err" >"$filter_stderr" |
| 33 |
|
| 34 |
[ ! -s "$filter_stderr" ] |
| 35 |
|
| 36 |
# At least one process line for dd must exist, like |
| 37 |
# 13847 be/4 root 0.00 B/s 693.28 M/s 0.00 % 0.00 % dd |
| 38 |
if ! grep -Eq "^[[:space:]]*$dd_pid[[:space:]].*dd$" "$out"; then |
| 39 |
echo "ERROR: Expected a line with '$dd_pid ... dd', but did not find it in the output:" >&2 |
| 40 |
cat "$out" >&2 |
| 41 |
exit 1 |
| 42 |
fi |
| 43 |
|
| 44 |
# No process line may have both read and write equal to zero, as in |
| 45 |
# 33 be/5 root 0.00 B/s 0.00 B/s ... ksmd |
| 46 |
if grep -Eq '^[[:space:]]*[0-9]+.*0\.00 B/s[[:space:]]+0\.00 B/s' "$out"; then |
| 47 |
echo "ERROR: Found an inactive process (both read and write are zero):" >&2 |
| 48 |
grep -E '^[[:space:]]*[0-9]+.*0\.00 B/s[[:space:]]+0\.00 B/s' "$out" >&2 |
| 49 |
exit 1 |
| 50 |
fi |