tests: do not truncate too far
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Fri, 3 May 2013 05:57:32 +0000 (08:57 +0300)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Fri, 3 May 2013 06:12:03 +0000 (09:12 +0300)
commit577e15ee08970f3c09413feef3421488e270c2bd
tree7e71463de99c5f75b0e5e419e74b5233069bb0b3
parent9113300a4f43042b47638382b6e5cd4de40975d2
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 <artem.bityutskiy@linux.intel.com>
tests/helpers.py