Lines Matching defs:block
1 //===-- Unittests for a block of memory -------------------------*- C++ -*-===//
13 #include "src/__support/block.h"
29 Block *block = *result;
31 EXPECT_EQ(reinterpret_cast<uintptr_t>(block) % alignof(Block), size_t{0});
32 EXPECT_TRUE(block->is_usable_space_aligned(alignof(max_align_t)));
34 Block *last = block->next();
39 EXPECT_EQ(last->prev_free(), block);
43 reinterpret_cast<uintptr_t>(last) - reinterpret_cast<uintptr_t>(block);
44 EXPECT_EQ(block->outer_size(), block_outer_size);
45 EXPECT_EQ(block->inner_size(),
47 EXPECT_EQ(block->prev_free(), static_cast<Block *>(nullptr));
48 EXPECT_FALSE(block->used());
61 Block *block = *result;
62 EXPECT_EQ(reinterpret_cast<uintptr_t>(block) % alignof(Block), size_t{0});
63 EXPECT_TRUE(block->is_usable_space_aligned(alignof(max_align_t)));
65 Block *last = block->next();
79 // Choose a split position such that the next block's usable space is 512
134 // split once, then split the original block again to ensure that the
172 Block *block = *result;
174 result = block->split(block->inner_size() + 1);
184 Block *block = *result;
186 result = block->split(block->inner_size() - sizeof(Block) + 1);
191 // Ensure that we can't ask for more space than the block actually has...
197 Block *block = *result;
199 result = block->split(block->inner_size() + 1);
204 // This block does support splitting with minimal payload size.
210 Block *block = *result;
212 result = block->split(0);
214 EXPECT_LE(block->outer_size(), sizeof(Block) + alignof(max_align_t));
218 // Likewise, the split block can be minimal-width.
240 Block *block = *result;
241 size_t orig_size = block->outer_size();
243 block->mark_used();
244 EXPECT_TRUE(block->used());
245 EXPECT_EQ(block->outer_size(), orig_size);
247 block->mark_free();
248 EXPECT_FALSE(block->used());
258 Block *block = *result;
260 block->mark_used();
261 result = block->split(kSplitN);
267 // merge block 3 and 2
317 Block *block = *result;
320 result = block->split(kSplitN);
323 block->mark_used();
324 EXPECT_FALSE(block->merge_next());
354 // Ensure we can allocate everything up to the block size within this block.
359 Block *block = *result;
361 if (i > block->inner_size())
364 auto info = Block::allocate(block, alignof(max_align_t), i);
365 EXPECT_NE(info.block, static_cast<Block *>(nullptr));
373 Block *block = *result;
376 if (Block::min_size_for_allocation(alignment, 1) > block->inner_size())
379 auto info = Block::allocate(block, alignment, 1);
380 EXPECT_NE(info.block, static_cast<Block *>(nullptr));
390 Block *block = *result;
391 uintptr_t orig_end = reinterpret_cast<uintptr_t>(block) + block->outer_size();
396 Block::allocate(block, alignof(max_align_t), SIZE);
398 // Since this is already aligned, there should be no previous block.
401 // Ensure we the block is aligned and large enough.
406 // Check the next block.
418 Block *block = *result;
420 uintptr_t orig_end = reinterpret_cast<uintptr_t>(block) + block->outer_size();
423 // it. We want to explicitly test that the block will split into one before
426 while (block->is_usable_space_aligned(alignment))
429 auto [aligned_block, prev, next] = Block::allocate(block, alignment, 10);
431 // Check the previous block was created appropriately. Since this block is the
432 // first block, a new one should be made before this.
439 // Ensure we the block is aligned and the size we expect.
443 // Check the next block.
455 Block *block = *result;
457 // Split the block roughly halfway and work on the second half.
458 auto result2 = block->split(kN / 2);
461 ASSERT_EQ(newblock->prev_free(), block);
462 size_t old_prev_size = block->outer_size();
465 // it. We want to explicitly test that the block will split into one before
471 // Ensure we can allocate in the new block.
474 // Now there should be no new previous block. Instead, the padding we did
475 // create should be merged into the original previous block.
477 EXPECT_EQ(aligned_block->prev_free(), block);
478 EXPECT_EQ(block->next(), aligned_block);
479 EXPECT_GT(block->outer_size(), old_prev_size);
484 // should be able to reconstruct the original block from the blocklets.
492 Block *block = *result;
494 Block *orig_block = block;
497 Block *last = block->next();
499 ASSERT_EQ(block->prev_free(), static_cast<Block *>(nullptr));
502 // it. We want to explicitly test that the block will split into one before
505 while (block->is_usable_space_aligned(alignment))
508 auto [aligned_block, prev, next] = Block::allocate(block, alignment, 1);