FDD-book/examples/part-06/ch26-usb-serial/lab03-bulk-loopback/test_echo.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

30 lines
679 B
Bash
Executable file

#!/bin/sh
#
# test_echo.sh - Minimal test for the bulk-loopback driver.
#
# Writes a short string to /dev/myfirst_usb0 and reads the result
# back. Exits 0 on match, 1 on mismatch.
set -eu
DEV=${DEV:-/dev/myfirst_usb0}
MSG=${MSG:-"hello usb"}
if [ ! -c "${DEV}" ]; then
echo "Device ${DEV} not present. Is the driver loaded and the"
echo "test hardware plugged in?"
exit 2
fi
echo "${MSG}" > "${DEV}"
# Read back up to len(MSG)+1 bytes. Allow short read.
got=$(dd if="${DEV}" bs=1 count=$((${#MSG}+1)) 2>/dev/null | tr -d '\n')
if [ "${got}" = "${MSG}" ]; then
echo "OK: echo loopback returned '${got}'"
exit 0
else
echo "FAIL: sent '${MSG}' got '${got}'"
exit 1
fi