summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/buildtool/build_engine/target_map/TARGETS2
-rw-r--r--test/buildtool/build_engine/target_map/target_map.test.cpp73
-rw-r--r--test/buildtool/common/TARGETS4
-rw-r--r--test/buildtool/common/repository_config.test.cpp35
-rw-r--r--test/buildtool/execution_api/execution_service/TARGETS2
-rw-r--r--test/buildtool/execution_api/execution_service/cas_server.test.cpp11
-rw-r--r--test/buildtool/execution_api/local/TARGETS4
-rw-r--r--test/buildtool/execution_api/local/local_api.test.cpp95
-rw-r--r--test/buildtool/execution_api/local/local_execution.test.cpp52
-rw-r--r--test/buildtool/execution_engine/executor/TARGETS2
-rw-r--r--test/buildtool/execution_engine/executor/executor_api_local.test.cpp52
-rw-r--r--test/buildtool/file_system/TARGETS3
-rw-r--r--test/buildtool/file_system/git_repo.test.cpp18
-rw-r--r--test/buildtool/file_system/object_cas.test.cpp9
-rw-r--r--test/buildtool/graph_traverser/TARGETS6
-rw-r--r--test/buildtool/graph_traverser/graph_traverser.test.hpp64
-rw-r--r--test/buildtool/graph_traverser/graph_traverser_local.test.cpp88
-rw-r--r--test/buildtool/graph_traverser/graph_traverser_remote.test.cpp59
-rw-r--r--test/buildtool/storage/TARGETS10
-rw-r--r--test/buildtool/storage/large_object_cas.test.cpp111
-rw-r--r--test/buildtool/storage/local_ac.test.cpp35
-rw-r--r--test/buildtool/storage/local_cas.test.cpp30
-rw-r--r--test/main.cpp13
-rw-r--r--test/other_tools/git_operations/TARGETS1
-rw-r--r--test/other_tools/git_operations/git_repo_remote.test.cpp45
-rw-r--r--test/utils/TARGETS14
-rw-r--r--test/utils/hermeticity/local.hpp57
-rw-r--r--test/utils/hermeticity/test_storage_config.hpp71
-rw-r--r--test/utils/remote_execution/main-remote-execution.cpp14
29 files changed, 511 insertions, 469 deletions
diff --git a/test/buildtool/build_engine/target_map/TARGETS b/test/buildtool/build_engine/target_map/TARGETS
index 9111efc7..ada1ce25 100644
--- a/test/buildtool/build_engine/target_map/TARGETS
+++ b/test/buildtool/build_engine/target_map/TARGETS
@@ -39,7 +39,7 @@
, ["@", "src", "src/buildtool/common", "config"]
, ["@", "src", "src/buildtool/serve_api/remote", "config"]
, ["@", "src", "src/buildtool/serve_api/remote", "serve_api"]
- , ["utils", "local_hermeticity"]
+ , ["utils", "test_storage_config"]
, ["utils", "test_serve_config"]
]
, "stage": ["test", "buildtool", "build_engine", "target_map"]
diff --git a/test/buildtool/build_engine/target_map/target_map.test.cpp b/test/buildtool/build_engine/target_map/target_map.test.cpp
index 76447242..1c688b1e 100644
--- a/test/buildtool/build_engine/target_map/target_map.test.cpp
+++ b/test/buildtool/build_engine/target_map/target_map.test.cpp
@@ -38,7 +38,7 @@
#include "src/buildtool/serve_api/remote/serve_api.hpp"
#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/storage.hpp"
-#include "test/utils/hermeticity/local.hpp"
+#include "test/utils/hermeticity/test_storage_config.hpp"
#include "test/utils/serve_service/test_serve_config.hpp"
namespace {
@@ -79,7 +79,10 @@ auto SetupConfig() -> RepositoryConfig {
} // namespace
-TEST_CASE_METHOD(HermeticLocalTestFixture, "simple targets", "[target_map]") {
+TEST_CASE("simple targets", "[target_map]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
auto repo_config = SetupConfig();
auto directory_entries =
BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config);
@@ -101,9 +104,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "simple targets", "[target_map]") {
auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment();
REQUIRE(serve_config);
- auto const storage = Storage::Create(&StorageConfig::Instance());
Auth auth{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config.Get(),
&storage,
/*repo_config=*/nullptr,
&auth,
@@ -526,9 +528,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "simple targets", "[target_map]") {
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "configuration deduplication",
- "[target_map]") {
+TEST_CASE("configuration deduplication", "[target_map]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
auto repo_config = SetupConfig();
auto directory_entries =
BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config);
@@ -550,10 +553,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment();
REQUIRE(serve_config);
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
Auth auth{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config.Get(),
&storage,
/*repo_config=*/nullptr,
&auth,
@@ -621,9 +622,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
CHECK(analysis_result.actions.size() == 2);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "generator functions in string arguments",
- "[target_map]") {
+TEST_CASE("generator functions in string arguments", "[target_map]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
auto repo_config = SetupConfig();
auto directory_entries =
BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config);
@@ -645,9 +647,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment();
REQUIRE(serve_config);
- auto const storage = Storage::Create(&StorageConfig::Instance());
Auth auth{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config.Get(),
&storage,
/*repo_config=*/nullptr,
&auth,
@@ -727,7 +728,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture, "built-in rules", "[target_map]") {
+TEST_CASE("built-in rules", "[target_map]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
auto repo_config = SetupConfig();
auto directory_entries =
BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config);
@@ -749,9 +753,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "built-in rules", "[target_map]") {
auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment();
REQUIRE(serve_config);
- auto const storage = Storage::Create(&StorageConfig::Instance());
Auth auth{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config.Get(),
&storage,
/*repo_config=*/nullptr,
&auth,
@@ -941,7 +944,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "built-in rules", "[target_map]") {
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture, "target reference", "[target_map]") {
+TEST_CASE("target reference", "[target_map]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
auto repo_config = SetupConfig();
auto directory_entries =
BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config);
@@ -963,9 +969,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "target reference", "[target_map]") {
auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment();
REQUIRE(serve_config);
- auto const storage = Storage::Create(&StorageConfig::Instance());
Auth auth{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config.Get(),
&storage,
/*repo_config=*/nullptr,
&auth,
@@ -1088,7 +1093,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "target reference", "[target_map]") {
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture, "trees", "[target_map]") {
+TEST_CASE("trees", "[target_map]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
auto repo_config = SetupConfig();
auto directory_entries =
BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config);
@@ -1110,9 +1118,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "trees", "[target_map]") {
auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment();
REQUIRE(serve_config);
- auto const storage = Storage::Create(&StorageConfig::Instance());
Auth auth{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config.Get(),
&storage,
/*repo_config=*/nullptr,
&auth,
@@ -1199,9 +1206,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "trees", "[target_map]") {
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "RESULT error reporting",
- "[target_map]") {
+TEST_CASE("RESULT error reporting", "[target_map]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
auto repo_config = SetupConfig();
auto directory_entries =
BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config);
@@ -1223,9 +1231,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment();
REQUIRE(serve_config);
- auto const storage = Storage::Create(&StorageConfig::Instance());
Auth auth{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config.Get(),
&storage,
/*repo_config=*/nullptr,
&auth,
@@ -1371,7 +1378,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture, "wrong arguments", "[target_map]") {
+TEST_CASE("wrong arguments", "[target_map]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
auto repo_config = SetupConfig();
auto directory_entries =
BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config);
@@ -1393,9 +1403,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "wrong arguments", "[target_map]") {
auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment();
REQUIRE(serve_config);
- auto const storage = Storage::Create(&StorageConfig::Instance());
Auth auth{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config.Get(),
&storage,
/*repo_config=*/nullptr,
&auth,
diff --git a/test/buildtool/common/TARGETS b/test/buildtool/common/TARGETS
index 75209401..d174de5b 100644
--- a/test/buildtool/common/TARGETS
+++ b/test/buildtool/common/TARGETS
@@ -51,8 +51,10 @@
, ["@", "src", "src/buildtool/common", "common"]
, ["@", "src", "src/buildtool/file_system", "file_root"]
, ["@", "src", "src/buildtool/file_system", "file_system_manager"]
- , ["utils", "local_hermeticity"]
+ , ["utils", "test_storage_config"]
, ["@", "src", "src/buildtool/execution_api/local", "local"]
+ , ["@", "src", "src/buildtool/storage", "storage"]
+ , ["@", "src", "src/buildtool/storage", "config"]
]
, "stage": ["test", "buildtool", "common"]
}
diff --git a/test/buildtool/common/repository_config.test.cpp b/test/buildtool/common/repository_config.test.cpp
index 131cf01f..4fd8362b 100644
--- a/test/buildtool/common/repository_config.test.cpp
+++ b/test/buildtool/common/repository_config.test.cpp
@@ -27,8 +27,9 @@
#include "src/buildtool/common/repository_config.hpp"
#include "src/buildtool/file_system/file_root.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/storage.hpp"
-#include "test/utils/hermeticity/local.hpp"
+#include "test/utils/hermeticity/test_storage_config.hpp"
namespace {
@@ -115,21 +116,21 @@ template <class T>
} // namespace
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Test missing repository",
- "[repository_config]") {
+TEST_CASE("Test missing repository", "[repository_config]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
RepositoryConfig config{};
- auto const storage = Storage::Create(&StorageConfig::Instance());
CHECK(config.Info("missing") == nullptr);
CHECK_FALSE(config.RepositoryKey(storage, "missing"));
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Compute key of fixed repository",
- "[repository_config]") {
+TEST_CASE("Compute key of fixed repository", "[repository_config]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
RepositoryConfig config{};
- auto const storage = Storage::Create(&StorageConfig::Instance());
SECTION("for single fixed repository") {
config.SetInfo("foo", CreateFixedRepoInfo());
@@ -156,11 +157,11 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Compute key of file repository",
- "[repository_config]") {
+TEST_CASE("Compute key of file repository", "[repository_config]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
RepositoryConfig config{};
- auto const storage = Storage::Create(&StorageConfig::Instance());
SECTION("for single file repository") {
config.SetInfo("foo", CreateFileRepoInfo());
@@ -175,11 +176,11 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Compare key of two repos with same content",
- "[repository_config]") {
+TEST_CASE("Compare key of two repos with same content", "[repository_config]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
RepositoryConfig config{};
- auto const storage = Storage::Create(&StorageConfig::Instance());
// create two different repo infos with same content (baz should be same)
config.SetInfo("foo", CreateFixedRepoInfo({{"dep", "baz0"}}));
diff --git a/test/buildtool/execution_api/execution_service/TARGETS b/test/buildtool/execution_api/execution_service/TARGETS
index c14db85c..754615d5 100644
--- a/test/buildtool/execution_api/execution_service/TARGETS
+++ b/test/buildtool/execution_api/execution_service/TARGETS
@@ -5,7 +5,7 @@
, "private-deps":
[ ["", "catch-main"]
, ["@", "catch2", "", "catch2"]
- , ["utils", "local_hermeticity"]
+ , ["utils", "test_storage_config"]
, [ "@"
, "src"
, "src/buildtool/execution_api/execution_service"
diff --git a/test/buildtool/execution_api/execution_service/cas_server.test.cpp b/test/buildtool/execution_api/execution_service/cas_server.test.cpp
index 5b6e50b5..a7791cd5 100644
--- a/test/buildtool/execution_api/execution_service/cas_server.test.cpp
+++ b/test/buildtool/execution_api/execution_service/cas_server.test.cpp
@@ -22,7 +22,7 @@
#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/storage.hpp"
-#include "test/utils/hermeticity/local.hpp"
+#include "test/utils/hermeticity/test_storage_config.hpp"
namespace {
[[nodiscard]] auto Upload(
@@ -41,12 +41,11 @@ namespace {
}
} // namespace
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "CAS Service: upload incomplete tree",
- "[execution_service]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("CAS Service: upload incomplete tree", "[execution_service]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
- auto cas_server = CASServiceImpl{&StorageConfig::Instance(), &storage};
+ auto cas_server = CASServiceImpl{&storage_config.Get(), &storage};
auto instance_name = std::string{"remote-execution"};
// Create an empty tree.
diff --git a/test/buildtool/execution_api/local/TARGETS b/test/buildtool/execution_api/local/TARGETS
index 282166a2..eb23c99a 100644
--- a/test/buildtool/execution_api/local/TARGETS
+++ b/test/buildtool/execution_api/local/TARGETS
@@ -12,7 +12,7 @@
, ["@", "src", "src/buildtool/file_system", "file_system_manager"]
, ["@", "src", "src/buildtool/logging", "log_level"]
, ["@", "src", "src/buildtool/logging", "logging"]
- , ["utils", "local_hermeticity"]
+ , ["utils", "test_storage_config"]
, ["@", "src", "src/buildtool/storage", "storage"]
, ["@", "src", "src/buildtool/storage", "config"]
]
@@ -27,7 +27,7 @@
, ["", "catch-main"]
, ["@", "src", "src/buildtool/execution_api/local", "local"]
, ["buildtool/execution_api/common", "api_test"]
- , ["utils", "local_hermeticity"]
+ , ["utils", "test_storage_config"]
, ["@", "src", "src/buildtool/storage", "storage"]
, ["@", "src", "src/buildtool/storage", "config"]
]
diff --git a/test/buildtool/execution_api/local/local_api.test.cpp b/test/buildtool/execution_api/local/local_api.test.cpp
index de875a2c..a2fee207 100644
--- a/test/buildtool/execution_api/local/local_api.test.cpp
+++ b/test/buildtool/execution_api/local/local_api.test.cpp
@@ -20,92 +20,91 @@
#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/storage.hpp"
#include "test/buildtool/execution_api/common/api_test.hpp"
-#include "test/utils/hermeticity/local.hpp"
+#include "test/utils/hermeticity/test_storage_config.hpp"
namespace {
class FactoryApi final {
public:
explicit FactoryApi(
- gsl::not_null<Storage const*> const& storage,
- gsl::not_null<StorageConfig const*> const& storage_config) noexcept
- : storage_{*storage}, storage_config_{*storage_config} {}
+ gsl::not_null<StorageConfig const*> const& storage_config,
+ gsl::not_null<Storage const*> const& storage) noexcept
+ : storage_config_{*storage_config}, storage_{*storage} {}
[[nodiscard]] auto operator()() const -> IExecutionApi::Ptr {
- return IExecutionApi::Ptr{
- new LocalApi{&StorageConfig::Instance(), &storage_}};
+ return IExecutionApi::Ptr{new LocalApi{&storage_config_, &storage_}};
}
private:
- Storage const& storage_;
StorageConfig const& storage_config_;
+ Storage const& storage_;
};
} // namespace
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalAPI: No input, no output",
- "[execution_api]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
- FactoryApi api_factory(&storage, &StorageConfig::Instance());
+TEST_CASE("LocalAPI: No input, no output", "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+ FactoryApi api_factory(&storage_config.Get(), &storage);
+
TestNoInputNoOutput(api_factory, {}, /*is_hermetic=*/true);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalAPI: No input, create output",
- "[execution_api]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
- FactoryApi api_factory(&storage, &StorageConfig::Instance());
+TEST_CASE("LocalAPI: No input, create output", "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+ FactoryApi api_factory(&storage_config.Get(), &storage);
+
TestNoInputCreateOutput(api_factory, {}, /*is_hermetic=*/true);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalAPI: One input copied to output",
- "[execution_api]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
- FactoryApi api_factory(&storage, &StorageConfig::Instance());
+TEST_CASE("LocalAPI: One input copied to output", "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+ FactoryApi api_factory(&storage_config.Get(), &storage);
+
TestOneInputCopiedToOutput(api_factory, {}, /*is_hermetic=*/true);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalAPI: Non-zero exit code, create output",
- "[execution_api]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
- FactoryApi api_factory(&storage, &StorageConfig::Instance());
+TEST_CASE("LocalAPI: Non-zero exit code, create output", "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+ FactoryApi api_factory(&storage_config.Get(), &storage);
+
TestNonZeroExitCodeCreateOutput(api_factory, {});
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalAPI: Retrieve two identical trees to path",
- "[execution_api]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
- FactoryApi api_factory(&storage, &StorageConfig::Instance());
+TEST_CASE("LocalAPI: Retrieve two identical trees to path", "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+ FactoryApi api_factory(&storage_config.Get(), &storage);
+
TestRetrieveTwoIdenticalTreesToPath(
api_factory, {}, "two_trees", /*is_hermetic=*/true);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalAPI: Retrieve file and symlink with same content to "
- "path",
- "[execution_api]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
- FactoryApi api_factory(&storage, &StorageConfig::Instance());
+TEST_CASE("LocalAPI: Retrieve file and symlink with same content to path",
+ "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+ FactoryApi api_factory(&storage_config.Get(), &storage);
+
TestRetrieveFileAndSymlinkWithSameContentToPath(
api_factory, {}, "file_and_symlink", /*is_hermetic=*/true);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalAPI: Retrieve mixed blobs and trees",
- "[execution_api]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
- FactoryApi api_factory(&storage, &StorageConfig::Instance());
+TEST_CASE("LocalAPI: Retrieve mixed blobs and trees", "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+ FactoryApi api_factory(&storage_config.Get(), &storage);
+
TestRetrieveMixedBlobsAndTrees(
api_factory, {}, "blobs_and_trees", /*is_hermetic=*/true);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalAPI: Create directory prior to execution",
- "[execution_api]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
- FactoryApi api_factory(&storage, &StorageConfig::Instance());
+TEST_CASE("LocalAPI: Create directory prior to execution", "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+ FactoryApi api_factory(&storage_config.Get(), &storage);
+
TestCreateDirPriorToExecution(api_factory, {}, /*is_hermetic=*/true);
}
diff --git a/test/buildtool/execution_api/local/local_execution.test.cpp b/test/buildtool/execution_api/local/local_execution.test.cpp
index 480b34df..bbd48ddc 100644
--- a/test/buildtool/execution_api/local/local_execution.test.cpp
+++ b/test/buildtool/execution_api/local/local_execution.test.cpp
@@ -28,7 +28,7 @@
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/storage.hpp"
-#include "test/utils/hermeticity/local.hpp"
+#include "test/utils/hermeticity/test_storage_config.hpp"
namespace {
@@ -58,13 +58,12 @@ inline void SetLauncher() {
} // namespace
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalExecution: No input, no output",
- "[execution_api]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("LocalExecution: No input, no output", "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
RepositoryConfig repo_config{};
- auto api = LocalApi(&StorageConfig::Instance(), &storage, &repo_config);
+ auto api = LocalApi(&storage_config.Get(), &storage, &repo_config);
std::string test_content("test");
std::vector<std::string> const cmdline = {"echo", "-n", test_content};
@@ -106,12 +105,13 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalExecution: No input, no output, env variables used",
- "[execution_api]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("LocalExecution: No input, no output, env variables used",
+ "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
RepositoryConfig repo_config{};
- auto api = LocalApi(&StorageConfig::Instance(), &storage, &repo_config);
+ auto api = LocalApi(&storage_config.Get(), &storage, &repo_config);
std::string test_content("test from env var");
std::vector<std::string> const cmdline = {
@@ -157,12 +157,12 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalExecution: No input, create output",
- "[execution_api]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("LocalExecution: No input, create output", "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
RepositoryConfig repo_config{};
- auto api = LocalApi(&StorageConfig::Instance(), &storage, &repo_config);
+ auto api = LocalApi(&storage_config.Get(), &storage, &repo_config);
std::string test_content("test");
auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content);
@@ -214,12 +214,12 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalExecution: One input copied to output",
- "[execution_api]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("LocalExecution: One input copied to output", "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
RepositoryConfig repo_config{};
- auto api = LocalApi(&StorageConfig::Instance(), &storage, &repo_config);
+ auto api = LocalApi(&storage_config.Get(), &storage, &repo_config);
std::string test_content("test");
auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content);
@@ -285,12 +285,12 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalExecution: Cache failed action's result",
- "[execution_api]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("LocalExecution: Cache failed action's result", "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
RepositoryConfig repo_config{};
- auto api = LocalApi(&StorageConfig::Instance(), &storage, &repo_config);
+ auto api = LocalApi(&storage_config.Get(), &storage, &repo_config);
auto flag = GetTestDir() / "flag";
std::vector<std::string> const cmdline = {
diff --git a/test/buildtool/execution_engine/executor/TARGETS b/test/buildtool/execution_engine/executor/TARGETS
index c1b50f35..2d82e097 100644
--- a/test/buildtool/execution_engine/executor/TARGETS
+++ b/test/buildtool/execution_engine/executor/TARGETS
@@ -51,7 +51,7 @@
, ["@", "src", "src/buildtool/execution_engine/executor", "executor"]
, ["@", "src", "src/buildtool/progress_reporting", "progress"]
, ["utils", "catch-main-remote-execution"]
- , ["utils", "local_hermeticity"]
+ , ["utils", "test_storage_config"]
, ["utils", "test_auth_config"]
, ["@", "catch2", "", "catch2"]
, ["@", "src", "src/buildtool/storage", "storage"]
diff --git a/test/buildtool/execution_engine/executor/executor_api_local.test.cpp b/test/buildtool/execution_engine/executor/executor_api_local.test.cpp
index ae6c3d4e..7d645e0e 100644
--- a/test/buildtool/execution_engine/executor/executor_api_local.test.cpp
+++ b/test/buildtool/execution_engine/executor/executor_api_local.test.cpp
@@ -24,24 +24,24 @@
#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/storage.hpp"
#include "test/buildtool/execution_engine/executor/executor_api.test.hpp"
-#include "test/utils/hermeticity/local.hpp"
+#include "test/utils/hermeticity/test_storage_config.hpp"
#include "test/utils/remote_execution/test_auth_config.hpp"
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Executor<LocalApi>: Upload blob",
- "[executor]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("Executor<LocalApi>: Upload blob", "[executor]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
RepositoryConfig repo_config{};
TestBlobUpload(&repo_config, [&] {
return std::make_unique<LocalApi>(
- &StorageConfig::Instance(), &storage, &repo_config);
+ &storage_config.Get(), &storage, &repo_config);
});
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Executor<LocalApi>: Compile hello world",
- "[executor]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("Executor<LocalApi>: Compile hello world", "[executor]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
RepositoryConfig repo_config{};
Statistics stats{};
Progress progress{};
@@ -53,15 +53,15 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
&progress,
[&] {
return std::make_unique<LocalApi>(
- &StorageConfig::Instance(), &storage, &repo_config);
+ &storage_config.Get(), &storage, &repo_config);
},
&*auth_config);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Executor<LocalApi>: Compile greeter",
- "[executor]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("Executor<LocalApi>: Compile greeter", "[executor]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
RepositoryConfig repo_config{};
Statistics stats{};
Progress progress{};
@@ -73,15 +73,15 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
&progress,
[&] {
return std::make_unique<LocalApi>(
- &StorageConfig::Instance(), &storage, &repo_config);
+ &storage_config.Get(), &storage, &repo_config);
},
&*auth_config);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Executor<LocalApi>: Upload and download trees",
- "[executor]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("Executor<LocalApi>: Upload and download trees", "[executor]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
RepositoryConfig repo_config{};
Statistics stats{};
Progress progress{};
@@ -93,15 +93,15 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
&progress,
[&] {
return std::make_unique<LocalApi>(
- &StorageConfig::Instance(), &storage, &repo_config);
+ &storage_config.Get(), &storage, &repo_config);
},
&*auth_config);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Executor<LocalApi>: Retrieve output directories",
- "[executor]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("Executor<LocalApi>: Retrieve output directories", "[executor]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+
RepositoryConfig repo_config{};
Statistics stats{};
Progress progress{};
@@ -113,7 +113,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
&progress,
[&] {
return std::make_unique<LocalApi>(
- &StorageConfig::Instance(), &storage, &repo_config);
+ &storage_config.Get(), &storage, &repo_config);
},
&*auth_config);
}
diff --git a/test/buildtool/file_system/TARGETS b/test/buildtool/file_system/TARGETS
index c202fa32..333e2b7e 100644
--- a/test/buildtool/file_system/TARGETS
+++ b/test/buildtool/file_system/TARGETS
@@ -27,7 +27,7 @@
, ["@", "src", "src/buildtool/common", "bazel_types"]
, ["@", "src", "src/buildtool/common", "common"]
, ["@", "src", "src/buildtool/storage", "config"]
- , ["utils", "local_hermeticity"]
+ , ["utils", "test_storage_config"]
]
, "stage": ["test", "buildtool", "file_system"]
}
@@ -127,6 +127,7 @@
, ["@", "src", "src/utils/cpp", "hex_string"]
, ["@", "src", "src/buildtool/storage", "config"]
, ["utils", "shell_quoting"]
+ , ["utils", "test_storage_config"]
]
, "stage": ["test", "buildtool", "file_system"]
}
diff --git a/test/buildtool/file_system/git_repo.test.cpp b/test/buildtool/file_system/git_repo.test.cpp
index 94801dfe..969f2072 100644
--- a/test/buildtool/file_system/git_repo.test.cpp
+++ b/test/buildtool/file_system/git_repo.test.cpp
@@ -32,6 +32,7 @@
#include "src/buildtool/storage/config.hpp"
#include "src/utils/cpp/atomic.hpp"
#include "src/utils/cpp/hex_string.hpp"
+#include "test/utils/hermeticity/test_storage_config.hpp"
#include "test/utils/shell_quoting.hpp"
namespace {
@@ -277,6 +278,8 @@ TEST_CASE("Single-threaded real repository local operations", "[git_repo]") {
// warning
TEST_CASE("Single-threaded fake repository operations -- batch 1",
"[git_repo]") {
+ auto const storage_config = TestStorageConfig::Create();
+
auto repo_path = TestUtils::CreateTestRepoWithCheckout();
REQUIRE(repo_path);
auto cas = GitCAS::Open(*repo_path);
@@ -419,7 +422,7 @@ TEST_CASE("Single-threaded fake repository operations -- batch 1",
// fetch all with base refspecs
REQUIRE(repo_fetch_all->LocalFetchViaTmpRepo(
- StorageConfig::Instance(), *repo_path, std::nullopt, logger));
+ storage_config.Get(), *repo_path, std::nullopt, logger));
// check commit is there after fetch
CHECK(*repo_fetch_all->CheckCommitExists(kRootCommit, logger));
@@ -438,7 +441,7 @@ TEST_CASE("Single-threaded fake repository operations -- batch 1",
// fetch branch
REQUIRE(repo_fetch_branch->LocalFetchViaTmpRepo(
- StorageConfig::Instance(), *repo_path, "master", logger));
+ storage_config.Get(), *repo_path, "master", logger));
// check commit is there after fetch
CHECK(*repo_fetch_branch->CheckCommitExists(kRootCommit, logger));
@@ -580,6 +583,8 @@ TEST_CASE("Single-threaded fake repository operations -- batch 2",
}
TEST_CASE("Multi-threaded fake repository operations", "[git_repo]") {
+ auto const storage_config = TestStorageConfig::Create();
+
/*
Test all fake repository operations while being done in parallel.
They are supposed to be thread-safe, so no conflicts should exist.
@@ -608,8 +613,11 @@ TEST_CASE("Multi-threaded fake repository operations", "[git_repo]") {
constexpr int NUM_CASES = 10;
for (int id{}; id < kNumThreads; ++id) {
threads.emplace_back(
- [&remote_cas, &remote_repo_path, &logger, &starting_signal](
- int tid) {
+ [&storage_config,
+ &remote_cas,
+ &remote_repo_path,
+ &logger,
+ &starting_signal](int tid) {
starting_signal.wait(false);
// cases based on thread number
switch (tid % NUM_CASES) {
@@ -729,7 +737,7 @@ TEST_CASE("Multi-threaded fake repository operations", "[git_repo]") {
REQUIRE(remote_repo->IsRepoFake());
// fetch all
REQUIRE(remote_repo->LocalFetchViaTmpRepo(
- StorageConfig::Instance(),
+ storage_config.Get(),
*remote_repo_path,
std::nullopt,
logger));
diff --git a/test/buildtool/file_system/object_cas.test.cpp b/test/buildtool/file_system/object_cas.test.cpp
index 2fc0a405..be9ba709 100644
--- a/test/buildtool/file_system/object_cas.test.cpp
+++ b/test/buildtool/file_system/object_cas.test.cpp
@@ -23,14 +23,15 @@
#include "src/buildtool/file_system/object_cas.hpp"
#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/storage/config.hpp"
-#include "test/utils/hermeticity/local.hpp"
+#include "test/utils/hermeticity/test_storage_config.hpp"
+
+TEST_CASE("ObjectCAS", "[file_system]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto gen_config = storage_config.Get().CreateGenerationConfig(0);
-TEST_CASE_METHOD(HermeticLocalTestFixture, "ObjectCAS", "[file_system]") {
std::string test_content{"test"};
auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content);
- auto gen_config = StorageConfig::Instance().CreateGenerationConfig(0);
-
SECTION("CAS for files") {
ObjectCAS<ObjectType::File> cas{gen_config.cas_f};
CHECK(not cas.BlobPath(test_digest));
diff --git a/test/buildtool/graph_traverser/TARGETS b/test/buildtool/graph_traverser/TARGETS
index d04e4365..bbf9e8ec 100644
--- a/test/buildtool/graph_traverser/TARGETS
+++ b/test/buildtool/graph_traverser/TARGETS
@@ -29,8 +29,10 @@
[ "graph_traverser_tests"
, ["@", "catch2", "", "catch2"]
, ["", "catch-main"]
- , ["utils", "local_hermeticity"]
, ["utils", "test_auth_config"]
+ , ["utils", "test_storage_config"]
+ , ["@", "src", "src/buildtool/storage", "config"]
+ , ["@", "src", "src/buildtool/storage", "storage"]
]
, "stage": ["test", "buildtool", "graph_traverser"]
}
@@ -44,6 +46,8 @@
, ["@", "catch2", "", "catch2"]
, ["utils", "catch-main-remote-execution"]
, ["utils", "test_auth_config"]
+ , ["@", "src", "src/buildtool/storage", "storage"]
+ , ["@", "src", "src/buildtool/storage", "config"]
]
, "stage": ["test", "buildtool", "graph_traverser"]
}
diff --git a/test/buildtool/graph_traverser/graph_traverser.test.hpp b/test/buildtool/graph_traverser/graph_traverser.test.hpp
index e8fe20bd..e83f876d 100644
--- a/test/buildtool/graph_traverser/graph_traverser.test.hpp
+++ b/test/buildtool/graph_traverser/graph_traverser.test.hpp
@@ -154,17 +154,17 @@ inline void SetLauncher() {
} // namespace
[[maybe_unused]] static void TestHelloWorldCopyMessage(
+ StorageConfig const& storage_config,
+ Storage const& storage,
gsl::not_null<Auth const*> const& auth,
bool is_hermetic = true) {
TestProject p("hello_world_copy_message");
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
SetLauncher();
auto const clargs = p.CmdLineArgs();
Statistics stats{};
Progress progress{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config,
&storage,
p.GetRepoConfig(),
auth,
@@ -195,7 +195,7 @@ inline void SetLauncher() {
SECTION("Executable is retrieved as executable") {
auto const clargs_exec = p.CmdLineArgs("_entry_points_get_executable");
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config,
&storage,
p.GetRepoConfig(),
auth,
@@ -228,17 +228,17 @@ inline void SetLauncher() {
}
[[maybe_unused]] static void TestCopyLocalFile(
+ StorageConfig const& storage_config,
+ Storage const& storage,
gsl::not_null<Auth const*> const& auth,
bool is_hermetic = true) {
TestProject p("copy_local_file");
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
SetLauncher();
auto const clargs = p.CmdLineArgs();
Statistics stats{};
Progress progress{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config,
&storage,
p.GetRepoConfig(),
auth,
@@ -265,17 +265,17 @@ inline void SetLauncher() {
}
[[maybe_unused]] static void TestSequencePrinterBuildLibraryOnly(
+ StorageConfig const& storage_config,
+ Storage const& storage,
gsl::not_null<Auth const*> const& auth,
bool is_hermetic = true) {
TestProject p("sequence_printer_build_library_only");
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
SetLauncher();
auto const clargs = p.CmdLineArgs();
Statistics stats{};
Progress progress{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config,
&storage,
p.GetRepoConfig(),
auth,
@@ -322,18 +322,18 @@ inline void SetLauncher() {
}
[[maybe_unused]] static void TestHelloWorldWithKnownSource(
+ StorageConfig const& storage_config,
+ Storage const& storage,
gsl::not_null<Auth const*> const& auth,
bool is_hermetic = true) {
TestProject full_hello_world("hello_world_copy_message");
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
SetLauncher();
auto const clargs_update_cpp =
full_hello_world.CmdLineArgs("_entry_points_upload_source");
Statistics stats{};
Progress progress{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config,
&storage,
full_hello_world.GetRepoConfig(),
auth,
@@ -385,17 +385,17 @@ inline void SetLauncher() {
}
}
-static void TestBlobsUploadedAndUsed(gsl::not_null<Auth const*> const& auth,
+static void TestBlobsUploadedAndUsed(StorageConfig const& storage_config,
+ Storage const& storage,
+ gsl::not_null<Auth const*> const& auth,
bool is_hermetic = true) {
TestProject p("use_uploaded_blobs");
auto const clargs = p.CmdLineArgs();
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
SetLauncher();
Statistics stats{};
Progress progress{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config,
&storage,
p.GetRepoConfig(),
auth,
@@ -430,17 +430,17 @@ static void TestBlobsUploadedAndUsed(gsl::not_null<Auth const*> const& auth,
}
static void TestEnvironmentVariablesSetAndUsed(
+ StorageConfig const& storage_config,
+ Storage const& storage,
gsl::not_null<Auth const*> const& auth,
bool is_hermetic = true) {
TestProject p("use_env_variables");
auto const clargs = p.CmdLineArgs();
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
SetLauncher();
Statistics stats{};
Progress progress{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config,
&storage,
p.GetRepoConfig(),
auth,
@@ -474,17 +474,17 @@ static void TestEnvironmentVariablesSetAndUsed(
}
}
-static void TestTreesUsed(gsl::not_null<Auth const*> const& auth,
+static void TestTreesUsed(StorageConfig const& storage_config,
+ Storage const& storage,
+ gsl::not_null<Auth const*> const& auth,
bool is_hermetic = true) {
TestProject p("use_trees");
auto const clargs = p.CmdLineArgs();
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
SetLauncher();
Statistics stats{};
Progress progress{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config,
&storage,
p.GetRepoConfig(),
auth,
@@ -518,17 +518,17 @@ static void TestTreesUsed(gsl::not_null<Auth const*> const& auth,
}
}
-static void TestNestedTreesUsed(gsl::not_null<Auth const*> const& auth,
+static void TestNestedTreesUsed(StorageConfig const& storage_config,
+ Storage const& storage,
+ gsl::not_null<Auth const*> const& auth,
bool is_hermetic = true) {
TestProject p("use_nested_trees");
auto const clargs = p.CmdLineArgs();
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
SetLauncher();
Statistics stats{};
Progress progress{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config,
&storage,
p.GetRepoConfig(),
auth,
@@ -562,15 +562,15 @@ static void TestNestedTreesUsed(gsl::not_null<Auth const*> const& auth,
}
}
-static void TestFlakyHelloWorldDetected(gsl::not_null<Auth const*> const& auth,
+static void TestFlakyHelloWorldDetected(StorageConfig const& storage_config,
+ Storage const& storage,
+ gsl::not_null<Auth const*> const& auth,
bool /*is_hermetic*/ = true) {
TestProject p("flaky_hello_world");
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
Statistics stats{};
Progress progress{};
- ApiBundle const apis{&StorageConfig::Instance(),
+ ApiBundle const apis{&storage_config,
&storage,
p.GetRepoConfig(),
auth,
diff --git a/test/buildtool/graph_traverser/graph_traverser_local.test.cpp b/test/buildtool/graph_traverser/graph_traverser_local.test.cpp
index 88990dc8..007d1386 100644
--- a/test/buildtool/graph_traverser/graph_traverser_local.test.cpp
+++ b/test/buildtool/graph_traverser/graph_traverser_local.test.cpp
@@ -14,69 +14,83 @@
#include "catch2/catch_test_macros.hpp"
#include "src/buildtool/auth/authentication.hpp"
+#include "src/buildtool/storage/config.hpp"
+#include "src/buildtool/storage/storage.hpp"
#include "test/buildtool/graph_traverser/graph_traverser.test.hpp"
-#include "test/utils/hermeticity/local.hpp"
+#include "test/utils/hermeticity/test_storage_config.hpp"
#include "test/utils/remote_execution/test_auth_config.hpp"
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Local: Output created when entry point is local artifact",
- "[graph_traverser]") {
+TEST_CASE("Local: Output created when entry point is local artifact",
+ "[graph_traverser]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
Auth auth{}; /*no TLS needed*/
- TestCopyLocalFile(&auth);
+
+ TestCopyLocalFile(storage_config.Get(), storage, &auth);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Local: Output created and contents are correct",
- "[graph_traverser]") {
+TEST_CASE("Local: Output created and contents are correct",
+ "[graph_traverser]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
Auth auth{}; /*no TLS needed*/
- TestHelloWorldCopyMessage(&auth);
+
+ TestHelloWorldCopyMessage(storage_config.Get(), storage, &auth);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Local: Actions are not re-run",
- "[graph_traverser]") {
+TEST_CASE("Local: Actions are not re-run", "[graph_traverser]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
Auth auth{}; /*no TLS needed*/
- TestSequencePrinterBuildLibraryOnly(&auth);
+
+ TestSequencePrinterBuildLibraryOnly(storage_config.Get(), storage, &auth);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Local: KNOWN artifact",
- "[graph_traverser]") {
+TEST_CASE("Local: KNOWN artifact", "[graph_traverser]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
Auth auth{}; /*no TLS needed*/
- TestHelloWorldWithKnownSource(&auth);
+
+ TestHelloWorldWithKnownSource(storage_config.Get(), storage, &auth);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Local: Blobs uploaded and correctly used",
- "[graph_traverser]") {
+TEST_CASE("Local: Blobs uploaded and correctly used", "[graph_traverser]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
Auth auth{}; /*no TLS needed*/
- TestBlobsUploadedAndUsed(&auth);
+
+ TestBlobsUploadedAndUsed(storage_config.Get(), storage, &auth);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Local: Environment variables are set and used",
- "[graph_traverser]") {
+TEST_CASE("Local: Environment variables are set and used",
+ "[graph_traverser]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
Auth auth{}; /*no TLS needed*/
- TestEnvironmentVariablesSetAndUsed(&auth);
+
+ TestEnvironmentVariablesSetAndUsed(storage_config.Get(), storage, &auth);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Local: Trees correctly used",
- "[graph_traverser]") {
+TEST_CASE("Local: Trees correctly used", "[graph_traverser]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
Auth auth{}; /*no TLS needed*/
- TestTreesUsed(&auth);
+
+ TestTreesUsed(storage_config.Get(), storage, &auth);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Local: Nested trees correctly used",
- "[graph_traverser]") {
+TEST_CASE("Local: Nested trees correctly used", "[graph_traverser]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
Auth auth{}; /*no TLS needed*/
- TestNestedTreesUsed(&auth);
+
+ TestNestedTreesUsed(storage_config.Get(), storage, &auth);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "Local: Detect flaky actions",
- "[graph_traverser]") {
+TEST_CASE("Local: Detect flaky actions", "[graph_traverser]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
Auth auth{}; /*no TLS needed*/
- TestFlakyHelloWorldDetected(&auth);
+
+ TestFlakyHelloWorldDetected(storage_config.Get(), storage, &auth);
}
diff --git a/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp b/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp
index e24a8d4e..d9de3b10 100644
--- a/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp
+++ b/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp
@@ -13,72 +13,111 @@
// limitations under the License.
#include "catch2/catch_test_macros.hpp"
+#include "src/buildtool/storage/config.hpp"
+#include "src/buildtool/storage/storage.hpp"
#include "test/buildtool/graph_traverser/graph_traverser.test.hpp"
#include "test/utils/remote_execution/test_auth_config.hpp"
+[[nodiscard]] static auto CreateConfig() -> StorageConfig {
+ auto cache_dir = FileSystemManager::GetCurrentDirectory() / "cache";
+ auto storage_config = StorageConfig::Instance();
+ if (not FileSystemManager::RemoveDirectory(cache_dir, true) or
+ not FileSystemManager::CreateDirectoryExclusive(cache_dir) or
+ not storage_config.SetBuildRoot(cache_dir)) {
+ std::exit(EXIT_FAILURE);
+ }
+ return storage_config;
+}
+
TEST_CASE("Remote: Output created and contents are correct",
"[graph_traverser]") {
+ StorageConfig const storage_config = CreateConfig();
+ auto const storage = Storage::Create(&storage_config);
auto auth_config = TestAuthConfig::ReadAuthConfigFromEnvironment();
REQUIRE(auth_config);
- TestHelloWorldCopyMessage(&*auth_config, false /* not hermetic */);
+ TestHelloWorldCopyMessage(
+ storage_config, storage, &*auth_config, false /* not hermetic */);
}
TEST_CASE("Remote: Output created when entry point is local artifact",
"[graph_traverser]") {
+ StorageConfig const storage_config = CreateConfig();
+ auto const storage = Storage::Create(&storage_config);
auto auth_config = TestAuthConfig::ReadAuthConfigFromEnvironment();
REQUIRE(auth_config);
- TestCopyLocalFile(&*auth_config, false /* not hermetic */);
+ TestCopyLocalFile(
+ storage_config, storage, &*auth_config, false /* not hermetic */);
}
TEST_CASE("Remote: Actions are not re-run", "[graph_traverser]") {
+ StorageConfig const storage_config = CreateConfig();
+ auto const storage = Storage::Create(&storage_config);
auto auth_config = TestAuthConfig::ReadAuthConfigFromEnvironment();
REQUIRE(auth_config);
- TestSequencePrinterBuildLibraryOnly(&*auth_config,
- false /* not hermetic */);
+ TestSequencePrinterBuildLibraryOnly(
+ storage_config, storage, &*auth_config, false /* not hermetic */);
}
TEST_CASE("Remote: KNOWN artifact", "[graph_traverser]") {
+ StorageConfig const storage_config = CreateConfig();
+ auto const storage = Storage::Create(&storage_config);
auto auth_config = TestAuthConfig::ReadAuthConfigFromEnvironment();
REQUIRE(auth_config);
- TestHelloWorldWithKnownSource(&*auth_config, false /* not hermetic */);
+ TestHelloWorldWithKnownSource(
+ storage_config, storage, &*auth_config, false /* not hermetic */);
}
TEST_CASE("Remote: Blobs uploaded and correctly used", "[graph_traverser]") {
+ StorageConfig const storage_config = CreateConfig();
+ auto const storage = Storage::Create(&storage_config);
auto auth_config = TestAuthConfig::ReadAuthConfigFromEnvironment();
REQUIRE(auth_config);
- TestBlobsUploadedAndUsed(&*auth_config, false /* not hermetic */);
+ TestBlobsUploadedAndUsed(
+ storage_config, storage, &*auth_config, false /* not hermetic */);
}
TEST_CASE("Remote: Environment variables are set and used",
"[graph_traverser]") {
+ StorageConfig const storage_config = CreateConfig();
+ auto const storage = Storage::Create(&storage_config);
auto auth_config = TestAuthConfig::ReadAuthConfigFromEnvironment();
REQUIRE(auth_config);
- TestEnvironmentVariablesSetAndUsed(&*auth_config, false /* not hermetic */);
+ TestEnvironmentVariablesSetAndUsed(
+ storage_config, storage, &*auth_config, false /* not hermetic */);
}
TEST_CASE("Remote: Trees correctly used", "[graph_traverser]") {
+ StorageConfig const storage_config = CreateConfig();
+ auto const storage = Storage::Create(&storage_config);
auto auth_config = TestAuthConfig::ReadAuthConfigFromEnvironment();
REQUIRE(auth_config);
- TestTreesUsed(&*auth_config, false /* not hermetic */);
+ TestTreesUsed(
+ storage_config, storage, &*auth_config, false /* not hermetic */);
}
TEST_CASE("Remote: Nested trees correctly used", "[graph_traverser]") {
+ StorageConfig const storage_config = CreateConfig();
+ auto const storage = Storage::Create(&storage_config);
auto auth_config = TestAuthConfig::ReadAuthConfigFromEnvironment();
REQUIRE(auth_config);
- TestNestedTreesUsed(&*auth_config, false /* not hermetic */);
+ TestNestedTreesUsed(
+ storage_config, storage, &*auth_config, false /* not hermetic */);
}
TEST_CASE("Remote: Detect flaky actions", "[graph_traverser]") {
+ StorageConfig const storage_config = CreateConfig();
+ auto const storage = Storage::Create(&storage_config);
auto auth_config = TestAuthConfig::ReadAuthConfigFromEnvironment();
REQUIRE(auth_config);
- TestFlakyHelloWorldDetected(&*auth_config, false /* not hermetic */);
+ TestFlakyHelloWorldDetected(
+ storage_config, storage, &*auth_config, false /* not hermetic */);
}
diff --git a/test/buildtool/storage/TARGETS b/test/buildtool/storage/TARGETS
index 6dfb4edb..4a2881c3 100644
--- a/test/buildtool/storage/TARGETS
+++ b/test/buildtool/storage/TARGETS
@@ -16,12 +16,14 @@
, "private-deps":
[ ["@", "catch2", "", "catch2"]
, ["", "catch-main"]
- , ["utils", "local_hermeticity"]
+ , ["utils", "test_storage_config"]
, ["@", "src", "src/buildtool/common", "common"]
, ["@", "src", "src/buildtool/file_system", "file_system_manager"]
, ["@", "src", "src/buildtool/file_system", "object_type"]
, ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"]
, ["utils", "blob_creator"]
+ , ["@", "src", "src/buildtool/storage", "storage"]
+ , ["@", "src", "src/buildtool/storage", "config"]
]
, "stage": ["test", "buildtool", "storage"]
}
@@ -36,7 +38,9 @@
, ["@", "src", "src/buildtool/common", "common"]
, ["@", "src", "src/buildtool/file_system", "file_system_manager"]
, ["@", "src", "src/buildtool/file_system", "object_type"]
- , ["utils", "local_hermeticity"]
+ , ["@", "src", "src/buildtool/storage", "storage"]
+ , ["@", "src", "src/buildtool/storage", "config"]
+ , ["utils", "test_storage_config"]
]
, "stage": ["test", "buildtool", "storage"]
}
@@ -51,7 +55,7 @@
, ["@", "src", "src/buildtool/file_system", "object_type"]
, ["@", "src", "src/buildtool/storage", "storage"]
, ["@", "src", "src/buildtool/storage", "config"]
- , ["utils", "local_hermeticity"]
+ , ["utils", "test_storage_config"]
, ["@", "src", "src/buildtool/common", "bazel_types"]
, ["utils", "large_object_utils"]
, ["@", "src", "src/utils/cpp", "tmp_dir"]
diff --git a/test/buildtool/storage/large_object_cas.test.cpp b/test/buildtool/storage/large_object_cas.test.cpp
index fda1449a..8daf1eaf 100644
--- a/test/buildtool/storage/large_object_cas.test.cpp
+++ b/test/buildtool/storage/large_object_cas.test.cpp
@@ -35,7 +35,7 @@
#include "src/buildtool/storage/large_object_cas.hpp"
#include "src/buildtool/storage/storage.hpp"
#include "src/utils/cpp/tmp_dir.hpp"
-#include "test/utils/hermeticity/local.hpp"
+#include "test/utils/hermeticity/test_storage_config.hpp"
#include "test/utils/large_objects/large_object_utils.hpp"
namespace {
@@ -97,10 +97,9 @@ class Tree final {
} // namespace
// Test splitting of a small tree.
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LargeObjectCAS: split a small tree",
- "[storage]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("LargeObjectCAS: split a small tree", "[storage]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
auto const& cas = storage.CAS();
// Create a small tree:
@@ -124,10 +123,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
// the result from the LargeCAS, no actual split must occur.
// The object can be implicitly reconstructed from the LargeCAS.
template <ObjectType kType>
-static void TestLarge() noexcept {
+static void TestLarge(StorageConfig const& storage_config,
+ Storage const& storage) noexcept {
SECTION("Large") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
static constexpr bool kIsTree = IsTreeObject(kType);
static constexpr bool kIsExec = IsExecutableObject(kType);
@@ -174,8 +172,7 @@ static void TestLarge() noexcept {
SECTION("Uplinking") {
// Increment generation:
- CHECK(GarbageCollector::TriggerGarbageCollection(
- StorageConfig::Instance()));
+ CHECK(GarbageCollector::TriggerGarbageCollection(storage_config));
// Check implicit splice:
auto spliced_path =
@@ -191,19 +188,15 @@ static void TestLarge() noexcept {
CHECK_FALSE(FileSystemManager::IsFile(path));
// Call split with disabled uplinking:
- auto const youngest_storage =
- ::Generation::Create(&StorageConfig::Instance());
+ auto const youngest_storage = ::Generation::Create(&storage_config);
auto pack_3 = kIsTree ? youngest_storage.CAS().SplitTree(digest)
: youngest_storage.CAS().SplitBlob(digest);
REQUIRE(pack_3);
CHECK(pack_3->size() == pack_1->size());
// Check there are no spliced results in all generations:
- for (std::size_t i = 0;
- i < StorageConfig::Instance().NumGenerations();
- ++i) {
- auto const storage = ::Generation::Create(
- &StorageConfig::Instance(), /*generation=*/i);
+ for (std::size_t i = 0; i < storage_config.NumGenerations(); ++i) {
+ auto const storage = ::Generation::Create(&storage_config);
auto generation_path =
kIsTree ? storage.CAS().TreePath(digest)
: storage.CAS().BlobPath(digest, kIsExec);
@@ -218,10 +211,8 @@ static void TestLarge() noexcept {
// blob.
// The object cannot be implicitly reconstructed.
template <ObjectType kType>
-static void TestSmall() noexcept {
+static void TestSmall(Storage const& storage) noexcept {
SECTION("Small") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
static constexpr bool kIsTree = IsTreeObject(kType);
static constexpr bool kIsExec = IsExecutableObject(kType);
@@ -276,10 +267,8 @@ static void TestSmall() noexcept {
// empty.
// The object cannot be implicitly reconstructed.
template <ObjectType kType>
-static void TestEmpty() noexcept {
+static void TestEmpty(Storage const& storage) noexcept {
SECTION("Empty") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
static constexpr bool kIsTree = IsTreeObject(kType);
static constexpr bool kIsExec = IsExecutableObject(kType);
@@ -327,10 +316,9 @@ static void TestEmpty() noexcept {
// what was expected.
// 3. Explicit splice fails, if some parts of the tree are missing.
template <ObjectType kType>
-static void TestExternal() noexcept {
+static void TestExternal(StorageConfig const& storage_config,
+ Storage const& storage) noexcept {
SECTION("External") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
static constexpr bool kIsTree = IsTreeObject(kType);
static constexpr bool kIsExec = IsExecutableObject(kType);
@@ -354,14 +342,13 @@ static void TestExternal() noexcept {
// External source is emulated by moving the large entry to an older
// generation and promoting the parts of the entry to the youngest
// generation:
- REQUIRE(GarbageCollector::TriggerGarbageCollection(
- StorageConfig::Instance()));
+ REQUIRE(GarbageCollector::TriggerGarbageCollection(storage_config));
for (auto const& part : *pack_1) {
static constexpr bool is_executable = false;
REQUIRE(cas.BlobPath(part, is_executable));
}
- auto const youngest = ::Generation::Create(&StorageConfig::Instance());
+ auto const youngest = ::Generation::Create(&storage_config);
SECTION("Proper request") {
if constexpr (kIsTree) {
@@ -428,10 +415,9 @@ static void TestExternal() noexcept {
// the large CAS, they must be deleted during compactification.
// All splitable objects in the generation must be split.
template <ObjectType kType>
-static void TestCompactification() {
+static void TestCompactification(StorageConfig const& storage_config,
+ Storage const& storage) {
SECTION("Compactify") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
static constexpr bool kIsTree = IsTreeObject(kType);
static constexpr bool kIsExec = IsExecutableObject(kType);
@@ -478,7 +464,7 @@ static void TestCompactification() {
: cas.BlobPath(digest, kIsExec);
};
- auto const latest = ::Generation::Create(&StorageConfig::Instance());
+ auto const latest = ::Generation::Create(&storage_config);
REQUIRE(get_path(latest.CAS(), digest).has_value());
REQUIRE(get_path(latest.CAS(), digest_2).has_value());
@@ -487,8 +473,8 @@ static void TestCompactification() {
// Compactify the youngest generation:
// Generation rotation is disabled to exclude uplinking.
static constexpr bool kNoRotation = true;
- REQUIRE(GarbageCollector::TriggerGarbageCollection(
- StorageConfig::Instance(), kNoRotation));
+ REQUIRE(GarbageCollector::TriggerGarbageCollection(storage_config,
+ kNoRotation));
// All entries must be deleted during compactification, and for blobs
// and executables there are no synchronized entries in the storage:
@@ -502,29 +488,30 @@ static void TestCompactification() {
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalCAS: Split-Splice",
- "[storage]") {
+TEST_CASE("LocalCAS: Split-Splice", "[storage]") {
+ auto const config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&config.Get());
+
SECTION("File") {
- TestLarge<ObjectType::File>();
- TestSmall<ObjectType::File>();
- TestEmpty<ObjectType::File>();
- TestExternal<ObjectType::File>();
- TestCompactification<ObjectType::File>();
+ TestLarge<ObjectType::File>(config.Get(), storage);
+ TestSmall<ObjectType::File>(storage);
+ TestEmpty<ObjectType::File>(storage);
+ TestExternal<ObjectType::File>(config.Get(), storage);
+ TestCompactification<ObjectType::File>(config.Get(), storage);
}
SECTION("Tree") {
- TestLarge<ObjectType::Tree>();
- TestSmall<ObjectType::Tree>();
- TestEmpty<ObjectType::Tree>();
- TestExternal<ObjectType::Tree>();
- TestCompactification<ObjectType::Tree>();
+ TestLarge<ObjectType::Tree>(config.Get(), storage);
+ TestSmall<ObjectType::Tree>(storage);
+ TestEmpty<ObjectType::Tree>(storage);
+ TestExternal<ObjectType::Tree>(config.Get(), storage);
+ TestCompactification<ObjectType::Tree>(config.Get(), storage);
}
SECTION("Executable") {
- TestLarge<ObjectType::Executable>();
- TestSmall<ObjectType::Executable>();
- TestEmpty<ObjectType::Executable>();
- TestExternal<ObjectType::Executable>();
- TestCompactification<ObjectType::Executable>();
+ TestLarge<ObjectType::Executable>(config.Get(), storage);
+ TestSmall<ObjectType::Executable>(storage);
+ TestEmpty<ObjectType::Executable>(storage);
+ TestExternal<ObjectType::Executable>(config.Get(), storage);
+ TestCompactification<ObjectType::Executable>(config.Get(), storage);
}
}
@@ -540,11 +527,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
// All large entries are preliminarily split and the spliced results are
// deleted. The youngest generation is empty. Uplinking must restore the
// object(and it's parts) and uplink them properly.
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LargeObjectCAS: uplink nested large objects",
- "[storage]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
+TEST_CASE("LargeObjectCAS: uplink nested large objects", "[storage]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
auto const& cas = storage.CAS();
// Randomize a large directory:
@@ -596,8 +581,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
REQUIRE(FileSystemManager::RemoveFile(*large_tree_path));
// Rotate generations:
- REQUIRE(
- GarbageCollector::TriggerGarbageCollection(StorageConfig::Instance()));
+ REQUIRE(GarbageCollector::TriggerGarbageCollection(storage_config.Get()));
// Ask to splice the large tree:
auto result_path = cas.TreePath(*large_tree_digest);
@@ -610,7 +594,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
CHECK_FALSE(FileSystemManager::IsFile(*nested_tree_path));
CHECK_FALSE(FileSystemManager::IsFile(*nested_blob_path));
- auto const latest = ::Generation::Create(&StorageConfig::Instance());
+ auto const latest = ::Generation::Create(&storage_config.Get());
// However, they might be reconstructed on request because there entries are
// in the latest generation:
@@ -621,10 +605,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
REQUIRE(split_nested_blob_2);
// Check there are no spliced results in old generations:
- for (std::size_t i = 1; i < StorageConfig::Instance().NumGenerations();
- ++i) {
+ for (std::size_t i = 1; i < storage_config.Get().NumGenerations(); ++i) {
auto const storage =
- ::Generation::Create(&StorageConfig::Instance(), /*generation=*/i);
+ ::Generation::Create(&storage_config.Get(), /*generation=*/i);
auto const& generation_cas = storage.CAS();
REQUIRE_FALSE(generation_cas.TreePath(*nested_tree_digest));
REQUIRE_FALSE(generation_cas.TreePath(*large_tree_digest));
diff --git a/test/buildtool/storage/local_ac.test.cpp b/test/buildtool/storage/local_ac.test.cpp
index f2ca3a15..fdd8eec6 100644
--- a/test/buildtool/storage/local_ac.test.cpp
+++ b/test/buildtool/storage/local_ac.test.cpp
@@ -22,7 +22,7 @@
#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/storage.hpp"
-#include "test/utils/hermeticity/local.hpp"
+#include "test/utils/hermeticity/test_storage_config.hpp"
[[nodiscard]] static auto RunDummyExecution(
gsl::not_null<LocalAC<true> const*> const& ac,
@@ -30,11 +30,9 @@
bazel_re::Digest const& action_id,
std::string const& seed) -> bool;
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalAC: Single action, single result",
- "[storage]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
+TEST_CASE("LocalAC: Single action, single result", "[storage]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
auto const& ac = storage.ActionCache();
auto const& cas = storage.CAS();
@@ -45,11 +43,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
CHECK(ac_result);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalAC: Two different actions, two different results",
- "[storage]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
+TEST_CASE("LocalAC: Two different actions, two different results",
+ "[storage]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
auto const& ac = storage.ActionCache();
auto const& cas = storage.CAS();
@@ -76,11 +73,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
CHECK(result_content1 != result_content2);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalAC: Two different actions, same two results",
- "[storage]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
+TEST_CASE("LocalAC: Two different actions, same two results", "[storage]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
auto const& ac = storage.ActionCache();
auto const& cas = storage.CAS();
@@ -107,11 +102,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
CHECK(result_content1 == result_content2);
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalAC: Same two actions, two different results",
- "[storage]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
-
+TEST_CASE("LocalAC: Same two actions, two different results", "[storage]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
auto const& ac = storage.ActionCache();
auto const& cas = storage.CAS();
diff --git a/test/buildtool/storage/local_cas.test.cpp b/test/buildtool/storage/local_cas.test.cpp
index b64ee780..ef77a6a1 100644
--- a/test/buildtool/storage/local_cas.test.cpp
+++ b/test/buildtool/storage/local_cas.test.cpp
@@ -23,16 +23,15 @@
#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/storage.hpp"
#include "test/utils/blob_creator.hpp"
-#include "test/utils/hermeticity/local.hpp"
+#include "test/utils/hermeticity/test_storage_config.hpp"
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalCAS: Add blob to storage from bytes",
- "[storage]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("LocalCAS: Add blob to storage from bytes", "[storage]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+ auto const& cas = storage.CAS();
std::string test_bytes("test");
- auto const& cas = storage.CAS();
auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_bytes);
// check blob not in storage
@@ -74,15 +73,15 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalCAS: Add blob to storage from non-executable file",
- "[storage]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("LocalCAS: Add blob to storage from non-executable file",
+ "[storage]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+ auto const& cas = storage.CAS();
std::filesystem::path non_exec_file{
"test/buildtool/storage/data/non_executable_file"};
- auto const& cas = storage.CAS();
auto test_blob = CreateBlobFromPath(non_exec_file);
REQUIRE(test_blob);
@@ -125,15 +124,14 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
}
}
-TEST_CASE_METHOD(HermeticLocalTestFixture,
- "LocalCAS: Add blob to storage from executable file",
- "[storage]") {
- auto const storage = Storage::Create(&StorageConfig::Instance());
+TEST_CASE("LocalCAS: Add blob to storage from executable file", "[storage]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+ auto const& cas = storage.CAS();
std::filesystem::path exec_file{
"test/buildtool/storage/data/executable_file"};
- auto const& cas = storage.CAS();
auto test_blob = CreateBlobFromPath(exec_file);
REQUIRE(test_blob);
diff --git a/test/main.cpp b/test/main.cpp
index c0caa056..e2758638 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -18,7 +18,6 @@
#include "catch2/catch_session.hpp"
#include "src/buildtool/file_system/git_context.hpp"
-#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/file_chunker.hpp"
#include "test/utils/logging/log_config.hpp"
@@ -33,18 +32,6 @@ auto main(int argc, char* argv[]) -> int {
*/
GitContext::Create();
- /**
- * Test must not assume the existence of a home directory, nor write there.
- * Hence we set the storage root to a fixed location under TEST_TMPDIR which
- * is set by the test launcher.
- */
- auto setup_ok = StorageConfig::Instance().SetBuildRoot(
- std::filesystem::path{std::string{std::getenv("TEST_TMPDIR")}} /
- ".test_build_root");
- if (not setup_ok) {
- return 1;
- }
-
// Initialize random content of the file chunker's map.
FileChunker::Initialize();
diff --git a/test/other_tools/git_operations/TARGETS b/test/other_tools/git_operations/TARGETS
index 57603ecc..1fe6b492 100644
--- a/test/other_tools/git_operations/TARGETS
+++ b/test/other_tools/git_operations/TARGETS
@@ -39,6 +39,7 @@
, ["@", "src", "src/buildtool/storage", "config"]
, ["@", "src", "src/utils/cpp", "atomic"]
, ["utils", "shell_quoting"]
+ , ["utils", "test_storage_config"]
]
, "stage": ["test", "other_tools", "git_operations"]
}
diff --git a/test/other_tools/git_operations/git_repo_remote.test.cpp b/test/other_tools/git_operations/git_repo_remote.test.cpp
index 89bfad23..0844205d 100644
--- a/test/other_tools/git_operations/git_repo_remote.test.cpp
+++ b/test/other_tools/git_operations/git_repo_remote.test.cpp
@@ -29,6 +29,7 @@
#include "src/buildtool/storage/config.hpp"
#include "src/other_tools/git_operations/git_repo_remote.hpp"
#include "src/utils/cpp/atomic.hpp"
+#include "test/utils/hermeticity/test_storage_config.hpp"
#include "test/utils/shell_quoting.hpp"
namespace {
@@ -222,6 +223,8 @@ TEST_CASE("Single-threaded real repository remote operations",
}
TEST_CASE("Single-threaded fake repository operations", "[git_repo_remote]") {
+ auto const storage_config = TestStorageConfig::Create();
+
auto repo_path = TestUtils::CreateTestRepoWithCheckout();
REQUIRE(repo_path);
auto cas = GitCAS::Open(*repo_path);
@@ -251,7 +254,7 @@ TEST_CASE("Single-threaded fake repository operations", "[git_repo_remote]") {
*repo_fetch_all->CheckCommitExists(kRootCommit, logger));
// fetch all with base refspecs
- REQUIRE(repo_fetch_all->FetchViaTmpRepo(StorageConfig::Instance(),
+ REQUIRE(repo_fetch_all->FetchViaTmpRepo(storage_config.Get(),
*repo_path,
std::nullopt,
{},
@@ -275,14 +278,13 @@ TEST_CASE("Single-threaded fake repository operations", "[git_repo_remote]") {
*repo_fetch_wRefspec->CheckCommitExists(kRootCommit, logger));
// fetch all
- REQUIRE(
- repo_fetch_wRefspec->FetchViaTmpRepo(StorageConfig::Instance(),
- *repo_path,
- "master",
- {},
- "git",
- {},
- logger));
+ REQUIRE(repo_fetch_wRefspec->FetchViaTmpRepo(storage_config.Get(),
+ *repo_path,
+ "master",
+ {},
+ "git",
+ {},
+ logger));
// check commit is there after fetch
CHECK(*repo_fetch_wRefspec->CheckCommitExists(kRootCommit, logger));
@@ -296,14 +298,8 @@ TEST_CASE("Single-threaded fake repository operations", "[git_repo_remote]") {
REQUIRE(repo_commit_upd);
// do remote ls
- auto fetched_commit =
- repo_commit_upd->UpdateCommitViaTmpRepo(StorageConfig::Instance(),
- *repo_path,
- "master",
- {},
- "git",
- {},
- logger);
+ auto fetched_commit = repo_commit_upd->UpdateCommitViaTmpRepo(
+ storage_config.Get(), *repo_path, "master", {}, "git", {}, logger);
REQUIRE(fetched_commit);
CHECK(*fetched_commit == kRootCommit);
@@ -311,6 +307,8 @@ TEST_CASE("Single-threaded fake repository operations", "[git_repo_remote]") {
}
TEST_CASE("Multi-threaded fake repository operations", "[git_repo_remote]") {
+ auto const storage_config = TestStorageConfig::Create();
+
/*
Test all fake repository operations while being done in parallel.
They are supposed to be thread-safe, so no conflicts should exist.
@@ -349,8 +347,11 @@ TEST_CASE("Multi-threaded fake repository operations", "[git_repo_remote]") {
constexpr int NUM_CASES = 4;
for (int id{}; id < kNumThreads; ++id) {
threads.emplace_back(
- [&target_repo, &remote_repo_path, &logger, &starting_signal](
- int tid) {
+ [&storage_config,
+ &target_repo,
+ &remote_repo_path,
+ &logger,
+ &starting_signal](int tid) {
starting_signal.wait(false);
// cases based on thread number
switch (tid % NUM_CASES) {
@@ -364,7 +365,7 @@ TEST_CASE("Multi-threaded fake repository operations", "[git_repo_remote]") {
case 1: {
// fetch with base refspecs
CHECK(target_repo->FetchViaTmpRepo(
- StorageConfig::Instance(),
+ storage_config.Get(),
*remote_repo_path,
std::nullopt,
{},
@@ -375,7 +376,7 @@ TEST_CASE("Multi-threaded fake repository operations", "[git_repo_remote]") {
case 2: {
// fetch specific branch
CHECK(target_repo->FetchViaTmpRepo(
- StorageConfig::Instance(),
+ storage_config.Get(),
*remote_repo_path,
"master",
{},
@@ -387,7 +388,7 @@ TEST_CASE("Multi-threaded fake repository operations", "[git_repo_remote]") {
// do remote ls
auto fetched_commit =
target_repo->UpdateCommitViaTmpRepo(
- StorageConfig::Instance(),
+ storage_config.Get(),
*remote_repo_path,
"master",
{},
diff --git a/test/utils/TARGETS b/test/utils/TARGETS
index f1bcf8d0..266c4046 100644
--- a/test/utils/TARGETS
+++ b/test/utils/TARGETS
@@ -39,17 +39,16 @@
]
, "stage": ["test", "utils"]
}
-, "local_hermeticity":
+, "test_storage_config":
{ "type": ["@", "rules", "CC", "library"]
- , "name": ["local_hermeticity"]
- , "hdrs": ["hermeticity/local.hpp"]
+ , "name": ["test_storage_config"]
+ , "hdrs": ["hermeticity/test_storage_config.hpp"]
, "deps":
- [ ["@", "src", "src/buildtool/common", "common"]
- , ["@", "src", "src/buildtool/execution_api/local", "config"]
- , ["@", "src", "src/buildtool/execution_api/local", "local"]
- , ["@", "src", "src/buildtool/file_system", "file_system_manager"]
+ [ ["@", "gsl", "", "gsl"]
, ["@", "src", "src/buildtool/logging", "log_level"]
, ["@", "src", "src/buildtool/logging", "logging"]
+ , ["@", "src", "src/buildtool/storage", "config"]
+ , ["@", "src", "src/utils/cpp", "tmp_dir"]
]
, "stage": ["test", "utils"]
}
@@ -73,7 +72,6 @@
, ["@", "src", "src/buildtool/execution_api/remote", "config"]
, ["@", "src", "src/buildtool/logging", "log_level"]
, ["@", "src", "src/buildtool/logging", "logging"]
- , ["@", "src", "src/buildtool/storage", "config"]
, ["@", "src", "src/buildtool/file_system", "git_context"]
, ["@", "src", "src/buildtool/file_system", "file_system_manager"]
, ["@", "src", "src/buildtool/compatibility", "compatibility"]
diff --git a/test/utils/hermeticity/local.hpp b/test/utils/hermeticity/local.hpp
deleted file mode 100644
index a547e59e..00000000
--- a/test/utils/hermeticity/local.hpp
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef INCLUDED_SRC_TEST_UTILS_HERMETICITY_LOCAL_HPP
-#define INCLUDED_SRC_TEST_UTILS_HERMETICITY_LOCAL_HPP
-
-#include <cstdlib>
-
-#include "src/buildtool/common/statistics.hpp"
-#include "src/buildtool/file_system/file_system_manager.hpp"
-#include "src/buildtool/logging/log_level.hpp"
-#include "src/buildtool/logging/logger.hpp"
-#include "src/buildtool/storage/config.hpp"
-#include "src/buildtool/storage/storage.hpp"
-
-class HermeticLocalTestFixture {
- public:
- HermeticLocalTestFixture() noexcept {
- static int id{};
- CreateAndSetCleanDiskCache(id++);
- }
-
- private:
- static void CreateAndSetCleanDiskCache(int case_id) {
- auto test_dir = FileSystemManager::GetCurrentDirectory();
- auto case_dir = test_dir / "tmp" / ("case_" + std::to_string(case_id));
-
- if (FileSystemManager::RemoveDirectory(case_dir, true) and
- FileSystemManager::CreateDirectoryExclusive(case_dir) and
- StorageConfig::Instance().SetBuildRoot(case_dir)) {
- // After the build root has been changed, the file roots of the
- // static storage instances need to be updated.
- Logger::Log(LogLevel::Debug,
- "created test-local cache dir {}",
- case_dir.string());
- }
- else {
- Logger::Log(LogLevel::Error,
- "failed to create a test-local cache dir {}",
- case_dir.string());
- std::exit(EXIT_FAILURE);
- }
- }
-};
-
-#endif // INCLUDED_SRC_TEST_UTILS_HERMETICITY_LOCAL_HPP
diff --git a/test/utils/hermeticity/test_storage_config.hpp b/test/utils/hermeticity/test_storage_config.hpp
new file mode 100644
index 00000000..e2906ad1
--- /dev/null
+++ b/test/utils/hermeticity/test_storage_config.hpp
@@ -0,0 +1,71 @@
+// Copyright 2024 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef INCLUDED_SRC_TEST_UTILS_HERMETICITY_TEST_STORAGE_CONFIG_HPP
+#define INCLUDED_SRC_TEST_UTILS_HERMETICITY_TEST_STORAGE_CONFIG_HPP
+
+#include <cstdlib> //std::exit, std::getenv
+#include <filesystem>
+#include <string>
+#include <utility> //std::move
+
+#include "gsl/gsl"
+#include "src/buildtool/logging/log_level.hpp"
+#include "src/buildtool/logging/logger.hpp"
+#include "src/buildtool/storage/config.hpp"
+#include "src/utils/cpp/tmp_dir.hpp"
+
+class TestStorageConfig final {
+ public:
+ /// \brief Create a unique StorageConfig that has the build root in a new
+ /// empty location. Uses TEST_TMPDIR environment variable to determine path
+ /// to the location.
+ [[nodiscard]] static auto Create() noexcept -> TestStorageConfig {
+ /**
+ * Test must not assume the existence of a home directory, nor write
+ * there. Hence we set the storage root to a fixed location under
+ * TEST_TMPDIR which is set by the test launcher.
+ */
+ auto const test_tempdir =
+ std::filesystem::path{std::string{std::getenv("TEST_TMPDIR")}} /
+ ".test_build_root";
+
+ StorageConfig config = StorageConfig::Instance();
+ auto temp_dir = TmpDir::Create(test_tempdir);
+ if (temp_dir == nullptr or
+ not config.SetBuildRoot(temp_dir->GetPath())) {
+ Logger::Log(LogLevel::Error,
+ "failed to create a test-local cache dir");
+ std::exit(EXIT_FAILURE);
+ }
+ Logger::Log(LogLevel::Debug,
+ "created test-local cache dir {}",
+ temp_dir->GetPath().string());
+ return TestStorageConfig{std::move(temp_dir), std::move(config)};
+ }
+
+ [[nodiscard]] auto Get() const noexcept -> StorageConfig const& {
+ return storage_config_;
+ }
+
+ private:
+ gsl::not_null<TmpDirPtr> const tmp_dir_;
+ StorageConfig const storage_config_;
+
+ explicit TestStorageConfig(gsl::not_null<TmpDirPtr> const& tmp_dir,
+ StorageConfig config) noexcept
+ : tmp_dir_{tmp_dir}, storage_config_{std::move(config)} {}
+};
+
+#endif // INCLUDED_SRC_TEST_UTILS_HERMETICITY_TEST_STORAGE_CONFIG_HPP
diff --git a/test/utils/remote_execution/main-remote-execution.cpp b/test/utils/remote_execution/main-remote-execution.cpp
index a691860a..091a8038 100644
--- a/test/utils/remote_execution/main-remote-execution.cpp
+++ b/test/utils/remote_execution/main-remote-execution.cpp
@@ -27,7 +27,6 @@
#include "src/buildtool/file_system/git_context.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
-#include "src/buildtool/storage/config.hpp"
#include "test/utils/logging/log_config.hpp"
#include "test/utils/remote_execution/test_auth_config.hpp"
#include "test/utils/test_env.hpp"
@@ -68,24 +67,11 @@ void wait_for_grpc_to_shutdown() {
return static_cast<bool>(RemoteExecutionConfig::RemoteAddress());
}
-[[nodiscard]] auto ConfigureBuildRoot() -> bool {
- auto cache_dir = FileSystemManager::GetCurrentDirectory() / "cache";
- if (not FileSystemManager::CreateDirectoryExclusive(cache_dir) or
- not StorageConfig::Instance().SetBuildRoot(cache_dir)) {
- return false;
- }
- return true;
-}
-
} // namespace
auto main(int argc, char* argv[]) -> int {
ConfigureLogging();
- if (not ConfigureBuildRoot()) {
- return EXIT_FAILURE;
- }
-
if (not ConfigureRemoteExecution()) {
return EXIT_FAILURE;
}