src/storage/blobfs/test/unit/allocator-test.cc
// Tests a case where navigation between multiple reserved and committed blocks
// requires non-trivial logic.
//
// This acts as a regression test against a bug encountered during prototyping,
// where navigating reserved blocks could unintentionally ignore collisions with
// the committed blocks.
Tests a case where navigation between multiple reserved and committed blocks
requires non-trivial logic.

This acts as a regression test against a bug encountered during prototyping,
where navigating reserved blocks could unintentionally ignore collisions with
the committed blocks.
Tests a case where navigation between multiple reserved and committed blocks requires non - trivial logic . This acts as a regression test against a bug encountered during prototyping where navigating reserved blocks could unintentionally ignore collisions with the committed blocks .
TEST(AllocatorTest, InterleavedReservation) {
  MockSpaceManager space_manager;
  std::unique_ptr<Allocator> allocator;
  InitializeAllocator(10, 5, &space_manager, &allocator);
   [R F F F F F F F F F]
   Reserve an extent of one block.
  fbl::Vector<ReservedExtent> reservation_group_a;
  ASSERT_EQ(allocator->ReserveBlocks(1, &reservation_group_a), ZX_OK);
  ASSERT_EQ(1ul, reservation_group_a.size());
   [R R F F F F F F F F]
   Reserve an extent of one block.
  fbl::Vector<ReservedExtent> reservation_group_b;
  ASSERT_EQ(allocator->ReserveBlocks(1, &reservation_group_b), ZX_OK);
  ASSERT_EQ(1ul, reservation_group_b.size());
   [R R C F F F F F F F]
   Allocate a single extent of one block, immediately following the prior
   reservations.
  {
    fbl::Vector<ReservedExtent> committed_extents;
    ASSERT_EQ(allocator->ReserveBlocks(1, &committed_extents), ZX_OK);
    ASSERT_EQ(1ul, committed_extents.size());
    allocator->MarkBlocksAllocated(committed_extents[0]);
  }
   [R R C R F F F F F F]
   Reserve an extent of one block.
  fbl::Vector<ReservedExtent> reservation_group_c;
  ASSERT_EQ(allocator->ReserveBlocks(1, &reservation_group_c), ZX_OK);
  ASSERT_EQ(1ul, reservation_group_c.size());
   [F R C R F F F F F F]
   Free the first extent.
  reservation_group_a.reset();
   We should still be able to reserve the remaining two extents, split
   across the reservations and the committed block.
  fbl::Vector<ReservedExtent> extents;
  ASSERT_EQ(allocator->ReserveBlocks(4, &extents), ZX_OK);
  ASSERT_EQ(2ul, extents.size());
}
TEST ( AllocatorTest , InterleavedReservation ) { MockSpaceManager space_manager ; std :: unique_ptr < Allocator > allocator ; InitializeAllocator ( 10 , 5 , & space_manager , & allocator ) ; fbl :: Vector < ReservedExtent > reservation_group_a ; ASSERT_EQ ( allocator -> ReserveBlocks ( 1 , & reservation_group_a ) , ZX_OK ) ; ASSERT_EQ ( 1ul , reservation_group_a . size ( ) ) ; fbl :: Vector < ReservedExtent > reservation_group_b ; ASSERT_EQ ( allocator -> ReserveBlocks ( 1 , & reservation_group_b ) , ZX_OK ) ; ASSERT_EQ ( 1ul , reservation_group_b . size ( ) ) ; { fbl :: Vector < ReservedExtent > committed_extents ; ASSERT_EQ ( allocator -> ReserveBlocks ( 1 , & committed_extents ) , ZX_OK ) ; ASSERT_EQ ( 1ul , committed_extents . size ( ) ) ; allocator -> MarkBlocksAllocated ( committed_extents [ 0 ] ) ; } fbl :: Vector < ReservedExtent > reservation_group_c ; ASSERT_EQ ( allocator -> ReserveBlocks ( 1 , & reservation_group_c ) , ZX_OK ) ; ASSERT_EQ ( 1ul , reservation_group_c . size ( ) ) ; reservation_group_a . reset ( ) ; fbl :: Vector < ReservedExtent > extents ; ASSERT_EQ ( allocator -> ReserveBlocks ( 4 , & extents ) , ZX_OK ) ; ASSERT_EQ ( 2ul , extents . size ( ) ) ; }
Tests a case where navigation between multiple reserved and committed blocks
requires non-trivial logic.
Tests a case where navigation between multiple reserved and committed blocks requires non - trivial logic .
// R: Reserved // C: Committed // F: Free // // [R F F F F F F F F F] // Reserve an extent of one block. // [R R F F F F F F F F] // Reserve an extent of one block. // [R R C F F F F F F F] // Allocate a single extent of one block, immediately following the prior // reservations. // [R R C R F F F F F F] // Reserve an extent of one block. // [F R C R F F F F F F] // Free the first extent. // We should still be able to reserve the remaining two extents, split // across the reservations and the committed block.