From: Ken Hornstein Date: Sat, 16 Mar 2013 03:45:54 +0000 (-0400) Subject: Support for locking tests in the test suite. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/1c8cf81caa1f8d56f8812b73d37cfc62a9815877?ds=inline;hp=--cc Support for locking tests in the test suite. --- 1c8cf81caa1f8d56f8812b73d37cfc62a9815877 diff --git a/Makefile.am b/Makefile.am index 0e64a27b..e8f64505 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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)" \ + supported_locks="$(supported_locks)" \ 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/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 \ @@ -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),' \ + -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) diff --git a/etc/mts.conf.in b/etc/mts.conf.in index 4e3deda6..bcf7b2f9 100644 --- a/etc/mts.conf.in +++ b/etc/mts.conf.in @@ -27,6 +27,22 @@ mmdfldir: %mailspool% # 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 diff --git a/m4/locking.m4 b/m4/locking.m4 index b70f225f..2895d882 100644 --- a/m4/locking.m4 +++ b/m4/locking.m4 @@ -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_SUBST([default_locking], [$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"])], [ diff --git a/test/common.sh.in b/test/common.sh.in index 2264d469..1f52004a 100644 --- a/test/common.sh.in +++ b/test/common.sh.in @@ -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 "$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 diff --git a/test/locking/test-datalocking b/test/locking/test-datalocking new file mode 100755 index 00000000..4c2d1935 --- /dev/null +++ b/test/locking/test-datalocking @@ -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 index 00000000..c795ce3d --- /dev/null +++ b/test/locking/test-spoollocking @@ -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" < +To: Some Other User +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?<