Sophie

Sophie

distrib > Fedora > 13 > i386 > media > updates > by-pkgid > ad80f2528ccaa35d67e1966a5084e03e > files > 7

nbd-2.9.20-1.fc13.i686.rpm

#!/bin/sh
# Yes, that's POSIX sh, not bash!

tmpnam=`mktemp`

ulimit -c unlimited

# Create a one-meg device
dd if=/dev/zero of=$tmpnam bs=1024 count=4096

echo $1

case $1 in
	*/cmd)
		# Test with export specified on command line
		./nbd-server -C /dev/null -p `pwd`/nbd-server.pid 11111 $tmpnam &
		# -p only works if nbd-server wasn't compiled with -DNOFORK or
		# -DNODAEMON, which I sometimes do for testing and debugging.
		PID=$!
		sleep 1
		./nbd-tester-client 127.0.0.1 11111
		retval=$?
	;;
	*/cfgsize)
		# Test oversized requests
		./nbd-server -C /dev/null -p `pwd`/nbd-server.pid 11111 $tmpnam &
		# -p only works if nbd-server wasn't compiled with -DNOFORK or
		# -DNODAEMON, which I sometimes do for testing and debugging.
		PID=$!
		sleep 1
		./nbd-tester-client 127.0.0.1 11111 -o
		retval=$?
	;;
	*/cfg1)
		# Test with export specified in config file
		cat > nbd-server.conf <<EOF
[generic]
	oldstyle = true
[export]
	exportname = $tmpnam
	port = 11112
EOF
		./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
		PID=$!
		sleep 1
		./nbd-tester-client 127.0.0.1 11112
		retval=$?
	;;
	*/cfgmulti)
		# Test with multiple exports specified in config file, and
		# testing more options too
		cat >nbd-server.conf <<EOF
[generic]
	oldstyle = true
[export1]
	exportname = $tmpnam
	port = 11113
	copyonwrite = true
	listenaddr = 127.0.0.1
[export2]
	exportname = $tmpnam
	port = 11114
	readonly = true
	listenaddr = 127.0.0.1
EOF
		./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
		PID=$!
		sleep 1
		./nbd-tester-client localhost 11113
		retval=$?
		if [ $retval -ne 0 ]
		then
			if [ -f nbd-server.pid ]
			then
				kill `cat nbd-server.pid`
				rm -f nbd-server.pid
			else
				kill $PID
			fi
			if [ -z "$2" ]
			then
				rm -f $tmpnam nbd-server.conf
			fi
			exit $retval
		fi
		./nbd-tester-client localhost 11114
		retval=$?
	;;
	*/cfgnew)
		# Test new-style exports
		cat >nbd-server.conf <<EOF
[generic]
[export1]
	exportname = $tmpnam
EOF
		./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
		PID=$!
		sleep 1
		./nbd-tester-client localhost -N export1
		retval=$?
	;;
	*)
		echo "E: unknown test $1"
		exit 1
	;;
esac
if [ -f nbd-server.pid ]
then
	kill `cat nbd-server.pid`
	rm -f nbd-server.pid
else
	kill $PID
fi
if [ -z "$2" ]
then
	rm -f $tmpnam nbd-server.conf
fi
if [ $retval -ne 0 ]
then
	exit $retval
fi