diff options
-rw-r--r-- | xdelta3/xdelta3-main.h | 120 | ||||
-rw-r--r-- | xdelta3/xdelta3-test.h | 56 |
2 files changed, 113 insertions, 63 deletions
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h index 575e5e5..e7ce493 100644 --- a/xdelta3/xdelta3-main.h +++ b/xdelta3/xdelta3-main.h | |||
@@ -219,7 +219,7 @@ static int option_verbose = DEFAULT_VERBOSE; | |||
219 | static int option_quiet = 0; | 219 | static int option_quiet = 0; |
220 | static int option_use_appheader = 1; | 220 | static int option_use_appheader = 1; |
221 | static uint8_t* option_appheader = NULL; | 221 | static uint8_t* option_appheader = NULL; |
222 | static int option_use_secondary = 0; | 222 | static int option_use_secondary = 1; |
223 | static const char* option_secondary = NULL; | 223 | static const char* option_secondary = NULL; |
224 | static int option_use_checksum = 1; | 224 | static int option_use_checksum = 1; |
225 | static const char* option_smatch_config = NULL; | 225 | static const char* option_smatch_config = NULL; |
@@ -338,7 +338,7 @@ static int | |||
338 | main_version (void) | 338 | main_version (void) |
339 | { | 339 | { |
340 | /* $Format: " XPR(NTR \"Xdelta version $Xdelta3Version$, Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, Joshua MacDonald\\n\");" $ */ | 340 | /* $Format: " XPR(NTR \"Xdelta version $Xdelta3Version$, Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, Joshua MacDonald\\n\");" $ */ |
341 | XPR(NTR "Xdelta version 3.0.10, Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Joshua MacDonald\n"); | 341 | XPR(NTR "Xdelta version 3.0.11, Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Joshua MacDonald\n"); |
342 | XPR(NTR "Xdelta comes with ABSOLUTELY NO WARRANTY.\n"); | 342 | XPR(NTR "Xdelta comes with ABSOLUTELY NO WARRANTY.\n"); |
343 | XPR(NTR "This is free software, and you are welcome to redistribute it\n"); | 343 | XPR(NTR "This is free software, and you are welcome to redistribute it\n"); |
344 | XPR(NTR "under certain conditions; see \"COPYING\" for details.\n"); | 344 | XPR(NTR "under certain conditions; see \"COPYING\" for details.\n"); |
@@ -391,7 +391,7 @@ reset_defaults(void) | |||
391 | option_verbose = DEFAULT_VERBOSE; | 391 | option_verbose = DEFAULT_VERBOSE; |
392 | option_quiet = 0; | 392 | option_quiet = 0; |
393 | option_appheader = NULL; | 393 | option_appheader = NULL; |
394 | option_use_secondary = 0; | 394 | option_use_secondary = 1; |
395 | option_secondary = NULL; | 395 | option_secondary = NULL; |
396 | option_smatch_config = NULL; | 396 | option_smatch_config = NULL; |
397 | option_no_compress = 0; | 397 | option_no_compress = 0; |
@@ -1155,70 +1155,72 @@ static int | |||
1155 | main_set_secondary_flags (xd3_config *config) | 1155 | main_set_secondary_flags (xd3_config *config) |
1156 | { | 1156 | { |
1157 | int ret; | 1157 | int ret; |
1158 | if (option_use_secondary) | 1158 | if (!option_use_secondary) |
1159 | { | 1159 | { |
1160 | /* The default secondary compressor is DJW, if it's compiled. */ | 1160 | return 0; |
1161 | if (option_secondary == NULL) | 1161 | } |
1162 | if (option_secondary == NULL) | ||
1163 | { | ||
1164 | /* Set a default secondary compressor if LZMA is built in, otherwise | ||
1165 | * default to no secondary compressor. */ | ||
1166 | if (SECONDARY_LZMA) | ||
1162 | { | 1167 | { |
1163 | if (SECONDARY_DJW) | 1168 | config->flags |= XD3_SEC_LZMA; |
1164 | { | ||
1165 | config->flags |= XD3_SEC_DJW; | ||
1166 | } | ||
1167 | } | 1169 | } |
1168 | else | 1170 | } |
1171 | else | ||
1172 | { | ||
1173 | if (strcmp (option_secondary, "lzma") == 0 && SECONDARY_LZMA) | ||
1169 | { | 1174 | { |
1170 | if (strcmp (option_secondary, "fgk") == 0 && SECONDARY_FGK) | 1175 | config->flags |= XD3_SEC_LZMA; |
1171 | { | 1176 | } |
1172 | config->flags |= XD3_SEC_FGK; | 1177 | else if (strcmp (option_secondary, "fgk") == 0 && SECONDARY_FGK) |
1173 | } | 1178 | { |
1174 | else if (strcmp (option_secondary, "lzma") == 0 && SECONDARY_LZMA) | 1179 | config->flags |= XD3_SEC_FGK; |
1180 | } | ||
1181 | else if (strncmp (option_secondary, "djw", 3) == 0 && SECONDARY_DJW) | ||
1182 | { | ||
1183 | usize_t level = XD3_DEFAULT_SECONDARY_LEVEL; | ||
1184 | |||
1185 | config->flags |= XD3_SEC_DJW; | ||
1186 | |||
1187 | if (strlen (option_secondary) > 3 && | ||
1188 | (ret = main_atou (option_secondary + 3, | ||
1189 | &level, | ||
1190 | 0, 9, 'S')) != 0 && | ||
1191 | !option_quiet) | ||
1175 | { | 1192 | { |
1176 | config->flags |= XD3_SEC_LZMA; | 1193 | return XD3_INVALID; |
1177 | } | 1194 | } |
1178 | else if (strncmp (option_secondary, "djw", 3) == 0 && SECONDARY_DJW) | ||
1179 | { | ||
1180 | usize_t level = XD3_DEFAULT_SECONDARY_LEVEL; | ||
1181 | 1195 | ||
1182 | config->flags |= XD3_SEC_DJW; | 1196 | /* XD3_SEC_NOXXXX flags disable secondary compression on |
1197 | * a per-section basis. For djw, ngroups=1 indicates | ||
1198 | * minimum work, ngroups=0 uses default settings, which | ||
1199 | * is > 1 groups by default. */ | ||
1200 | if (level < 1) { config->flags |= XD3_SEC_NODATA; } | ||
1201 | if (level < 7) { config->sec_data.ngroups = 1; } | ||
1202 | else { config->sec_data.ngroups = 0; } | ||
1183 | 1203 | ||
1184 | if (strlen (option_secondary) > 3 && | 1204 | if (level < 3) { config->flags |= XD3_SEC_NOINST; } |
1185 | (ret = main_atou (option_secondary + 3, | 1205 | if (level < 8) { config->sec_inst.ngroups = 1; } |
1186 | &level, | 1206 | else { config->sec_inst.ngroups = 0; } |
1187 | 0, 9, 'S')) != 0 && | ||
1188 | !option_quiet) | ||
1189 | { | ||
1190 | return XD3_INVALID; | ||
1191 | } | ||
1192 | 1207 | ||
1193 | /* XD3_SEC_NOXXXX flags disable secondary compression on | 1208 | if (level < 5) { config->flags |= XD3_SEC_NOADDR; } |
1194 | * a per-section basis. For djw, ngroups=1 indicates | 1209 | if (level < 9) { config->sec_addr.ngroups = 1; } |
1195 | * minimum work, ngroups=0 uses default settings, which | 1210 | else { config->sec_addr.ngroups = 0; } |
1196 | * is > 1 groups by default. */ | 1211 | } |
1197 | if (level < 1) { config->flags |= XD3_SEC_NODATA; } | 1212 | else if (*option_secondary == 0 || |
1198 | if (level < 7) { config->sec_data.ngroups = 1; } | 1213 | strcmp (option_secondary, "none") == 0) |
1199 | else { config->sec_data.ngroups = 0; } | 1214 | { |
1200 | 1215 | } | |
1201 | if (level < 3) { config->flags |= XD3_SEC_NOINST; } | 1216 | else |
1202 | if (level < 8) { config->sec_inst.ngroups = 1; } | 1217 | { |
1203 | else { config->sec_inst.ngroups = 0; } | 1218 | if (!option_quiet) |
1204 | |||
1205 | if (level < 5) { config->flags |= XD3_SEC_NOADDR; } | ||
1206 | if (level < 9) { config->sec_addr.ngroups = 1; } | ||
1207 | else { config->sec_addr.ngroups = 0; } | ||
1208 | } | ||
1209 | else if (strcmp (option_secondary, "none") == 0 && SECONDARY_DJW) | ||
1210 | { | ||
1211 | /* No secondary */ | ||
1212 | } | ||
1213 | else | ||
1214 | { | 1219 | { |
1215 | if (!option_quiet) | 1220 | XPR(NT "unrecognized or not compiled secondary compressor: %s\n", |
1216 | { | 1221 | option_secondary); |
1217 | XPR(NT "unrecognized secondary compressor type: %s\n", | ||
1218 | option_secondary); | ||
1219 | return XD3_INVALID; | ||
1220 | } | ||
1221 | } | 1222 | } |
1223 | return XD3_INVALID; | ||
1222 | } | 1224 | } |
1223 | } | 1225 | } |
1224 | 1226 | ||
@@ -2400,7 +2402,7 @@ main_secondary_decompress_check (main_file *file, | |||
2400 | usize_t i; | 2402 | usize_t i; |
2401 | usize_t try_read = xd3_min (input_size, XD3_ALLOCSIZE); | 2403 | usize_t try_read = xd3_min (input_size, XD3_ALLOCSIZE); |
2402 | size_t check_nread = 0; | 2404 | size_t check_nread = 0; |
2403 | uint8_t check_buf[XD3_ALLOCSIZE]; /* TODO: stack limit */ | 2405 | uint8_t check_buf[XD3_ALLOCSIZE]; /* TODO: heap allocate */ |
2404 | const main_extcomp *decompressor = NULL; | 2406 | const main_extcomp *decompressor = NULL; |
2405 | 2407 | ||
2406 | if ((ret = main_file_read (file, check_buf, | 2408 | if ((ret = main_file_read (file, check_buf, |
@@ -3742,8 +3744,8 @@ int main (int argc, char **argv) | |||
3742 | case 'J': option_no_output = 1; break; | 3744 | case 'J': option_no_output = 1; break; |
3743 | case 'S': if (my_optarg == NULL) | 3745 | case 'S': if (my_optarg == NULL) |
3744 | { | 3746 | { |
3745 | option_use_secondary = 1; | 3747 | option_use_secondary = 0; |
3746 | option_secondary = "none"; | 3748 | option_secondary = NULL; |
3747 | } | 3749 | } |
3748 | else | 3750 | else |
3749 | { | 3751 | { |
diff --git a/xdelta3/xdelta3-test.h b/xdelta3/xdelta3-test.h index 97330bb..8e186e2 100644 --- a/xdelta3/xdelta3-test.h +++ b/xdelta3/xdelta3-test.h | |||
@@ -233,7 +233,8 @@ static void | |||
233 | test_unlink (char* file) | 233 | test_unlink (char* file) |
234 | { | 234 | { |
235 | int ret; | 235 | int ret; |
236 | if ((ret = unlink (file)) != 0 && errno != ENOENT) | 236 | if (file != NULL && *file != 0 && |
237 | (ret = unlink (file)) != 0 && errno != ENOENT) | ||
237 | { | 238 | { |
238 | XPR(NT "unlink %s failed: %s\n", file, strerror(ret)); | 239 | XPR(NT "unlink %s failed: %s\n", file, strerror(ret)); |
239 | } | 240 | } |
@@ -258,6 +259,9 @@ int test_setup (void) | |||
258 | static int x = 0; | 259 | static int x = 0; |
259 | pid_t pid = getpid(); | 260 | pid_t pid = getpid(); |
260 | x++; | 261 | x++; |
262 | |||
263 | test_cleanup(); | ||
264 | |||
261 | snprintf_func (TEST_TARGET_FILE, TESTFILESIZE, | 265 | snprintf_func (TEST_TARGET_FILE, TESTFILESIZE, |
262 | "/tmp/xdtest.%d.target.%d", pid, x); | 266 | "/tmp/xdtest.%d.target.%d", pid, x); |
263 | snprintf_func (TEST_SOURCE_FILE, TESTFILESIZE, | 267 | snprintf_func (TEST_SOURCE_FILE, TESTFILESIZE, |
@@ -272,6 +276,7 @@ int test_setup (void) | |||
272 | "/tmp/xdtest.%d.copy.%d", pid, x); | 276 | "/tmp/xdtest.%d.copy.%d", pid, x); |
273 | snprintf_func (TEST_NOPERM_FILE, TESTFILESIZE, | 277 | snprintf_func (TEST_NOPERM_FILE, TESTFILESIZE, |
274 | "/tmp/xdtest.%d.noperm.%d", pid, x); | 278 | "/tmp/xdtest.%d.noperm.%d", pid, x); |
279 | |||
275 | test_cleanup(); | 280 | test_cleanup(); |
276 | return 0; | 281 | return 0; |
277 | } | 282 | } |
@@ -1509,7 +1514,8 @@ IF_DJW (static int test_secondary_huff (xd3_stream *stream, usize_t gp) | |||
1509 | { return test_secondary (stream, & djw_sec_type, gp); }) | 1514 | { return test_secondary (stream, & djw_sec_type, gp); }) |
1510 | IF_LZMA (static int test_secondary_lzma (xd3_stream *stream, usize_t gp) | 1515 | IF_LZMA (static int test_secondary_lzma (xd3_stream *stream, usize_t gp) |
1511 | { return test_secondary (stream, & lzma_sec_type, gp); }) | 1516 | { return test_secondary (stream, & lzma_sec_type, gp); }) |
1512 | #endif | 1517 | |
1518 | #endif /* SECONDARY_ANY */ | ||
1513 | 1519 | ||
1514 | /*********************************************************************** | 1520 | /*********************************************************************** |
1515 | TEST INSTRUCTION TABLE | 1521 | TEST INSTRUCTION TABLE |
@@ -1906,7 +1912,7 @@ test_recode_command2 (xd3_stream *stream, int has_source, | |||
1906 | recoded_adler32 ? "" : "-n ", | 1912 | recoded_adler32 ? "" : "-n ", |
1907 | !change_apphead ? "" : | 1913 | !change_apphead ? "" : |
1908 | (recoded_apphead ? "-A=recode_apphead " : "-A= "), | 1914 | (recoded_apphead ? "-A=recode_apphead " : "-A= "), |
1909 | recoded_secondary ? "-S djw " : "-S none ", | 1915 | recoded_secondary ? "-S djw " : "-S= ", |
1910 | TEST_DELTA_FILE, | 1916 | TEST_DELTA_FILE, |
1911 | TEST_COPY_FILE); | 1917 | TEST_COPY_FILE); |
1912 | 1918 | ||
@@ -2002,6 +2008,7 @@ test_recode_command2 (xd3_stream *stream, int has_source, | |||
2002 | { | 2008 | { |
2003 | return ret; | 2009 | return ret; |
2004 | } | 2010 | } |
2011 | test_cleanup (); | ||
2005 | 2012 | ||
2006 | return 0; | 2013 | return 0; |
2007 | } | 2014 | } |
@@ -2040,7 +2047,46 @@ test_recode_command (xd3_stream *stream, int ignore) | |||
2040 | 2047 | ||
2041 | return 0; | 2048 | return 0; |
2042 | } | 2049 | } |
2043 | #endif | 2050 | |
2051 | #if SECONDARY_LZMA | ||
2052 | int test_secondary_lzma_default (xd3_stream *stream, int ignore) | ||
2053 | { | ||
2054 | char ecmd[TESTBUFSIZE]; | ||
2055 | int ret; | ||
2056 | |||
2057 | test_setup (); | ||
2058 | |||
2059 | if ((ret = test_make_inputs (stream, NULL, NULL))) | ||
2060 | { | ||
2061 | return ret; | ||
2062 | } | ||
2063 | |||
2064 | /* First encode */ | ||
2065 | snprintf_func (ecmd, TESTBUFSIZE, "%s -e %s %s", | ||
2066 | program_name, | ||
2067 | TEST_TARGET_FILE, | ||
2068 | TEST_DELTA_FILE); | ||
2069 | |||
2070 | if ((ret = system (ecmd)) != 0) | ||
2071 | { | ||
2072 | return XD3_INTERNAL; | ||
2073 | } | ||
2074 | |||
2075 | if ((ret = check_vcdiff_header (stream, | ||
2076 | TEST_DELTA_FILE, | ||
2077 | "VCDIFF secondary compressor", | ||
2078 | "lzma", | ||
2079 | 1))) | ||
2080 | { | ||
2081 | return ret; | ||
2082 | } | ||
2083 | |||
2084 | test_cleanup (); | ||
2085 | return 0; | ||
2086 | } | ||
2087 | |||
2088 | #endif /* SECONDARY_LZMA */ | ||
2089 | #endif /* SHELL_TESTS */ | ||
2044 | 2090 | ||
2045 | /*********************************************************************** | 2091 | /*********************************************************************** |
2046 | EXTERNAL I/O DECOMPRESSION/RECOMPRESSION | 2092 | EXTERNAL I/O DECOMPRESSION/RECOMPRESSION |
@@ -2422,6 +2468,7 @@ test_appheader (xd3_stream *stream, int ignore) | |||
2422 | return XD3_INVALID; // Must have crashed! | 2468 | return XD3_INVALID; // Must have crashed! |
2423 | } | 2469 | } |
2424 | 2470 | ||
2471 | test_cleanup (); | ||
2425 | return 0; | 2472 | return 0; |
2426 | } | 2473 | } |
2427 | 2474 | ||
@@ -2915,6 +2962,7 @@ xd3_selftest (void) | |||
2915 | DO_TEST (recode_command, 0, 0); | 2962 | DO_TEST (recode_command, 0, 0); |
2916 | #endif | 2963 | #endif |
2917 | 2964 | ||
2965 | IF_LZMA (DO_TEST (secondary_lzma_default, 0, 0)); | ||
2918 | IF_LZMA (DO_TEST (secondary_lzma, 0, 1)); | 2966 | IF_LZMA (DO_TEST (secondary_lzma, 0, 1)); |
2919 | IF_DJW (DO_TEST (secondary_huff, 0, DJW_MAX_GROUPS)); | 2967 | IF_DJW (DO_TEST (secondary_huff, 0, DJW_MAX_GROUPS)); |
2920 | IF_FGK (DO_TEST (secondary_fgk, 0, 1)); | 2968 | IF_FGK (DO_TEST (secondary_fgk, 0, 1)); |