r337: Check multi-file export in 'make check', too; and tell automake that we have...
authoryoe <yoe>
Wed, 18 Jun 2008 10:38:22 +0000 (10:38 +0000)
committeryoe <yoe>
Wed, 18 Jun 2008 10:38:22 +0000 (10:38 +0000)
Makefile.am
nbd-server.c
simple_test

index d9fad16..d909a2b 100644 (file)
@@ -1,6 +1,7 @@
 bin_PROGRAMS = nbd-server
 EXTRA_PROGRAMS = nbd-client knbd-client
-TESTS = $(srcdir)/simple_test
+TESTS_ENVIRONMENT=$(srcdir)/simple_test
+TESTS = cmd cfg1 cfgmulti
 check_PROGRAMS = nbd-tester-client
 knbd_client_SOURCES = nbd-client.c cliserv.h
 nbd_client_SOURCES = nbd-client.c cliserv.h
@@ -24,3 +25,6 @@ nbd-server.5.in: nbd-server.5.sgml
        mv NBD-SERVER.5 nbd-server.5.in
 dist-hook:
        rm -Rf `find $(distdir) -name '.svn' -type d -print`
+cmd:
+cfg1:
+cfgmulti:
index 8f44c24..a683f8c 100644 (file)
@@ -170,6 +170,7 @@ typedef enum {
  **/
 typedef struct {
        gchar* exportname;    /**< (unprocessed) filename of the file we're exporting */
+       gchar* cowname;      /**< template for the filename of the copy-on-write file */
        off_t expected_size; /**< size of the exported file as it was told to
                               us through configuration */
        gchar* listenaddr;   /**< The IP address we're listening on */
@@ -558,6 +559,7 @@ GArray* parse_cfile(gchar* f, GError** e) {
                { "sparse_cow", FALSE,  PARAM_BOOL,     NULL, F_SPARSE },
                { "sdp",        FALSE,  PARAM_BOOL,     NULL, F_SDP },
                { "listenaddr", FALSE,  PARAM_STRING,   NULL, 0 },
+               { "cowname",    FALSE,  PARAM_STRING,   NULL, 0 },
        };
        const int lp_size=sizeof(lp)/sizeof(PARAM);
        PARAM gp[] = {
@@ -604,6 +606,9 @@ GArray* parse_cfile(gchar* f, GError** e) {
                lp[8].target=lp[9].target=lp[10].target=
                                lp[11].target=lp[12].target=&(s.flags);
                lp[13].target=&(s.listenaddr);
+               lp[14].target=&(s.cowname);
+
+               s.cowname = "$F-$I-$P.diff";
 
                /* After the [generic] group, start parsing exports */
                if(i==1) {
index 71226f2..4b6b521 100755 (executable)
@@ -6,43 +6,83 @@ tmpnam=`mktemp`
 # Create a one-meg device
 dd if=/dev/zero of=$tmpnam bs=1024 count=1024
 
-./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 localhost 11111
-retval=$?
-if [ -f nbd-server.pid ]
-then
-       kill `cat nbd-server.pid`
-else
-       kill $PID
-fi
-rm -f nbd-server.pid
-if [ $retval -ne 0 ]
-then
-       rm -f $tmpnam
-       exit $retval
-fi
-cat > nbd-server.conf <<EOF
+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 localhost 11111
+               retval=$?
+       ;;
+
+       ./cfg1)
+               # Test with export specified in config file
+               cat > nbd-server.conf <<EOF
 [generic]
 [export]
        exportname = $tmpnam
        port = 11111
 EOF
-./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
-PID=$!
-sleep 1
-./nbd-tester-client localhost 11111
-retval=$?
+               ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
+               PID=$!
+               sleep 1
+               ./nbd-tester-client localhost 11111
+               retval=$?
+       ;;
+       ./cfgmulti)
+               # Test with multiple exports specified in config file, and
+               # testing more options too
+               cat >nbd-server.conf <<EOF
+[generic]
+[export1]
+       exportname = $tmpnam
+       port = 11111
+       copyonwrite = true
+       listenaddr = 127.0.0.1
+[export2]
+       exportname = $tmpnam
+       port = 11112
+       readonly = true
+EOF
+               ./nbd-server -C nbd-server.conf -p `pwd`/nbd-server.pid &
+               PID=$!
+               sleep 1
+               ./nbd-tester-client localhost 11111
+               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 11112
+               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
-rm -f nbd-server.pid
-rm -f nbd-server.conf
-rm -f $tmpnam
-exit $retval
+if [ $retval -ne 0 ]
+then
+       exit $retval
+fi
+rm -f $tmpnam nbd-server.conf