summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/buildtool/execution_api/bazel/bazel_api.test.cpp14
-rw-r--r--test/buildtool/execution_api/local/local_api.test.cpp14
-rwxr-xr-xtest/buildtool/execution_engine/executor/executor.test.cpp17
-rw-r--r--test/buildtool/execution_engine/traverser/traverser.test.cpp24
-rw-r--r--test/buildtool/graph_traverser/graph_traverser.test.hpp4
-rw-r--r--test/buildtool/logging/logger.test.cpp21
-rw-r--r--test/utils/container_matchers.hpp11
-rw-r--r--test/utils/hermeticity/local.hpp5
8 files changed, 58 insertions, 52 deletions
diff --git a/test/buildtool/execution_api/bazel/bazel_api.test.cpp b/test/buildtool/execution_api/bazel/bazel_api.test.cpp
index 952edcda..debce848 100644
--- a/test/buildtool/execution_api/bazel/bazel_api.test.cpp
+++ b/test/buildtool/execution_api/bazel/bazel_api.test.cpp
@@ -9,7 +9,7 @@
namespace {
-auto api_factory = []() {
+auto const kApiFactory = []() {
static auto const& server = RemoteExecutionConfig::Instance();
return IExecutionApi::Ptr{
new BazelApi{"remote-execution", server.Host(), server.Port(), {}}};
@@ -18,27 +18,27 @@ auto api_factory = []() {
} // namespace
TEST_CASE("BazelAPI: No input, no output", "[execution_api]") {
- TestNoInputNoOutput(api_factory, ReadPlatformPropertiesFromEnv());
+ TestNoInputNoOutput(kApiFactory, ReadPlatformPropertiesFromEnv());
}
TEST_CASE("BazelAPI: No input, create output", "[execution_api]") {
- TestNoInputCreateOutput(api_factory, ReadPlatformPropertiesFromEnv());
+ TestNoInputCreateOutput(kApiFactory, ReadPlatformPropertiesFromEnv());
}
TEST_CASE("BazelAPI: One input copied to output", "[execution_api]") {
- TestOneInputCopiedToOutput(api_factory, ReadPlatformPropertiesFromEnv());
+ TestOneInputCopiedToOutput(kApiFactory, ReadPlatformPropertiesFromEnv());
}
TEST_CASE("BazelAPI: Non-zero exit code, create output", "[execution_api]") {
- TestNonZeroExitCodeCreateOutput(api_factory,
+ TestNonZeroExitCodeCreateOutput(kApiFactory,
ReadPlatformPropertiesFromEnv());
}
TEST_CASE("BazelAPI: Retrieve two identical trees to path", "[execution_api]") {
TestRetrieveTwoIdenticalTreesToPath(
- api_factory, ReadPlatformPropertiesFromEnv(), "remote");
+ kApiFactory, ReadPlatformPropertiesFromEnv(), "remote");
}
TEST_CASE("BazelAPI: Create directory prior to execution", "[execution_api]") {
- TestCreateDirPriorToExecution(api_factory, ReadPlatformPropertiesFromEnv());
+ TestCreateDirPriorToExecution(kApiFactory, ReadPlatformPropertiesFromEnv());
}
diff --git a/test/buildtool/execution_api/local/local_api.test.cpp b/test/buildtool/execution_api/local/local_api.test.cpp
index 7ffd65fd..22563084 100644
--- a/test/buildtool/execution_api/local/local_api.test.cpp
+++ b/test/buildtool/execution_api/local/local_api.test.cpp
@@ -8,43 +8,43 @@
namespace {
-auto api_factory = []() { return IExecutionApi::Ptr{new LocalApi()}; };
+auto const kApiFactory = []() { return IExecutionApi::Ptr{new LocalApi()}; };
} // namespace
TEST_CASE_METHOD(HermeticLocalTestFixture,
"LocalAPI: No input, no output",
"[execution_api]") {
- TestNoInputNoOutput(api_factory, {}, /*is_hermetic=*/true);
+ TestNoInputNoOutput(kApiFactory, {}, /*is_hermetic=*/true);
}
TEST_CASE_METHOD(HermeticLocalTestFixture,
"LocalAPI: No input, create output",
"[execution_api]") {
- TestNoInputCreateOutput(api_factory, {}, /*is_hermetic=*/true);
+ TestNoInputCreateOutput(kApiFactory, {}, /*is_hermetic=*/true);
}
TEST_CASE_METHOD(HermeticLocalTestFixture,
"LocalAPI: One input copied to output",
"[execution_api]") {
- TestOneInputCopiedToOutput(api_factory, {}, /*is_hermetic=*/true);
+ TestOneInputCopiedToOutput(kApiFactory, {}, /*is_hermetic=*/true);
}
TEST_CASE_METHOD(HermeticLocalTestFixture,
"LocalAPI: Non-zero exit code, create output",
"[execution_api]") {
- TestNonZeroExitCodeCreateOutput(api_factory, {});
+ TestNonZeroExitCodeCreateOutput(kApiFactory, {});
}
TEST_CASE_METHOD(HermeticLocalTestFixture,
"LocalAPI: Retrieve two identical trees to path",
"[execution_api]") {
TestRetrieveTwoIdenticalTreesToPath(
- api_factory, {}, "local", /*is_hermetic=*/true);
+ kApiFactory, {}, "local", /*is_hermetic=*/true);
}
TEST_CASE_METHOD(HermeticLocalTestFixture,
"LocalAPI: Create directory prior to execution",
"[execution_api]") {
- TestCreateDirPriorToExecution(api_factory, {}, /*is_hermetic=*/true);
+ TestCreateDirPriorToExecution(kApiFactory, {}, /*is_hermetic=*/true);
}
diff --git a/test/buildtool/execution_engine/executor/executor.test.cpp b/test/buildtool/execution_engine/executor/executor.test.cpp
index 63f41521..beec0842 100755
--- a/test/buildtool/execution_engine/executor/executor.test.cpp
+++ b/test/buildtool/execution_engine/executor/executor.test.cpp
@@ -130,16 +130,13 @@ class TestApi : public IExecutionApi {
}
auto Upload(BlobContainer const& blobs, bool /*unused*/) noexcept
-> bool final {
- for (auto const& blob : blobs) {
- if (config_.artifacts[blob.data].uploads) {
- continue; // for local artifacts
- }
- if (config_.artifacts[blob.digest.hash()].uploads) {
- continue; // for known and action artifacts
- }
- return false;
- }
- return true;
+ return std::all_of(
+ blobs.begin(), blobs.end(), [this](auto const& blob) {
+ return config_.artifacts[blob.data]
+ .uploads // for local artifacts
+ or config_.artifacts[blob.digest.hash()]
+ .uploads; // for known and action artifacts
+ });
}
auto UploadTree(
std::vector<
diff --git a/test/buildtool/execution_engine/traverser/traverser.test.cpp b/test/buildtool/execution_engine/traverser/traverser.test.cpp
index 63d1fad6..693097d5 100644
--- a/test/buildtool/execution_engine/traverser/traverser.test.cpp
+++ b/test/buildtool/execution_engine/traverser/traverser.test.cpp
@@ -95,16 +95,20 @@ class TestExecutor {
build_info_->SetName(name_);
bool const all_deps_available = AllAvailable(action->Children());
if (all_deps_available) {
- for (auto const& [name, node] : action->OutputFiles()) {
- if (not build_info_->InsertCorrectlyBuilt(
- node->Content().Id())) {
- [[maybe_unused]] auto was_it_added =
- build_info_->InsertIncorrectlyBuilt(
- node->Content().Id());
- return false;
- }
- }
- return true;
+ return std::all_of(
+ action->OutputFiles().begin(),
+ action->OutputFiles().end(),
+ [this](auto const& entry) {
+ auto const& [name, node] = entry;
+ if (not build_info_->InsertCorrectlyBuilt(
+ node->Content().Id())) {
+ [[maybe_unused]] auto was_it_added =
+ build_info_->InsertIncorrectlyBuilt(
+ node->Content().Id());
+ return false;
+ }
+ return true;
+ });
}
for (auto const& [name, node] : action->OutputFiles()) {
[[maybe_unused]] auto was_it_added =
diff --git a/test/buildtool/graph_traverser/graph_traverser.test.hpp b/test/buildtool/graph_traverser/graph_traverser.test.hpp
index 54211f44..634c37e1 100644
--- a/test/buildtool/graph_traverser/graph_traverser.test.hpp
+++ b/test/buildtool/graph_traverser/graph_traverser.test.hpp
@@ -79,7 +79,6 @@ class TestProject {
"_entry_points";
std::string example_name_{};
std::filesystem::path root_dir_{};
- static inline int id_{};
bool run_local_{};
void SetupConfig() {
@@ -90,6 +89,7 @@ class TestProject {
auto GenerateFromEntryPoints(nlohmann::json const& entry_points)
-> CommandLineArguments {
+ static int id{};
GraphTraverser::CommandLineArguments gtargs{0, {}, {}, {}, {}};
@@ -98,7 +98,7 @@ class TestProject {
clargs.graph_description = root_dir_ / "graph_description";
clargs.gtargs.jobs = std::max(1U, std::thread::hardware_concurrency());
clargs.gtargs.stage = StageArguments{
- kOutputDirPrefix / (example_name_ + std::to_string(id_++))};
+ kOutputDirPrefix / (example_name_ + std::to_string(id++))};
if (not run_local_) {
clargs.gtargs.endpoint.remote_execution_address =
ReadRemoteAddressFromEnv();
diff --git a/test/buildtool/logging/logger.test.cpp b/test/buildtool/logging/logger.test.cpp
index 329b69b0..ac28889b 100644
--- a/test/buildtool/logging/logger.test.cpp
+++ b/test/buildtool/logging/logger.test.cpp
@@ -9,25 +9,32 @@
// Stores prints from test sink instances
class TestPrints {
+ struct PrintData {
+ std::atomic<int> counter{};
+ std::unordered_map<int, std::vector<std::string>> prints{};
+ };
+
public:
static void Print(int sink_id, std::string const& print) noexcept {
- prints_[sink_id].push_back(print);
+ Data().prints[sink_id].push_back(print);
}
[[nodiscard]] static auto Read(int sink_id) noexcept
-> std::vector<std::string> {
- return prints_[sink_id];
+ return Data().prints[sink_id];
}
static void Clear() noexcept {
- prints_.clear();
- counter_ = 0;
+ Data().prints.clear();
+ Data().counter = 0;
}
- static auto GetId() noexcept -> int { return counter_++; }
+ static auto GetId() noexcept -> int { return Data().counter++; }
private:
- static inline std::atomic<int> counter_{};
- static inline std::unordered_map<int, std::vector<std::string>> prints_{};
+ [[nodiscard]] static auto Data() noexcept -> PrintData& {
+ static PrintData instance{};
+ return instance;
+ }
};
// Test sink, prints to TestPrints depending on its own instance id.
diff --git a/test/utils/container_matchers.hpp b/test/utils/container_matchers.hpp
index c52a7d16..42c0dfb4 100644
--- a/test/utils/container_matchers.hpp
+++ b/test/utils/container_matchers.hpp
@@ -155,12 +155,11 @@ class ContainerUnorderedMatcher : public Catch::MatcherBase<LeftContainer> {
std::iter_swap(it_to_elem, last_to_check);
return true;
};
- for (auto const& element : lhs) {
- if (not check_exists_and_remove(element)) {
- return false;
- }
- }
- return true;
+ return std::all_of(lhs.begin(),
+ lhs.end(),
+ [&check_exists_and_remove](auto const& element) {
+ return check_exists_and_remove(element);
+ });
}
};
diff --git a/test/utils/hermeticity/local.hpp b/test/utils/hermeticity/local.hpp
index 5e844b50..a7eeb728 100644
--- a/test/utils/hermeticity/local.hpp
+++ b/test/utils/hermeticity/local.hpp
@@ -9,13 +9,12 @@
class HermeticLocalTestFixture {
public:
HermeticLocalTestFixture() noexcept {
+ static int id{};
Statistics::Instance().Reset();
- CreateAndSetCleanDiskCache(id_++);
+ CreateAndSetCleanDiskCache(id++);
}
private:
- static inline int id_{};
-
static void CreateAndSetCleanDiskCache(int case_id) {
auto test_dir = FileSystemManager::GetCurrentDirectory();
auto case_dir = test_dir / "tmp" / ("case_" + std::to_string(case_id));