2 # Test all combinations of alignment of the end-of-message delimiter
3 # with the end of a stdio buffer
11 if [ ! -z "$VALGRIND_ME" ]; then
13 # Lack of quotes here is important
14 VALGRIND="valgrind --quiet --error-exitcode=1"
15 echo "Running tests under valgrind: takes ages!"
20 # First check that all our various pieces of text are
21 # intact. (Since we're dealing in exact byte alignment
22 # minor corruptions such as line ending changes could
23 # render the tests useless.)
24 (cd "$THISDIR" && md5sum *.txt > "$MH_TEST_DIR/inctest.md5sums")
25 diff -u "$THISDIR/md5sums" "$MH_TEST_DIR/inctest.md5sums"
27 FILLER="$THISDIR/filler.txt"
28 FROMLINE="$THISDIR/fromline.txt"
29 HDR="$THISDIR/msgheader.txt"
31 if grep -q From "$FILLER"; then
32 echo "Somebody's messed with $FILLER -- it must not contain"
33 echo "anything that might look like a message delimiter!"
37 # a sort of worst-case guess for the buffer size;
38 # obviously a buffer boundary for this will be a boundary
39 # for any smaller power of two size.
40 # If you need to increase this you'll need to make filler.txt
44 FROMLINESZ="$(wc -c "$FROMLINE" | cut -d ' ' -f 1)"
45 HDRSZ="$(wc -c "$HDR" | cut -d ' ' -f 1)"
47 # makembox_A mboxname sz
48 # Assemble a mailbox into file mboxname, with two messages, such
49 # that the first is exactly sz bytes long (including its header
50 # and its initial 'From' line and the newline which terminates it
51 # but not the newline which mbox format demands after each message)
52 # We also leave the body of message one in mboxname.body
53 # (the body of message two is always $FILLER in its entirety)
58 WANTSZ="$(($SZ - $HDRSZ - $FROMLINESZ - 1))"
59 dd if="$FILLER" of="$MBOX.body" bs="$WANTSZ" count=1 2>/dev/null
61 cat "$FROMLINE" "$HDR" "$MBOX.body" > "$MBOX"
63 cat "$FROMLINE" "$HDR" "$FILLER" >> "$MBOX"
67 # make_mbox_B mboxname sz
68 # Test B makes a mailbox with one message of sz bytes long,
69 # which ends in a partial mbox delimiter (ie part of the string
70 # \n\nFrom '). To both do this and be a valid mbox this means
71 # it has to end with two newlines (one of which is in the message
72 # body and one of which is the mbox format mandated one)
77 WANTSZ="$(($SZ - $HDRSZ - $FROMLINESZ - 1))"
78 dd if="$FILLER" of="$MBOX.body" bs="$WANTSZ" count=1 2>/dev/null
80 cat "$FROMLINE" "$HDR" "$MBOX.body" > "$MBOX"
85 # Do a single test with message one's body of size sz.
88 makembox_A "$MH_TEST_DIR/eom-align.mbox" $STDIO_BUFSZ
89 $VALGRIND inc -silent -file "$MH_TEST_DIR/eom-align.mbox"
90 # We know the messages should be 11 and 12 in inbox
91 # Now get the bodies back out.
92 sed -e '1,/^$/d' "$MH_TEST_DIR/Mail/inbox/11" > "$MH_TEST_DIR/eom-align.inbox.body1"
93 sed -e '1,/^$/d' "$MH_TEST_DIR/Mail/inbox/12" > "$MH_TEST_DIR/eom-align.inbox.body2"
94 diff -u "$MH_TEST_DIR/eom-align.mbox.body" "$MH_TEST_DIR/eom-align.inbox.body1"
95 diff -u "$FILLER" "$MH_TEST_DIR/eom-align.inbox.body2"
103 makembox_B "$MH_TEST_DIR/eom-align.mbox" $STDIO_BUFSZ
104 $VALGRIND inc -silent -file "$MH_TEST_DIR/eom-align.mbox"
105 # We know the message should be 11 in the inbox
106 sed -e '1,/^$/d' "$MH_TEST_DIR/Mail/inbox/11" > "$MH_TEST_DIR/eom-align.inbox.body1"
107 diff -u "$MH_TEST_DIR/eom-align.mbox.body" "$MH_TEST_DIR/eom-align.inbox.body1"
112 # Cover a decent range around the stdio buffer size to make sure we catch
113 # any corner cases whether they relate to total message size equal to
114 # buffer size or to body size equal to buffer size.
115 START=$(($STDIO_BUFSZ - 16))
116 FINISH=$(($STDIO_BUFSZ + $HDRSZ + $FROMLINESZ + 32))
117 echo "Testing inc of files with various alignments of eom marker with buffer size..."
118 for sz in $(seq $START $FINISH); do
119 progress_update $sz $START $FINISH