brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · 692da23 Raw
74 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/// \file10/// This file implements the tests for ActionCaches.11///12//===----------------------------------------------------------------------===//13 14#include "llvm/CAS/ActionCache.h"15#include "CASTestConfig.h"16#include "llvm/CAS/ObjectStore.h"17#include "llvm/Testing/Support/Error.h"18#include "gtest/gtest.h"19 20using namespace llvm;21using namespace llvm::cas;22 23TEST_P(CASTest, ActionCacheHit) {24  std::unique_ptr<ObjectStore> CAS = createObjectStore();25  std::unique_ptr<ActionCache> Cache = createActionCache();26 27  std::optional<ObjectProxy> ID;28  ASSERT_THAT_ERROR(CAS->createProxy({}, "1").moveInto(ID), Succeeded());29  std::optional<CASID> ResultID;30  ASSERT_THAT_ERROR(Cache->put(*ID, *ID), Succeeded());31  ASSERT_THAT_ERROR(Cache->get(*ID).moveInto(ResultID), Succeeded());32  ASSERT_TRUE(ResultID);33  std::optional<ObjectRef> Result = CAS->getReference(*ResultID);34  ASSERT_TRUE(Result);35  ASSERT_EQ(*ID, *Result);36}37 38TEST_P(CASTest, ActionCacheMiss) {39  std::unique_ptr<ObjectStore> CAS = createObjectStore();40  std::unique_ptr<ActionCache> Cache = createActionCache();41 42  std::optional<ObjectProxy> ID1, ID2;43  ASSERT_THAT_ERROR(CAS->createProxy({}, "1").moveInto(ID1), Succeeded());44  ASSERT_THAT_ERROR(CAS->createProxy({}, "2").moveInto(ID2), Succeeded());45  ASSERT_THAT_ERROR(Cache->put(*ID1, *ID2), Succeeded());46  // This is a cache miss for looking up a key doesn't exist.47  std::optional<CASID> Result1;48  ASSERT_THAT_ERROR(Cache->get(*ID2).moveInto(Result1), Succeeded());49  ASSERT_FALSE(Result1);50 51  ASSERT_THAT_ERROR(Cache->put(*ID2, *ID1), Succeeded());52  // Cache hit after adding the value.53  std::optional<CASID> Result2;54  ASSERT_THAT_ERROR(Cache->get(*ID2).moveInto(Result2), Succeeded());55  ASSERT_TRUE(Result2);56  std::optional<ObjectRef> Ref = CAS->getReference(*Result2);57  ASSERT_TRUE(Ref);58  ASSERT_EQ(*ID1, *Ref);59}60 61TEST_P(CASTest, ActionCacheRewrite) {62  std::unique_ptr<ObjectStore> CAS = createObjectStore();63  std::unique_ptr<ActionCache> Cache = createActionCache();64 65  std::optional<ObjectProxy> ID1, ID2;66  ASSERT_THAT_ERROR(CAS->createProxy({}, "1").moveInto(ID1), Succeeded());67  ASSERT_THAT_ERROR(CAS->createProxy({}, "2").moveInto(ID2), Succeeded());68  ASSERT_THAT_ERROR(Cache->put(*ID1, *ID1), Succeeded());69  // Writing to the same key with different value is error.70  ASSERT_THAT_ERROR(Cache->put(*ID1, *ID2), Failed());71  // Writing the same value multiple times to the same key is fine.72  ASSERT_THAT_ERROR(Cache->put(*ID1, *ID1), Succeeded());73}74