| 1 |
#!/bin/sh |
| 2 |
# Verify that iotop-c respects the requested iteration count |
| 3 |
# and exits promptly in batch mode. |
| 4 |
|
| 5 |
set -eu |
| 6 |
|
| 7 |
cleanup() { |
| 8 |
rm -f "$out" "$err" "$filtered_err" |
| 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 |
filtered_err=$(mktemp) |
| 21 |
|
| 22 |
iteration_count=3 |
| 23 |
|
| 24 |
iotop-c -b --iter "$iteration_count" >"$out" 2>"$err" || true |
| 25 |
filter_stderr <"$err" >"$filtered_err" |
| 26 |
|
| 27 |
[ ! -s "$filtered_err" ] |
| 28 |
|
| 29 |
# Count how many times the header appears |
| 30 |
count="$(grep -c "Total DISK READ" "$out" || true)" |
| 31 |
|
| 32 |
if [ "$count" -ne "$iteration_count" ]; then |
| 33 |
echo "ERROR: Expected $iteration_count headers, but found $count" >&2 |
| 34 |
exit 1 |
| 35 |
fi |