cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-test-hbitmap-Add-non-advancing-iter_next-tests.patch

26ba25
From 4dc36767c7dacd88e0ce52aea59dad6bccb167c4 Mon Sep 17 00:00:00 2001
26ba25
From: John Snow <jsnow@redhat.com>
26ba25
Date: Tue, 20 Nov 2018 18:18:08 +0000
26ba25
Subject: [PATCH 14/35] test-hbitmap: Add non-advancing iter_next tests
26ba25
26ba25
RH-Author: John Snow <jsnow@redhat.com>
26ba25
Message-id: <20181120181828.15132-5-jsnow@redhat.com>
26ba25
Patchwork-id: 83064
26ba25
O-Subject: [RHEL8/rhel qemu-kvm PATCH 04/24] test-hbitmap: Add non-advancing iter_next tests
26ba25
Bugzilla: 1518989
26ba25
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
26ba25
From: Max Reitz <mreitz@redhat.com>
26ba25
26ba25
Add a function that wraps hbitmap_iter_next() and always calls it in
26ba25
non-advancing mode first, and in advancing mode next.  The result should
26ba25
always be the same.
26ba25
26ba25
By using this function everywhere we called hbitmap_iter_next() before,
26ba25
we should get good test coverage for non-advancing hbitmap_iter_next().
26ba25
26ba25
Signed-off-by: Max Reitz <mreitz@redhat.com>
26ba25
Reviewed-by: Fam Zheng <famz@redhat.com>
26ba25
Reviewed-by: John Snow <jsnow@redhat.com>
26ba25
Message-id: 20180613181823.13618-9-mreitz@redhat.com
26ba25
Signed-off-by: Max Reitz <mreitz@redhat.com>
26ba25
(cherry picked from commit 269576848ec3d57d2d958cf5ac69b08c44adf816)
26ba25
Signed-off-by: John Snow <jsnow@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 tests/test-hbitmap.c | 36 ++++++++++++++++++++++++------------
26ba25
 1 file changed, 24 insertions(+), 12 deletions(-)
26ba25
26ba25
diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c
26ba25
index f2158f7..5e67ac1 100644
26ba25
--- a/tests/test-hbitmap.c
26ba25
+++ b/tests/test-hbitmap.c
26ba25
@@ -30,6 +30,18 @@ typedef struct TestHBitmapData {
26ba25
 } TestHBitmapData;
26ba25
 
26ba25
 
26ba25
+static int64_t check_hbitmap_iter_next(HBitmapIter *hbi)
26ba25
+{
26ba25
+    int next0, next1;
26ba25
+
26ba25
+    next0 = hbitmap_iter_next(hbi, false);
26ba25
+    next1 = hbitmap_iter_next(hbi, true);
26ba25
+
26ba25
+    g_assert_cmpint(next0, ==, next1);
26ba25
+
26ba25
+    return next0;
26ba25
+}
26ba25
+
26ba25
 /* Check that the HBitmap and the shadow bitmap contain the same data,
26ba25
  * ignoring the same "first" bits.
26ba25
  */
