X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fbup%2Ft%2Fthashsplit.py;h=7ddcf3473915414ebaf5b91455df829db976cdeb;hb=2660592aa67e987fb5ab8351ecea142faedc8e53;hp=62d973e6410a51ca55e3d4ff6b86709388c3c511;hpb=e3297ae411842ca61ed0f94afc97b302e50bdf85;p=bup.git diff --git a/lib/bup/t/thashsplit.py b/lib/bup/t/thashsplit.py index 62d973e..7ddcf34 100644 --- a/lib/bup/t/thashsplit.py +++ b/lib/bup/t/thashsplit.py @@ -1,7 +1,84 @@ -from bup import hashsplit, _helpers -from wvtest import * from cStringIO import StringIO +from wvtest import * + +from bup import hashsplit, _helpers, helpers + + +def nr_regions(x, max_count=None): + return list(hashsplit._nonresident_page_regions(''.join(map(chr, x)), + max_count)) + +@wvtest +def test_nonresident_page_regions(): + WVPASSEQ(nr_regions([]), []) + WVPASSEQ(nr_regions([1]), []) + WVPASSEQ(nr_regions([0]), [(0, 1)]) + WVPASSEQ(nr_regions([1, 0]), [(1, 1)]) + WVPASSEQ(nr_regions([0, 0]), [(0, 2)]) + WVPASSEQ(nr_regions([1, 0, 1]), [(1, 1)]) + WVPASSEQ(nr_regions([1, 0, 0]), [(1, 2)]) + WVPASSEQ(nr_regions([0, 1, 0]), [(0, 1), (2, 1)]) + WVPASSEQ(nr_regions([0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0]), + [(0, 2), (5, 3), (9, 2)]) + WVPASSEQ(nr_regions([2, 42, 3, 101]), [(0, 2)]) + # Test limit + WVPASSEQ(nr_regions([0, 0, 0], None), [(0, 3)]) + WVPASSEQ(nr_regions([0, 0, 0], 1), [(0, 1), (1, 1), (2, 1)]) + WVPASSEQ(nr_regions([0, 0, 0], 2), [(0, 2), (2, 1)]) + WVPASSEQ(nr_regions([0, 0, 0], 3), [(0, 3)]) + WVPASSEQ(nr_regions([0, 0, 0], 4), [(0, 3)]) + WVPASSEQ(nr_regions([0, 0, 1], None), [(0, 2)]) + WVPASSEQ(nr_regions([0, 0, 1], 1), [(0, 1), (1, 1)]) + WVPASSEQ(nr_regions([0, 0, 1], 2), [(0, 2)]) + WVPASSEQ(nr_regions([0, 0, 1], 3), [(0, 2)]) + WVPASSEQ(nr_regions([1, 0, 0], None), [(1, 2)]) + WVPASSEQ(nr_regions([1, 0, 0], 1), [(1, 1), (2, 1)]) + WVPASSEQ(nr_regions([1, 0, 0], 2), [(1, 2)]) + WVPASSEQ(nr_regions([1, 0, 0], 3), [(1, 2)]) + WVPASSEQ(nr_regions([1, 0, 0, 0, 1], None), [(1, 3)]) + WVPASSEQ(nr_regions([1, 0, 0, 0, 1], 1), [(1, 1), (2, 1), (3, 1)]) + WVPASSEQ(nr_regions([1, 0, 0, 0, 1], 2), [(1, 2), (3, 1)]) + WVPASSEQ(nr_regions([1, 0, 0, 0, 1], 3), [(1, 3)]) + WVPASSEQ(nr_regions([1, 0, 0, 0, 1], 4), [(1, 3)]) + + +@wvtest +def test_uncache_ours_upto(): + history = [] + def mock_fadvise_pages_done(f, ofs, len): + history.append((f, ofs, len)) + + uncache_upto = hashsplit._uncache_ours_upto + page_size = helpers.sc_page_size + orig_pages_done = hashsplit._fadvise_pages_done + try: + hashsplit._fadvise_pages_done = mock_fadvise_pages_done + history = [] + uncache_upto(42, 0, (0, 1), iter([])) + WVPASSEQ([], history) + uncache_upto(42, page_size, (0, 1), iter([])) + WVPASSEQ([(42, 0, 1)], history) + history = [] + uncache_upto(42, page_size, (0, 3), iter([(5, 2)])) + WVPASSEQ([], history) + uncache_upto(42, 2 * page_size, (0, 3), iter([(5, 2)])) + WVPASSEQ([], history) + uncache_upto(42, 3 * page_size, (0, 3), iter([(5, 2)])) + WVPASSEQ([(42, 0, 3)], history) + history = [] + uncache_upto(42, 5 * page_size, (0, 3), iter([(5, 2)])) + WVPASSEQ([(42, 0, 3)], history) + history = [] + uncache_upto(42, 6 * page_size, (0, 3), iter([(5, 2)])) + WVPASSEQ([(42, 0, 3)], history) + history = [] + uncache_upto(42, 7 * page_size, (0, 3), iter([(5, 2)])) + WVPASSEQ([(42, 0, 3), (42, 5, 2)], history) + finally: + hashsplit._fadvise_pages_done = orig_pages_done + + @wvtest def test_rolling_sums(): WVPASS(_helpers.selftest())