Blame SOURCES/kvm-tests-add-tests-for-hbitmap_next_dirty_area.patch

7711c0
From b60d35c274a27a49097d99c626a70d18d313bff2 Mon Sep 17 00:00:00 2001
7711c0
From: John Snow <jsnow@redhat.com>
7711c0
Date: Wed, 20 Mar 2019 21:48:32 +0100
7711c0
Subject: [PATCH 039/163] tests: add tests for hbitmap_next_dirty_area
7711c0
7711c0
RH-Author: John Snow <jsnow@redhat.com>
7711c0
Message-id: <20190320214838.22027-5-jsnow@redhat.com>
7711c0
Patchwork-id: 84996
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 04/10] tests: add tests for hbitmap_next_dirty_area
7711c0
Bugzilla: 1691048
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
RH-Acked-by: Max Reitz <mreitz@redhat.com>
7711c0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
7711c0
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7711c0
7711c0
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7711c0
(cherry picked from commit bb6a0ec10ee3f791835f1479a8a3226f64cb6d75)
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 tests/test-hbitmap.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++
7711c0
 1 file changed, 107 insertions(+)
7711c0
7711c0
diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c
7711c0
index c0da31a..4f312e9 100644
7711c0
--- a/tests/test-hbitmap.c
7711c0
+++ b/tests/test-hbitmap.c
7711c0
@@ -1016,6 +1016,106 @@ static void test_hbitmap_next_zero_4(TestHBitmapData *data, const void *unused)
7711c0
     test_hbitmap_next_zero_do(data, 4);
7711c0
 }
7711c0
 
7711c0
+static void test_hbitmap_next_dirty_area_check(TestHBitmapData *data,
7711c0
+                                               uint64_t offset,
7711c0
+                                               uint64_t count)
7711c0
+{
7711c0
+    uint64_t off1, off2;
7711c0
+    uint64_t len1 = 0, len2;
7711c0
+    bool ret1, ret2;
7711c0
+    int64_t end;
7711c0
+
7711c0
+    off1 = offset;
7711c0
+    len1 = count;
7711c0
+    ret1 = hbitmap_next_dirty_area(data->hb, &off1, &len1);
7711c0
+
7711c0
+    end = offset > data->size || data->size - offset < count ? data->size :
7711c0
+                                                               offset + count;
7711c0
+
7711c0
+    for (off2 = offset; off2 < end && !hbitmap_get(data->hb, off2); off2++) {
7711c0
+        ;
7711c0
+    }
7711c0
+
7711c0
+    for (len2 = 1; off2 + len2 < end && hbitmap_get(data->hb, off2 + len2);
7711c0
+         len2++) {
7711c0
+        ;
7711c0
+    }
7711c0
+
7711c0
+    ret2 = off2 < end;
7711c0
+    if (!ret2) {
7711c0
+        /* leave unchanged */
7711c0
+        off2 = offset;
7711c0
+        len2 = count;
7711c0
+    }
7711c0
+
7711c0
+    g_assert_cmpint(ret1, ==, ret2);
7711c0
+    g_assert_cmpint(off1, ==, off2);
7711c0
+    g_assert_cmpint(len1, ==, len2);
7711c0
+}
7711c0
+
7711c0
+static void test_hbitmap_next_dirty_area_do(TestHBitmapData *data,
7711c0
+                                            int granularity)
7711c0
+{
7711c0
+    hbitmap_test_init(data, L3, granularity);
7711c0
+    test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX);
7711c0
+    test_hbitmap_next_dirty_area_check(data, 0, 1);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L3 - 1, 1);
7711c0
+
7711c0
+    hbitmap_set(data->hb, L2, 1);
7711c0
+    test_hbitmap_next_dirty_area_check(data, 0, 1);
7711c0
+    test_hbitmap_next_dirty_area_check(data, 0, L2);
7711c0
+    test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 - 1, UINT64_MAX);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 - 1, 1);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 - 1, 2);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 - 1, 3);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2, UINT64_MAX);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2, 1);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 + 1, 1);
7711c0
+
7711c0
+    hbitmap_set(data->hb, L2 + 5, L1);
7711c0
+    test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 - 2, 8);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 + 1, 5);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 + 1, 3);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 + 4, L1);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 + 5, L1);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 + 7, L1);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 + L1, L1);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2, 0);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 + 1, 0);
7711c0
+
7711c0
+    hbitmap_set(data->hb, L2 * 2, L3 - L2 * 2);
7711c0
+    test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2, UINT64_MAX);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 + 1, UINT64_MAX);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 + 5 + L1 - 1, UINT64_MAX);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 + 5 + L1, 5);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 * 2 - L1, L1 + 1);
7711c0
+    test_hbitmap_next_dirty_area_check(data, L2 * 2, L2);
7711c0
+
7711c0
+    hbitmap_set(data->hb, 0, L3);
7711c0
+    test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX);
7711c0
+}
7711c0
+
7711c0
+static void test_hbitmap_next_dirty_area_0(TestHBitmapData *data,
7711c0
+                                           const void *unused)
7711c0
+{
7711c0
+    test_hbitmap_next_dirty_area_do(data, 0);
7711c0
+}
7711c0
+
7711c0
+static void test_hbitmap_next_dirty_area_1(TestHBitmapData *data,
7711c0
+                                           const void *unused)
7711c0
+{
7711c0
+    test_hbitmap_next_dirty_area_do(data, 1);
7711c0
+}
7711c0
+
7711c0
+static void test_hbitmap_next_dirty_area_4(TestHBitmapData *data,
7711c0
+                                           const void *unused)
7711c0
+{
7711c0
+    test_hbitmap_next_dirty_area_do(data, 4);
7711c0
+}
7711c0
+
7711c0
 int main(int argc, char **argv)
7711c0
 {
7711c0
     g_test_init(&argc, &argv, NULL);
7711c0
@@ -1082,6 +1182,13 @@ int main(int argc, char **argv)
7711c0
     hbitmap_test_add("/hbitmap/next_zero/next_zero_4",
7711c0
                      test_hbitmap_next_zero_4);
7711c0
 
7711c0
+    hbitmap_test_add("/hbitmap/next_dirty_area/next_dirty_area_0",
7711c0
+                     test_hbitmap_next_dirty_area_0);
7711c0
+    hbitmap_test_add("/hbitmap/next_dirty_area/next_dirty_area_1",
7711c0
+                     test_hbitmap_next_dirty_area_1);
7711c0
+    hbitmap_test_add("/hbitmap/next_dirty_area/next_dirty_area_4",
7711c0
+                     test_hbitmap_next_dirty_area_4);
7711c0
+
7711c0
     g_test_run();
7711c0
 
7711c0
     return 0;
7711c0
-- 
7711c0
1.8.3.1
7711c0