From: Artem Bityutskiy Date: Fri, 3 May 2013 05:57:32 +0000 (+0300) Subject: tests: do not truncate too far X-Git-Tag: v2.5~49 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=577e15ee08970f3c09413feef3421488e270c2bd;p=tools%2Fbmap-tools.git tests: do not truncate too far This patch changes the '_create_random_sparse_file()' function behavier a little and teaches it to not truncate files too far. For example, if we asked '_create_random_sparse_file()' to create an 8193 bytes sparse file, it could do the following: 1. Map the first 4KiB block 2. Map the second 4KiB block 3. Truncate to 12KiB 4. And at the end truncate to 8183 bytes This worked fine on ext4 - we ended up with a file with 2 first blocks mapped and an unmapped block at the end. However, on btrfs this leads to a file with all 3 blocks mapped (I assume 1 block = 4KiB). And this is not a bug, this is just how btrfs allocates blocks and we cannot, generally speaking, make any assumptions about the allocation algorithms. This patch changes '_create_random_sparse_file()' and makes it avoid truncating files too far. Namely, we will truncate only to the end of the last block. Now the tests pass on btrfs (kernel version 3.8.6). Signed-off-by: Artem Bityutskiy --- diff --git a/tests/helpers.py b/tests/helpers.py index 2b771b8..22a72fc 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -37,7 +37,7 @@ def _create_random_sparse_file(file_obj, size): file_obj.seek(block * block_size + seek) file_obj.write(chr(random.getrandbits(8)) * write) else: - file_obj.truncate((block + 1) * block_size) + file_obj.truncate(block * block_size) return map_the_block