]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/bufferlist: ensure rebuild_aligned_size_and_memory() always rebuilds. 46216/head
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 21 Jan 2022 01:50:22 +0000 (01:50 +0000)
committerRadosław Zarzyński <rzarzyns@redhat.com>
Tue, 10 May 2022 12:33:26 +0000 (14:33 +0200)
Before the patch the test case was showing an unreliable behaviour
dependent on the underlying memory allocator. It was because
the bufferlist rebuild can be skipped, resulting in unchanged number
of buffers, if all of them begin at aligned addresses.

The commit fixes that by allocating a 4 KiB-aligned buffer and
offsetting it by a small constant (42) to ensure the memory added
to the bufferlist begins at non-4 KiB address.

Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
(cherry picked from commit 88176acd27b0d495abf9396c7ae2c6ec3fa46b1b)

src/test/bufferlist.cc

index a76dfbd44b514584381a7d075ecab2779e9020ea..0beb9ce09360c723d338590ccc8486d52e53a27e 100644 (file)
@@ -1660,13 +1660,14 @@ TEST(BufferList, rebuild_aligned_size_and_memory) {
      * scenario where the first bptr is both size and memory aligned and
      * the second is 0-length */
     bl.clear();
-    bufferptr ptr1(buffer::create_aligned(4096, 4096));
-    bl.append(ptr1);
-    bufferptr ptr(10);
-    /* bl.back().length() must be 0 */
-    bl.append(ptr, 0, 0);
+    bl.append(bufferptr{buffer::create_aligned(4096, 4096)});
+    bufferptr ptr(buffer::create_aligned(42, 4096));
+    /* bl.back().length() must be 0. offset set to 42 guarantees
+     * the entire list is unaligned. */
+    bl.append(ptr, 42, 0);
     EXPECT_EQ(bl.get_num_buffers(), 2);
     EXPECT_EQ(bl.back().length(), 0);
+    EXPECT_FALSE(bl.is_aligned(4096));
     /* rebuild_aligned() calls rebuild_aligned_size_and_memory().
      * we assume the rebuild always happens. */
     EXPECT_TRUE(bl.rebuild_aligned(4096));