Remove double "it", and redundant information about defaults
[nbd.git] / simple_test
index 9bd3d07..a05a6a5 100755 (executable)
@@ -2,16 +2,20 @@
 # Yes, that's POSIX sh, not bash!
 
 tmpnam=`mktemp`
+conffile=${tmpnam}.conf
+pidfile=${tmpnam}.pid
+
+ulimit -c unlimited
 
 # Create a one-meg device
-dd if=/dev/zero of=$tmpnam bs=1024 count=1024
+dd if=/dev/zero of=$tmpnam bs=1024 count=4096 >/dev/null 2>&1
 
 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 &
+               ./nbd-server -C /dev/null -p ${pidfile} 11111 $tmpnam &
                # -p only works if nbd-server wasn't compiled with -DNOFORK or
                # -DNODAEMON, which I sometimes do for testing and debugging.
                PID=$!
@@ -19,17 +23,26 @@ case $1 in
                ./nbd-tester-client 127.0.0.1 11111
                retval=$?
        ;;
-
+       */cfgsize)
+               # Test oversized requests
+               ./nbd-server -C /dev/null -p ${pidfile} 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
+               cat > ${conffile} <<EOF
 [generic]
        oldstyle = true
 [export]
        exportname = $tmpnam
        port = 11112
 EOF
-               ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
+               ./nbd-server -C ${conffile} -p ${pidfile} &
                PID=$!
                sleep 1
                ./nbd-tester-client 127.0.0.1 11112
@@ -38,7 +51,7 @@ EOF
        */cfgmulti)
                # Test with multiple exports specified in config file, and
                # testing more options too
-               cat >nbd-server.conf <<EOF
+               cat >${conffile} <<EOF
 [generic]
        oldstyle = true
 [export1]
@@ -50,22 +63,26 @@ EOF
        exportname = $tmpnam
        port = 11114
        readonly = true
+       listenaddr = 127.0.0.1
 EOF
-               ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
+               ./nbd-server -C ${conffile} -p ${pidfile} &
                PID=$!
                sleep 1
                ./nbd-tester-client localhost 11113
                retval=$?
                if [ $retval -ne 0 ]
                then
-                       if [ -f nbd-server.pid ]
+                       if [ -f ${pidfile} ]
                        then
-                               kill `cat nbd-server.pid`
-                               rm -f nbd-server.pid
+                               kill `cat ${pidfile}`
+                               rm -f ${pidfile}
                        else
                                kill $PID
                        fi
-                       rm -f $tmpnam nbd-server.conf
+                       if [ -z "$2" ]
+                       then
+                               rm -f $tmpnam ${conffile}
+                       fi
                        exit $retval
                fi
                ./nbd-tester-client localhost 11114
@@ -73,34 +90,62 @@ EOF
        ;;
        */cfgnew)
                # Test new-style exports
-               cat >nbd-server.conf <<EOF
+               cat >${conffile} <<EOF
 [generic]
 [export1]
        exportname = $tmpnam
-       copyonwrite = true
-       listenaddr = 127.0.0.1
-[export2]
-       exportname = $tmpnam
-       readonly = true
 EOF
-               ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
+               ./nbd-server -C ${conffile} -p ${pidfile} &
                PID=$!
                sleep 1
                ./nbd-tester-client localhost -N export1
                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
-                       rm -f $tmpnam nbd-server.conf
-                       exit $retval
-               fi
-               ./nbd-tester-client localhost -N export2
+       ;;
+       */write)
+               # Test writing
+               cat >${conffile} <<EOF
+[generic]
+[export1]
+       exportname = $tmpnam
+EOF
+               ./nbd-server -C ${conffile} -p ${pidfile} &
+               PID=$!
+               sleep 1
+               ./nbd-tester-client localhost -N export1 -w
+               retval=$?
+       ;;
+       */flush)
+               # Test writes with flush
+               cat >${conffile} <<EOF
+[generic]
+[export1]
+       exportname = $tmpnam
+       flush = true
+       fua = true
+       rotational = true
+EOF
+               ./nbd-server -C ${conffile} -p ${pidfile} &
+               PID=$!
+               sleep 1
+               ./nbd-tester-client localhost -N export1 -w -f
+               retval=$?
+       ;;
+       */integrity)
+               # Integrity test
+               cat >${conffile} <<EOF
+[generic]
+[export1]
+       exportname = $tmpnam
+       flush = true
+       fua = true
+       rotational = true
+EOF
+               # we need a bigger disk
+               dd if=/dev/zero of=$tmpnam bs=1M count=50 >/dev/null 2>&1
+               ./nbd-server -C ${conffile} -p ${pidfile} &
+               PID=$!
+               sleep 1
+               ./nbd-tester-client localhost -N export1 -i
                retval=$?
        ;;
        *)
@@ -108,15 +153,18 @@ EOF
                exit 1
        ;;
 esac
-if [ -f nbd-server.pid ]
+if [ -f ${pidfile} ]
 then
-       kill `cat nbd-server.pid`
-       rm -f nbd-server.pid
+       kill `cat ${pidfile}`
+       rm -f ${pidfile}
 else
        kill $PID
 fi
+if [ -z "$2" ]
+then
+       rm -f $tmpnam ${conffile}
+fi
 if [ $retval -ne 0 ]
 then
        exit $retval
 fi
-rm -f $tmpnam nbd-server.conf