From efd72b85cccd9b00388cd16722d6238d5eb193c3 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sun, 19 Mar 2017 11:53:16 +0100 Subject: [PATCH] autotest: implement much more thorough resumption verification the test will now make a test run for every journaled step, both right before and right after the logging. --- src/common.h | 1 + src/main.c | 2 ++ src/run-tests.pl | 59 ++++++++++++++++++++++++++++++++++++++++-------- src/sync.c | 4 ++++ 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/common.h b/src/common.h index ac3d2d3..12c8890 100644 --- a/src/common.h +++ b/src/common.h @@ -81,6 +81,7 @@ typedef unsigned int uint; #define ZERODELAY 0x2000 extern int DFlags; +extern int JLimit; extern int UseFSync; extern char FieldDelimiter; diff --git a/src/main.c b/src/main.c index 929db08..2a57eb6 100644 --- a/src/main.c +++ b/src/main.c @@ -32,6 +32,7 @@ #include int DFlags; +int JLimit; int UseFSync = 1; #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__CYGWIN__) char FieldDelimiter = ';'; @@ -684,6 +685,7 @@ main( int argc, char **argv ) break; case 'J': DFlags |= KEEPJOURNAL; + JLimit = strtol( ochar, &ochar, 10 ); break; case 'Z': DFlags |= ZERODELAY; diff --git a/src/run-tests.pl b/src/run-tests.pl index 3dac390..2dce057 100755 --- a/src/run-tests.pl +++ b/src/run-tests.pl @@ -641,9 +641,10 @@ sub test($$$@) return 0 if (scalar(@ARGV) && !grep { $_ eq $ttl } @ARGV); print "Testing: ".$ttl." ...\n"; - mkchan($$sx[0], $$sx[1], @{ $$sx[2] }); &writecfg(@sfx); + mkchan($$sx[0], $$sx[1], @{ $$sx[2] }); + my ($xc, @ret) = runsync("-J", "1-initial.log"); if ($xc || ckchan("slave/.mbsyncstate.new", $tx)) { print "Input:\n"; @@ -662,42 +663,80 @@ sub test($$$@) } my @nj = readfile("slave/.mbsyncstate.journal"); - ($xc, @ret) = runsync("-0 --no-expunge", "2-replay.log"); - if ($xc || ckstate("slave/.mbsyncstate", @{ $$tx[2] })) { + my ($jxc, @jret) = runsync("-0 --no-expunge", "2-replay.log"); + if ($jxc || ckstate("slave/.mbsyncstate", @{ $$tx[2] })) { print "Journal replay failed.\n"; print "Options:\n"; print " [ ".join(", ", map('"'.qm($_).'"', @sfx))." ], [ \"-0\", \"--no-expunge\" ]\n"; print "Old State:\n"; printstate(@{ $$sx[2] }); print "Journal:\n".join("", @nj)."\n"; - if (!$xc) { + if (!$jxc) { print "Expected New State:\n"; printstate(@{ $$tx[2] }); print "New State:\n"; showstate("slave/.mbsyncstate"); } print "Debug output:\n"; - print @ret; + print @jret; exit 1; } - ($xc, @ret) = runsync("", "3-verify.log"); - if ($xc || ckchan("slave/.mbsyncstate", $tx)) { + my ($ixc, @iret) = runsync("", "3-verify.log"); + if ($ixc || ckchan("slave/.mbsyncstate", $tx)) { print "Idempotence verification run failed.\n"; print "Input == Expected result:\n"; printchan($tx); print "Options:\n"; print " [ ".join(", ", map('"'.qm($_).'"', @sfx))." ]\n"; - if (!$xc) { + if (!$ixc) { print "Actual result:\n"; showchan("slave/.mbsyncstate"); } print "Debug output:\n"; - print @ret; + print @iret; exit 1; } - killcfg(); rmtree "slave"; rmtree "master"; + + my $njl = (@nj - 1) * 2; + for (my $l = 2; $l < $njl; $l++) { + mkchan($$sx[0], $$sx[1], @{ $$sx[2] }); + + my ($nxc, @nret) = runsync("-J$l", "4-interrupt.log"); + if ($nxc != (100 + ($l & 1)) << 8) { + print "Interrupting at step $l/$njl failed.\n"; + print "Debug output:\n"; + print @nret; + exit 1; + } + + ($nxc, @nret) = runsync("-J", "5-resume.log"); + if ($nxc || ckchan("slave/.mbsyncstate.new", $tx)) { + print "Resuming from step $l/$njl failed.\n"; + print "Input:\n"; + printchan($sx); + print "Options:\n"; + print " [ ".join(", ", map('"'.qm($_).'"', @sfx))." ]\n"; + my @nnj = readfile("slave/.mbsyncstate.journal"); + print "Journal:\n".join("", @nnj[0..($l / 2 - 1)])."-------\n".join("", @nnj[($l / 2)..$#nnj])."\n"; + print "Full journal:\n".join("", @nj)."\n"; + if (!$nxc) { + print "Expected result:\n"; + printchan($tx); + print "Actual result:\n"; + showchan("slave/.mbsyncstate"); + } + print "Debug output:\n"; + print @nret; + exit 1; + } + + rmtree "slave"; + rmtree "master"; + } + + killcfg(); } diff --git a/src/sync.c b/src/sync.c index 1663939..66e201c 100644 --- a/src/sync.c +++ b/src/sync.c @@ -212,9 +212,13 @@ jFprintf( sync_vars_t *svars, const char *msg, ... ) { va_list va; + if (JLimit && !--JLimit) + exit( 101 ); va_start( va, msg ); vFprintf( svars->jfp, msg, va ); va_end( va ); + if (JLimit && !--JLimit) + exit( 100 ); } static void