mirror of
https://github.com/ebrandi/FDD-book.git
synced 2026-12-06 08:33:30 +00:00
Organize companion code and materials by book part: part-01/ Foundations part-02/ Kernel & driver fundamentals part-03/ Character & block devices part-04/ Networking & storage part-05/ Buses & advanced topics part-06/ Debugging & performance part-07/ Real-world drivers appendices/ Supplementary material README.md Overview and build instructions
37 lines
897 B
Bash
Executable file
37 lines
897 B
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# attach_detach_cycle.sh -- stress the attach/detach path.
|
|
#
|
|
# Runs N detach/attach cycles against the myfirst0 device. Reports
|
|
# any failed cycle and any malloc leak observed afterwards.
|
|
|
|
set -eu
|
|
|
|
CYCLES="${1:-50}"
|
|
|
|
say() { printf '=== %s ===\n' "$1"; }
|
|
fail() { printf 'FAIL: %s\n' "$1" >&2; exit 1; }
|
|
|
|
SELECTOR=$(pciconf -l | awk '/^myfirst0/{print $1}' \
|
|
| sed 's/myfirst0@//')
|
|
[ -n "$SELECTOR" ] || fail "myfirst0 not present; load the driver first"
|
|
|
|
say "Cycling $CYCLES times"
|
|
|
|
i=1
|
|
while [ "$i" -le "$CYCLES" ]; do
|
|
devctl detach myfirst0 || fail "detach on cycle $i"
|
|
sleep 0.1
|
|
devctl attach "$SELECTOR" || fail "attach on cycle $i"
|
|
sleep 0.1
|
|
i=$((i + 1))
|
|
done
|
|
|
|
say "Cycle complete; checking leaks"
|
|
|
|
LEAK=$(vmstat -m | awk '/^ *myfirst /{print $3}')
|
|
if [ "${LEAK:-0}" -gt 0 ]; then
|
|
fail "$LEAK live myfirst allocations after cycle"
|
|
fi
|
|
|
|
say "Success"
|