From a7a349bc9083d948e6277fb22dbbad225e1f38f2 Mon Sep 17 00:00:00 2001 From: Thomas Hahn Date: Mon, 12 Aug 2024 12:03:50 -0400 Subject: [PATCH 1/2] Fix bug in nda_mem test --- test/c++/nda_mem.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/c++/nda_mem.cpp b/test/c++/nda_mem.cpp index e4d163e6..51db6c88 100644 --- a/test/c++/nda_mem.cpp +++ b/test/c++/nda_mem.cpp @@ -301,14 +301,16 @@ TEST(NDA, MemoryMultiBucketAllocator) { bucket2[0] = allo.allocate_zero(chunksize); EXPECT_EQ(allo.buckets().size(), 2); EXPECT_TRUE(allo.owns(bucket2[0])); - EXPECT_TRUE(allo.buckets()[1].owns(bucket2[0])); + EXPECT_TRUE(allo.buckets()[0].owns(bucket2[0]) != allo.buckets()[1].owns(bucket2[0])); // deallocate and reallocate in the 1st bucket + std::size_t idx = 0; + if (allo.buckets()[1].owns(bucket1[20])) idx = 1; allo.deallocate(bucket1[20]); - EXPECT_FALSE(allo.buckets()[0].is_full()); + EXPECT_FALSE(allo.buckets()[idx].is_full()); auto mb_realloc = allo.allocate_zero(chunksize); - EXPECT_TRUE(allo.buckets()[0].owns(mb_realloc)); - EXPECT_TRUE(allo.buckets()[0].is_full()); + EXPECT_TRUE(allo.buckets()[idx].owns(mb_realloc)); + EXPECT_TRUE(allo.buckets()[idx].is_full()); // erase 2nd bucket allo.deallocate(bucket2[0]); From 168570bcd7b129e5e68a7c42dd3d62fc94a0c905 Mon Sep 17 00:00:00 2001 From: Nils Wentzell Date: Fri, 27 Sep 2024 12:47:02 -0400 Subject: [PATCH 2/2] Iterate on nda_mem test fix --- test/c++/nda_mem.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/c++/nda_mem.cpp b/test/c++/nda_mem.cpp index 51db6c88..f23501b6 100644 --- a/test/c++/nda_mem.cpp +++ b/test/c++/nda_mem.cpp @@ -301,16 +301,20 @@ TEST(NDA, MemoryMultiBucketAllocator) { bucket2[0] = allo.allocate_zero(chunksize); EXPECT_EQ(allo.buckets().size(), 2); EXPECT_TRUE(allo.owns(bucket2[0])); - EXPECT_TRUE(allo.buckets()[0].owns(bucket2[0]) != allo.buckets()[1].owns(bucket2[0])); + // The new bucket may be first inside allo.buckets(), + // as it respects memory ordering. Let's get the indeces + std::size_t first_bucket_idx = allo.buckets()[1].owns(bucket1[0]); + std::size_t second_bucket_idx = allo.buckets()[1].owns(bucket2[0]); + EXPECT_TRUE(allo.buckets()[first_bucket_idx].is_full()); + EXPECT_FALSE(allo.buckets()[first_bucket_idx].owns(bucket2[0])); + EXPECT_TRUE(allo.buckets()[second_bucket_idx].owns(bucket2[0])); // deallocate and reallocate in the 1st bucket - std::size_t idx = 0; - if (allo.buckets()[1].owns(bucket1[20])) idx = 1; allo.deallocate(bucket1[20]); - EXPECT_FALSE(allo.buckets()[idx].is_full()); + EXPECT_FALSE(allo.buckets()[first_bucket_idx].is_full()); auto mb_realloc = allo.allocate_zero(chunksize); - EXPECT_TRUE(allo.buckets()[idx].owns(mb_realloc)); - EXPECT_TRUE(allo.buckets()[idx].is_full()); + EXPECT_TRUE(allo.buckets()[first_bucket_idx].owns(mb_realloc)); + EXPECT_TRUE(allo.buckets()[first_bucket_idx].is_full()); // erase 2nd bucket allo.deallocate(bucket2[0]);