]> diplodocus.org Git - nmh/commitdiff
Support for locking tests in the test suite.
authorKen Hornstein <kenh@pobox.com>
Sat, 16 Mar 2013 03:45:54 +0000 (23:45 -0400)
committerKen Hornstein <kenh@pobox.com>
Sat, 16 Mar 2013 03:45:54 +0000 (23:45 -0400)
Makefile.am
etc/mts.conf.in
m4/locking.m4
test/common.sh.in
test/locking/test-datalocking [new file with mode: 0755]
test/locking/test-spoollocking [new file with mode: 0755]

index 0e64a27bd06056937816e4b524e6dec71df6a199..e8f64505e1b07feeb627e6bfbcdce1059e638076 100644 (file)
@@ -37,6 +37,7 @@ TESTS_ENVIRONMENT = MH_OBJ_DIR="@abs_builddir@" \
                    MH_TEST_DIR="@abs_builddir@/test/testdir" \
                    auxexecdir="$(auxexecdir)" bindir="$(bindir)" \
                    mandir="$(mandir)" sysconfdir="$(sysconfdir)" \
                    MH_TEST_DIR="@abs_builddir@/test/testdir" \
                    auxexecdir="$(auxexecdir)" bindir="$(bindir)" \
                    mandir="$(mandir)" sysconfdir="$(sysconfdir)" \
+                   supported_locks="$(supported_locks)" \
                    MULTIBYTE_ENABLED=$(MULTIBYTE_ENABLED) \
                    ICONV_ENABLED=$(ICONV_ENABLED) \
                    $(TESTS_SHELL) ## Keep at end of TESTS_ENVIRONMENT.
                    MULTIBYTE_ENABLED=$(MULTIBYTE_ENABLED) \
                    ICONV_ENABLED=$(ICONV_ENABLED) \
                    $(TESTS_SHELL) ## Keep at end of TESTS_ENVIRONMENT.
@@ -58,7 +59,9 @@ TESTS = test/ali/test-ali test/anno/test-anno \
        test/inc/test-deb359167 test/inc/test-eom-align \
        test/inc/test-inc-scanout test/inc/test-msgchk \
        test/inc/test-pop \
        test/inc/test-deb359167 test/inc/test-eom-align \
        test/inc/test-inc-scanout test/inc/test-msgchk \
        test/inc/test-pop \
-       test/install-mh/test-install-mh test/manpages/test-manpages \
+       test/install-mh/test-install-mh \
+       test/locking/test-datalocking test/locking/test-spoollocking \
+       test/manpages/test-manpages \
        test/mhbuild/test-forw test/mhbuild/test-utf8-body \
        test/mhlist/test-mhlist test/mhmail/test-mhmail \
        test/mhparam/test-mhparam test/mhpath/test-mhpath \
        test/mhbuild/test-forw test/mhbuild/test-utf8-body \
        test/mhlist/test-mhlist test/mhmail/test-mhmail \
        test/mhparam/test-mhparam test/mhpath/test-mhpath \
@@ -448,6 +451,8 @@ etc/mts.conf: $(srcdir)/etc/mts.conf.in Makefile
        $(SED) -e 's,%mts%,$(MTS),' \
               -e 's,%mailspool%,$(mailspool),' \
               -e 's,%smtpservers%,$(smtpservers),' \
        $(SED) -e 's,%mts%,$(MTS),' \
               -e 's,%mailspool%,$(mailspool),' \
               -e 's,%smtpservers%,$(smtpservers),' \
+              -e 's,%default_locking%,$(default_locking),' \
+              -e 's,%supported_locks%,$(supported_locks),' \
                                < $(srcdir)/etc/mts.conf.in > $@
 
 etc/mhn.defaults: $(srcdir)/etc/mhn.defaults.sh $(MHNSEARCHPROG)
                                < $(srcdir)/etc/mts.conf.in > $@
 
 etc/mhn.defaults: $(srcdir)/etc/mhn.defaults.sh $(MHNSEARCHPROG)
index 4e3deda6769cd39995b2162642b28a0274d9d2aa..bcf7b2f941521be56b5cab628b1347c6f9f54c62 100644 (file)
@@ -27,6 +27,22 @@ mmdfldir: %mailspool%
 # are kept.  If this is empty, the user's login name is used.
 mmdflfil:
 
 # are kept.  If this is empty, the user's login name is used.
 mmdflfil:
 
+#
+# The locking algorithm to use on the spool file.  Valid settings are:
+#
+#   fcntl      Locking using the fcntl() function
+#   dot                "Dot" locking using an external lock file
+#   flock      Locking using the flock() function (if supported by OS)
+#   lockf      Locking using the lockf() function (if supported by OS)
+#
+# Locking algorithms supported on this installation are:
+#
+#      %supported_locks%
+#
+# The default spool locking configured on this system is %default_locking%;
+# change the line below to get a different value
+#spoollocking: %default_locking%
+
 # Hardcoded POP server name (prevents inc'ing from local mail spool).
 #pophost: localhost
 
 # Hardcoded POP server name (prevents inc'ing from local mail spool).
 #pophost: localhost
 