26ba25
@@ -46,7 +58,7 @@ static void hbitmap_test_check(TestHBitmapData *data,
26ba25
 
26ba25
     i = first;
26ba25
     for (;;) {
26ba25
-        next = hbitmap_iter_next(&hbi, true);
26ba25
+        next = check_hbitmap_iter_next(&hbi;;
26ba25
         if (next < 0) {
26ba25
             next = data->size;
26ba25
         }
26ba25
@@ -435,25 +447,25 @@ static void test_hbitmap_iter_granularity(TestHBitmapData *data,
26ba25
     /* Note that hbitmap_test_check has to be invoked manually in this test.  */
26ba25
     hbitmap_test_init(data, 131072 << 7, 7);
26ba25
     hbitmap_iter_init(&hbi, data->hb, 0);
26ba25
-    g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);
26ba25
+    g_assert_cmpint(check_hbitmap_iter_next(&hbi), <, 0);
26ba25
 
26ba25
     hbitmap_test_set(data, ((L2 + L1 + 1) << 7) + 8, 8);
26ba25
     hbitmap_iter_init(&hbi, data->hb, 0);
26ba25
-    g_assert_cmpint(hbitmap_iter_next(&hbi, true), ==, (L2 + L1 + 1) << 7);
26ba25
-    g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);
26ba25
+    g_assert_cmpint(check_hbitmap_iter_next(&hbi), ==, (L2 + L1 + 1) << 7);
26ba25
+    g_assert_cmpint(check_hbitmap_iter_next(&hbi), <, 0);
26ba25
 
26ba25
     hbitmap_iter_init(&hbi, data->hb, (L2 + L1 + 2) << 7);
26ba25
     g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);
26ba25
 
26ba25
     hbitmap_test_set(data, (131072 << 7) - 8, 8);
26ba25
     hbitmap_iter_init(&hbi, data->hb, 0);
26ba25
-    g_assert_cmpint(hbitmap_iter_next(&hbi, true), ==, (L2 + L1 + 1) << 7);
26ba25
-    g_assert_cmpint(hbitmap_iter_next(&hbi, true), ==, 131071 << 7);
26ba25
-    g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);
26ba25
+    g_assert_cmpint(check_hbitmap_iter_next(&hbi), ==, (L2 + L1 + 1) << 7);
26ba25
+    g_assert_cmpint(check_hbitmap_iter_next(&hbi), ==, 131071 << 7);
26ba25
+    g_assert_cmpint(check_hbitmap_iter_next(&hbi), <, 0);
26ba25
 
26ba25
     hbitmap_iter_init(&hbi, data->hb, (L2 + L1 + 2) << 7);
26ba25
-    g_assert_cmpint(hbitmap_iter_next(&hbi, true), ==, 131071 << 7);
26ba25
-    g_assert_cmpint(hbitmap_iter_next(&hbi, true), <, 0);
26ba25
+    g_assert_cmpint(check_hbitmap_iter_next(&hbi), ==, 131071 << 7);
26ba25
+    g_assert_cmpint(check_hbitmap_iter_next(&hbi), <, 0);
26ba25
 }
26ba25
 
26ba25
 static void hbitmap_test_set_boundary_bits(TestHBitmapData *data, ssize_t diff)
26ba25
@@ -893,7 +905,7 @@ static void test_hbitmap_serialize_zeroes(TestHBitmapData *data,
26ba25
     for (i = 0; i < num_positions; i++) {
26ba25
         hbitmap_deserialize_zeroes(data->hb, positions[i], min_l1, true);
26ba25
         hbitmap_iter_init(&iter, data->hb, 0);
26ba25
-        next = hbitmap_iter_next(&iter, true);
26ba25
+        next = check_hbitmap_iter_next(&iter);
26ba25
         if (i == num_positions - 1) {
26ba25
             g_assert_cmpint(next, ==, -1);
26ba25
         } else {
26ba25
@@ -919,10 +931,10 @@ static void test_hbitmap_iter_and_reset(TestHBitmapData *data,
26ba25
 
26ba25
     hbitmap_iter_init(&hbi, data->hb, BITS_PER_LONG - 1);
26ba25
 
26ba25
-    hbitmap_iter_next(&hbi, true);
26ba25
+    check_hbitmap_iter_next(&hbi;;
26ba25
 
26ba25
     hbitmap_reset_all(data->hb);
26ba25
-    hbitmap_iter_next(&hbi, true);
26ba25
+    check_hbitmap_iter_next(&hbi;;
26ba25
 }
26ba25
 
26ba25
 static void test_hbitmap_next_zero_check(TestHBitmapData *data, int64_t start)
26ba25
-- 
26ba25
1.8.3.1
26ba25