From: Artem Bityutskiy Date: Tue, 27 Nov 2012 13:11:21 +0000 (+0200) Subject: test_fiemap: add Fiemap module unit test X-Git-Tag: v1.0~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=109c9ac57cd67d2886490e34157bc25134bf609c;p=tools%2Fbmap-tools.git test_fiemap: add Fiemap module unit test Change-Id: I0da8bb80f8b15fd27695381324bb213726cfeca2 Signed-off-by: Artem Bityutskiy --- diff --git a/tests/test_fiemap.py b/tests/test_fiemap.py new file mode 100644 index 0000000..a6dff22 --- /dev/null +++ b/tests/test_fiemap.py @@ -0,0 +1,68 @@ +""" This test verifies Fiemap module functionality. It generates random sparse +files and make sure FIEMAP returns correct information about the holes. """ + +import unittest +import itertools + +import tests.helpers +from bmaptools import Fiemap + +class Error(Exception): + """ A class for exceptions generated by this test. """ + pass + +def _do_test(f_image, mapped, holes): + """ Verifiy that Fiemap reports the correct mapped areas and holes ranges + fro the 'f_image' file object. The 'mapped' and 'holes' lists contains the + correct ranges. """ + + # Make sure that Fiemap's get_mapped_ranges() returns the same ranges as + # we have in the 'mapped' list. + fiemap = Fiemap.Fiemap(f_image) + fiemap_iterator = fiemap.get_mapped_ranges(0, fiemap.blocks_cnt) + iterator = itertools.izip_longest(fiemap_iterator, mapped) + + for range1, range2 in iterator: + if range1[0] > range1[1]: + raise Error("bad mapped area range %d-%d" % (range1[0], range1[1])) + + if range1 != range2: + raise Error("mapped areas mismatch: %d-%d as per Fiemap module, " \ + "%d-%d in the image file '%s'" \ + % (range1[0], range1[1], range2[0], range2[1], + f_image.name)) + + # Make sure that Fiemap's get_unmapped_ranges() returns the same ranges as + # we have in the 'holes' list. + fiemap_iterator = fiemap.get_unmapped_ranges(0, fiemap.blocks_cnt) + iterator = itertools.izip_longest(fiemap_iterator, holes) + + for range1, range2 in iterator: + if range1[0] > range1[1]: + raise Error("bad hole range %d-%d" % (range1[0], range1[1])) + + if range1 != range2: + raise Error("holes mismatch: %d-%d as per Fiemap module, %d-%d " \ + "in the image file '%s'" \ + % (range1[0], range1[1], range2[0], range2[1], + f_image.name)) + +class TestCreateCopy(unittest.TestCase): + """ The test class for this unit tests. Basically executes the '_do_test()' + function for different sparse files. """ + + @staticmethod + def test(): + """ The test entry point. Executes the '_do_test()' function for files + of different sizes, holes distribution and format. """ + + # Delete all the test-related temporary files automatically + delete = True + # Create all the test-related temporary files in the default directory + # (usually /tmp). + directory = None + + iterator = tests.helpers.generate_test_files(delete = delete, + directory = directory) + for f_image, mapped, holes in iterator: + _do_test(f_image, mapped, holes)