diff options
Diffstat (limited to 'test/buildtool/execution_engine/executor')
5 files changed, 122 insertions, 63 deletions
diff --git a/test/buildtool/execution_engine/executor/TARGETS b/test/buildtool/execution_engine/executor/TARGETS index a3e97d89..991cecc3 100644 --- a/test/buildtool/execution_engine/executor/TARGETS +++ b/test/buildtool/execution_engine/executor/TARGETS @@ -10,6 +10,7 @@ , "srcs": ["executor.test.cpp"] , "private-deps": [ ["@", "src", "src/buildtool/common", "artifact_factory"] + , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/execution_api/common", "common"] , ["@", "src", "src/buildtool/execution_engine/dag", "dag"] , ["@", "src", "src/buildtool/execution_engine/executor", "executor"] @@ -26,6 +27,7 @@ , "private-deps": [ "executor_api_tests" , ["@", "src", "src/buildtool/common", "artifact_factory"] + , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/execution_api/local", "local"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/execution_engine/dag", "dag"] @@ -44,6 +46,7 @@ , "private-deps": [ "executor_api_tests" , ["@", "src", "src/buildtool/common", "artifact_factory"] + , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/execution_engine/executor", "executor"] diff --git a/test/buildtool/execution_engine/executor/executor.test.cpp b/test/buildtool/execution_engine/executor/executor.test.cpp index 0df8bd0f..55417016 100644 --- a/test/buildtool/execution_engine/executor/executor.test.cpp +++ b/test/buildtool/execution_engine/executor/executor.test.cpp @@ -18,6 +18,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_factory.hpp" +#include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/execution_engine/executor/executor.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" @@ -205,17 +206,18 @@ class TestApi : public IExecutionApi { TestApiConfig config_{}; }; -static void SetupConfig(std::filesystem::path const& ws) { +[[nodiscard]] auto SetupConfig(std::filesystem::path const& ws) + -> RepositoryConfig { auto info = RepositoryConfig::RepositoryInfo{FileRoot{ws}}; - RepositoryConfig::Instance().Reset(); - RepositoryConfig::Instance().SetInfo("", std::move(info)); + RepositoryConfig repo_config{}; + repo_config.SetInfo("", std::move(info)); + return repo_config; } [[nodiscard]] static auto CreateTest(gsl::not_null<DependencyGraph*> const& g, std::filesystem::path const& ws) - -> TestApiConfig { + -> std::pair<TestApiConfig, RepositoryConfig> { using path = std::filesystem::path; - SetupConfig(ws); auto const local_cpp_desc = ArtifactDescription{path{"local.cpp"}, ""}; auto const known_cpp_desc = ArtifactDescription{ @@ -243,14 +245,14 @@ static void SetupConfig(std::filesystem::path const& ws) { config.response.cached = true; config.response.exit_code = 0; - return config; + return std::make_pair(config, SetupConfig(ws)); } TEST_CASE("Executor: Process artifact", "[executor]") { std::filesystem::path workspace_path{ "test/buildtool/execution_engine/executor"}; DependencyGraph g; - auto config = CreateTest(&g, workspace_path); + auto [config, repo_config] = CreateTest(&g, workspace_path); auto const local_cpp_desc = ArtifactFactory::DescribeLocalArtifact("local.cpp", ""); @@ -262,7 +264,7 @@ TEST_CASE("Executor: Process artifact", "[executor]") { SECTION("Processing succeeds for valid config") { auto api = TestApi::Ptr{new TestApi{config}}; - Executor runner{api.get(), api.get(), {}}; + Executor runner{&repo_config, api.get(), api.get(), {}}; CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id))); CHECK(runner.Process(g.ArtifactNodeWithId(known_cpp_id))); @@ -272,7 +274,7 @@ TEST_CASE("Executor: Process artifact", "[executor]") { config.artifacts["local.cpp"].uploads = false; auto api = TestApi::Ptr{new TestApi{config}}; - Executor runner{api.get(), api.get(), {}}; + Executor runner{&repo_config, api.get(), api.get(), {}}; CHECK(not runner.Process(g.ArtifactNodeWithId(local_cpp_id))); CHECK(runner.Process(g.ArtifactNodeWithId(known_cpp_id))); @@ -282,7 +284,7 @@ TEST_CASE("Executor: Process artifact", "[executor]") { config.artifacts["known.cpp"].available = false; auto api = TestApi::Ptr{new TestApi{config}}; - Executor runner{api.get(), api.get(), {}}; + Executor runner{&repo_config, api.get(), api.get(), {}}; CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id))); CHECK(not runner.Process(g.ArtifactNodeWithId(known_cpp_id))); @@ -294,7 +296,7 @@ TEST_CASE("Executor: Process action", "[executor]") { "test/buildtool/execution_engine/executor"}; DependencyGraph g; - auto config = CreateTest(&g, workspace_path); + auto [config, repo_config] = CreateTest(&g, workspace_path); auto const local_cpp_desc = ArtifactFactory::DescribeLocalArtifact("local.cpp", ""); @@ -315,7 +317,7 @@ TEST_CASE("Executor: Process action", "[executor]") { SECTION("Processing succeeds for valid config") { auto api = TestApi::Ptr{new TestApi{config}}; - Executor runner{api.get(), api.get(), {}}; + Executor runner{&repo_config, api.get(), api.get(), {}}; CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id))); CHECK(runner.Process(g.ArtifactNodeWithId(known_cpp_id))); @@ -328,7 +330,7 @@ TEST_CASE("Executor: Process action", "[executor]") { config.response.cached = false; auto api = TestApi::Ptr{new TestApi{config}}; - Executor runner{api.get(), api.get(), {}}; + Executor runner{&repo_config, api.get(), api.get(), {}}; CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id))); CHECK(runner.Process(g.ArtifactNodeWithId(known_cpp_id))); @@ -341,7 +343,7 @@ TEST_CASE("Executor: Process action", "[executor]") { config.artifacts["output2.exe"].available = false; auto api = TestApi::Ptr{new TestApi{config}}; - Executor runner{api.get(), api.get(), {}}; + Executor runner{&repo_config, api.get(), api.get(), {}}; CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id))); CHECK(runner.Process(g.ArtifactNodeWithId(known_cpp_id))); @@ -357,7 +359,7 @@ TEST_CASE("Executor: Process action", "[executor]") { config.execution.failed = true; auto api = TestApi::Ptr{new TestApi{config}}; - Executor runner{api.get(), api.get(), {}}; + Executor runner{&repo_config, api.get(), api.get(), {}}; CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id))); CHECK(runner.Process(g.ArtifactNodeWithId(known_cpp_id))); @@ -370,7 +372,7 @@ TEST_CASE("Executor: Process action", "[executor]") { config.response.exit_code = 1; auto api = TestApi::Ptr{new TestApi{config}}; - Executor runner{api.get(), api.get(), {}}; + Executor runner{&repo_config, api.get(), api.get(), {}}; CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id))); CHECK(runner.Process(g.ArtifactNodeWithId(known_cpp_id))); @@ -386,7 +388,7 @@ TEST_CASE("Executor: Process action", "[executor]") { config.execution.outputs = {"output1.exe" /*, "output2.exe"*/}; auto api = TestApi::Ptr{new TestApi{config}}; - Executor runner{api.get(), api.get(), {}}; + Executor runner{&repo_config, api.get(), api.get(), {}}; CHECK(runner.Process(g.ArtifactNodeWithId(local_cpp_id))); CHECK(runner.Process(g.ArtifactNodeWithId(known_cpp_id))); diff --git a/test/buildtool/execution_engine/executor/executor_api.test.hpp b/test/buildtool/execution_engine/executor/executor_api.test.hpp index bd02e0fb..85b19911 100755 --- a/test/buildtool/execution_engine/executor/executor_api.test.hpp +++ b/test/buildtool/execution_engine/executor/executor_api.test.hpp @@ -21,6 +21,7 @@ #include "src/buildtool/common/artifact.hpp" #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/common/artifact_factory.hpp" +#include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/execution_engine/dag/dag.hpp" @@ -30,14 +31,16 @@ using ApiFactory = std::function<IExecutionApi::Ptr()>; -static inline void SetupConfig() { +static inline void SetupConfig(RepositoryConfig* repo_config) { auto info = RepositoryConfig::RepositoryInfo{FileRoot{ std::filesystem::path{"test/buildtool/execution_engine/executor"}}}; - RepositoryConfig::Instance().SetInfo("", std::move(info)); + repo_config->Reset(); + repo_config->SetInfo("", std::move(info)); } -static inline void RunBlobUpload(ApiFactory const& factory) { - SetupConfig(); +static inline void RunBlobUpload(RepositoryConfig* repo_config, + ApiFactory const& factory) { + SetupConfig(repo_config); auto api = factory(); std::string const blob = "test"; CHECK(api->Upload(BlobContainer{{BazelBlob{ @@ -77,12 +80,13 @@ template <class Executor> return tree_artifact->Content().Info(); } -static inline void RunHelloWorldCompilation(ApiFactory const& factory, +static inline void RunHelloWorldCompilation(RepositoryConfig* repo_config, + ApiFactory const& factory, bool is_hermetic = true, int expected_queued = 0, int expected_cached = 0) { using path = std::filesystem::path; - SetupConfig(); + SetupConfig(repo_config); auto const main_cpp_desc = ArtifactDescription{path{"data/hello_world/main.cpp"}, ""}; auto const& main_cpp_id = main_cpp_desc.Id(); @@ -103,8 +107,10 @@ static inline void RunHelloWorldCompilation(ApiFactory const& factory, CHECK(g.ArtifactNodeWithId(exec_id)->HasBuilderAction()); auto api = factory(); - Executor runner{ - api.get(), api.get(), RemoteExecutionConfig::PlatformProperties()}; + Executor runner{repo_config, + api.get(), + api.get(), + RemoteExecutionConfig::PlatformProperties()}; // upload local artifacts auto const* main_cpp_node = g.ArtifactNodeWithId(main_cpp_id); @@ -132,13 +138,14 @@ static inline void RunHelloWorldCompilation(ApiFactory const& factory, } } -static inline void RunGreeterCompilation(ApiFactory const& factory, +static inline void RunGreeterCompilation(RepositoryConfig* repo_config, + ApiFactory const& factory, std::string const& greetcpp, bool is_hermetic = true, int expected_queued = 0, int expected_cached = 0) { using path = std::filesystem::path; - SetupConfig(); + SetupConfig(repo_config); auto const greet_hpp_desc = ArtifactDescription{path{"data/greeter/greet.hpp"}, ""}; auto const& greet_hpp_id = greet_hpp_desc.Id(); @@ -206,8 +213,10 @@ static inline void RunGreeterCompilation(ApiFactory const& factory, CHECK(g.Add({compile_greet_desc, make_lib_desc, make_exe_desc})); auto api = factory(); - Executor runner{ - api.get(), api.get(), RemoteExecutionConfig::PlatformProperties()}; + Executor runner{repo_config, + api.get(), + api.get(), + RemoteExecutionConfig::PlatformProperties()}; // upload local artifacts for (auto const& id : {greet_hpp_id, greet_cpp_id, main_cpp_id}) { @@ -241,52 +250,65 @@ static inline void RunGreeterCompilation(ApiFactory const& factory, } } -[[maybe_unused]] static void TestBlobUpload(ApiFactory const& factory) { - SetupConfig(); +[[maybe_unused]] static void TestBlobUpload(RepositoryConfig* repo_config, + ApiFactory const& factory) { + SetupConfig(repo_config); // NOLINTNEXTLINE - RunBlobUpload(factory); + RunBlobUpload(repo_config, factory); } [[maybe_unused]] static void TestHelloWorldCompilation( + RepositoryConfig* repo_config, ApiFactory const& factory, bool is_hermetic = true) { - SetupConfig(); + SetupConfig(repo_config); // expecting 1 action queued, 0 results from cache // NOLINTNEXTLINE - RunHelloWorldCompilation(factory, is_hermetic, 1, 0); + RunHelloWorldCompilation(repo_config, factory, is_hermetic, 1, 0); SECTION("Running same compilation again") { // expecting 2 actions queued, 1 result from cache // NOLINTNEXTLINE - RunHelloWorldCompilation(factory, is_hermetic, 2, 1); + RunHelloWorldCompilation(repo_config, factory, is_hermetic, 2, 1); } } -[[maybe_unused]] static void TestGreeterCompilation(ApiFactory const& factory, - bool is_hermetic = true) { - SetupConfig(); +[[maybe_unused]] static void TestGreeterCompilation( + RepositoryConfig* repo_config, + ApiFactory const& factory, + bool is_hermetic = true) { + SetupConfig(repo_config); // expecting 3 action queued, 0 results from cache // NOLINTNEXTLINE - RunGreeterCompilation(factory, "greet.cpp", is_hermetic, 3, 0); + RunGreeterCompilation(repo_config, factory, "greet.cpp", is_hermetic, 3, 0); SECTION("Running same compilation again") { // expecting 6 actions queued, 3 results from cache - // NOLINTNEXTLINE - RunGreeterCompilation(factory, "greet.cpp", is_hermetic, 6, 3); + RunGreeterCompilation(repo_config, + factory, + "greet.cpp", + is_hermetic, + 6, // NOLINT + 3); } SECTION("Running modified compilation") { // expecting 6 actions queued, 2 results from cache - // NOLINTNEXTLINE - RunGreeterCompilation(factory, "greet_mod.cpp", is_hermetic, 6, 2); + RunGreeterCompilation(repo_config, + factory, + "greet_mod.cpp", + is_hermetic, + 6, // NOLINT + 2); } } -static inline void TestUploadAndDownloadTrees(ApiFactory const& factory, +static inline void TestUploadAndDownloadTrees(RepositoryConfig* repo_config, + ApiFactory const& factory, bool /*is_hermetic*/ = true, int /*expected_queued*/ = 0, int /*expected_cached*/ = 0) { - SetupConfig(); + SetupConfig(repo_config); auto tmpdir = GetTestDir(); auto foo = std::string{"foo"}; @@ -314,8 +336,10 @@ static inline void TestUploadAndDownloadTrees(ApiFactory const& factory, auto foo_id = g.AddArtifact(foo_desc); auto bar_id = g.AddArtifact(bar_desc); - Executor runner{ - api.get(), api.get(), RemoteExecutionConfig::PlatformProperties()}; + Executor runner{repo_config, + api.get(), + api.get(), + RemoteExecutionConfig::PlatformProperties()}; REQUIRE(runner.Process(g.ArtifactNodeWithId(foo_id))); REQUIRE(runner.Process(g.ArtifactNodeWithId(bar_id))); @@ -415,11 +439,12 @@ static inline void TestUploadAndDownloadTrees(ApiFactory const& factory, } } -static inline void TestRetrieveOutputDirectories(ApiFactory const& factory, +static inline void TestRetrieveOutputDirectories(RepositoryConfig* repo_config, + ApiFactory const& factory, bool /*is_hermetic*/ = true, int /*expected_queued*/ = 0, int /*expected_cached*/ = 0) { - SetupConfig(); + SetupConfig(repo_config); auto tmpdir = GetTestDir(); auto const make_tree_id = std::string{"make_tree"}; @@ -457,8 +482,10 @@ static inline void TestRetrieveOutputDirectories(ApiFactory const& factory, // run action auto api = factory(); - Executor runner{ - api.get(), api.get(), RemoteExecutionConfig::PlatformProperties()}; + Executor runner{repo_config, + api.get(), + api.get(), + RemoteExecutionConfig::PlatformProperties()}; REQUIRE(runner.Process(action)); // read output @@ -502,8 +529,10 @@ static inline void TestRetrieveOutputDirectories(ApiFactory const& factory, // run action auto api = factory(); - Executor runner{ - api.get(), api.get(), RemoteExecutionConfig::PlatformProperties()}; + Executor runner{repo_config, + api.get(), + api.get(), + RemoteExecutionConfig::PlatformProperties()}; REQUIRE(runner.Process(action)); // read output @@ -563,8 +592,10 @@ static inline void TestRetrieveOutputDirectories(ApiFactory const& factory, // run action auto api = factory(); - Executor runner{ - api.get(), api.get(), RemoteExecutionConfig::PlatformProperties()}; + Executor runner{repo_config, + api.get(), + api.get(), + RemoteExecutionConfig::PlatformProperties()}; REQUIRE(runner.Process(action)); // read output @@ -629,7 +660,8 @@ static inline void TestRetrieveOutputDirectories(ApiFactory const& factory, // run action auto api = factory(); - Executor runner{api.get(), + Executor runner{repo_config, + api.get(), api.get(), RemoteExecutionConfig::PlatformProperties()}; CHECK_FALSE(runner.Process(action)); @@ -649,7 +681,8 @@ static inline void TestRetrieveOutputDirectories(ApiFactory const& factory, // run action auto api = factory(); - Executor runner{api.get(), + Executor runner{repo_config, + api.get(), api.get(), RemoteExecutionConfig::PlatformProperties()}; CHECK_FALSE(runner.Process(action)); 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 3f5f2ac9..f196e98b 100755 --- a/test/buildtool/execution_engine/executor/executor_api_local.test.cpp +++ b/test/buildtool/execution_engine/executor/executor_api_local.test.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include "catch2/catch_test_macros.hpp" +#include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/execution_api/local/local_api.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/execution_engine/executor/executor.hpp" @@ -22,29 +23,39 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "Executor<LocalApi>: Upload blob", "[executor]") { - TestBlobUpload([&] { return std::make_unique<LocalApi>(); }); + RepositoryConfig repo_config{}; + TestBlobUpload(&repo_config, + [&] { return std::make_unique<LocalApi>(&repo_config); }); } TEST_CASE_METHOD(HermeticLocalTestFixture, "Executor<LocalApi>: Compile hello world", "[executor]") { - TestHelloWorldCompilation([&] { return std::make_unique<LocalApi>(); }); + RepositoryConfig repo_config{}; + TestHelloWorldCompilation( + &repo_config, [&] { return std::make_unique<LocalApi>(&repo_config); }); } TEST_CASE_METHOD(HermeticLocalTestFixture, "Executor<LocalApi>: Compile greeter", "[executor]") { - TestGreeterCompilation([&] { return std::make_unique<LocalApi>(); }); + RepositoryConfig repo_config{}; + TestGreeterCompilation( + &repo_config, [&] { return std::make_unique<LocalApi>(&repo_config); }); } TEST_CASE_METHOD(HermeticLocalTestFixture, "Executor<LocalApi>: Upload and download trees", "[executor]") { - TestUploadAndDownloadTrees([&] { return std::make_unique<LocalApi>(); }); + RepositoryConfig repo_config{}; + TestUploadAndDownloadTrees( + &repo_config, [&] { return std::make_unique<LocalApi>(&repo_config); }); } TEST_CASE_METHOD(HermeticLocalTestFixture, "Executor<LocalApi>: Retrieve output directories", "[executor]") { - TestRetrieveOutputDirectories([&] { return std::make_unique<LocalApi>(); }); + RepositoryConfig repo_config{}; + TestRetrieveOutputDirectories( + &repo_config, [&] { return std::make_unique<LocalApi>(&repo_config); }); } diff --git a/test/buildtool/execution_engine/executor/executor_api_remote_bazel.test.cpp b/test/buildtool/execution_engine/executor/executor_api_remote_bazel.test.cpp index fb34749f..4df56ec2 100755 --- a/test/buildtool/execution_engine/executor/executor_api_remote_bazel.test.cpp +++ b/test/buildtool/execution_engine/executor/executor_api_remote_bazel.test.cpp @@ -13,28 +13,32 @@ // limitations under the License. #include "catch2/catch_test_macros.hpp" +#include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/execution_api/remote/bazel/bazel_api.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/execution_engine/executor/executor.hpp" #include "test/buildtool/execution_engine/executor/executor_api.test.hpp" TEST_CASE("Executor<BazelApi>: Upload blob", "[executor]") { + RepositoryConfig repo_config{}; ExecutionConfiguration config; auto const& info = RemoteExecutionConfig::RemoteAddress(); - TestBlobUpload([&] { + TestBlobUpload(&repo_config, [&] { return BazelApi::Ptr{ new BazelApi{"remote-execution", info->host, info->port, config}}; }); } TEST_CASE("Executor<BazelApi>: Compile hello world", "[executor]") { + RepositoryConfig repo_config{}; ExecutionConfiguration config; config.skip_cache_lookup = false; auto const& info = RemoteExecutionConfig::RemoteAddress(); TestHelloWorldCompilation( + &repo_config, [&] { return BazelApi::Ptr{new BazelApi{ "remote-execution", info->host, info->port, config}}; @@ -43,12 +47,14 @@ TEST_CASE("Executor<BazelApi>: Compile hello world", "[executor]") { } TEST_CASE("Executor<BazelApi>: Compile greeter", "[executor]") { + RepositoryConfig repo_config{}; ExecutionConfiguration config; config.skip_cache_lookup = false; auto const& info = RemoteExecutionConfig::RemoteAddress(); TestGreeterCompilation( + &repo_config, [&] { return BazelApi::Ptr{new BazelApi{ "remote-execution", info->host, info->port, config}}; @@ -57,12 +63,14 @@ TEST_CASE("Executor<BazelApi>: Compile greeter", "[executor]") { } TEST_CASE("Executor<BazelApi>: Upload and download trees", "[executor]") { + RepositoryConfig repo_config{}; ExecutionConfiguration config; config.skip_cache_lookup = false; auto const& info = RemoteExecutionConfig::RemoteAddress(); TestUploadAndDownloadTrees( + &repo_config, [&] { return BazelApi::Ptr{new BazelApi{ "remote-execution", info->host, info->port, config}}; @@ -71,12 +79,14 @@ TEST_CASE("Executor<BazelApi>: Upload and download trees", "[executor]") { } TEST_CASE("Executor<BazelApi>: Retrieve output directories", "[executor]") { + RepositoryConfig repo_config{}; ExecutionConfiguration config; config.skip_cache_lookup = false; auto const& info = RemoteExecutionConfig::RemoteAddress(); TestRetrieveOutputDirectories( + &repo_config, [&] { return BazelApi::Ptr{new BazelApi{ "remote-execution", info->host, info->port, config}}; |