index b70f225f3bb0e189f3a166d93e5f900bd22d0dfc..2895d882779f5214a5bfb98416e8223a5b054e87 100644 (file)
@@ -35,9 +35,17 @@ AS_CASE([$with_locking],
 
 AC_DEFINE_UNQUOTED([DEFAULT_LOCKING], ["$with_locking"],
   [The default lock type for the mail spool file])
 
 AC_DEFINE_UNQUOTED([DEFAULT_LOCKING], ["$with_locking"],
   [The default lock type for the mail spool file])
+AC_SUBST([default_locking], [$with_locking])
 
 AC_MSG_RESULT([$with_locking])
 
 
 AC_MSG_RESULT([$with_locking])
 
+supported_locks="fcntl dot"
+AS_IF([test x"$ac_cv_func_flock" = x"yes"],
+  [supported_locks="$supported_locks flock"])
+AS_IF([test x"$ac_cv_func_lockf" = x"yes"],
+  [supported_locks="$supported_locks lockf"])
+AC_SUBST([supported_locks])
+
 dnl Should we use a locking directory?
 AC_ARG_ENABLE([lockdir],
   [AS_HELP_STRING([--enable-lockdir=dir], [Store dot-lock files in "dir"])], [
 dnl Should we use a locking directory?
 AC_ARG_ENABLE([lockdir],
   [AS_HELP_STRING([--enable-lockdir=dir], [Store dot-lock files in "dir"])], [
index 2264d469dd304ede3b58a6ce6e065b50da5bc1a1..1f52004aae3c59b245d0312dedd53b28203a91c5 100644 (file)
@@ -13,6 +13,7 @@ test -z "$auxexecdir"  &&  auxexecdir="@libdir@"
 test -z "$bindir"  &&  bindir="@bindir@"
 test -z "$mandir"  &&  mandir="@mandir@"
 test -z "$sysconfdir"  &&  sysconfdir="@sysconfdir@"
 test -z "$bindir"  &&  bindir="@bindir@"
 test -z "$mandir"  &&  mandir="@mandir@"
 test -z "$sysconfdir"  &&  sysconfdir="@sysconfdir@"
+test -z "$supported_locks"  &&  supported_locks="@supported_locks@"
 test -z "$MULTIBYTE_ENABLED"  &&  MULTIBYTE_ENABLED="@MULTIBYTE_ENABLED@"
 test -z "$ICONV_ENABLED"  &&  ICONV_ENABLED="@ICONV_ENABLED@"
 export MH_TEST_DIR auxexecdir bindir mandir sysconfdir
 test -z "$MULTIBYTE_ENABLED"  &&  MULTIBYTE_ENABLED="@MULTIBYTE_ENABLED@"
 test -z "$ICONV_ENABLED"  &&  ICONV_ENABLED="@ICONV_ENABLED@"
 export MH_TEST_DIR auxexecdir bindir mandir sysconfdir
diff --git a/test/locking/test-datalocking b/test/locking/test-datalocking
new file mode 100755 (executable)
index 0000000..4c2d193
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/sh
+######################################################
+#
+# Test the locking of nmh metadata
+#
+######################################################
+
+set -e
+
+if test -z "${MH_OBJ_DIR}"; then
+    srcdir=`dirname $0`/../..
+    MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
+fi
+
+. "$MH_OBJ_DIR/test/common.sh"
+
+setup_test
+
+#
+# Set things up so we have a "cur" sequence
+#
+
+show +inbox 1 -nocheckmime -showproc cat > /dev/null
+
+#
+# mark read & writes sequences files, so use it to exercise the locking code
+# for each locking algorithm
+#
+
+for locktype in $supported_locks
+do
+    mv -f ${MH} ${MH}.old
+    sed -e '/^datalocking:/d' < ${MH}.old > ${MH}
+    rm -f ${MH}.old
+
+    echo "datalocking: $locktype" >> ${MH}
+
+    mark 2 4 6 -sequence test -add
+
+    run_test 'mark -list' 'cur: 1
+test: 2 4 6'
+
+    mark all -sequence test -delete
+
+done
+
+exit ${failed:-0}
diff --git a/test/locking/test-spoollocking b/test/locking/test-spoollocking
new file mode 100755 (executable)
index 0000000..c795ce3
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/sh
+######################################################
+#
+# Test the locking of nmh spool file
+#
+######################################################
+
+set -e
+
+if test -z "${MH_OBJ_DIR}"; then
+    srcdir=`dirname $0`/../..
+    MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
+fi
+
+. "$MH_OBJ_DIR/test/common.sh"
+
+setup_test
+
+testmessage="$MH_TEST_DIR/testmessage"
+
+cat > "$testmessage" <<EOM
+Received: From somewhere
+From: No Such User <nosuch@example.com>
+To: Some Other User <someother@example.com>
+Subject: Hello, how are you?
+Date: Sun, 17 Dec 2006 12:13:14 -0500
+
+This is a test; will it work?
+EOM
+
+#
+# invoke "inc" for each locking algorithm
+#
+
+for locktype in $supported_locks
+do
+    mv -f ${MHMTSCONF} ${MHMTSCONF}.backup
+    sed -e '/^datalocking:/d' < ${MHMTSCONF}.backup > ${MHMTSCONF}
+    rm -f ${MHMTSCONF}.backup
+
+    echo "spoollocking: $locktype" >> ${MHMTSCONF}
+
+    run_test "inc -notruncate -width 80 -file $testmessage" \
+"Incorporating new mail into inbox...
+
+  11+ 12/17 No Such User       Hello, how are you?<<This is a test; will it wor
+$testmessage not zero'd"
+
+    rmm 11
+
+done
+
+rm -f "$testmessage"
+
+exit ${failed:-0}