yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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