[bmap-tools] [PATCH 09/14] test_filemap: improve the test
Artem Bityutskiy
dedekind1 at gmail.com
Tue Jan 21 12:34:30 EST 2014
From: Artem Bityutskiy <artem.bityutskiy at intel.com>
The test did not cover the 'block_is_mapped()' and 'block_is_unmapped()'
methods of the Filemap module - improve this. Also, test both 'FilemapFiemap'
and 'FilemapSeek' classes.
On top of this, do not fail if the kernel of the file-system does not support
FIEMAP or SEEK_HOLE.
Change-Id: Iaa81f60e93084b5ada489b9fbbcf65568563335e
Signed-off-by: Artem Bityutskiy <artem.bityutskiy at intel.com>
---
tests/test_filemap.py | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/tests/test_filemap.py b/tests/test_filemap.py
index a9d3cef..478695d 100644
--- a/tests/test_filemap.py
+++ b/tests/test_filemap.py
@@ -88,17 +88,25 @@ def _check_ranges(f_image, filemap, first_block, blocks_cnt,
ranges_type, first_block, blocks_cnt,
check[0], check[1]))
-def _do_test(f_image, mapped, unmapped):
+ for block in xrange(correct[0], correct[1] + 1):
+ if ranges_type is "mapped" and filemap.block_is_unmapped(block):
+ raise Error("range %d-%d of file '%s' is mapped, but"
+ "'block_is_unmapped(%d) returned 'True'"
+ % (correct[0], correct[1], f_image.name, block))
+ if ranges_type is "unmapped" and filemap.block_is_mapped(block):
+ raise Error("range %d-%d of file '%s' is unmapped, but"
+ "'block_is_mapped(%d) returned 'True'"
+ % (correct[0], correct[1], f_image.name, block))
+
+
+def _do_test(f_image, filemap, mapped, unmapped):
"""
- Verify that Filemap reports the correct mapped and unmapped areas for the
- 'f_image' file object. The 'mapped' and 'unmapped' lists contain the
- correct ranges.
+ Verify that the 'Filemap' module provides correct mapped and unmapped areas
+ for the 'f_image' file object. The 'mapped' and 'unmapped' lists contain
+ the correct ranges. The 'filemap' is one of the classed from the 'Filemap'
+ module.
"""
- # Make sure that 'Filemap' module's 'get_mapped_ranges()' returns the same
- # ranges as we have in the 'mapped' list.
- filemap = Filemap.filemap(f_image)
-
# Check both 'get_mapped_ranges()' and 'get_unmapped_ranges()' for the
# entire file.
first_block = 0
@@ -140,4 +148,11 @@ class TestCreateCopy(unittest.TestCase):
iterator = tests.helpers.generate_test_files(max_size, directory,
delete)
for f_image, _, mapped, unmapped in iterator:
- _do_test(f_image, mapped, unmapped)
+ try:
+ fiemap = Filemap.FilemapFiemap(f_image)
+ _do_test(f_image, fiemap, mapped, unmapped)
+
+ seek = Filemap.FilemapSeek(f_image)
+ _do_test(f_image, seek, mapped, unmapped)
+ except Filemap.ErrorNotSupp:
+ pass
--
1.8.3.1
More information about the Bmap-tools
mailing list