Fix space_bitmap_test
This patch is part of the chain preparing for making kPageSize
non-constexpr in a future patch.
space_bitmap_test uses page size as template parameter.
Update the test to access page size as a variable instead.
Test: Same as for I5430741a8494b340ed7fd2d8692c41a59ad9c530.
The whole patches chain was tested as a whole.
Change-Id: I996275a043621c3a1147e184300e55d57b849d67
diff --git a/runtime/gc/accounting/space_bitmap_test.cc b/runtime/gc/accounting/space_bitmap_test.cc
index 72fcef0..7b55600 100644
--- a/runtime/gc/accounting/space_bitmap_test.cc
+++ b/runtime/gc/accounting/space_bitmap_test.cc
@@ -151,8 +151,8 @@
uint32_t val_;
};
-template <size_t kAlignment, typename TestFn>
-static void RunTest(TestFn&& fn) NO_THREAD_SAFETY_ANALYSIS {
+template <typename TestFn>
+static void RunTest(size_t alignment, TestFn&& fn) NO_THREAD_SAFETY_ANALYSIS {
uint8_t* heap_begin = reinterpret_cast<uint8_t*>(0x10000000);
size_t heap_capacity = 16 * MB;
@@ -164,7 +164,7 @@
ContinuousSpaceBitmap::Create("test bitmap", heap_begin, heap_capacity));
for (int j = 0; j < 10000; ++j) {
- size_t offset = RoundDown(r.next() % heap_capacity, kAlignment);
+ size_t offset = RoundDown(r.next() % heap_capacity, alignment);
bool set = r.next() % 2 == 1;
if (set) {
@@ -175,12 +175,12 @@
}
for (int j = 0; j < 50; ++j) {
- const size_t offset = RoundDown(r.next() % heap_capacity, kAlignment);
+ const size_t offset = RoundDown(r.next() % heap_capacity, alignment);
const size_t remain = heap_capacity - offset;
- const size_t end = offset + RoundDown(r.next() % (remain + 1), kAlignment);
+ const size_t end = offset + RoundDown(r.next() % (remain + 1), alignment);
size_t manual = 0;
- for (uintptr_t k = offset; k < end; k += kAlignment) {
+ for (uintptr_t k = offset; k < end; k += alignment) {
if (space_bitmap.Test(reinterpret_cast<mirror::Object*>(heap_begin + k))) {
manual++;
}
@@ -194,8 +194,7 @@
}
}
-template <size_t kAlignment>
-static void RunTestCount() {
+static void RunTestCount(size_t alignment) {
auto count_test_fn = [](ContinuousSpaceBitmap* space_bitmap,
uintptr_t range_begin,
uintptr_t range_end,
@@ -205,19 +204,18 @@
space_bitmap->VisitMarkedRange(range_begin, range_end, count_fn);
EXPECT_EQ(count, manual_count);
};
- RunTest<kAlignment>(count_test_fn);
+ RunTest(alignment, count_test_fn);
}
TEST_F(SpaceBitmapTest, VisitorObjectAlignment) {
- RunTestCount<kObjectAlignment>();
+ RunTestCount(kObjectAlignment);
}
TEST_F(SpaceBitmapTest, VisitorPageAlignment) {
- RunTestCount<kPageSize>();
+ RunTestCount(kPageSize);
}
-template <size_t kAlignment>
-void RunTestOrder() {
+void RunTestOrder(size_t alignment) {
auto order_test_fn = [](ContinuousSpaceBitmap* space_bitmap,
uintptr_t range_begin,
uintptr_t range_end,
@@ -242,15 +240,15 @@
EXPECT_NE(nullptr, last_ptr);
}
};
- RunTest<kAlignment>(order_test_fn);
+ RunTest(alignment, order_test_fn);
}
TEST_F(SpaceBitmapTest, OrderObjectAlignment) {
- RunTestOrder<kObjectAlignment>();
+ RunTestOrder(kObjectAlignment);
}
TEST_F(SpaceBitmapTest, OrderPageAlignment) {
- RunTestOrder<kPageSize>();
+ RunTestOrder(kPageSize);
}
} // namespace accounting