aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/CAS/ActionCacheTest.cpp
diff options
context:
space:
mode:
authorSteven Wu <stevenwu@apple.com>2024-10-29 10:37:37 -0700
committerSteven Wu <stevenwu@apple.com>2024-10-29 10:37:37 -0700
commit0acb07c50c259b2022ef4bf60d414e4616e171d5 (patch)
tree071f604b046c8e84b725c3125c1235c3ae373fb5 /llvm/unittests/CAS/ActionCacheTest.cpp
parentb510cdb895b9188e5819c4c85a6dab22a4d14385 (diff)
parentbe2c38e110a7e595bd27f0bf92ad5762108c96a8 (diff)
downloadllvm-users/cachemeifyoucan/spr/cas-add-ondiskcas.zip
llvm-users/cachemeifyoucan/spr/cas-add-ondiskcas.tar.gz
llvm-users/cachemeifyoucan/spr/cas-add-ondiskcas.tar.bz2
[𝘀𝗽𝗿] initial versionusers/cachemeifyoucan/spr/cas-add-ondiskcas
Created using spr 1.3.5
Diffstat (limited to 'llvm/unittests/CAS/ActionCacheTest.cpp')
-rw-r--r--llvm/unittests/CAS/ActionCacheTest.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/llvm/unittests/CAS/ActionCacheTest.cpp b/llvm/unittests/CAS/ActionCacheTest.cpp
new file mode 100644
index 0000000..a74a3e9
--- /dev/null
+++ b/llvm/unittests/CAS/ActionCacheTest.cpp
@@ -0,0 +1,73 @@
+//===- ActionCacheTest.cpp ------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CAS/ActionCache.h"
+#include "CASTestConfig.h"
+#include "llvm/CAS/ObjectStore.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::cas;
+
+TEST_P(CASTest, ActionCacheHit) {
+ std::shared_ptr<ObjectStore> CAS = createObjectStore();
+ std::unique_ptr<ActionCache> Cache = createActionCache();
+
+ std::optional<ObjectProxy> ID;
+ ASSERT_THAT_ERROR(CAS->createProxy(std::nullopt, "1").moveInto(ID),
+ Succeeded());
+ std::optional<CASID> ResultID;
+ ASSERT_THAT_ERROR(Cache->put(*ID, *ID), Succeeded());
+ ASSERT_THAT_ERROR(Cache->get(*ID).moveInto(ResultID), Succeeded());
+ ASSERT_TRUE(ResultID);
+ std::optional<ObjectRef> Result = CAS->getReference(*ResultID);
+ ASSERT_TRUE(Result);
+ ASSERT_EQ(*ID, *Result);
+}
+
+TEST_P(CASTest, ActionCacheMiss) {
+ std::shared_ptr<ObjectStore> CAS = createObjectStore();
+ std::unique_ptr<ActionCache> Cache = createActionCache();
+
+ std::optional<ObjectProxy> ID1, ID2;
+ ASSERT_THAT_ERROR(CAS->createProxy(std::nullopt, "1").moveInto(ID1),
+ Succeeded());
+ ASSERT_THAT_ERROR(CAS->createProxy(std::nullopt, "2").moveInto(ID2),
+ Succeeded());
+ ASSERT_THAT_ERROR(Cache->put(*ID1, *ID2), Succeeded());
+ // This is a cache miss for looking up a key doesn't exist.
+ std::optional<CASID> Result1;
+ ASSERT_THAT_ERROR(Cache->get(*ID2).moveInto(Result1), Succeeded());
+ ASSERT_FALSE(Result1);
+
+ ASSERT_THAT_ERROR(Cache->put(*ID2, *ID1), Succeeded());
+ // Cache hit after adding the value.
+ std::optional<CASID> Result2;
+ ASSERT_THAT_ERROR(Cache->get(*ID2).moveInto(Result2), Succeeded());
+ ASSERT_TRUE(Result2);
+ std::optional<ObjectRef> Ref = CAS->getReference(*Result2);
+ ASSERT_TRUE(Ref);
+ ASSERT_EQ(*ID1, *Ref);
+}
+
+TEST_P(CASTest, ActionCacheRewrite) {
+ std::shared_ptr<ObjectStore> CAS = createObjectStore();
+ std::unique_ptr<ActionCache> Cache = createActionCache();
+
+ std::optional<ObjectProxy> ID1, ID2;
+ ASSERT_THAT_ERROR(CAS->createProxy(std::nullopt, "1").moveInto(ID1),
+ Succeeded());
+ ASSERT_THAT_ERROR(CAS->createProxy(std::nullopt, "2").moveInto(ID2),
+ Succeeded());
+ ASSERT_THAT_ERROR(Cache->put(*ID1, *ID1), Succeeded());
+ // Writing to the same key with different value is error.
+ ASSERT_THAT_ERROR(Cache->put(*ID1, *ID2), Failed());
+ // Writing the same value multiple times to the same key is fine.
+ ASSERT_THAT_ERROR(Cache->put(*ID1, *ID1), Succeeded());
+}