summaryrefslogtreecommitdiff
path: root/xdelta3/testing/regtest.cc
diff options
context:
space:
mode:
authorJoshua MacDonald <josh.macdonald@gmail.com>2015-05-04 21:14:27 -0700
committerJoshua MacDonald <josh.macdonald@gmail.com>2015-05-04 21:14:27 -0700
commit30b5745de795fba5f9425b3f0c043d1b44e1ceaf (patch)
treebbba560662c8d7d2105f3fca56757729e6b6f801 /xdelta3/testing/regtest.cc
parentaaa50352cef1452e1d3cd97d9fc90209715c0861 (diff)
More followup on issue 188, correction to frontier_blkno calculation (was wrong when last block is full)
Diffstat (limited to 'xdelta3/testing/regtest.cc')
-rw-r--r--xdelta3/testing/regtest.cc64
1 files changed, 51 insertions, 13 deletions
diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc
index 69f8f80..aec3b2a 100644
--- a/xdelta3/testing/regtest.cc
+++ b/xdelta3/testing/regtest.cc
@@ -12,12 +12,14 @@ public:
12 Options() 12 Options()
13 : encode_srcwin_maxsz(1<<20), 13 : encode_srcwin_maxsz(1<<20),
14 block_size(Constants::BLOCK_SIZE), 14 block_size(Constants::BLOCK_SIZE),
15 window_size(Constants::WINDOW_SIZE),
15 size_known(false), 16 size_known(false),
16 iopt_size(XD3_DEFAULT_IOPT_SIZE), 17 iopt_size(XD3_DEFAULT_IOPT_SIZE),
17 smatch_cfg(XD3_SMATCH_DEFAULT) { } 18 smatch_cfg(XD3_SMATCH_DEFAULT) { }
18 19
19 xoff_t encode_srcwin_maxsz; 20 xoff_t encode_srcwin_maxsz;
20 size_t block_size; 21 size_t block_size;
22 xoff_t window_size;
21 bool size_known; 23 bool size_known;
22 usize_t iopt_size; 24 usize_t iopt_size;
23 xd3_smatch_cfg smatch_cfg; 25 xd3_smatch_cfg smatch_cfg;
@@ -56,7 +58,7 @@ public:
56 xd3_init_config(&encode_config, XD3_ADLER32); 58 xd3_init_config(&encode_config, XD3_ADLER32);
57 xd3_init_config(&decode_config, XD3_ADLER32); 59 xd3_init_config(&decode_config, XD3_ADLER32);
58 60
59 encode_config.winsize = Constants::WINDOW_SIZE; 61 encode_config.winsize = options.window_size;
60 encode_config.iopt_size = options.iopt_size; 62 encode_config.iopt_size = options.iopt_size;
61 encode_config.smatch_cfg = options.smatch_cfg; 63 encode_config.smatch_cfg = options.smatch_cfg;
62 64
@@ -152,10 +154,10 @@ public:
152 Block *block = (encoding ? &encode_source_block : &decode_source_block); 154 Block *block = (encoding ? &encode_source_block : &decode_source_block);
153 if (encoding) { 155 if (encoding) {
154 IF_DEBUG1(XPR(NTR "[srcblock] %"Q"u last srcpos %"Q"u " 156 IF_DEBUG1(XPR(NTR "[srcblock] %"Q"u last srcpos %"Q"u "
155 "encodepos %"Q"u\n", 157 "encodepos %"Q"u\n",
156 encode_source.getblkno, 158 encode_source.getblkno,
157 encode_stream.match_last_srcpos, 159 encode_stream.match_last_srcpos,
158 encode_stream.input_position + encode_stream.total_in)); 160 encode_stream.input_position + encode_stream.total_in));
159 } 161 }
160 162
161 source_iterator.SetBlock(src->getblkno); 163 source_iterator.SetBlock(src->getblkno);
@@ -228,10 +230,10 @@ public:
228 ExtFile *coded_data, 230 ExtFile *coded_data,
229 const Options &options) { 231 const Options &options) {
230 vector<const char*> ecmd; 232 vector<const char*> ecmd;
231 char wbuf[16]; 233 char bbuf[16];
232 snprintf(wbuf, sizeof(wbuf), "-B%"Q"u", options.encode_srcwin_maxsz); 234 snprintf(bbuf, sizeof(bbuf), "-B%"Q"u", options.encode_srcwin_maxsz);
233 ecmd.push_back("xdelta3"); 235 ecmd.push_back("xdelta3");
234 ecmd.push_back(wbuf); 236 ecmd.push_back(bbuf);
235 ecmd.push_back("-s"); 237 ecmd.push_back("-s");
236 ecmd.push_back(source_file.Name()); 238 ecmd.push_back(source_file.Name());
237 ecmd.push_back(target_file.Name()); 239 ecmd.push_back(target_file.Name());
@@ -244,7 +246,7 @@ public:
244 vector<const char*> dcmd; 246 vector<const char*> dcmd;
245 ExtFile recon_file; 247 ExtFile recon_file;
246 dcmd.push_back("xdelta3"); 248 dcmd.push_back("xdelta3");
247 ecmd.push_back(wbuf); 249 ecmd.push_back(bbuf);
248 dcmd.push_back("-d"); 250 dcmd.push_back("-d");
249 dcmd.push_back("-s"); 251 dcmd.push_back("-s");
250 dcmd.push_back(source_file.Name()); 252 dcmd.push_back(source_file.Name());
@@ -837,7 +839,6 @@ void TestCopyWindow() {
837 options.encode_srcwin_maxsz = size; 839 options.encode_srcwin_maxsz = size;
838 options.iopt_size = 128; 840 options.iopt_size = 128;
839 options.smatch_cfg = XD3_SMATCH_SLOW; 841 options.smatch_cfg = XD3_SMATCH_SLOW;
840 options.size_known = false;
841 842
842 Block block1; 843 Block block1;
843 InMemoryEncodeDecode(spec0, spec1, &block1, options); 844 InMemoryEncodeDecode(spec0, spec1, &block1, options);
@@ -952,7 +953,7 @@ void TestHalfBlockCopy() {
952 Options options; 953 Options options;
953 options.encode_srcwin_maxsz = Constants::BLOCK_SIZE * b; 954 options.encode_srcwin_maxsz = Constants::BLOCK_SIZE * b;
954 955
955 Block block0; 956 // Block block0;
956 Block block1; 957 Block block1;
957 InMemoryEncodeDecode(spec0, spec1, &block0, options); 958 InMemoryEncodeDecode(spec0, spec1, &block0, options);
958 InMemoryEncodeDecode(spec1, spec0, &block1, options); 959 InMemoryEncodeDecode(spec1, spec0, &block1, options);
@@ -978,7 +979,6 @@ void TestHalfBlockCopy() {
978 // When there are fewer than 3 source blocks. 979 // When there are fewer than 3 source blocks.
979 CHECK_EQ(nocopy_adds, delta1.AddedBytes()); 980 CHECK_EQ(nocopy_adds, delta1.AddedBytes());
980 } 981 }
981 // XPR(NT "0=%zu 1=%zu\n", delta0.AddedBytes(), delta1.AddedBytes());
982 } 982 }
983 983
984 Options options; 984 Options options;
@@ -997,7 +997,6 @@ void TestHalfBlockCopy() {
997 CHECK_GE(onecopy_adds + 1, delta0.AddedBytes()); 997 CHECK_GE(onecopy_adds + 1, delta0.AddedBytes());
998 998
999 CHECK_EQ(onecopy_adds, delta1.AddedBytes()); 999 CHECK_EQ(onecopy_adds, delta1.AddedBytes());
1000 // XPR(NT "0=%zu 1=%zu\n", delta0.AddedBytes(), delta1.AddedBytes());
1001} 1000}
1002 1001
1003void FourWayMergeTest(const FileSpec &spec0, 1002void FourWayMergeTest(const FileSpec &spec0,
@@ -1200,6 +1199,44 @@ void TestMergeCommand2() {
1200 } 1199 }
1201} 1200}
1202 1201
1202void TestLastFrontierBlock() {
1203 // This test constructs an input that can expose
1204 // https://github.com/jmacd/xdelta/issues/188
1205 // when run through the command-line with source via a FIFO.
1206 // That is not tested here, but the test stays.
1207 if (Constants::WINDOW_SIZE < XD3_ALLOCSIZE)
1208 {
1209 return;
1210 }
1211
1212 MTRandom rand;
1213 FileSpec spec0(&rand);
1214 FileSpec spec1(&rand);
1215 const xoff_t size = XD3_ALLOCSIZE * 64; // == XD3_MINSRCWINSZ * 2
1216 const xoff_t edit = XD3_ALLOCSIZE;
1217
1218 Options options;
1219 options.encode_srcwin_maxsz = XD3_MINSRCWINSZ;
1220 options.block_size = XD3_ALLOCSIZE;
1221 options.window_size = XD3_MINSRCWINSZ;
1222 options.size_known = false;
1223
1224 spec0.GenerateFixedSize(size);
1225
1226 ChangeList cl;
1227
1228 // Modify the 0th byte in order to induce indexing of subsequent
1229 // bytes, but allow copying most of the file to keep the test fast.
1230 cl.push_back(Change(Change::MODIFY, 1, edit * 31));
1231 cl.push_back(Change(Change::COPYOVER, edit, edit * 31, edit * 63));
1232
1233 spec0.ModifyTo(ChangeListMutator(cl), &spec1);
1234
1235 Block noblock;
1236 InMemoryEncodeDecode(spec0, spec1, &noblock, options);
1237 InMemoryEncodeDecode(spec1, spec0, &noblock, options);
1238}
1239
1203}; // class Regtest<Constants> 1240}; // class Regtest<Constants>
1204 1241
1205#define TEST(x) XPR(NTR #x "...\n"); regtest.x() 1242#define TEST(x) XPR(NTR #x "...\n"); regtest.x()
@@ -1232,6 +1269,7 @@ void MainTest() {
1232 TEST(TestCopyFromEnd); 1269 TEST(TestCopyFromEnd);
1233 TEST(TestNonBlocking); 1270 TEST(TestNonBlocking);
1234 TEST(TestHalfBlockCopy); 1271 TEST(TestHalfBlockCopy);
1272 TEST(TestLastFrontierBlock);
1235 TEST(TestMergeCommand1); 1273 TEST(TestMergeCommand1);
1236 TEST(TestMergeCommand2); 1274 TEST(TestMergeCommand2);
1237} 1275}