test_filemap: improve the test
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Sun, 19 Jan 2014 14:51:34 +0000 (16:51 +0200)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Tue, 21 Jan 2014 17:16:23 +0000 (19:16 +0200)
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@intel.com>
tests/test_filemap.py

index a9d3cef941004be3fd221565177281555720ddc1..478695d47b89e0a25eb0300079832351d5cf325f 100644 (file)
@@ -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