brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 19522e9 Raw
68 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/BuiltinUnifiedCASDatabases.h"10#include "CASTestConfig.h"11#include "llvm/CAS/ActionCache.h"12#include "llvm/CAS/ObjectStore.h"13#include "llvm/Testing/Support/Error.h"14#include "llvm/Testing/Support/SupportHelpers.h"15#include "gtest/gtest.h"16 17using namespace llvm;18using namespace llvm::cas;19 20TEST_F(OnDiskCASTest, UnifiedCASMaterializationCheckPreventsGarbageCollection) {21  unittest::TempDir Temp("on-disk-unified-cas", /*Unique=*/true);22 23  auto WithCAS = [&](llvm::function_ref<void(ObjectStore &)> Action) {24    std::pair<std::unique_ptr<ObjectStore>, std::unique_ptr<ActionCache>> DBs;25    ASSERT_THAT_ERROR(26        createOnDiskUnifiedCASDatabases(Temp.path()).moveInto(DBs),27        Succeeded());28    ObjectStore &CAS = *DBs.first;29    ASSERT_THAT_ERROR(CAS.setSizeLimit(1), Succeeded());30    Action(CAS);31  };32 33  std::optional<CASID> ID;34 35  // Create an object in the CAS.36  WithCAS([&ID](ObjectStore &CAS) {37    std::optional<ObjectRef> Ref;38    ASSERT_THAT_ERROR(CAS.store({}, "blah").moveInto(Ref), Succeeded());39    ASSERT_TRUE(Ref.has_value());40 41    ID = CAS.getID(*Ref);42  });43 44  // Check materialization and prune the storage.45  WithCAS([&ID](ObjectStore &CAS) {46    std::optional<ObjectRef> Ref = CAS.getReference(*ID);47    ASSERT_TRUE(Ref.has_value());48 49    std::optional<bool> IsMaterialized;50    ASSERT_THAT_ERROR(CAS.isMaterialized(*Ref).moveInto(IsMaterialized),51                      Succeeded());52    ASSERT_TRUE(IsMaterialized);53 54    ASSERT_THAT_ERROR(CAS.pruneStorageData(), Succeeded());55  });56 57  // Verify that the previous materialization check kept the object in the CAS.58  WithCAS([&ID](ObjectStore &CAS) {59    std::optional<ObjectRef> Ref = CAS.getReference(*ID);60    ASSERT_TRUE(Ref.has_value());61 62    std::optional<bool> IsMaterialized;63    ASSERT_THAT_ERROR(CAS.isMaterialized(*Ref).moveInto(IsMaterialized),64                      Succeeded());65    ASSERT_TRUE(IsMaterialized);66  });67}68