summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-07-29 12:49:31 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-07-30 12:10:06 +0200
commit35fe9c1e07464de85ea8138c574c0bc7d07c5a48 (patch)
treee4492c243a867ba593826b25f7f73a389d4e883d /test
parentb393090c220da61dd1c197adfac42dc47ad74f8a (diff)
downloadjustbuild-35fe9c1e07464de85ea8138c574c0bc7d07c5a48.tar.gz
executor: Use ApiBundle
...instead of separate local and remote instances. For tests, where different implementations of the IExecutionApi interface are used, ApiBundle instances are created by explicitly setting the struct fields instead of using ApiBundle::Create.
Diffstat (limited to 'test')
-rw-r--r--test/buildtool/execution_engine/executor/TARGETS2
-rw-r--r--test/buildtool/execution_engine/executor/executor.test.cpp37
-rw-r--r--test/buildtool/execution_engine/executor/executor_api.test.hpp51
-rw-r--r--test/utils/TARGETS12
-rw-r--r--test/utils/executor/test_api_bundle.hpp35
5 files changed, 88 insertions, 49 deletions
diff --git a/test/buildtool/execution_engine/executor/TARGETS b/test/buildtool/execution_engine/executor/TARGETS
index ef01b6fc..ab257156 100644
--- a/test/buildtool/execution_engine/executor/TARGETS
+++ b/test/buildtool/execution_engine/executor/TARGETS
@@ -17,6 +17,7 @@
, ["@", "src", "src/buildtool/compatibility", "compatibility"]
, ["@", "catch2", "", "catch2"]
, ["@", "gsl", "", "gsl"]
+ , ["utils", "test_api_bundle"]
, ["utils", "test_remote_config"]
]
, "stage": ["test", "buildtool", "execution_engine", "executor"]
@@ -42,6 +43,7 @@
, ["", "catch-main"]
, ["@", "catch2", "", "catch2"]
, ["@", "gsl", "", "gsl"]
+ , ["utils", "test_api_bundle"]
]
, "stage": ["test", "buildtool", "execution_engine", "executor"]
}
diff --git a/test/buildtool/execution_engine/executor/executor.test.cpp b/test/buildtool/execution_engine/executor/executor.test.cpp
index 2e8a03aa..15752c94 100644
--- a/test/buildtool/execution_engine/executor/executor.test.cpp
+++ b/test/buildtool/execution_engine/executor/executor.test.cpp
@@ -35,6 +35,7 @@
#include "src/buildtool/execution_engine/executor/executor.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/progress_reporting/progress.hpp"
+#include "test/utils/executor/test_api_bundle.hpp"
/// \brief Mockup API test config.
struct TestApiConfig {
@@ -296,9 +297,9 @@ TEST_CASE("Executor: Process artifact", "[executor]") {
RemoteContext const remote_context{.auth = &auth,
.retry_config = &retry_config,
.exec_config = &remote_config};
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{&repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
&stats,
@@ -320,9 +321,9 @@ TEST_CASE("Executor: Process artifact", "[executor]") {
RemoteContext const remote_context{.auth = &auth,
.retry_config = &retry_config,
.exec_config = &remote_config};
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{&repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
&stats,
@@ -344,9 +345,9 @@ TEST_CASE("Executor: Process artifact", "[executor]") {
RemoteContext const remote_context{.auth = &auth,
.retry_config = &retry_config,
.exec_config = &remote_config};
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{&repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
&stats,
@@ -393,9 +394,9 @@ TEST_CASE("Executor: Process action", "[executor]") {
RemoteContext const remote_context{.auth = &auth,
.retry_config = &retry_config,
.exec_config = &remote_config};
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{&repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
&stats,
@@ -420,9 +421,9 @@ TEST_CASE("Executor: Process action", "[executor]") {
RemoteContext const remote_context{.auth = &auth,
.retry_config = &retry_config,
.exec_config = &remote_config};
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{&repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
&stats,
@@ -447,9 +448,9 @@ TEST_CASE("Executor: Process action", "[executor]") {
RemoteContext const remote_context{.auth = &auth,
.retry_config = &retry_config,
.exec_config = &remote_config};
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{&repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
&stats,
@@ -477,9 +478,9 @@ TEST_CASE("Executor: Process action", "[executor]") {
RemoteContext const remote_context{.auth = &auth,
.retry_config = &retry_config,
.exec_config = &remote_config};
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{&repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
&stats,
@@ -504,9 +505,9 @@ TEST_CASE("Executor: Process action", "[executor]") {
RemoteContext const remote_context{.auth = &auth,
.retry_config = &retry_config,
.exec_config = &remote_config};
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{&repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
&stats,
@@ -534,9 +535,9 @@ TEST_CASE("Executor: Process action", "[executor]") {
RemoteContext const remote_context{.auth = &auth,
.retry_config = &retry_config,
.exec_config = &remote_config};
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{&repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
&stats,
diff --git a/test/buildtool/execution_engine/executor/executor_api.test.hpp b/test/buildtool/execution_engine/executor/executor_api.test.hpp
index 7bbc9d8f..bef97e85 100644
--- a/test/buildtool/execution_engine/executor/executor_api.test.hpp
+++ b/test/buildtool/execution_engine/executor/executor_api.test.hpp
@@ -38,6 +38,7 @@
#include "src/buildtool/execution_engine/executor/executor.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/progress_reporting/progress.hpp"
+#include "test/utils/executor/test_api_bundle.hpp"
#include "test/utils/remote_execution/test_remote_config.hpp"
using ApiFactory = std::function<IExecutionApi::Ptr()>;
@@ -147,13 +148,9 @@ static inline void RunHelloWorldCompilation(
: HashFunction::Type::GitSHA1};
auto api = factory();
- Executor runner{repo_config,
- api.get(),
- api.get(),
- &remote_context,
- hash_function,
- stats,
- progress};
+ auto const apis = CreateTestApiBundle(hash_function, api);
+ Executor runner{
+ repo_config, &apis, &remote_context, hash_function, stats, progress};
// upload local artifacts
auto const* main_cpp_node = g.ArtifactNodeWithId(main_cpp_id);
@@ -281,13 +278,9 @@ static inline void RunGreeterCompilation(
: HashFunction::Type::GitSHA1};
auto api = factory();
- Executor runner{repo_config,
- api.get(),
- api.get(),
- &remote_context,
- hash_function,
- stats,
- progress};
+ auto const apis = CreateTestApiBundle(hash_function, api);
+ Executor runner{
+ repo_config, &apis, &remote_context, hash_function, stats, progress};
// upload local artifacts
for (auto const& id : {greet_hpp_id, greet_cpp_id, main_cpp_id}) {
@@ -455,13 +448,9 @@ static inline void TestUploadAndDownloadTrees(
.retry_config = &retry_config,
.exec_config = &*remote_config};
- Executor runner{repo_config,
- api.get(),
- api.get(),
- &remote_context,
- hash_function,
- stats,
- progress};
+ auto const apis = CreateTestApiBundle(hash_function, api);
+ Executor runner{
+ repo_config, &apis, &remote_context, hash_function, stats, progress};
REQUIRE(runner.Process(g.ArtifactNodeWithId(foo_id)));
REQUIRE(runner.Process(g.ArtifactNodeWithId(bar_id)));
@@ -630,9 +619,9 @@ static inline void TestRetrieveOutputDirectories(
// run action
auto api = factory();
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
stats,
@@ -683,9 +672,9 @@ static inline void TestRetrieveOutputDirectories(
// run action
auto api = factory();
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
stats,
@@ -753,9 +742,9 @@ static inline void TestRetrieveOutputDirectories(
// run action
auto api = factory();
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
stats,
@@ -825,9 +814,9 @@ static inline void TestRetrieveOutputDirectories(
// run action
auto api = factory();
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
stats,
@@ -850,9 +839,9 @@ static inline void TestRetrieveOutputDirectories(
// run action
auto api = factory();
+ auto const apis = CreateTestApiBundle(hash_function, api);
Executor runner{repo_config,
- api.get(),
- api.get(),
+ &apis,
&remote_context,
hash_function,
stats,
diff --git a/test/utils/TARGETS b/test/utils/TARGETS
index dd16466a..8a8aea6c 100644
--- a/test/utils/TARGETS
+++ b/test/utils/TARGETS
@@ -170,6 +170,18 @@
, ["@", "src", "src/buildtool/crypto", "hash_function"]
]
}
+, "test_api_bundle":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["test_api_bundle"]
+ , "hdrs": ["executor/test_api_bundle.hpp"]
+ , "stage": ["test", "utils"]
+ , "deps":
+ [ ["@", "gsl", "", "gsl"]
+ , ["@", "src", "src/buildtool/crypto", "hash_function"]
+ , ["@", "src", "src/buildtool/execution_api/common", "api_bundle"]
+ , ["@", "src", "src/buildtool/execution_api/common", "common"]
+ ]
+ }
, "TESTS":
{ "type": "install"
, "tainted": ["test"]
diff --git a/test/utils/executor/test_api_bundle.hpp b/test/utils/executor/test_api_bundle.hpp
new file mode 100644
index 00000000..1b582ce6
--- /dev/null
+++ b/test/utils/executor/test_api_bundle.hpp
@@ -0,0 +1,35 @@
+// 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_EXECUTOR_TEST_API_BUNDLE_HPP
+#define INCLUDED_SRC_TEST_UTILS_EXECUTOR_TEST_API_BUNDLE_HPP
+
+#include <utility> // std::move
+
+#include "gsl/gsl"
+#include "src/buildtool/crypto/hash_function.hpp"
+#include "src/buildtool/execution_api/common/api_bundle.hpp"
+#include "src/buildtool/execution_api/common/execution_api.hpp"
+
+/// \brief Creates an ApiBundle that contains a given IExecutionApi
+/// implementation. As only the hash_function field is actually needed, the
+/// remote_context and repo_config are not needed to be provided.
+[[nodiscard]] static auto CreateTestApiBundle(
+ HashFunction hash_function,
+ gsl::not_null<IExecutionApi::Ptr> const& api) noexcept -> ApiBundle {
+ return ApiBundle{
+ .hash_function = hash_function, .local = api, .remote = api};
+}
+
+#endif // INCLUDED_SRC_TEST_UTILS_EXECUTOR_TEST_API_BUNDLE_HPP