From 0fef30425e5fd7151a71dc3e63a9687caada1c96 Mon Sep 17 00:00:00 2001 From: "josh.macdonald" Date: Mon, 26 Oct 2009 02:33:06 +0000 Subject: Fix the source_decompression test, which tests that appheader overrides compression magic number. --- xdelta3/xdelta3-main.h | 74 +++++++++++++++++++++++++++++++++++++++----------- xdelta3/xdelta3-test.h | 22 ++++++--------- xdelta3/xdelta3.c | 19 ++++++------- 3 files changed, 76 insertions(+), 39 deletions(-) (limited to 'xdelta3') diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h index 0babbf1..1aaef4f 100644 --- a/xdelta3/xdelta3-main.h +++ b/xdelta3/xdelta3-main.h @@ -373,6 +373,9 @@ static int main_input (xd3_cmd cmd, main_file *ifile, static void main_get_appheader (xd3_stream *stream, main_file *ifile, main_file *output, main_file *sfile); +static int main_getblk_func (xd3_stream *stream, + xd3_source *source, + xoff_t blkno); static int main_help (void); static int @@ -2665,14 +2668,22 @@ static int main_read_primary_input (main_file *ifile, uint8_t *buf, usize_t size, - usize_t *nread) + usize_t *nread, + int is_source) { #if EXTERNAL_COMPRESSION if (option_decompress_inputs && ifile->flags & RD_FIRST) { ifile->flags &= ~RD_FIRST; - return main_decompress_input_check (ifile, buf, size, nread); + if (is_source && ifile->compressor == NULL) + { + /* Application header overrides magic number. */ + } + else + { + return main_decompress_input_check (ifile, buf, size, nread); + } } #endif @@ -2755,21 +2766,17 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, usize_t i; uint8_t *tmp_buf = NULL; xoff_t source_size = 0; - int seekable = 0; int source_size_known = 0; main_blklru_list_init (& lru_list); main_blklru_list_init (& lru_free); - IF_DEBUG1 (DP(RINT "[main_set_source] %s\n", sfile->filename)); - /* Open it, check for seekability, set required xd3_source fields. */ if (allow_fake_source) { sfile->mode = XO_READ; sfile->realname = sfile->filename; sfile->nread = 0; - seekable = 1; source_size_known = 1; } else @@ -2784,7 +2791,6 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, stat_val = main_file_stat (sfile, &source_size); if (stat_val == 0) { - seekable = 1; source_size_known = 1; if (option_verbose > 1) @@ -2794,7 +2800,6 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, } else { - seekable = 0; source_size_known = 0; if (option_verbose > 1) @@ -2816,6 +2821,18 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, source->blksize = (option_srcwinsz / LRU_SIZE); } + if (source_size_known) + { + IF_DEBUG2 (DP(RINT "[main_set_source] %s size %"Q"u\n", + sfile->filename, source_size)); + } + else + { + IF_DEBUG2 (DP(RINT "[main_set_source] %s size not known\n", + sfile->filename, source_size)); + } + + source->name = sfile->filename; source->ioh = sfile; source->curblkno = 0; @@ -2867,10 +2884,16 @@ main_set_source (xd3_stream *stream, xd3_cmd cmd, main_blklru_list_push_back (& lru_free, & lru[i]); } + if ((ret = main_getblk_func (stream, source, 0))) + { + XPR(NT "error reading first block: %s\n", xd3_mainerror (ret)); + return ret; + } + return 0; error: - IF_DEBUG1 (DP(RINT "[main_set_source] error %s\n", xd3_strerror (ret))); + IF_DEBUG2 (DP(RINT "[main_set_source] error %s\n", xd3_strerror (ret))); if (tmp_buf != NULL) { main_free (tmp_buf); @@ -3020,7 +3043,8 @@ main_getblk_func (xd3_stream *stream, if ((ret = main_read_primary_input (sfile, (uint8_t*) blru->blk, source->blksize, - & nread))) + & nread, + 1 /* source */))) { return ret; } @@ -3039,7 +3063,8 @@ main_getblk_func (xd3_stream *stream, if ((ret = main_read_primary_input (sfile, (uint8_t*) blru->blk, source->blksize, - & nread))) + & nread, + 1 /* source */))) { return ret; } @@ -3049,7 +3074,7 @@ main_getblk_func (xd3_stream *stream, main_blklru_list_push_back (& lru_list, blru); - if (option_verbose > 3) + if (option_verbose > 2) { if (blru->blkno != (xoff_t)-1) { @@ -3070,6 +3095,9 @@ main_getblk_func (xd3_stream *stream, source->onblk = nread; blru->size = nread; + IF_DEBUG1 (DP(RINT "[main_getblk] blkno %"Q"u onblk %u\n", + blkno, nread)); + return 0; } @@ -3255,7 +3283,7 @@ main_input (xd3_cmd cmd, { /* When not decoding, set source now. The decoder delays this * step until XD3_GOTHEADER. */ - if (sfile->filename != NULL) + if (sfile && sfile->filename != NULL) { if ((ret = main_set_source (& stream, cmd, sfile, & source))) { @@ -3265,6 +3293,19 @@ main_input (xd3_cmd cmd, XD3_ASSERT(stream.src != NULL); } } + + if (cmd == CMD_PRINTHDR || + cmd == CMD_PRINTHDRS || + cmd == CMD_PRINTDELTA || + cmd == CMD_RECODE) + { + if (sfile->filename == NULL) + { + allow_fake_source = 1; + sfile->filename = ""; + main_set_source (& stream, cmd, sfile, & source); + } + } /* This times each window. */ get_millisecs_since (); @@ -3283,7 +3324,8 @@ main_input (xd3_cmd cmd, try_read = (usize_t) min ((xoff_t) config.winsize, input_remain); if ((ret = main_read_primary_input (ifile, main_bdata, - try_read, & nread))) + try_read, & nread, + 0 /* !source */))) { return EXIT_FAILURE; } @@ -3914,7 +3956,7 @@ main (int argc, char **argv) if (option_verbose > 0) { XPR(NT "warning: -D option ignored, " - "external compression support was not compiled\n"); + "external compression support was not compiled\n"); } #else option_decompress_inputs = 0; @@ -3925,7 +3967,7 @@ main (int argc, char **argv) if (option_verbose > 0) { XPR(NT "warning: -R option ignored, " - "external compression support was not compiled\n"); + "external compression support was not compiled\n"); } #else option_recompress_outputs = 0; diff --git a/xdelta3/xdelta3-test.h b/xdelta3/xdelta3-test.h index d60bf2d..21d7283 100644 --- a/xdelta3/xdelta3-test.h +++ b/xdelta3/xdelta3-test.h @@ -144,6 +144,7 @@ static int do_cmd (xd3_stream *stream, const char *buf) if (WIFEXITED (ret)) { stream->msg = "command exited non-zero"; + IF_DEBUG1 (DP(RINT "command was: %s\n", buf)); } else { @@ -1894,15 +1895,11 @@ test_recode_command2 (xd3_stream *stream, int has_source, /* Check recode changes. */ - /* TODO! This test is broken! */ if ((ret = check_vcdiff_header (stream, TEST_COPY_FILE, "VCDIFF window indicator", "VCD_SOURCE", - has_source))) - { - DP(RINT "TEST IS BROKEN: %s\n", xd3_strerror (ret)); - } + has_source))) { return ret; } if ((ret = check_vcdiff_header (stream, TEST_COPY_FILE, @@ -2172,35 +2169,35 @@ test_source_decompression (xd3_stream *stream, int ignore) /* Now the two identical files are compressed. Delta-encode the target, * with decompression. */ - sprintf (buf, "%s -eq -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_TARGET_FILE, TEST_DELTA_FILE); + sprintf (buf, "%s -v -eq -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_TARGET_FILE, TEST_DELTA_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } /* Decode the delta file with recompression disabled, should get an * uncompressed file out. */ - sprintf (buf, "%s -dq -R -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_DELTA_FILE, TEST_RECON_FILE); + sprintf (buf, "%s -v -dq -R -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_DELTA_FILE, TEST_RECON_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } if ((ret = compare_files (stream, TEST_COPY_FILE, TEST_RECON_FILE))) { return ret; } /* Decode the delta file with recompression, should get a compressed file * out. But we can't compare compressed files directly. */ - sprintf (buf, "%s -dqf -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_DELTA_FILE, TEST_RECON_FILE); + sprintf (buf, "%s -v -dqf -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_DELTA_FILE, TEST_RECON_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } sprintf (buf, "%s %s < %s > %s", ext->decomp_cmdname, ext->decomp_options, TEST_RECON_FILE, TEST_RECON2_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } if ((ret = compare_files (stream, TEST_COPY_FILE, TEST_RECON2_FILE))) { return ret; } /* Encode with decompression disabled */ - sprintf (buf, "%s -feqD -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_TARGET_FILE, TEST_DELTA_FILE); + sprintf (buf, "%s -v -feqD -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_TARGET_FILE, TEST_DELTA_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } /* Decode the delta file with recompression enabled, it doesn't matter, * should get the compressed file out. */ - sprintf (buf, "%s -fdq -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_DELTA_FILE, TEST_RECON_FILE); + sprintf (buf, "%s -v -fdq -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_DELTA_FILE, TEST_RECON_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } if ((ret = compare_files (stream, TEST_TARGET_FILE, TEST_RECON_FILE))) { return ret; } /* Try again with recompression disabled, it doesn't make a difference. */ - sprintf (buf, "%s -fqRd -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_DELTA_FILE, TEST_RECON_FILE); + sprintf (buf, "%s -v -fqRd -s%s %s %s", program_name, TEST_SOURCE_FILE, TEST_DELTA_FILE, TEST_RECON_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } if ((ret = compare_files (stream, TEST_TARGET_FILE, TEST_RECON_FILE))) { return ret; } test_cleanup(); @@ -2813,14 +2810,13 @@ xd3_selftest (void) DO_TEST (stdout_behavior, 0, 0); DO_TEST (no_output, 0, 0); DO_TEST (command_line_arguments, 0, 0); - // TODO BROKEN!! - //DO_TEST (recode_command, 0, 0); #if EXTERNAL_COMPRESSION DO_TEST (source_decompression, 0, 0); DO_TEST (externally_compressed_io, 0, 0); #endif + DO_TEST (recode_command, 0, 0); #endif /* WIN32 */ IF_DJW (DO_TEST (secondary_huff, 0, DJW_MAX_GROUPS)); diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index 515b083..0bbf338 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c @@ -2516,7 +2516,6 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno) } ret = stream->getblk (stream, source, blkno); - IF_DEBUG1 (DP(RINT "[getblk] func ret %d\n", ret)); if (ret != 0) { stream->msg = "getblk failed"; @@ -2541,7 +2540,7 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno) { if (!source->eof_known) { - IF_DEBUG1 (DP(RINT "[getblk] eof block has %d bytes; source length known %"Q"u\n", + IF_DEBUG2 (DP(RINT "[getblk] eof block has %d bytes; source length known %"Q"u\n", xd3_bytes_on_srcblk (source, blkno), xd3_source_eof (source))); source->eof_known = 1; @@ -2552,7 +2551,7 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno) } XD3_ASSERT (source->curblk != NULL); - IF_DEBUG1 (DP(RINT "[getblk] read source block %"Q"u onblk %u blksize %u\n", + IF_DEBUG2 (DP(RINT "[getblk] read source block %"Q"u onblk %u blksize %u\n", blkno, source->onblk, source->blksize)); if (blkno == source->max_blkno) @@ -3773,7 +3772,7 @@ xd3_encode_input (xd3_stream *stream) return XD3_WINSTART; case ENC_SEARCH: - IF_DEBUG1 (DP(RINT "[SEARCH] match_state %d avail_in %u %s\n", + IF_DEBUG2 (DP(RINT "[SEARCH] match_state %d avail_in %u %s\n", stream->match_state, stream->avail_in, stream->src ? "source" : "no source")); /* Reentrant matching. */ @@ -4080,7 +4079,7 @@ xd3_process_memory (int is_encode, exit: if (ret != 0) { - IF_DEBUG1 (DP(RINT "process_memory: %d: %s\n", ret, stream.msg)); + IF_DEBUG2 (DP(RINT "process_memory: %d: %s\n", ret, stream.msg)); } xd3_free_stream(&stream); return ret; @@ -4335,7 +4334,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos) * TestNonBlockingProgress test! */ if (srcpos != 0 && srcpos == stream->match_last_srcpos) { - IF_DEBUG1(DP(RINT "[match_setup] looping failure\n")); + IF_DEBUG2(DP(RINT "[match_setup] looping failure\n")); goto bad; } @@ -4389,7 +4388,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos) } } - IF_DEBUG1(DP(RINT "[match_setup] srcpos %"Q"u unrestricted back %u fwd %u\n", + IF_DEBUG2(DP(RINT "[match_setup] srcpos %"Q"u unrestricted back %u fwd %u\n", srcpos, stream->match_maxback, stream->match_maxfwd)); @@ -4402,7 +4401,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos) /* Restricted case: fail if the srcpos lies outside the source window */ if ((srcpos < src->srcbase) || (srcpos > (src->srcbase + (xoff_t) src->srclen))) { - IF_DEBUG1(DP(RINT "[match_setup] restricted source window failure\n")); + IF_DEBUG2(DP(RINT "[match_setup] restricted source window failure\n")); goto bad; } else @@ -4421,7 +4420,7 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos) stream->match_maxfwd = srcavail; } - IF_DEBUG1(DP(RINT "[match_setup] srcpos %"Q"u restricted back %u fwd %u\n", + IF_DEBUG2(DP(RINT "[match_setup] srcpos %"Q"u restricted back %u fwd %u\n", srcpos, stream->match_maxback, stream->match_maxfwd)); @@ -4514,7 +4513,7 @@ xd3_source_extend_match (xd3_stream *stream) usize_t tryrem; /* tryrem is the number of matchable bytes */ usize_t matched; - IF_DEBUG1(DP(RINT "[extend match] srcpos %"Q"u\n", + IF_DEBUG2(DP(RINT "[extend match] srcpos %"Q"u\n", stream->match_srcpos)); XD3_ASSERT (src != NULL); -- cgit v1.2.3