summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2023-02-24 15:49:14 +0100
committerOliver Reiche <oliver.reiche@huawei.com>2023-03-13 17:28:59 +0100
commit42b452e72f536b63bac080880b8daa481099793c (patch)
tree0af1a60e5e0fefb5572df38e092def3d8ac74c05 /test
parent546bf5beebf2eb75e7b325f8f18969b4dd34a169 (diff)
downloadjustbuild-42b452e72f536b63bac080880b8daa481099793c.tar.gz
Storage: Reworked storage and garbage collection
The improved GC implementation uses refactored storage classes instead of directly accessing "unknown" file paths. The required storage class refactoring is quite substantial and outlined in the following paragraphs. The module `buildtool/file_system` was extended by: - `ObjectCAS`: a plain CAS implementation for reading/writing blobs and computing digests for a given `ObjectType`. Depending on that type, files written to the file system may have different properties (e.g., the x-bit set) or the digest may be computed differently (e.g., tree digests in non-compatible mode). A new module `buildtool/storage` was introduced containing: - `LocalCAS`: provides a common interface for the "logical CAS", which internally combines three `ObjectCAS`s, one for each `ObjectType` (file, executable, tree). - `LocalAC`: implements the action cache, which needs the `LocalCAS` for storing cache values. - `TargetCache`: implements the high-level target cache, which also needs the `LocalCAS` for storing cache values. - `LocalStorage`: combines the storage classes `LocalCAS`, `LocalAC`, and `TargetCache`. Those are initialized with settings from `StorageConfig`, such as the build root base path or number of generations for the garbage collector. `LocalStorage` is templated with a Boolean parameter `kDoGlobalUplink`, which indicates that, on every read/write access, the garbage collector should be used for uplinking across all generations (global). - `GarbageCollector`: responsible for garbage collection and the global uplinking across all generations. To do so, it employs instances of `LocalStorage` with `kDoGlobalUplink` set to false, in order to avoid endless recursion. The actual (local) uplinking within two single generations is performed by the corresponding storage class (e.g., `TargetCache` implements uplinking of target cache entries between two target cache generations etc.). Thereby, the actual knowledge how data should be uplinked is implemented by the instance that is responsible for creating the data in the first place.
Diffstat (limited to 'test')
-rw-r--r--test/buildtool/TARGETS1
-rw-r--r--test/buildtool/common/repository_config.test.cpp7
-rw-r--r--test/buildtool/execution_api/bazel/TARGETS2
-rw-r--r--test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp2
-rw-r--r--test/buildtool/execution_api/local/TARGETS45
-rw-r--r--test/buildtool/file_system/TARGETS14
-rw-r--r--test/buildtool/file_system/object_cas.test.cpp (renamed from test/buildtool/execution_api/local/local_cas.test.cpp)10
-rw-r--r--test/buildtool/storage/TARGETS37
-rwxr-xr-xtest/buildtool/storage/data/executable_file (renamed from test/buildtool/execution_api/data/executable_file)0
-rwxr-xr-xtest/buildtool/storage/data/non_executable_file (renamed from test/buildtool/execution_api/data/non_executable_file)0
-rw-r--r--test/buildtool/storage/data/subdir1/file1 (renamed from test/buildtool/execution_api/data/subdir1/file1)0
-rw-r--r--test/buildtool/storage/data/subdir1/subdir2/file2 (renamed from test/buildtool/execution_api/data/subdir1/subdir2/file2)0
-rw-r--r--test/buildtool/storage/local_ac.test.cpp (renamed from test/buildtool/execution_api/local/local_ac.test.cpp)38
-rw-r--r--test/buildtool/storage/local_cas.test.cpp (renamed from test/buildtool/execution_api/local/local_storage.test.cpp)114
-rw-r--r--test/utils/hermeticity/local.hpp12
15 files changed, 132 insertions, 150 deletions
diff --git a/test/buildtool/TARGETS b/test/buildtool/TARGETS
index f7fb17ce..89d4cf15 100644
--- a/test/buildtool/TARGETS
+++ b/test/buildtool/TARGETS
@@ -12,6 +12,7 @@
, [["./", "logging", "TESTS"], "logging"]
, [["./", "main", "TESTS"], "main"]
, [["./", "multithreading", "TESTS"], "multithreading"]
+ , [["./", "storage", "TESTS"], "storage"]
, [["./", "system", "TESTS"], "system"]
]
}
diff --git a/test/buildtool/common/repository_config.test.cpp b/test/buildtool/common/repository_config.test.cpp
index 13d0bab9..406ca2fe 100644
--- a/test/buildtool/common/repository_config.test.cpp
+++ b/test/buildtool/common/repository_config.test.cpp
@@ -14,7 +14,7 @@
#include "catch2/catch.hpp"
#include "src/buildtool/common/repository_config.hpp"
-#include "src/buildtool/execution_api/local/local_cas.hpp"
+#include "src/buildtool/storage/storage.hpp"
#include "test/utils/hermeticity/local.hpp"
namespace {
@@ -73,9 +73,10 @@ template <class T>
// Read graph from CAS
[[nodiscard]] auto ReadGraph(std::string const& hash) -> nlohmann::json {
- auto& cas = LocalCAS<ObjectType::File>::Instance();
+ auto const& cas = Storage::Instance().CAS();
auto blob = cas.BlobPath(
- ArtifactDigest{hash, /*does not matter*/ 0, /*is_tree=*/false});
+ ArtifactDigest{hash, /*does not matter*/ 0, /*is_tree=*/false},
+ /*is_executable=*/false);
REQUIRE(blob);
auto content = FileSystemManager::ReadFile(*blob);
REQUIRE(content);
diff --git a/test/buildtool/execution_api/bazel/TARGETS b/test/buildtool/execution_api/bazel/TARGETS
index 26026139..1b70c429 100644
--- a/test/buildtool/execution_api/bazel/TARGETS
+++ b/test/buildtool/execution_api/bazel/TARGETS
@@ -62,7 +62,7 @@
{ "type": ["@", "rules", "CC/test", "test"]
, "name": ["msg_factory"]
, "srcs": ["bazel_msg_factory.test.cpp"]
- , "data": [["test/buildtool/execution_api", "test_data"]]
+ , "data": [["test/buildtool/storage", "test_data"]]
, "private-deps":
[ ["@", "catch2", "", "catch2"]
, ["test", "catch-main"]
diff --git a/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp b/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp
index e91d6d9e..67deb467 100644
--- a/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp
+++ b/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp
@@ -22,7 +22,7 @@
#include "src/buildtool/file_system/object_type.hpp"
TEST_CASE("Bazel internals: MessageFactory", "[execution_api]") {
- std::filesystem::path workspace{"test/buildtool/execution_api/data"};
+ std::filesystem::path workspace{"test/buildtool/storage/data"};
std::filesystem::path subdir1 = workspace / "subdir1";
std::filesystem::path subdir2 = subdir1 / "subdir2";
diff --git a/test/buildtool/execution_api/local/TARGETS b/test/buildtool/execution_api/local/TARGETS
index 22c459ce..c0131568 100644
--- a/test/buildtool/execution_api/local/TARGETS
+++ b/test/buildtool/execution_api/local/TARGETS
@@ -1,31 +1,4 @@
-{ "local_cas":
- { "type": ["@", "rules", "CC/test", "test"]
- , "name": ["local_cas"]
- , "srcs": ["local_cas.test.cpp"]
- , "private-deps":
- [ ["@", "catch2", "", "catch2"]
- , ["test", "catch-main"]
- , ["src/buildtool/crypto", "hash_function"]
- , ["src/buildtool/execution_api/local", "local"]
- , ["src/buildtool/file_system", "file_system_manager"]
- , ["test/utils", "local_hermeticity"]
- ]
- , "stage": ["test", "buildtool", "execution_api", "local"]
- }
-, "local_ac":
- { "type": ["@", "rules", "CC/test", "test"]
- , "name": ["local_ac"]
- , "srcs": ["local_ac.test.cpp"]
- , "private-deps":
- [ ["@", "catch2", "", "catch2"]
- , ["test", "catch-main"]
- , ["src/buildtool/execution_api/local", "local"]
- , ["src/buildtool/file_system", "file_system_manager"]
- , ["test/utils", "local_hermeticity"]
- ]
- , "stage": ["test", "buildtool", "execution_api", "local"]
- }
-, "local_execution":
+{ "local_execution":
{ "type": ["@", "rules", "CC/test", "test"]
, "name": ["local_execution"]
, "srcs": ["local_execution.test.cpp"]
@@ -51,23 +24,9 @@
]
, "stage": ["test", "buildtool", "execution_api", "local"]
}
-, "local_storage":
- { "type": ["@", "rules", "CC/test", "test"]
- , "name": ["local_storage"]
- , "srcs": ["local_storage.test.cpp"]
- , "data": [["test/buildtool/execution_api", "test_data"]]
- , "private-deps":
- [ ["@", "catch2", "", "catch2"]
- , ["test", "catch-main"]
- , ["src/buildtool/execution_api/local", "local"]
- , ["test/utils", "local_hermeticity"]
- ]
- , "stage": ["test", "buildtool", "execution_api", "local"]
- }
, "TESTS":
{ "type": "install"
, "tainted": ["test"]
- , "deps":
- ["local_ac", "local_api", "local_cas", "local_execution", "local_storage"]
+ , "deps": ["local_api", "local_execution"]
}
}
diff --git a/test/buildtool/file_system/TARGETS b/test/buildtool/file_system/TARGETS
index 285cafac..93477387 100644
--- a/test/buildtool/file_system/TARGETS
+++ b/test/buildtool/file_system/TARGETS
@@ -10,6 +10,19 @@
]
, "stage": ["test", "buildtool", "file_system"]
}
+, "object_cas":
+ { "type": ["@", "rules", "CC/test", "test"]
+ , "name": ["object_cas"]
+ , "srcs": ["object_cas.test.cpp"]
+ , "private-deps":
+ [ ["@", "catch2", "", "catch2"]
+ , ["test", "catch-main"]
+ , ["src/buildtool/crypto", "hash_function"]
+ , ["src/buildtool/file_system", "file_system_manager"]
+ , ["test/utils", "local_hermeticity"]
+ ]
+ , "stage": ["test", "buildtool", "file_system"]
+ }
, "git_tree":
{ "type": ["@", "rules", "CC/test", "test"]
, "name": ["git_tree"]
@@ -93,6 +106,7 @@
, "deps":
[ "file_root"
, "file_system_manager"
+ , "object_cas"
, "git_tree"
, "directory_entries"
, "git_repo"
diff --git a/test/buildtool/execution_api/local/local_cas.test.cpp b/test/buildtool/file_system/object_cas.test.cpp
index 14a86628..bf20a287 100644
--- a/test/buildtool/execution_api/local/local_cas.test.cpp
+++ b/test/buildtool/file_system/object_cas.test.cpp
@@ -16,16 +16,17 @@
#include "catch2/catch.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
-#include "src/buildtool/execution_api/local/local_cas.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
+#include "src/buildtool/file_system/object_cas.hpp"
#include "test/utils/hermeticity/local.hpp"
-TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalCAS", "[execution_api]") {
+TEST_CASE_METHOD(HermeticLocalTestFixture, "ObjectCAS", "[file_system]") {
std::string test_content{"test"};
auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content);
SECTION("CAS for files") {
- LocalCAS<ObjectType::File> cas{};
+ ObjectCAS<ObjectType::File> cas{StorageConfig::GenerationCacheDir(0) /
+ "casf"};
CHECK(not cas.BlobPath(test_digest));
SECTION("Add blob from bytes and verify") {
@@ -63,7 +64,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalCAS", "[execution_api]") {
}
SECTION("CAS for executables") {
- LocalCAS<ObjectType::Executable> cas{};
+ ObjectCAS<ObjectType::Executable> cas{
+ StorageConfig::GenerationCacheDir(0) / "casx"};
CHECK(not cas.BlobPath(test_digest));
SECTION("Add blob from bytes and verify") {
diff --git a/test/buildtool/storage/TARGETS b/test/buildtool/storage/TARGETS
new file mode 100644
index 00000000..abfab7b7
--- /dev/null
+++ b/test/buildtool/storage/TARGETS
@@ -0,0 +1,37 @@
+{ "test_data":
+ { "type": ["@", "rules", "data", "staged"]
+ , "srcs":
+ [ "data/executable_file"
+ , "data/non_executable_file"
+ , "data/subdir1/file1"
+ , "data/subdir1/subdir2/file2"
+ ]
+ , "stage": ["test", "buildtool", "storage"]
+ }
+, "local_cas":
+ { "type": ["@", "rules", "CC/test", "test"]
+ , "name": ["local_cas"]
+ , "srcs": ["local_cas.test.cpp"]
+ , "data": [["test/buildtool/storage", "test_data"]]
+ , "private-deps":
+ [ ["@", "catch2", "", "catch2"]
+ , ["test", "catch-main"]
+ , ["test/utils", "local_hermeticity"]
+ ]
+ , "stage": ["test", "buildtool", "storage"]
+ }
+, "local_ac":
+ { "type": ["@", "rules", "CC/test", "test"]
+ , "name": ["local_ac"]
+ , "srcs": ["local_ac.test.cpp"]
+ , "private-deps":
+ [ ["@", "catch2", "", "catch2"]
+ , ["test", "catch-main"]
+ , ["src/buildtool/file_system", "file_system_manager"]
+ , ["test/utils", "local_hermeticity"]
+ ]
+ , "stage": ["test", "buildtool", "storage"]
+ }
+, "TESTS":
+ {"type": "install", "tainted": ["test"], "deps": ["local_cas", "local_ac"]}
+}
diff --git a/test/buildtool/execution_api/data/executable_file b/test/buildtool/storage/data/executable_file
index 30d74d25..30d74d25 100755
--- a/test/buildtool/execution_api/data/executable_file
+++ b/test/buildtool/storage/data/executable_file
diff --git a/test/buildtool/execution_api/data/non_executable_file b/test/buildtool/storage/data/non_executable_file
index 30d74d25..30d74d25 100755
--- a/test/buildtool/execution_api/data/non_executable_file
+++ b/test/buildtool/storage/data/non_executable_file
diff --git a/test/buildtool/execution_api/data/subdir1/file1 b/test/buildtool/storage/data/subdir1/file1
index 30d74d25..30d74d25 100644
--- a/test/buildtool/execution_api/data/subdir1/file1
+++ b/test/buildtool/storage/data/subdir1/file1
diff --git a/test/buildtool/execution_api/data/subdir1/subdir2/file2 b/test/buildtool/storage/data/subdir1/subdir2/file2
index 30d74d25..30d74d25 100644
--- a/test/buildtool/execution_api/data/subdir1/subdir2/file2
+++ b/test/buildtool/storage/data/subdir1/subdir2/file2
diff --git a/test/buildtool/execution_api/local/local_ac.test.cpp b/test/buildtool/storage/local_ac.test.cpp
index b37bced9..19da0e59 100644
--- a/test/buildtool/execution_api/local/local_ac.test.cpp
+++ b/test/buildtool/storage/local_ac.test.cpp
@@ -16,21 +16,21 @@
#include "catch2/catch.hpp"
#include "gsl-lite/gsl-lite.hpp"
-#include "src/buildtool/execution_api/local/local_ac.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
+#include "src/buildtool/storage/storage.hpp"
#include "test/utils/hermeticity/local.hpp"
[[nodiscard]] static auto RunDummyExecution(
- gsl::not_null<LocalAC*> const& ac,
- gsl::not_null<LocalCAS<ObjectType::File>*> cas_,
+ gsl::not_null<LocalAC<true> const*> const& ac,
+ gsl::not_null<LocalCAS<true> const*> const& cas_,
bazel_re::Digest const& action_id,
std::string const& seed) -> bool;
TEST_CASE_METHOD(HermeticLocalTestFixture,
"LocalAC: Single action, single result",
- "[execution_api]") {
- LocalCAS cas{};
- LocalAC ac{&cas};
+ "[storage]") {
+ auto const& ac = Storage::Instance().ActionCache();
+ auto const& cas = Storage::Instance().CAS();
auto action_id = ArtifactDigest::Create<ObjectType::File>("action");
CHECK(not ac.CachedResult(action_id));
@@ -41,9 +41,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
TEST_CASE_METHOD(HermeticLocalTestFixture,
"LocalAC: Two different actions, two different results",
- "[execution_api]") {
- LocalCAS cas{};
- LocalAC ac{&cas};
+ "[storage]") {
+ auto const& ac = Storage::Instance().ActionCache();
+ auto const& cas = Storage::Instance().CAS();
auto action_id1 = ArtifactDigest::Create<ObjectType::File>("action1");
auto action_id2 = ArtifactDigest::Create<ObjectType::File>("action2");
@@ -70,9 +70,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
TEST_CASE_METHOD(HermeticLocalTestFixture,
"LocalAC: Two different actions, same two results",
- "[execution_api]") {
- LocalCAS cas{};
- LocalAC ac{&cas};
+ "[storage]") {
+ auto const& ac = Storage::Instance().ActionCache();
+ auto const& cas = Storage::Instance().CAS();
auto action_id1 = ArtifactDigest::Create<ObjectType::File>("action1");
auto action_id2 = ArtifactDigest::Create<ObjectType::File>("action2");
@@ -98,10 +98,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalAC: Same two actions, two differnet results",
- "[execution_api]") {
- LocalCAS cas{};
- LocalAC ac{&cas};
+ "LocalAC: Same two actions, two different results",
+ "[storage]") {
+ auto const& ac = Storage::Instance().ActionCache();
+ auto const& cas = Storage::Instance().CAS();
auto action_id = ArtifactDigest::Create<ObjectType::File>("same action");
CHECK(not ac.CachedResult(action_id));
@@ -123,15 +123,15 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
CHECK(result_content1 != result_content2);
}
-auto RunDummyExecution(gsl::not_null<LocalAC*> const& ac,
- gsl::not_null<LocalCAS<ObjectType::File>*> cas_,
+auto RunDummyExecution(gsl::not_null<LocalAC<true> const*> const& ac,
+ gsl::not_null<LocalCAS<true> const*> const& cas_,
bazel_re::Digest const& action_id,
std::string const& seed) -> bool {
bazel_re::ActionResult result{};
*result.add_output_files() = [&]() {
bazel_re::OutputFile out{};
out.set_path(seed);
- auto digest = cas_->StoreBlobFromBytes("");
+ auto digest = cas_->StoreBlob("");
out.set_allocated_digest(
gsl::owner<bazel_re::Digest*>{new bazel_re::Digest{*digest}});
out.set_is_executable(false);
diff --git a/test/buildtool/execution_api/local/local_storage.test.cpp b/test/buildtool/storage/local_cas.test.cpp
index ff2493ae..95d119bf 100644
--- a/test/buildtool/execution_api/local/local_storage.test.cpp
+++ b/test/buildtool/storage/local_cas.test.cpp
@@ -15,34 +15,34 @@
#include <string>
#include "catch2/catch.hpp"
-#include "src/buildtool/execution_api/local/local_storage.hpp"
+#include "src/buildtool/storage/storage.hpp"
#include "test/utils/hermeticity/local.hpp"
TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalStorage: Add blob to storage from bytes",
- "[execution_api]") {
+ "LocalCAS: Add blob to storage from bytes",
+ "[storage]") {
std::string test_bytes("test");
- LocalStorage storage{};
+ auto const& cas = Storage::Instance().CAS();
auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_bytes);
// check blob not in storage
- CHECK(not storage.BlobPath(test_digest, true));
- CHECK(not storage.BlobPath(test_digest, false));
+ CHECK(not cas.BlobPath(test_digest, true));
+ CHECK(not cas.BlobPath(test_digest, false));
// ensure previous calls did not accidentially create the blob
- CHECK(not storage.BlobPath(test_digest, true));
- CHECK(not storage.BlobPath(test_digest, false));
+ CHECK(not cas.BlobPath(test_digest, true));
+ CHECK(not cas.BlobPath(test_digest, false));
SECTION("Add non-executable blob to storage") {
- CHECK(storage.StoreBlob(test_bytes, false));
+ CHECK(cas.StoreBlob(test_bytes, false));
- auto file_path = storage.BlobPath(test_digest, false);
+ auto file_path = cas.BlobPath(test_digest, false);
REQUIRE(file_path);
CHECK(FileSystemManager::IsFile(*file_path));
CHECK(not FileSystemManager::IsExecutable(*file_path));
- auto exe_path = storage.BlobPath(test_digest, true);
+ auto exe_path = cas.BlobPath(test_digest, true);
REQUIRE(exe_path);
CHECK(FileSystemManager::IsFile(*exe_path));
CHECK(FileSystemManager::IsExecutable(*exe_path));
@@ -50,14 +50,14 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
SECTION("Add executable blob to storage") {
- CHECK(storage.StoreBlob(test_bytes, true));
+ CHECK(cas.StoreBlob(test_bytes, true));
- auto file_path = storage.BlobPath(test_digest, false);
+ auto file_path = cas.BlobPath(test_digest, false);
REQUIRE(file_path);
CHECK(FileSystemManager::IsFile(*file_path));
CHECK(not FileSystemManager::IsExecutable(*file_path));
- auto exe_path = storage.BlobPath(test_digest, true);
+ auto exe_path = cas.BlobPath(test_digest, true);
REQUIRE(exe_path);
CHECK(FileSystemManager::IsFile(*exe_path));
CHECK(FileSystemManager::IsExecutable(*exe_path));
@@ -66,47 +66,32 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalStorage: Add blob to storage from non-executable file",
- "[execution_api]") {
+ "LocalCAS: Add blob to storage from non-executable file",
+ "[storage]") {
std::filesystem::path non_exec_file{
- "test/buildtool/execution_api/data/non_executable_file"};
+ "test/buildtool/storage/data/non_executable_file"};
- LocalStorage storage{};
+ auto const& cas = Storage::Instance().CAS();
auto test_blob = CreateBlobFromFile(non_exec_file);
REQUIRE(test_blob);
// check blob not in storage
- CHECK(not storage.BlobPath(test_blob->digest, true));
- CHECK(not storage.BlobPath(test_blob->digest, false));
+ CHECK(not cas.BlobPath(test_blob->digest, true));
+ CHECK(not cas.BlobPath(test_blob->digest, false));
// ensure previous calls did not accidentially create the blob
- CHECK(not storage.BlobPath(test_blob->digest, true));
- CHECK(not storage.BlobPath(test_blob->digest, false));
-
- SECTION("Add blob to storage without specifying x-bit") {
- CHECK(storage.StoreBlob(non_exec_file));
-
- auto file_path = storage.BlobPath(test_blob->digest, false);
- REQUIRE(file_path);
- CHECK(FileSystemManager::IsFile(*file_path));
- CHECK(not FileSystemManager::IsExecutable(*file_path));
-
- auto exe_path = storage.BlobPath(test_blob->digest, true);
- REQUIRE(exe_path);
- CHECK(FileSystemManager::IsFile(*exe_path));
- CHECK(FileSystemManager::IsExecutable(*exe_path));
- CHECK(not FileSystemManager::IsExecutable(*file_path));
- }
+ CHECK(not cas.BlobPath(test_blob->digest, true));
+ CHECK(not cas.BlobPath(test_blob->digest, false));
SECTION("Add non-executable blob to storage") {
- CHECK(storage.StoreBlob(non_exec_file, false));
+ CHECK(cas.StoreBlob(non_exec_file, false));
- auto file_path = storage.BlobPath(test_blob->digest, false);
+ auto file_path = cas.BlobPath(test_blob->digest, false);
REQUIRE(file_path);
CHECK(FileSystemManager::IsFile(*file_path));
CHECK(not FileSystemManager::IsExecutable(*file_path));
- auto exe_path = storage.BlobPath(test_blob->digest, true);
+ auto exe_path = cas.BlobPath(test_blob->digest, true);
REQUIRE(exe_path);
CHECK(FileSystemManager::IsFile(*exe_path));
CHECK(FileSystemManager::IsExecutable(*exe_path));
@@ -114,14 +99,14 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
SECTION("Add executable blob to storage") {
- CHECK(storage.StoreBlob(non_exec_file, true));
+ CHECK(cas.StoreBlob(non_exec_file, true));
- auto file_path = storage.BlobPath(test_blob->digest, false);
+ auto file_path = cas.BlobPath(test_blob->digest, false);
REQUIRE(file_path);
CHECK(FileSystemManager::IsFile(*file_path));
CHECK(not FileSystemManager::IsExecutable(*file_path));
- auto exe_path = storage.BlobPath(test_blob->digest, true);
+ auto exe_path = cas.BlobPath(test_blob->digest, true);
REQUIRE(exe_path);
CHECK(FileSystemManager::IsFile(*exe_path));
CHECK(FileSystemManager::IsExecutable(*exe_path));
@@ -130,47 +115,32 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalStorage: Add blob to storage from executable file",
- "[execution_api]") {
+ "LocalCAS: Add blob to storage from executable file",
+ "[storage]") {
std::filesystem::path exec_file{
- "test/buildtool/execution_api/data/executable_file"};
+ "test/buildtool/storage/data/executable_file"};
- LocalStorage storage{};
+ auto const& cas = Storage::Instance().CAS();
auto test_blob = CreateBlobFromFile(exec_file);
REQUIRE(test_blob);
// check blob not in storage
- CHECK(not storage.BlobPath(test_blob->digest, true));
- CHECK(not storage.BlobPath(test_blob->digest, false));
+ CHECK(not cas.BlobPath(test_blob->digest, true));
+ CHECK(not cas.BlobPath(test_blob->digest, false));
// ensure previous calls did not accidentially create the blob
- CHECK(not storage.BlobPath(test_blob->digest, true));
- CHECK(not storage.BlobPath(test_blob->digest, false));
-
- SECTION("Add blob to storage without specifying x-bit") {
- CHECK(storage.StoreBlob(exec_file));
-
- auto file_path = storage.BlobPath(test_blob->digest, false);
- REQUIRE(file_path);
- CHECK(FileSystemManager::IsFile(*file_path));
- CHECK(not FileSystemManager::IsExecutable(*file_path));
-
- auto exe_path = storage.BlobPath(test_blob->digest, true);
- REQUIRE(exe_path);
- CHECK(FileSystemManager::IsFile(*exe_path));
- CHECK(FileSystemManager::IsExecutable(*exe_path));
- CHECK(not FileSystemManager::IsExecutable(*file_path));
- }
+ CHECK(not cas.BlobPath(test_blob->digest, true));
+ CHECK(not cas.BlobPath(test_blob->digest, false));
SECTION("Add non-executable blob to storage") {
- CHECK(storage.StoreBlob(exec_file, false));
+ CHECK(cas.StoreBlob(exec_file, false));
- auto file_path = storage.BlobPath(test_blob->digest, false);
+ auto file_path = cas.BlobPath(test_blob->digest, false);
REQUIRE(file_path);
CHECK(FileSystemManager::IsFile(*file_path));
CHECK(not FileSystemManager::IsExecutable(*file_path));
- auto exe_path = storage.BlobPath(test_blob->digest, true);
+ auto exe_path = cas.BlobPath(test_blob->digest, true);
REQUIRE(exe_path);
CHECK(FileSystemManager::IsFile(*exe_path));
CHECK(FileSystemManager::IsExecutable(*exe_path));
@@ -178,14 +148,14 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
SECTION("Add executable blob to storage") {
- CHECK(storage.StoreBlob(exec_file, true));
+ CHECK(cas.StoreBlob(exec_file, true));
- auto file_path = storage.BlobPath(test_blob->digest, false);
+ auto file_path = cas.BlobPath(test_blob->digest, false);
REQUIRE(file_path);
CHECK(FileSystemManager::IsFile(*file_path));
CHECK(not FileSystemManager::IsExecutable(*file_path));
- auto exe_path = storage.BlobPath(test_blob->digest, true);
+ auto exe_path = cas.BlobPath(test_blob->digest, true);
REQUIRE(exe_path);
CHECK(FileSystemManager::IsFile(*exe_path));
CHECK(FileSystemManager::IsExecutable(*exe_path));
diff --git a/test/utils/hermeticity/local.hpp b/test/utils/hermeticity/local.hpp
index 0b55723a..2b67cf10 100644
--- a/test/utils/hermeticity/local.hpp
+++ b/test/utils/hermeticity/local.hpp
@@ -16,10 +16,10 @@
#define INCLUDED_SRC_TEST_UTILS_HERMETICITY_LOCAL_HPP
#include "src/buildtool/common/statistics.hpp"
-#include "src/buildtool/execution_api/local/config.hpp"
-#include "src/buildtool/execution_api/local/local_cas.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/logging/logger.hpp"
+#include "src/buildtool/storage/config.hpp"
+#include "src/buildtool/storage/storage.hpp"
class HermeticLocalTestFixture {
public:
@@ -36,12 +36,10 @@ class HermeticLocalTestFixture {
if (FileSystemManager::RemoveDirectory(case_dir, true) and
FileSystemManager::CreateDirectoryExclusive(case_dir) and
- LocalExecutionConfig::SetBuildRoot(case_dir)) {
+ StorageConfig::SetBuildRoot(case_dir)) {
// After the build root has been changed, the file roots of the
- // static CAS instances needs to be updated.
- LocalCAS<ObjectType::File>::Instance().Reset();
- LocalCAS<ObjectType::Executable>::Instance().Reset();
- LocalCAS<ObjectType::Tree>::Instance().Reset();
+ // static storage instances need to be updated.
+ Storage::Reinitialize();
Logger::Log(LogLevel::Debug,
"created test-local cache dir {}",
case_dir.string());