X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=tests%2Fwlfuzz.c;h=35cefbe5c3846d9fcaae2c4d5a8fb762f983dff0;hb=c6274b2faeab6a144ec51c5cf17380d7811c650a;hp=51607869fb11913b3ddc0a0b9e7093e0658eb34f;hpb=37d9c3935130128901f6eee8d7531d8ae4b1bca6;p=wimlib diff --git a/tests/wlfuzz.c b/tests/wlfuzz.c index 51607869..35cefbe5 100644 --- a/tests/wlfuzz.c +++ b/tests/wlfuzz.c @@ -498,48 +498,67 @@ get_random_write_flags(void) return write_flags; } +static uint32_t +get_random_chunk_size(int min_order, int max_order) +{ + return 1 << (min_order + (rand32() % (max_order - min_order + 1))); +} + static void op__create_new_wim(void) { printf(":::op__create_new_wim\n"); const tchar *wimfile; - WIMStruct *wim; + enum wimlib_compression_type ctype = WIMLIB_COMPRESSION_TYPE_NONE; + uint32_t chunk_size = 0; + uint32_t solid_chunk_size = 0; int write_flags; + WIMStruct *wim; if (num_wimfiles_in_use == MAX_NUM_WIMS) return; wimfile = select_new_wimfile(); - CHECK_RET(wimlib_create_new_wim(WIMLIB_COMPRESSION_TYPE_NONE, &wim)); - /* Select a random compression type and chunk size. */ - switch (rand32() % 8) { - default: - CHECK_RET(wimlib_set_output_compression_type(wim, WIMLIB_COMPRESSION_TYPE_NONE)); + switch (rand32() % 4) { + case 0: break; - case 3 ... 4: - CHECK_RET(wimlib_set_output_compression_type(wim, WIMLIB_COMPRESSION_TYPE_XPRESS)); - CHECK_RET(wimlib_set_output_chunk_size(wim, 1 << (12 + rand32() % 5))); + case 1: + ctype = WIMLIB_COMPRESSION_TYPE_XPRESS; + chunk_size = get_random_chunk_size(12, 16); break; - case 5 ... 6: - CHECK_RET(wimlib_set_output_compression_type(wim, WIMLIB_COMPRESSION_TYPE_LZX)); + case 2: + ctype = WIMLIB_COMPRESSION_TYPE_LZX; if (randbool()) - CHECK_RET(wimlib_set_output_chunk_size(wim, 1 << 15)); + chunk_size = 1 << 15; else - CHECK_RET(wimlib_set_output_chunk_size(wim, 1 << (15 + rand32() % 7))); + chunk_size = get_random_chunk_size(15, 21); break; - case 7: - CHECK_RET(wimlib_set_output_compression_type(wim, WIMLIB_COMPRESSION_TYPE_LZMS)); - CHECK_RET(wimlib_set_output_chunk_size(wim, 1 << (15 + rand32() % 12))); + case 3: + ctype = WIMLIB_COMPRESSION_TYPE_LZMS; + chunk_size = get_random_chunk_size(15, 28); + if (randbool()) + solid_chunk_size = get_random_chunk_size(15, 26); + else + solid_chunk_size = get_random_chunk_size(26, 28); break; } /* Select random write flags. */ write_flags = get_random_write_flags(); - printf("Creating %"TS" with write flags 0x%08x\n", wimfile, write_flags); + printf("Creating %"TS" with write flags 0x%08x, compression_type=%"TS", chunk_size=%u, solid_chunk_size=%u\n", + wimfile, write_flags, + wimlib_get_compression_type_string(ctype), + chunk_size, solid_chunk_size); + + CHECK_RET(wimlib_create_new_wim(ctype, &wim)); + if (chunk_size != 0) + CHECK_RET(wimlib_set_output_chunk_size(wim, chunk_size)); + if (solid_chunk_size != 0) + CHECK_RET(wimlib_set_output_pack_chunk_size(wim, solid_chunk_size)); CHECK_RET(wimlib_write(wim, wimfile, WIMLIB_ALL_IMAGES, write_flags, 0)); @@ -722,14 +741,29 @@ op__apply_and_capture_test(void) CHECK_RET(wimlib_add_image(wim, (void *)rand32, NULL, NULL, WIMLIB_ADD_FLAG_GENERATE_TEST_DATA | WIMLIB_ADD_FLAG_NORPFIX)); + + image = get_image_count(wim); + + printf("generated wim%d image %d\n", index, image); + + { + /* + * Compare the in-memory version of the generated image with a + * version written to disk + */ + WIMStruct *tmp_wim; + + CHECK_RET(wimlib_write(wim, T("tmp.wim"), image, 0, 0)); + CHECK_RET(wimlib_open_wim(T("tmp.wim"), 0, &tmp_wim)); + CHECK_RET(wimlib_compare_images(wim, image, tmp_wim, 1, 0)); + wimlib_free(tmp_wim); + } + overwrite_wim(wim); wimlib_free(wim); /* Apply the generated image. */ wim = open_wim(index); - image = get_image_count(wim); - printf("apply and capture wim%d; generated image is index %d\n", - index, image); delete_directory_tree(TMP_TARGET_NAME); #ifdef WITH_NTFS_3G if (rand32() & 1) { @@ -739,20 +773,19 @@ op__apply_and_capture_test(void) extract_flags |= WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES; extract_flags |= WIMLIB_EXTRACT_FLAG_STRICT_TIMESTAMPS; add_flags |= WIMLIB_ADD_FLAG_NTFS; - cmp_flags |= WIMLIB_CMP_FLAG_COMPRESSION_NOT_PRESERVED; + cmp_flags |= WIMLIB_CMP_FLAG_NTFS_3G_MODE; create_ntfs_volume(TMP_TARGET_NAME); } else #endif { #ifdef __WIN32__ printf("applying in Windows mode\n"); + cmp_flags |= WIMLIB_CMP_FLAG_WINDOWS_MODE; #else /* __WIN32__ */ printf("applying in UNIX mode\n"); - cmp_flags |= WIMLIB_CMP_FLAG_SHORT_NAMES_NOT_PRESERVED; - cmp_flags |= WIMLIB_CMP_FLAG_ATTRIBUTES_NOT_PRESERVED; - cmp_flags |= WIMLIB_CMP_FLAG_SECURITY_NOT_PRESERVED; - cmp_flags |= WIMLIB_CMP_FLAG_ADS_NOT_PRESERVED; - cmp_flags |= WIMLIB_CMP_FLAG_IMAGE2_SHOULD_HAVE_SYMLINKS; + extract_flags |= WIMLIB_EXTRACT_FLAG_UNIX_DATA; + add_flags |= WIMLIB_ADD_FLAG_UNIX_DATA; + cmp_flags |= WIMLIB_CMP_FLAG_UNIX_MODE; #endif /* !__WIN32__ */ } add_flags |= WIMLIB_ADD_FLAG_NORPFIX; @@ -812,6 +845,7 @@ unregister_all_backing_wims(const tchar drive_letter) overlay_list, 32768, &bytes_returned, NULL)) { ASSERT(GetLastError() == ERROR_INVALID_FUNCTION || + GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_FILE_NOT_FOUND, "FSCTL_ENUM_OVERLAY failed; error=%u", GetLastError()); return; @@ -891,7 +925,8 @@ op__wimboot_test(void) printf("comparing wimboot.wim:%d with wim%d:%d\n", image, index2, image_count + 1); - CHECK_RET(wimlib_compare_images(wim, image, wim2, image_count + 1, 0)); + CHECK_RET(wimlib_compare_images(wim, image, wim2, image_count + 1, + WIMLIB_CMP_FLAG_WINDOWS_MODE)); wimlib_free(wim); wimlib_free(wim2);