brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 966fa03 Raw
67 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/CAS/OnDiskDataAllocator.h"10#include "llvm/CAS/MappedFileRegionArena.h"11#include "llvm/Config/llvm-config.h"12#include "llvm/Support/Alignment.h"13#include "llvm/Testing/Support/Error.h"14#include "llvm/Testing/Support/SupportHelpers.h"15 16#if LLVM_ENABLE_ONDISK_CAS17 18using namespace llvm;19using namespace llvm::cas;20 21TEST(OnDiskDataAllocatorTest, Allocate) {22  unittest::TempDir Temp("data-allocator", /*Unique=*/true);23  constexpr size_t MB = 1024u * 1024u;24 25  std::optional<OnDiskDataAllocator> Allocator;26  ASSERT_THAT_ERROR(OnDiskDataAllocator::create(27                        Temp.path("allocator"), "data", /*MaxFileSize=*/MB,28                        /*NewFileInitialSize=*/std::nullopt)29                        .moveInto(Allocator),30                    Succeeded());31 32  // Allocate.33  {34    for (size_t Size = 1; Size < 16; ++Size) {35      OnDiskDataAllocator::OnDiskPtr P;36      ASSERT_THAT_ERROR(Allocator->allocate(Size).moveInto(P), Succeeded());37      EXPECT_TRUE(38          isAligned(MappedFileRegionArena::getAlign(), P.getOffset().get()));39    }40  }41 42  // Out of space.43  {44    OnDiskDataAllocator::OnDiskPtr P;45    ASSERT_THAT_ERROR(Allocator->allocate(MB).moveInto(P), Failed());46  }47 48  // Check size and capacity.49  {50    ASSERT_EQ(Allocator->capacity(), MB);51    ASSERT_LE(Allocator->size(), MB);52  }53 54  // Get.55  {56    OnDiskDataAllocator::OnDiskPtr P;57    ASSERT_THAT_ERROR(Allocator->allocate(32).moveInto(P), Succeeded());58    ArrayRef<char> Data;59    ASSERT_THAT_ERROR(Allocator->get(P.getOffset(), 16).moveInto(Data),60                      Succeeded());61    ASSERT_THAT_ERROR(Allocator->get(P.getOffset(), 1025).moveInto(Data),62                      Failed());63  }64}65 66#endif // LLVM_ENABLE_ONDISK_CAS67