"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "xdelta3-test.h" between
xdelta3-3.0.11.tar.gz and xdelta3-3.1.0.tar.gz

About: xdelta is a tool and library for differential compression (supports VCDIFF encoding and decoding). Beta version.

xdelta3-test.h  (xdelta3-3.0.11):xdelta3-test.h  (xdelta3-3.1.0)
skipping to change at line 142 skipping to change at line 142
#define TESTFILESIZE (1024) #define TESTFILESIZE (1024)
static char TEST_TARGET_FILE[TESTFILESIZE]; static char TEST_TARGET_FILE[TESTFILESIZE];
static char TEST_SOURCE_FILE[TESTFILESIZE]; static char TEST_SOURCE_FILE[TESTFILESIZE];
static char TEST_DELTA_FILE[TESTFILESIZE]; static char TEST_DELTA_FILE[TESTFILESIZE];
static char TEST_RECON_FILE[TESTFILESIZE]; static char TEST_RECON_FILE[TESTFILESIZE];
static char TEST_RECON2_FILE[TESTFILESIZE]; static char TEST_RECON2_FILE[TESTFILESIZE];
static char TEST_COPY_FILE[TESTFILESIZE]; static char TEST_COPY_FILE[TESTFILESIZE];
static char TEST_NOPERM_FILE[TESTFILESIZE]; static char TEST_NOPERM_FILE[TESTFILESIZE];
#define CHECK(cond) if (!(cond)) { XPR(NT "check failure: " #cond); abort(); } #define CHECK(cond) \
if (!(cond)) { \
XPR(NT __FILE__":%d: check failure: " #cond, __LINE__); \
abort(); }
#if SHELL_TESTS #if SHELL_TESTS
/* Use a fixed soft config so that test values are fixed. See also /* Use a fixed soft config so that test values are fixed. See also
* test_compress_text(). */ * test_compress_text(). */
static const char* test_softcfg_str = "-C9,3,4,8,2,36,70"; static const char* test_softcfg_str = "-C9,3,4,8,2,36,70";
#endif #endif
/*********************************************************************** /***********************************************************************
TEST HELPERS TEST HELPERS
***********************************************************************/ ***********************************************************************/
skipping to change at line 202 skipping to change at line 205
usize_t sum = 0; usize_t sum = 0;
usize_t mean = 50; usize_t mean = 50;
usize_t n_rounds = 1000000; usize_t n_rounds = 1000000;
double average, error; double average, error;
double allowed_error = 0.1; double allowed_error = 0.1;
mt_init (& static_mtrand, 0x9f73f7fe); mt_init (& static_mtrand, 0x9f73f7fe);
for (i = 0; i < n_rounds; i += 1) for (i = 0; i < n_rounds; i += 1)
{ {
sum += mt_exp_rand (mean, USIZE_T_MAX); sum += mt_exp_rand (mean, UINT32_MAX);
} }
average = (double) sum / (double) n_rounds; average = (double) sum / (double) n_rounds;
error = average - (double) mean; error = average - (double) mean;
if (error < allowed_error && error > -allowed_error) if (error < allowed_error && error > -allowed_error)
{ {
return 0; return 0;
} }
skipping to change at line 707 skipping to change at line 710
test_forward_match (xd3_stream *stream, int unused) test_forward_match (xd3_stream *stream, int unused)
{ {
usize_t i; usize_t i;
uint8_t buf1[256], buf2[256]; uint8_t buf1[256], buf2[256];
memset(buf1, 0, 256); memset(buf1, 0, 256);
memset(buf2, 0, 256); memset(buf2, 0, 256);
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
CHECK(xd3_forward_match(buf1, buf2, i) == (int)i); CHECK(xd3_forward_match(buf1, buf2, i) == i);
} }
for (i = 0; i < 255; i++) for (i = 0; i < 255; i++)
{ {
buf2[i] = 1; buf2[i] = 1;
CHECK(xd3_forward_match(buf1, buf2, 256) == (int)i); CHECK(xd3_forward_match(buf1, buf2, 256) == i);
buf2[i] = 0; buf2[i] = 0;
} }
return 0; return 0;
} }
/*********************************************************************** /***********************************************************************
Address cache Address cache
***********************************************************************/ ***********************************************************************/
skipping to change at line 762 skipping to change at line 765
/* First pass: encode addresses */ /* First pass: encode addresses */
xd3_init_cache (& stream->acache); xd3_init_cache (& stream->acache);
for (offset = 1; offset < ADDR_CACHE_ROUNDS; offset += 1) for (offset = 1; offset < ADDR_CACHE_ROUNDS; offset += 1)
{ {
double p; double p;
usize_t addr; usize_t addr;
usize_t prev_i; usize_t prev_i;
usize_t nearby; usize_t nearby;
p = (mt_random (&static_mtrand) / (double)USIZE_T_MAX); p = (mt_random (&static_mtrand) / (double)UINT32_MAX);
prev_i = mt_random (&static_mtrand) % offset; prev_i = mt_random (&static_mtrand) % offset;
nearby = (mt_random (&static_mtrand) % 256) % offset; nearby = (mt_random (&static_mtrand) % 256) % offset;
nearby = xd3_max (1U, nearby); nearby = xd3_max (1U, nearby);
if (p < 0.1) { addr = addrs[offset-nearby]; } if (p < 0.1) { addr = addrs[offset-nearby]; }
else if (p < 0.4) { addr = xd3_min (addrs[prev_i] + nearby, offset-1); } else if (p < 0.4) { addr = xd3_min (addrs[prev_i] + nearby, offset-1); }
else { addr = prev_i; } else { addr = prev_i; }
if ((ret = xd3_encode_address (stream, addr, offset, & modes[offset]))) { return ret; } if ((ret = xd3_encode_address (stream, addr, offset, & modes[offset]))) { return ret; }
skipping to change at line 793 skipping to change at line 796
} }
buf_max = big_buf + offset; buf_max = big_buf + offset;
buf = big_buf; buf = big_buf;
/* Second pass: decode addresses */ /* Second pass: decode addresses */
xd3_init_cache (& stream->acache); xd3_init_cache (& stream->acache);
for (offset = 1; offset < ADDR_CACHE_ROUNDS; offset += 1) for (offset = 1; offset < ADDR_CACHE_ROUNDS; offset += 1)
{ {
uint32_t addr; usize_t addr;
if ((ret = xd3_decode_address (stream, offset, modes[offset], & buf, buf_m if ((ret = xd3_decode_address (stream, offset, modes[offset],
ax, & addr))) { return ret; } & buf, buf_max, & addr)))
{
return ret;
}
if (addr != addrs[offset]) if (addr != addrs[offset])
{ {
stream->msg = "incorrect decoded address"; stream->msg = "incorrect decoded address";
return XD3_INTERNAL; return XD3_INTERNAL;
} }
} }
/* Check that every byte, mode was used. */ /* Check that every byte, mode was used. */
if (buf != buf_max) if (buf != buf_max)
skipping to change at line 1421 skipping to change at line 1428
} }
if ((ret = sec_dists[test_i] (stream, in_head))) { goto fail; } if ((ret = sec_dists[test_i] (stream, in_head))) { goto fail; }
if ((ret = sec->init (stream, enc_stream, 1)) != 0) { goto fail; } if ((ret = sec->init (stream, enc_stream, 1)) != 0) { goto fail; }
/* Encode data */ /* Encode data */
if ((ret = sec->encode (stream, enc_stream, if ((ret = sec->encode (stream, enc_stream,
in_head, out_head, & cfg))) in_head, out_head, & cfg)))
{ {
XPR(NT "test %u: encode: %s", test_i, stream->msg); XPR(NT "test %"W"u: encode: %s", test_i, stream->msg);
goto fail; goto fail;
} }
/* Calculate sizes, allocate contiguous arrays for decoding */ /* Calculate sizes, allocate contiguous arrays for decoding */
input_size = xd3_sizeof_output (in_head); input_size = xd3_sizeof_output (in_head);
compress_size = xd3_sizeof_output (out_head); compress_size = xd3_sizeof_output (out_head);
XPR(NTR "%.3f", 8.0 * (double) compress_size / (double) input_size); XPR(NTR "%.3f", 8.0 * (double) compress_size / (double) input_size);
if ((dec_input = (uint8_t*) xd3_alloc (stream, compress_size, 1)) == NULL || if ((dec_input = (uint8_t*) xd3_alloc (stream, compress_size, 1)) == NULL ||
skipping to change at line 1460 skipping to change at line 1467
{ {
memcpy (dec_correct + p_off, p->base, p->next); memcpy (dec_correct + p_off, p->base, p->next);
} }
CHECK(p_off == input_size); CHECK(p_off == input_size);
if ((ret = test_secondary_decode (stream, sec, input_size, if ((ret = test_secondary_decode (stream, sec, input_size,
compress_size, dec_input, compress_size, dec_input,
dec_correct, dec_output))) dec_correct, dec_output)))
{ {
XPR(NT "test %u: decode: %s", test_i, stream->msg); XPR(NT "test %"W"u: decode: %s", test_i, stream->msg);
goto fail; goto fail;
} }
/* Single-bit error test, only cover the first 10 bytes. /* Single-bit error test, only cover the first 10 bytes.
* Some non-failures are expected in the Huffman case: * Some non-failures are expected in the Huffman case:
* Changing the clclen array, for example, may not harm the * Changing the clclen array, for example, may not harm the
* decoding. Really looking for faults here. */ * decoding. Really looking for faults here. */
{ {
int i; int i;
int bytes = xd3_min (compress_size, 10U); int bytes = xd3_min (compress_size, 10U);
skipping to change at line 1580 skipping to change at line 1587
{ {
stream->msg = "wrong double instruction"; stream->msg = "wrong double instruction";
return XD3_INTERNAL; return XD3_INTERNAL;
} }
} }
} }
return 0; return 0;
} }
static int
test_checksum_step (xd3_stream *stream, int ignore)
{
const int bufsize = 128;
uint8_t buf[128];
for (int i = 0; i < bufsize; i++)
{
buf[i] = mt_random (&static_mtrand) & 0xff;
}
for (usize_t cksize = 4; cksize <= 32; cksize += 3)
{
xd3_hash_cfg h1;
usize_t x;
int ret;
if ((ret = xd3_size_hashtable (stream, XD3_ALLOCSIZE, cksize, &h1)) != 0)
{
return ret;
}
x = xd3_large_cksum (&h1, buf, cksize);
for (usize_t pos = 0; pos <= (bufsize - cksize); pos++)
{
usize_t y = xd3_large_cksum (&h1, buf + pos, cksize);
if (x != y)
{
stream->msg = "checksum != incremental checksum";
return XD3_INTERNAL;
}
x = xd3_large_cksum_update (&h1, x, buf + pos, cksize);
}
xd3_free (stream, h1.powers);
}
return 0;
}
/*********************************************************************** /***********************************************************************
64BIT STREAMING 64BIT STREAMING
***********************************************************************/ ***********************************************************************/
/* This test encodes and decodes a series of 1 megabyte windows, each /* This test encodes and decodes a series of 1 megabyte windows, each
* containing a long run of zeros along with a single xoff_t size * containing a long run of zeros along with a single xoff_t size
* record to indicate the sequence. */ * record to indicate the sequence. */
static int static int
test_streaming (xd3_stream *in_stream, uint8_t *encbuf, uint8_t *decbuf, uint8_t *delbuf, usize_t megs) test_streaming (xd3_stream *in_stream, uint8_t *encbuf, uint8_t *decbuf, uint8_t *delbuf, usize_t megs)
{ {
skipping to change at line 2052 skipping to change at line 2098
} }
} }
DOT (); DOT ();
} }
} }
return 0; return 0;
} }
#if SECONDARY_LZMA #if SECONDARY_LZMA
int test_secondary_lzma_default (xd3_stream *stream, int ignore) static int test_secondary_lzma_default (xd3_stream *stream, int ignore)
{ {
char ecmd[TESTBUFSIZE]; char ecmd[TESTBUFSIZE];
int ret; int ret;
test_setup (); test_setup ();
if ((ret = test_make_inputs (stream, NULL, NULL))) if ((ret = test_make_inputs (stream, NULL, NULL)))
{ {
return ret; return ret;
} }
skipping to change at line 2717 skipping to change at line 2763
{ {
xd3_rinst *inst = xd3_rlist_pop_front (& stream->iopt_used); xd3_rinst *inst = xd3_rlist_pop_front (& stream->iopt_used);
switch (inst->type) switch (inst->type)
{ {
case XD3_RUN: *rptr++ = 'R'; break; case XD3_RUN: *rptr++ = 'R'; break;
case XD3_CPY: *rptr++ = 'C'; break; case XD3_CPY: *rptr++ = 'C'; break;
default: CHECK(0); default: CHECK(0);
} }
snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%d/%d", snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%"W"u/%"W"u",
inst->pos, inst->size); inst->pos, inst->size);
rptr += strlen (rptr); rptr += strlen (rptr);
if (inst->type == XD3_CPY) if (inst->type == XD3_CPY)
{ {
*rptr++ = '@'; *rptr++ = '@';
snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%"Q"d", inst->addr); snprintf_func (rptr, rbuf+TESTBUFSIZE-rptr, "%"Q"u", inst->addr);
rptr += strlen (rptr); rptr += strlen (rptr);
} }
*rptr++ = ' '; *rptr++ = ' ';
xd3_rlist_push_back (& stream->iopt_free, inst); xd3_rlist_push_back (& stream->iopt_free, inst);
} }
if (rptr != rbuf) if (rptr != rbuf)
{ {
rptr -= 1; *rptr = 0; rptr -= 1; *rptr = 0;
} }
if (strcmp (rbuf, test->result) != 0) if (strcmp (rbuf, test->result) != 0)
{ {
XPR(NT "test %u: expected %s: got %s", i, test->result, rbuf); XPR(NT "test %"W"u: expected %s: got %s", i, test->result, rbuf);
stream->msg = "wrong result"; stream->msg = "wrong result";
return XD3_INTERNAL; return XD3_INTERNAL;
} }
} }
return 0; return 0;
} }
/* /*
* This is a test for many overlapping instructions. It must be a lazy * This is a test for many overlapping instructions. It must be a lazy
skipping to change at line 2815 skipping to change at line 2861
CHECK(tpos == recon_size); CHECK(tpos == recon_size);
CHECK(memcmp(target, recon, recon_size) == 0); CHECK(memcmp(target, recon, recon_size) == 0);
return 0; return 0;
} }
/* /*
* This tests the 32/64bit ambiguity for source-window matching. * This tests the 32/64bit ambiguity for source-window matching.
*/ */
#if !XD3_USE_LARGESIZET
static int static int
test_source_cksum_offset (xd3_stream *stream, int ignore) test_source_cksum_offset (xd3_stream *stream, int ignore)
{ {
xd3_source source; xd3_source source;
// Inputs are: // Inputs are:
struct { struct {
xoff_t cpos; // stream->srcwin_cksum_pos; xoff_t cpos; // stream->srcwin_cksum_pos;
xoff_t ipos; // stream->total_in; xoff_t ipos; // stream->total_in;
xoff_t size; // stream->src->size; xoff_t size; // stream->src->size;
usize_t input; // input 32-bit offset usize_t input; // input 32-bit offset
xoff_t output; // output 64-bit offset xoff_t output; // output 64-bit offset
skipping to change at line 2851 skipping to change at line 2898
{ 25771983104ULL, 25770000000ULL, 26414808769ULL, 2139216707UL, 23614053187U LL }, { 25771983104ULL, 25770000000ULL, 26414808769ULL, 2139216707UL, 23614053187U LL },
#endif #endif
{ 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 },
}, *test_ptr; }, *test_ptr;
stream->src = &source; stream->src = &source;
for (test_ptr = cksum_test; test_ptr->cpos; test_ptr++) { for (test_ptr = cksum_test; test_ptr->cpos; test_ptr++) {
xoff_t r; xoff_t r;
stream->srcwin_cksum_pos = test_ptr->cpos; stream->srcwin_cksum_pos = test_ptr->cpos;
stream->total_in = test_ptr->ipos; stream->total_in = test_ptr->ipos;
r = xd3_source_cksum_offset(stream, test_ptr->input); r = xd3_source_cksum_offset(stream, test_ptr->input);
CHECK(r == test_ptr->output); CHECK(r == test_ptr->output);
} }
return 0; return 0;
} }
#endif /* !XD3_USE_LARGESIZET */
static int static int
test_in_memory (xd3_stream *stream, int ignore) test_in_memory (xd3_stream *stream, int ignore)
{ {
// test_text is 256 bytes // test_text is 256 bytes
uint8_t ibuf[sizeof(test_text)]; uint8_t ibuf[sizeof(test_text)];
uint8_t dbuf[sizeof(test_text)]; uint8_t dbuf[sizeof(test_text)];
uint8_t obuf[sizeof(test_text)]; uint8_t obuf[sizeof(test_text)];
usize_t size = sizeof(test_text); usize_t size = sizeof(test_text);
usize_t dsize, osize; usize_t dsize, osize;
skipping to change at line 2902 skipping to change at line 2950
return XD3_INTERNAL; return XD3_INTERNAL;
} }
return 0; return 0;
} }
/*********************************************************************** /***********************************************************************
TEST MAIN TEST MAIN
***********************************************************************/ ***********************************************************************/
static int int xd3_selftest (void)
xd3_selftest (void)
{ {
#define DO_TEST(fn,flags,arg) \ #define DO_TEST(fn,flags,arg) \
do { \ do { \
xd3_stream stream; \ xd3_stream stream; \
xd3_config config; \ xd3_config config; \
xd3_init_config (& config, flags); \ xd3_init_config (& config, flags); \
XPR(NT "testing " #fn "%s...", \ XPR(NT "testing " #fn "%s...", \
flags ? (" (" #flags ")") : ""); \ flags ? (" (" #flags ")") : ""); \
if ((ret = xd3_config_stream (& stream, & config) == 0) && \ if ((ret = xd3_config_stream (& stream, & config) == 0) && \
(ret = test_ ## fn (& stream, arg)) == 0) { \ (ret = test_ ## fn (& stream, arg)) == 0) { \
skipping to change at line 2931 skipping to change at line 2978
int ret; int ret;
DO_TEST (random_numbers, 0, 0); DO_TEST (random_numbers, 0, 0);
DO_TEST (printf_xoff, 0, 0); DO_TEST (printf_xoff, 0, 0);
DO_TEST (decode_integer_end_of_input, 0, 0); DO_TEST (decode_integer_end_of_input, 0, 0);
DO_TEST (decode_integer_overflow, 0, 0); DO_TEST (decode_integer_overflow, 0, 0);
DO_TEST (encode_decode_uint32_t, 0, 0); DO_TEST (encode_decode_uint32_t, 0, 0);
DO_TEST (encode_decode_uint64_t, 0, 0); DO_TEST (encode_decode_uint64_t, 0, 0);
DO_TEST (usize_t_overflow, 0, 0); DO_TEST (usize_t_overflow, 0, 0);
DO_TEST (checksum_step, 0, 0);
DO_TEST (forward_match, 0, 0); DO_TEST (forward_match, 0, 0);
DO_TEST (address_cache, 0, 0); DO_TEST (address_cache, 0, 0);
DO_TEST (string_matching, 0, 0); DO_TEST (string_matching, 0, 0);
DO_TEST (choose_instruction, 0, 0); DO_TEST (choose_instruction, 0, 0);
DO_TEST (identical_behavior, 0, 0); DO_TEST (identical_behavior, 0, 0);
DO_TEST (in_memory, 0, 0); DO_TEST (in_memory, 0, 0);
DO_TEST (iopt_flush_instructions, 0, 0); DO_TEST (iopt_flush_instructions, 0, 0);
#if !XD3_USE_LARGESIZET
DO_TEST (source_cksum_offset, 0, 0); DO_TEST (source_cksum_offset, 0, 0);
#endif
DO_TEST (decompress_single_bit_error, 0, 3); DO_TEST (decompress_single_bit_error, 0, 3);
DO_TEST (decompress_single_bit_error, XD3_ADLER32, 3); DO_TEST (decompress_single_bit_error, XD3_ADLER32, 3);
IF_LZMA (DO_TEST (decompress_single_bit_error, XD3_SEC_LZMA, 54)); IF_LZMA (DO_TEST (decompress_single_bit_error, XD3_SEC_LZMA, 54));
IF_FGK (DO_TEST (decompress_single_bit_error, XD3_SEC_FGK, 3)); IF_FGK (DO_TEST (decompress_single_bit_error, XD3_SEC_FGK, 3));
IF_DJW (DO_TEST (decompress_single_bit_error, XD3_SEC_DJW, 8)); IF_DJW (DO_TEST (decompress_single_bit_error, XD3_SEC_DJW, 8));
#if SHELL_TESTS #if SHELL_TESTS
DO_TEST (force_behavior, 0, 0); DO_TEST (force_behavior, 0, 0);
 End of changes. 23 change blocks. 
19 lines changed or deleted 67 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS