diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2009-03-08 03:39:35 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2009-03-08 03:39:35 +0000 |
commit | c2ac8336ee676ec6f2d3a24e6eeb339a5fda30ba (patch) | |
tree | e0206139b17183de6393f9826da9873a15a2bc00 /xdelta3/testing | |
parent | 9be16d928d7386488efc34bd99293b3360105da0 (diff) |
Testing for issue 79. TODO around xdelta3.c:3926 successful.
Diffstat (limited to 'xdelta3/testing')
-rw-r--r-- | xdelta3/testing/file.h | 8 | ||||
-rw-r--r-- | xdelta3/testing/modify.h | 2 | ||||
-rw-r--r-- | xdelta3/testing/regtest.cc | 40 | ||||
-rw-r--r-- | xdelta3/testing/sizes.h | 34 | ||||
-rw-r--r-- | xdelta3/testing/test.h | 2 |
5 files changed, 67 insertions, 19 deletions
diff --git a/xdelta3/testing/file.h b/xdelta3/testing/file.h index f06da2b..9bfbf4c 100644 --- a/xdelta3/testing/file.h +++ b/xdelta3/testing/file.h | |||
@@ -258,6 +258,10 @@ public: | |||
258 | return blkno_; | 258 | return blkno_; |
259 | } | 259 | } |
260 | 260 | ||
261 | xoff_t Blocks() const { | ||
262 | return spec_.Blocks(blksize_); | ||
263 | } | ||
264 | |||
261 | xoff_t Offset() const { | 265 | xoff_t Offset() const { |
262 | return blkno_ * blksize_; | 266 | return blkno_ * blksize_; |
263 | } | 267 | } |
@@ -274,8 +278,8 @@ public: | |||
274 | xoff_t blocks = spec_.Blocks(blksize_); | 278 | xoff_t blocks = spec_.Blocks(blksize_); |
275 | xoff_t size = spec_.Size(); | 279 | xoff_t size = spec_.Size(); |
276 | 280 | ||
277 | CHECK((blkno_ < blocks) || | 281 | DCHECK((blkno_ < blocks) || |
278 | (blkno_ == blocks && size % blksize_ == 0)); | 282 | (blkno_ == blocks && size % blksize_ == 0)); |
279 | 283 | ||
280 | if (blkno_ == blocks) { | 284 | if (blkno_ == blocks) { |
281 | return 0; | 285 | return 0; |
diff --git a/xdelta3/testing/modify.h b/xdelta3/testing/modify.h index 4b2cea8..baa8861 100644 --- a/xdelta3/testing/modify.h +++ b/xdelta3/testing/modify.h | |||
@@ -152,6 +152,8 @@ public: | |||
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | // This check verifies that the modify does not extend past the | ||
156 | // source_table EOF. | ||
155 | CHECK_LE(m_end, i_end); | 157 | CHECK_LE(m_end, i_end); |
156 | } | 158 | } |
157 | 159 | ||
diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc index 910a8db..7618b38 100644 --- a/xdelta3/testing/regtest.cc +++ b/xdelta3/testing/regtest.cc | |||
@@ -64,21 +64,30 @@ void InMemoryEncodeDecode(const FileSpec &source_file, | |||
64 | xd3_set_source (&encode_stream, &encode_source); | 64 | xd3_set_source (&encode_stream, &encode_source); |
65 | xd3_set_source (&decode_stream, &decode_source); | 65 | xd3_set_source (&decode_stream, &decode_source); |
66 | 66 | ||
67 | BlockIterator source_iterator(source_file); | 67 | BlockIterator source_iterator(source_file, Constants::BLOCK_SIZE); |
68 | BlockIterator target_iterator(target_file); | 68 | BlockIterator target_iterator(target_file, Constants::READ_SIZE); |
69 | Block encode_source_block, decode_source_block; | 69 | Block encode_source_block, decode_source_block; |
70 | Block decoded_block, target_block; | 70 | Block decoded_block, target_block; |
71 | bool encoding = true; | 71 | bool encoding = true; |
72 | bool done = false; | 72 | bool done = false; |
73 | bool done_after_input = false; | ||
73 | 74 | ||
74 | DP(RINT "source %"Q"u target %"Q"u\n", | 75 | DP(RINT "source %"Q"u[%"Q"u] target %"Q"u[%lu] winsize %lu\n", |
75 | source_file.Size(), target_file.Size()); | 76 | source_file.Size(), Constants::BLOCK_SIZE, |
77 | target_file.Size(), Constants::READ_SIZE, | ||
78 | Constants::WINDOW_SIZE); | ||
76 | 79 | ||
77 | while (!done) { | 80 | while (!done) { |
78 | target_iterator.Get(&target_block); | 81 | target_iterator.Get(&target_block); |
79 | 82 | ||
80 | if (target_file.Blocks() == 0 || | 83 | xoff_t blks = target_iterator.Blocks(); |
81 | target_iterator.Blkno() == (target_file.Blocks() - 1)) { | 84 | |
85 | //DP(RINT "target in %s: %llu..%llu %"Q"u(%"Q"u) verified %"Q"u\n", | ||
86 | // encoding ? "encoding" : "decoding", | ||
87 | // target_iterator.Offset(), target_iterator.Offset() + target_block.Size(), | ||
88 | // target_iterator.Blkno(), blks, verified_bytes); | ||
89 | |||
90 | if (blks == 0 || target_iterator.Blkno() == (blks - 1)) { | ||
82 | xd3_set_flags(&encode_stream, XD3_FLUSH | encode_stream.flags); | 91 | xd3_set_flags(&encode_stream, XD3_FLUSH | encode_stream.flags); |
83 | } | 92 | } |
84 | 93 | ||
@@ -93,7 +102,7 @@ void InMemoryEncodeDecode(const FileSpec &source_file, | |||
93 | ret = xd3_decode_input(&decode_stream); | 102 | ret = xd3_decode_input(&decode_stream); |
94 | } | 103 | } |
95 | 104 | ||
96 | //DP(RINT "%s = %s\n", encoding ? "encoding" : "decoding", | 105 | //DP(RINT "%s = %s\n", encoding ? "E " : " D", |
97 | // xd3_strerror(ret)); | 106 | // xd3_strerror(ret)); |
98 | 107 | ||
99 | switch (ret) { | 108 | switch (ret) { |
@@ -141,6 +150,11 @@ void InMemoryEncodeDecode(const FileSpec &source_file, | |||
141 | encoding = true; | 150 | encoding = true; |
142 | goto process; | 151 | goto process; |
143 | } else { | 152 | } else { |
153 | if (done_after_input) { | ||
154 | done = true; | ||
155 | continue; | ||
156 | } | ||
157 | |||
144 | if (target_block.Size() < target_iterator.BlockSize()) { | 158 | if (target_block.Size() < target_iterator.BlockSize()) { |
145 | encoding = false; | 159 | encoding = false; |
146 | } else { | 160 | } else { |
@@ -152,8 +166,7 @@ void InMemoryEncodeDecode(const FileSpec &source_file, | |||
152 | case XD3_WINFINISH: | 166 | case XD3_WINFINISH: |
153 | if (encoding) { | 167 | if (encoding) { |
154 | if (encode_stream.flags & XD3_FLUSH) { | 168 | if (encode_stream.flags & XD3_FLUSH) { |
155 | done = true; | 169 | done_after_input = true; |
156 | continue; | ||
157 | } | 170 | } |
158 | encoding = false; | 171 | encoding = false; |
159 | } else { | 172 | } else { |
@@ -285,7 +298,7 @@ void TestFirstByte() { | |||
285 | spec0.ModifyTo(Modify1stByte(), &spec1); | 298 | spec0.ModifyTo(Modify1stByte(), &spec1); |
286 | CHECK_EQ(1, CmpDifferentBytes(spec0, spec1)); | 299 | CHECK_EQ(1, CmpDifferentBytes(spec0, spec1)); |
287 | 300 | ||
288 | SizeIterator<size_t, Sizes> si(&rand, 0); | 301 | SizeIterator<size_t, Sizes> si(&rand, Constants::TEST_ROUNDS); |
289 | 302 | ||
290 | for (; !si.Done(); si.Next()) { | 303 | for (; !si.Done(); si.Next()) { |
291 | size_t size = si.Get(); | 304 | size_t size = si.Get(); |
@@ -517,7 +530,7 @@ void TestNonBlockingProgress() { | |||
517 | FileSpec spec1(&rand); | 530 | FileSpec spec1(&rand); |
518 | FileSpec spec2(&rand); | 531 | FileSpec spec2(&rand); |
519 | 532 | ||
520 | spec0.GenerateFixedSize(Constants::BLOCK_SIZE * 2); | 533 | spec0.GenerateFixedSize(Constants::BLOCK_SIZE * 3); |
521 | 534 | ||
522 | // This is a lazy target match | 535 | // This is a lazy target match |
523 | Change ct(Change::OVERWRITE, 22, | 536 | Change ct(Change::OVERWRITE, 22, |
@@ -581,7 +594,7 @@ void TestBlockInMemory() { | |||
581 | InMemoryEncodeDecode(spec0, spec1, &block); | 594 | InMemoryEncodeDecode(spec0, spec1, &block); |
582 | 595 | ||
583 | Delta delta(block); | 596 | Delta delta(block); |
584 | CHECK_EQ(1, delta.Windows()); | 597 | CHECK_EQ(spec1.Blocks(Constants::WINDOW_SIZE), delta.Windows()); |
585 | } | 598 | } |
586 | 599 | ||
587 | void FourWayMergeTest(const FileSpec &spec0, | 600 | void FourWayMergeTest(const FileSpec &spec0, |
@@ -616,7 +629,7 @@ void FourWayMergeTest(const FileSpec &spec0, | |||
616 | mcmd.push_back(out.Name()); | 629 | mcmd.push_back(out.Name()); |
617 | mcmd.push_back(NULL); | 630 | mcmd.push_back(NULL); |
618 | 631 | ||
619 | DP(RINT "Running one merge: %s\n", CommandToString(mcmd).c_str()); | 632 | //DP(RINT "Running one merge: %s\n", CommandToString(mcmd).c_str()); |
620 | CHECK_EQ(0, xd3_main_cmdline(mcmd.size() - 1, | 633 | CHECK_EQ(0, xd3_main_cmdline(mcmd.size() - 1, |
621 | const_cast<char**>(&mcmd[0]))); | 634 | const_cast<char**>(&mcmd[0]))); |
622 | 635 | ||
@@ -786,6 +799,7 @@ int main(int argc, char **argv) { | |||
786 | UnitTest<SmallBlock>(); | 799 | UnitTest<SmallBlock>(); |
787 | MainTest<SmallBlock>(); | 800 | MainTest<SmallBlock>(); |
788 | MainTest<MixedBlock>(); | 801 | MainTest<MixedBlock>(); |
802 | MainTest<PrimeBlock>(); | ||
789 | MainTest<OversizeBlock>(); | 803 | MainTest<OversizeBlock>(); |
790 | MainTest<LargeBlock>(); | 804 | MainTest<LargeBlock>(); |
791 | return 0; | 805 | return 0; |
diff --git a/xdelta3/testing/sizes.h b/xdelta3/testing/sizes.h index 7048c34..a8f79a6 100644 --- a/xdelta3/testing/sizes.h +++ b/xdelta3/testing/sizes.h | |||
@@ -66,39 +66,65 @@ size_t LargeSizes::sizes[] = { | |||
66 | 66 | ||
67 | size_t LargeSizes::max_value = 1<<20; | 67 | size_t LargeSizes::max_value = 1<<20; |
68 | 68 | ||
69 | // Base constants | ||
70 | struct BaseConstants { | ||
71 | static const size_t TEST_ROUNDS; | ||
72 | }; | ||
73 | |||
74 | const size_t BaseConstants::TEST_ROUNDS = 10; | ||
75 | |||
69 | // Regtest<> arguments | 76 | // Regtest<> arguments |
70 | struct SmallBlock { | 77 | struct SmallBlock : public BaseConstants { |
71 | static const xoff_t BLOCK_SIZE; | 78 | static const xoff_t BLOCK_SIZE; |
72 | static const size_t WINDOW_SIZE; | 79 | static const size_t WINDOW_SIZE; |
80 | static const size_t READ_SIZE; | ||
73 | typedef SmallSizes Sizes; | 81 | typedef SmallSizes Sizes; |
74 | }; | 82 | }; |
75 | 83 | ||
84 | const size_t SmallBlock::READ_SIZE = 1<<7; | ||
76 | const xoff_t SmallBlock::BLOCK_SIZE = 1<<7; | 85 | const xoff_t SmallBlock::BLOCK_SIZE = 1<<7; |
77 | const size_t SmallBlock::WINDOW_SIZE = 1<<7; | 86 | const size_t SmallBlock::WINDOW_SIZE = 1<<7; |
78 | 87 | ||
79 | struct LargeBlock { | 88 | struct LargeBlock : public BaseConstants { |
80 | static const xoff_t BLOCK_SIZE; | 89 | static const xoff_t BLOCK_SIZE; |
81 | static const size_t WINDOW_SIZE; | 90 | static const size_t WINDOW_SIZE; |
91 | static const size_t READ_SIZE; | ||
82 | typedef LargeSizes Sizes; | 92 | typedef LargeSizes Sizes; |
83 | }; | 93 | }; |
84 | 94 | ||
95 | const size_t LargeBlock::READ_SIZE = (1 << 20); | ||
85 | const xoff_t LargeBlock::BLOCK_SIZE = (1 << 20); | 96 | const xoff_t LargeBlock::BLOCK_SIZE = (1 << 20); |
86 | const size_t LargeBlock::WINDOW_SIZE = (1 << 20); | 97 | const size_t LargeBlock::WINDOW_SIZE = (1 << 20); |
87 | 98 | ||
88 | struct MixedBlock { | 99 | struct MixedBlock : public BaseConstants { |
89 | static const xoff_t BLOCK_SIZE; | 100 | static const xoff_t BLOCK_SIZE; |
90 | static const size_t WINDOW_SIZE; | 101 | static const size_t WINDOW_SIZE; |
102 | static const size_t READ_SIZE; | ||
91 | typedef SmallSizes Sizes; | 103 | typedef SmallSizes Sizes; |
92 | }; | 104 | }; |
93 | 105 | ||
106 | const size_t MixedBlock::READ_SIZE = 1<<6; | ||
94 | const xoff_t MixedBlock::BLOCK_SIZE = 1<<7; | 107 | const xoff_t MixedBlock::BLOCK_SIZE = 1<<7; |
95 | const size_t MixedBlock::WINDOW_SIZE = 1<<8; | 108 | const size_t MixedBlock::WINDOW_SIZE = 1<<8; |
96 | 109 | ||
97 | struct OversizeBlock { | 110 | struct OversizeBlock : public BaseConstants { |
98 | static const xoff_t BLOCK_SIZE; | 111 | static const xoff_t BLOCK_SIZE; |
99 | static const size_t WINDOW_SIZE; | 112 | static const size_t WINDOW_SIZE; |
113 | static const size_t READ_SIZE; | ||
100 | typedef SmallSizes Sizes; | 114 | typedef SmallSizes Sizes; |
101 | }; | 115 | }; |
102 | 116 | ||
117 | const size_t OversizeBlock::READ_SIZE = (1<<6) + (1<<7); | ||
103 | const xoff_t OversizeBlock::BLOCK_SIZE = 1<<8; | 118 | const xoff_t OversizeBlock::BLOCK_SIZE = 1<<8; |
104 | const size_t OversizeBlock::WINDOW_SIZE = 1<<7; | 119 | const size_t OversizeBlock::WINDOW_SIZE = 1<<7; |
120 | |||
121 | struct PrimeBlock : public BaseConstants { | ||
122 | static const xoff_t BLOCK_SIZE; | ||
123 | static const size_t WINDOW_SIZE; | ||
124 | static const size_t READ_SIZE; | ||
125 | typedef SmallSizes Sizes; | ||
126 | }; | ||
127 | |||
128 | const size_t PrimeBlock::READ_SIZE = 71; | ||
129 | const xoff_t PrimeBlock::BLOCK_SIZE = 7 * 127; | ||
130 | const size_t PrimeBlock::WINDOW_SIZE = 73; | ||
diff --git a/xdelta3/testing/test.h b/xdelta3/testing/test.h index 8a6d865..d10ec58 100644 --- a/xdelta3/testing/test.h +++ b/xdelta3/testing/test.h | |||
@@ -32,6 +32,8 @@ extern "C" { | |||
32 | abort(); \ | 32 | abort(); \ |
33 | } } while (false) | 33 | } } while (false) |
34 | 34 | ||
35 | #define DCHECK(x) | ||
36 | |||
35 | #include <string> | 37 | #include <string> |
36 | using std::string; | 38 | using std::string; |
37 | 39 | ||