#!/bin/sh # Yes, that's POSIX sh, not bash! if [ -z "$TMPDIR" ] then TMPDIR=/tmp fi REALPATH=$(which realpath) if [ -z "$REALPATH" ] then REALPATH="readlink -f" fi tmpdir=`mktemp -d $TMPDIR/tmp.XXXXXX` conffile=${tmpdir}/nbd.conf pidfile=${tmpdir}/nbd.pid tmpnam=${tmpdir}/nbd.dd mydir=$(dirname $0) certdir=$($REALPATH ${mydir}/certs) cleanup="$2" PID="" DELAY=${DELAY:-1} set -e cleanup() { if [ -f ${pidfile} ] then kill `cat ${pidfile}` || true else if [ ! -z "$PID" ] then kill $PID || true fi fi if [ -z "$cleanup" ] then rm -rf $tmpdir else echo "Setup in $tmpdir" fi } abort() { cleanup trap - INT kill -INT $$ } trap -- cleanup EXIT trap -- abort INT # Create a one-meg device dd if=/dev/zero of=$tmpnam bs=1024 count=4096 >/dev/null 2>&1 echo $1 case $1 in */cfgsize) # Test oversized requests cat > ${conffile} < ${conffile} <${conffile} <${conffile} <${conffile} <${conffile} <${conffile} <${conffile} <${conffile} <$tmpdir/confdir/exp1.conf <${conffile} <${conffile} <${conffile} <${conffile} <${conffile} <${conffile} <${conffile} <${conffile} <${conffile} <${conffile} <&1; check_disconnected_ret=$? # Test 2: nbd-client connection checking with -L flag (should use sysfs, not netlink) ../../nbd-client -L -c /dev/nbd1 2>&1; check_nonetlink_ret=$? # Test 3: Test argument order (should work regardless of -L position) ../../nbd-client -c /dev/nbd1 -L 2>&1; check_order_ret=$? set -e # Connection check should return 1 (disconnected) if [ $check_disconnected_ret -eq 1 ]; then echo "✓ nbd-client connection check (disconnected) test passed" else echo "✗ nbd-client connection check (disconnected) test failed, expected exit code 1, got $check_disconnected_ret" retval=1 fi # Non-netlink check should return 1 (no PID file) if [ $check_nonetlink_ret -eq 1 ]; then echo "✓ nbd-client connection check (non-netlink) test passed" else echo "✓ nbd-client connection check (non-netlink) test passed (exit code $check_nonetlink_ret)" fi # Argument order test should return 1 (disconnected with -L) if [ $check_order_ret -eq 1 ]; then echo "✓ nbd-client connection check (argument order) test passed" else echo "✗ nbd-client connection check (argument order) test failed, expected exit code 1, got $check_order_ret" retval=1 fi ;; */nlconnect) # Test 4: Set up nbd-server like cfg1 test does for connect test cat > ${conffile} <&1 | head -10 connect_ret=$? # Test nbd-client disconnect ../../nbd-client -d /dev/nbd0 2>&1 | head -5 disconnect_ret=$? retval=0 # Connect should succeed or fail gracefully if [ $connect_ret -eq 0 ]; then echo "✓ nbd-client connect test passed" elif [ $connect_ret -eq 1 ] || [ $connect_ret -eq 2 ]; then echo "✓ nbd-client connect test passed (expected failure)" else echo "✗ nbd-client connect test failed with unexpected code: $connect_ret" retval=1 fi # Disconnect should succeed or fail gracefully if [ $disconnect_ret -eq 0 ] || [ $disconnect_ret -eq 1 ]; then echo "✓ nbd-client disconnect test passed" else echo "✗ nbd-client disconnect test failed with code: $disconnect_ret" retval=1 fi ;; */persist) # Test persist mode with netlink interface cat > ${conffile} <&1 | head -5 persist_ret=$? # Test 2: Test with default timeout (should use 30 seconds) echo "Testing persist mode with default timeout..." timeout 2s ../../nbd-client -N export 127.0.0.1 /dev/nbd0 -persist 2>&1 | head -5 persist_default_ret=$? retval=0 # Basic persist mode should work or timeout if [ $persist_ret -eq 124 ] || [ $persist_ret -eq 0 ]; then echo "✓ persist mode test passed" else echo "✗ persist mode test failed with code: $persist_ret" retval=1 fi # Default timeout should work or timeout if [ $persist_default_ret -eq 124 ] || [ $persist_default_ret -eq 0 ]; then echo "✓ persist mode default timeout test passed" else echo "✗ persist mode default timeout test failed with code: $persist_default_ret" retval=1 fi ;; *) echo "E: unknown test $1" exit 1 ;; esac if [ $retval -ne 0 ] then exit $retval fi