FDD-book/examples/part-02/ch07-writing-your-first-driver/scripts/stress_test.sh
Edson Brandi 6e6dac94fe Add book companion files under examples/
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
2026-04-25 16:51:00 +00:00

28 lines
623 B
Bash
Executable file

#!/bin/sh
#
# Repeatedly load and unload the myfirst module to look for leaks or
# crashes that only show up over many cycles. Run from the same
# directory as your built myfirst.ko.
#
# Usage: sudo ./stress_test.sh [iterations]
set -e
ITERATIONS="${1:-100}"
MODULE="myfirst"
if [ ! -f "./${MODULE}.ko" ]; then
echo "stress_test.sh: ./${MODULE}.ko not found" >&2
exit 1
fi
i=1
while [ "$i" -le "$ITERATIONS" ]; do
echo "Iteration $i / $ITERATIONS"
kldload "./${MODULE}.ko"
sleep 0.1
kldunload "${MODULE}"
i=$((i + 1))
done
echo "Stress test completed: ${ITERATIONS} cycles without errors."