diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-12 14:28:13 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-13 14:41:00 +0200 |
commit | 5fb67de531fead44123ff30ee5cf37340fc63a0b (patch) | |
tree | 0e1c7c8810e8ee311467e5e07ebb8ff2902adf28 /test | |
parent | dd15af0ba4b22348e38d535aadc9fa5e929f3824 (diff) | |
download | justbuild-5fb67de531fead44123ff30ee5cf37340fc63a0b.tar.gz |
Use TestHashType in tests
...instead of calling ProtocolTraits::IsCompatible
Diffstat (limited to 'test')
28 files changed, 129 insertions, 227 deletions
diff --git a/test/buildtool/build_engine/base_maps/TARGETS b/test/buildtool/build_engine/base_maps/TARGETS index bb145bac..97871ad2 100644 --- a/test/buildtool/build_engine/base_maps/TARGETS +++ b/test/buildtool/build_engine/base_maps/TARGETS @@ -69,6 +69,7 @@ , ["@", "src", "src/buildtool/build_engine/base_maps", "entity_name_data"] , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "build_engine", "base_maps"] } diff --git a/test/buildtool/build_engine/base_maps/source_map.test.cpp b/test/buildtool/build_engine/base_maps/source_map.test.cpp index bd1e71ba..ab5323e4 100644 --- a/test/buildtool/build_engine/base_maps/source_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/source_map.test.cpp @@ -32,6 +32,7 @@ #include "src/buildtool/multithreading/async_map_consumer.hpp" #include "src/buildtool/multithreading/task_system.hpp" #include "test/buildtool/build_engine/base_maps/test_repo.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" namespace { @@ -89,16 +90,14 @@ auto ReadSourceTarget(EntityName const& id, } // namespace TEST_CASE("from file") { + auto const hash_type = TestHashType::ReadFromEnvironment(); + nlohmann::json artifacts; auto name = EntityName{"", ".", "file"}; auto consumer = [&artifacts](auto values) { artifacts = (*values[0])->Artifacts()->ToJson(); }; - auto const hash_type = ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1; - SECTION("via file") { CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); CHECK(artifacts["file"]["type"] == "LOCAL"); @@ -108,24 +107,22 @@ TEST_CASE("from file") { SECTION("via git tree") { CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); CHECK(artifacts["file"]["type"] == "KNOWN"); - CHECK(artifacts["file"]["data"]["id"] == - (ProtocolTraits::Instance().IsCompatible() ? kEmptySha256 - : kEmptySha1)); + CHECK( + artifacts["file"]["data"]["id"] == + (ProtocolTraits::IsNative(hash_type) ? kEmptySha1 : kEmptySha256)); CHECK(artifacts["file"]["data"]["size"] == 0); } } TEST_CASE("not present at all") { + auto const hash_type = TestHashType::ReadFromEnvironment(); + bool consumed{false}; bool failure_called{false}; auto name = EntityName{"", ".", "does_not_exist"}; auto consumer = [&consumed](auto /*unused*/) { consumed = true; }; auto fail_func = [&failure_called]() { failure_called = true; }; - auto const hash_type = ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1; - SECTION("via file") { CHECK_FALSE(ReadSourceTarget( name, consumer, hash_type, /*use_git=*/false, fail_func)); @@ -142,16 +139,14 @@ TEST_CASE("not present at all") { } TEST_CASE("malformed entry") { + auto const hash_type = TestHashType::ReadFromEnvironment(); + bool consumed{false}; bool failure_called{false}; auto name = EntityName{"", ".", "bad_entry"}; auto consumer = [&consumed](auto /*unused*/) { consumed = true; }; auto fail_func = [&failure_called]() { failure_called = true; }; - auto const hash_type = ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1; - SECTION("via git tree") { CHECK_FALSE(ReadSourceTarget( name, consumer, hash_type, /*use_git=*/false, fail_func)); @@ -168,16 +163,14 @@ TEST_CASE("malformed entry") { } TEST_CASE("subdir file") { + auto const hash_type = TestHashType::ReadFromEnvironment(); + nlohmann::json artifacts; auto name = EntityName{"", "foo", "bar/file"}; auto consumer = [&artifacts](auto values) { artifacts = (*values[0])->Artifacts()->ToJson(); }; - auto const hash_type = ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1; - SECTION("via file") { CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); CHECK(artifacts["bar/file"]["type"] == "LOCAL"); @@ -187,24 +180,22 @@ TEST_CASE("subdir file") { SECTION("via git tree") { CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); CHECK(artifacts["bar/file"]["type"] == "KNOWN"); - CHECK(artifacts["bar/file"]["data"]["id"] == - (ProtocolTraits::Instance().IsCompatible() ? kEmptySha256 - : kEmptySha1)); + CHECK( + artifacts["bar/file"]["data"]["id"] == + (ProtocolTraits::IsNative(hash_type) ? kEmptySha1 : kEmptySha256)); CHECK(artifacts["bar/file"]["data"]["size"] == 0); } } TEST_CASE("subdir symlink") { + auto const hash_type = TestHashType::ReadFromEnvironment(); + nlohmann::json artifacts; auto name = EntityName{"", "foo", "link"}; auto consumer = [&artifacts](auto values) { artifacts = (*values[0])->Artifacts()->ToJson(); }; - auto const hash_type = ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1; - SECTION("via file") { CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); CHECK(artifacts["link"]["type"] == "LOCAL"); @@ -215,8 +206,8 @@ TEST_CASE("subdir symlink") { CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); CHECK(artifacts["link"]["type"] == "KNOWN"); CHECK(artifacts["link"]["data"]["id"] == - (ProtocolTraits::Instance().IsCompatible() ? kSrcLinkIdSha256 - : kSrcLinkIdSha1)); + (ProtocolTraits::IsNative(hash_type) ? kSrcLinkIdSha1 + : kSrcLinkIdSha256)); CHECK(artifacts["link"]["data"]["size"] == 5); // content: dummy } } diff --git a/test/buildtool/common/TARGETS b/test/buildtool/common/TARGETS index 1355af3f..020d0f28 100644 --- a/test/buildtool/common/TARGETS +++ b/test/buildtool/common/TARGETS @@ -9,9 +9,9 @@ , ["@", "src", "src/buildtool/common", "artifact_description"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/common", "artifact_digest_factory"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/crypto", "hash_function"] , ["@", "src", "src/buildtool/file_system", "object_type"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "common"] } @@ -25,8 +25,8 @@ , ["@", "json", "", "json"] , ["@", "src", "src/buildtool/common", "action_description"] , ["@", "src", "src/buildtool/common", "common"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "common"] } diff --git a/test/buildtool/common/action_description.test.cpp b/test/buildtool/common/action_description.test.cpp index 504f6aa3..65f5d92e 100644 --- a/test/buildtool/common/action_description.test.cpp +++ b/test/buildtool/common/action_description.test.cpp @@ -20,14 +20,8 @@ #include "nlohmann/json.hpp" #include "src/buildtool/common/action.hpp" #include "src/buildtool/common/artifact_description.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/crypto/hash_function.hpp" - -[[nodiscard]] static inline auto GetHashType(bool compatible) noexcept - -> HashFunction::Type { - return compatible ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1; -} +#include "test/utils/hermeticity/test_hash_function_type.hpp" TEST_CASE("From JSON", "[action_description]") { using path = std::filesystem::path; @@ -45,8 +39,7 @@ TEST_CASE("From JSON", "[action_description]") { desc.Inputs()} .ToJson(); - auto const hash_type = - GetHashType(ProtocolTraits::Instance().IsCompatible()); + auto const hash_type = TestHashType::ReadFromEnvironment(); SECTION("Parse full action") { auto description = ActionDescription::FromJson(hash_type, "id", json); REQUIRE(description); diff --git a/test/buildtool/common/artifact_description.test.cpp b/test/buildtool/common/artifact_description.test.cpp index 99a24964..44acaae6 100644 --- a/test/buildtool/common/artifact_description.test.cpp +++ b/test/buildtool/common/artifact_description.test.cpp @@ -22,14 +22,12 @@ #include "src/buildtool/common/artifact.hpp" #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/artifact_digest_factory.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" static auto NamedDigest(std::string const& str) -> ArtifactDigest { - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; return ArtifactDigestFactory::HashDataAs<ObjectType::File>(hash_function, str); } @@ -40,18 +38,11 @@ static auto NamedDigest(std::string const& str) -> ArtifactDigest { lhs.Info() == rhs.Info(); } -[[nodiscard]] static inline auto GetHashType(bool compatible) noexcept - -> HashFunction::Type { - return compatible ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1; -} - TEST_CASE("Local artifact", "[artifact_description]") { auto local_desc = ArtifactDescription::CreateLocal( std::filesystem::path{"local_path"}, "repo"); auto from_json = ArtifactDescription::FromJson( - GetHashType(ProtocolTraits::Instance().IsCompatible()), - local_desc.ToJson()); + TestHashType::ReadFromEnvironment(), local_desc.ToJson()); CHECK(local_desc == *from_json); } @@ -60,24 +51,21 @@ TEST_CASE("Known artifact", "[artifact_description]") { auto known_desc = ArtifactDescription::CreateKnown( NamedDigest("f_fake_hash"), ObjectType::File); auto from_json = ArtifactDescription::FromJson( - GetHashType(ProtocolTraits::Instance().IsCompatible()), - known_desc.ToJson()); + TestHashType::ReadFromEnvironment(), known_desc.ToJson()); CHECK(known_desc == *from_json); } SECTION("Executable object") { auto known_desc = ArtifactDescription::CreateKnown( NamedDigest("x_fake_hash"), ObjectType::Executable); auto from_json = ArtifactDescription::FromJson( - GetHashType(ProtocolTraits::Instance().IsCompatible()), - known_desc.ToJson()); + TestHashType::ReadFromEnvironment(), known_desc.ToJson()); CHECK(known_desc == *from_json); } SECTION("Symlink object") { auto known_desc = ArtifactDescription::CreateKnown( NamedDigest("l_fake_hash"), ObjectType::Symlink); auto from_json = ArtifactDescription::FromJson( - GetHashType(ProtocolTraits::Instance().IsCompatible()), - known_desc.ToJson()); + TestHashType::ReadFromEnvironment(), known_desc.ToJson()); CHECK(known_desc == *from_json); } } @@ -86,8 +74,7 @@ TEST_CASE("Action artifact", "[artifact_description]") { auto action_desc = ArtifactDescription::CreateAction( "action_id", std::filesystem::path{"out_path"}); auto from_json = ArtifactDescription::FromJson( - GetHashType(ProtocolTraits::Instance().IsCompatible()), - action_desc.ToJson()); + TestHashType::ReadFromEnvironment(), action_desc.ToJson()); CHECK(action_desc == *from_json); } @@ -98,8 +85,7 @@ TEST_CASE("From JSON", "[artifact_description]") { .ToJson(); auto action = ArtifactDescription::CreateAction("id", "output").ToJson(); - auto const hash_type = - GetHashType(ProtocolTraits::Instance().IsCompatible()); + auto const hash_type = TestHashType::ReadFromEnvironment(); SECTION("Parse artifacts") { CHECK(ArtifactDescription::FromJson(hash_type, local)); CHECK(ArtifactDescription::FromJson(hash_type, known)); @@ -177,20 +163,19 @@ TEST_CASE("From JSON", "[artifact_description]") { TEST_CASE("Description missing mandatory key/value pair", "[artifact_description]") { nlohmann::json const missing_type = {{"data", {{"path", "some/path"}}}}; - CHECK(not ArtifactDescription::FromJson( - GetHashType(ProtocolTraits::Instance().IsCompatible()), missing_type)); + CHECK(not ArtifactDescription::FromJson(TestHashType::ReadFromEnvironment(), + missing_type)); nlohmann::json const missing_data = {{"type", "LOCAL"}}; - CHECK(not ArtifactDescription::FromJson( - GetHashType(ProtocolTraits::Instance().IsCompatible()), missing_data)); + CHECK(not ArtifactDescription::FromJson(TestHashType::ReadFromEnvironment(), + missing_data)); } TEST_CASE("Local artifact description contains incorrect value for \"data\"", "[artifact_description]") { nlohmann::json const local_art_missing_path = { {"type", "LOCAL"}, {"data", nlohmann::json::object()}}; - CHECK(not ArtifactDescription::FromJson( - GetHashType(ProtocolTraits::Instance().IsCompatible()), - local_art_missing_path)); + CHECK(not ArtifactDescription::FromJson(TestHashType::ReadFromEnvironment(), + local_art_missing_path)); } TEST_CASE("Known artifact description contains incorrect value for \"data\"", @@ -202,24 +187,21 @@ TEST_CASE("Known artifact description contains incorrect value for \"data\"", {"type", "KNOWN"}, {"data", {{"size", 15}, {"file_type", file_type}}}}; CHECK(not ArtifactDescription::FromJson( - GetHashType(ProtocolTraits::Instance().IsCompatible()), - known_art_missing_id)); + TestHashType::ReadFromEnvironment(), known_art_missing_id)); } SECTION("missing \"size\"") { nlohmann::json const known_art_missing_size = { {"type", "KNOWN"}, {"data", {{"id", "known_input"}, {"file_type", file_type}}}}; CHECK(not ArtifactDescription::FromJson( - GetHashType(ProtocolTraits::Instance().IsCompatible()), - known_art_missing_size)); + TestHashType::ReadFromEnvironment(), known_art_missing_size)); } SECTION("missing \"file_type\"") { nlohmann::json const known_art_missing_file_type = { {"type", "KNOWN"}, {"data", {{"id", "known_input"}, {"size", 15}}}}; CHECK(not ArtifactDescription::FromJson( - GetHashType(ProtocolTraits::Instance().IsCompatible()), - known_art_missing_file_type)); + TestHashType::ReadFromEnvironment(), known_art_missing_file_type)); } } @@ -227,13 +209,11 @@ TEST_CASE("Action artifact description contains incorrect value for \"data\"", "[artifact_description]") { nlohmann::json const action_art_missing_id = { {"type", "ACTION"}, {"data", {{"path", "output/path"}}}}; - CHECK(not ArtifactDescription::FromJson( - GetHashType(ProtocolTraits::Instance().IsCompatible()), - action_art_missing_id)); + CHECK(not ArtifactDescription::FromJson(TestHashType::ReadFromEnvironment(), + action_art_missing_id)); nlohmann::json const action_art_missing_path = { {"type", "ACTION"}, {"data", {{"id", "action_id"}}}}; - CHECK(not ArtifactDescription::FromJson( - GetHashType(ProtocolTraits::Instance().IsCompatible()), - action_art_missing_path)); + CHECK(not ArtifactDescription::FromJson(TestHashType::ReadFromEnvironment(), + action_art_missing_path)); } diff --git a/test/buildtool/execution_api/bazel/TARGETS b/test/buildtool/execution_api/bazel/TARGETS index 64e52ad6..02b55b78 100644 --- a/test/buildtool/execution_api/bazel/TARGETS +++ b/test/buildtool/execution_api/bazel/TARGETS @@ -9,13 +9,13 @@ , ["utils", "test_auth_config"] , ["utils", "test_remote_config"] , ["@", "src", "src/buildtool/common", "bazel_digest_factory"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/common/remote", "retry_config"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -30,12 +30,12 @@ , ["utils", "test_auth_config"] , ["utils", "test_remote_config"] , ["@", "src", "src/buildtool/common", "bazel_digest_factory"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/common/remote", "retry_config"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -50,12 +50,12 @@ , ["utils", "test_auth_config"] , ["utils", "test_remote_config"] , ["@", "src", "src/buildtool/common", "bazel_digest_factory"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -77,6 +77,7 @@ , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -97,8 +98,8 @@ , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/common", "artifact_digest_factory"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] , ["@", "src", "src/buildtool/execution_api/common", "common"] , [ "@" , "src" @@ -122,7 +123,7 @@ , ["@", "src", "src/buildtool/execution_api/remote", "bazel"] , ["buildtool/execution_api/common", "api_test"] , ["@", "src", "src/buildtool/crypto", "hash_function"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } diff --git a/test/buildtool/execution_api/bazel/bazel_api.test.cpp b/test/buildtool/execution_api/bazel/bazel_api.test.cpp index 5dc4198d..16c45aae 100644 --- a/test/buildtool/execution_api/bazel/bazel_api.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_api.test.cpp @@ -18,11 +18,11 @@ #include <string> #include "catch2/catch_test_macros.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "test/buildtool/execution_api/common/api_test.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" #include "test/utils/remote_execution/test_remote_config.hpp" @@ -59,15 +59,13 @@ class FactoryApi final { TEST_CASE("BazelAPI: No input, no output", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestNoInputNoOutput(api_factory, remote_config->platform_properties); @@ -75,15 +73,13 @@ TEST_CASE("BazelAPI: No input, no output", "[execution_api]") { TEST_CASE("BazelAPI: No input, create output", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestNoInputCreateOutput(api_factory, remote_config->platform_properties); @@ -91,15 +87,13 @@ TEST_CASE("BazelAPI: No input, create output", "[execution_api]") { TEST_CASE("BazelAPI: One input copied to output", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestOneInputCopiedToOutput(api_factory, remote_config->platform_properties); @@ -107,15 +101,13 @@ TEST_CASE("BazelAPI: One input copied to output", "[execution_api]") { TEST_CASE("BazelAPI: Non-zero exit code, create output", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestNonZeroExitCodeCreateOutput(api_factory, @@ -124,15 +116,13 @@ TEST_CASE("BazelAPI: Non-zero exit code, create output", "[execution_api]") { TEST_CASE("BazelAPI: Retrieve two identical trees to path", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestRetrieveTwoIdenticalTreesToPath( @@ -142,15 +132,13 @@ TEST_CASE("BazelAPI: Retrieve two identical trees to path", "[execution_api]") { TEST_CASE("BazelAPI: Retrieve file and symlink with same content to path", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestRetrieveFileAndSymlinkWithSameContentToPath( @@ -159,15 +147,13 @@ TEST_CASE("BazelAPI: Retrieve file and symlink with same content to path", TEST_CASE("BazelAPI: Retrieve mixed blobs and trees", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestRetrieveMixedBlobsAndTrees( @@ -176,15 +162,13 @@ TEST_CASE("BazelAPI: Retrieve mixed blobs and trees", "[execution_api]") { TEST_CASE("BazelAPI: Create directory prior to execution", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestCreateDirPriorToExecution(api_factory, diff --git a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp index 4be61071..e8234282 100644 --- a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp @@ -21,13 +21,13 @@ #include "catch2/catch_test_macros.hpp" #include "gsl/gsl" #include "src/buildtool/common/bazel_digest_factory.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" #include "test/utils/remote_execution/test_remote_config.hpp" @@ -50,10 +50,7 @@ TEST_CASE("Bazel internals: CAS Client", "[execution_api]") { SECTION("Valid digest and blob") { // digest of "test" - HashFunction const hash_function{ - ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto digest = BazelDigestFactory::HashDataAs<ObjectType::File>( hash_function, content); diff --git a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp index a0f77066..e7df319b 100644 --- a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp @@ -18,11 +18,11 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/bazel_digest_factory.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" #include "test/utils/remote_execution/bazel_action_creator.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" #include "test/utils/remote_execution/test_remote_config.hpp" @@ -31,9 +31,7 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { std::string instance_name{"remote-execution"}; std::string content("test"); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto test_digest = BazelDigestFactory::HashDataAs<ObjectType::File>( hash_function, content); @@ -115,9 +113,7 @@ TEST_CASE("Bazel internals: Execution Client using env variables", std::string instance_name{"remote-execution"}; std::string content("contents of env variable"); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto test_digest = BazelDigestFactory::HashDataAs<ObjectType::File>( hash_function, content); diff --git a/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp b/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp index 8ec074f9..5262971c 100644 --- a/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp @@ -23,11 +23,11 @@ #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/artifact_digest_factory.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/common/artifact_blob_container.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" namespace { /// \brief Create a blob from the content found in file or symlink pointed to by @@ -62,9 +62,7 @@ TEST_CASE("Bazel internals: MessageFactory", "[execution_api]") { std::filesystem::path link = subdir1 / "link"; REQUIRE(FileSystemManager::CreateSymlink("file1", link)); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; // create the corresponding blobs auto file1_blob = CreateBlobFromPath(file1, hash_function); diff --git a/test/buildtool/execution_api/bazel/bazel_network.test.cpp b/test/buildtool/execution_api/bazel/bazel_network.test.cpp index c69e7619..8224de74 100644 --- a/test/buildtool/execution_api/bazel/bazel_network.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_network.test.cpp @@ -29,6 +29,7 @@ #include "src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" #include "test/utils/remote_execution/test_remote_config.hpp" @@ -46,9 +47,7 @@ TEST_CASE("Bazel network: write/read blobs", "[execution_api]") { RetryConfig retry_config{}; // default retry config - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto network = BazelNetwork{instance_name, remote_config->remote_address->host, @@ -97,7 +96,8 @@ TEST_CASE("Bazel network: write/read blobs", "[execution_api]") { } TEST_CASE("Bazel network: read blobs with unknown size", "[execution_api]") { - if (ProtocolTraits::Instance().IsCompatible()) { + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + if (not ProtocolTraits::IsNative(hash_function.GetType())) { // only supported in native mode return; } @@ -113,10 +113,6 @@ TEST_CASE("Bazel network: read blobs with unknown size", "[execution_api]") { RetryConfig retry_config{}; // default retry config - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - auto network = BazelNetwork{instance_name, remote_config->remote_address->host, remote_config->remote_address->port, diff --git a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp index 1956a6a3..c8b7cac6 100644 --- a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp @@ -21,12 +21,12 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/common/bazel_digest_factory.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/execution_api/common/execution_common.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" #include "test/utils/remote_execution/test_remote_config.hpp" @@ -45,9 +45,7 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { &*auth_config}; auto uuid = CreateUUIDVersion4(*CreateProcessUniqueId()); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; SECTION("Upload small blob") { std::string instance_name{"remote-execution"}; @@ -152,9 +150,7 @@ TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") { &*auth_config}; auto uuid = CreateUUIDVersion4(*CreateProcessUniqueId()); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; SECTION("Upload small blobs") { std::string instance_name{"remote-execution"}; diff --git a/test/buildtool/execution_api/common/TARGETS b/test/buildtool/execution_api/common/TARGETS index f58bb4f0..6a7dff89 100644 --- a/test/buildtool/execution_api/common/TARGETS +++ b/test/buildtool/execution_api/common/TARGETS @@ -5,7 +5,6 @@ , "deps": [ ["@", "catch2", "", "catch2"] , ["@", "src", "src/buildtool/common", "artifact_description"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/common", "artifact_digest_factory"] , ["@", "src", "src/buildtool/execution_api/common", "common"] , ["@", "src", "src/buildtool/execution_api/local", "config"] @@ -13,6 +12,7 @@ , ["@", "src", "src/buildtool/logging", "log_level"] , ["@", "src", "src/buildtool/logging", "logging"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_api", "common"] } diff --git a/test/buildtool/execution_api/common/api_test.hpp b/test/buildtool/execution_api/common/api_test.hpp index 3c4052b3..4b84d66a 100644 --- a/test/buildtool/execution_api/common/api_test.hpp +++ b/test/buildtool/execution_api/common/api_test.hpp @@ -25,7 +25,6 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/common/artifact_digest_factory.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/common/execution_action.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" @@ -34,6 +33,7 @@ #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" using ApiFactory = std::function<IExecutionApi::Ptr()>; using ExecProps = std::map<std::string, std::string>; @@ -140,9 +140,7 @@ using ExecProps = std::map<std::string, std::string>; bool is_hermetic = false) { std::string test_content("test"); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto test_digest = ArtifactDigestFactory::HashDataAs<ObjectType::File>( hash_function, test_content); @@ -224,9 +222,7 @@ using ExecProps = std::map<std::string, std::string>; bool is_hermetic = false) { std::string test_content("test"); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto test_digest = ArtifactDigestFactory::HashDataAs<ObjectType::File>( hash_function, test_content); @@ -315,9 +311,7 @@ using ExecProps = std::map<std::string, std::string>; ExecProps const& props) { std::string test_content("test"); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto test_digest = ArtifactDigestFactory::HashDataAs<ObjectType::File>( hash_function, test_content); diff --git a/test/buildtool/execution_api/execution_service/TARGETS b/test/buildtool/execution_api/execution_service/TARGETS index 776f0f2b..2c935848 100644 --- a/test/buildtool/execution_api/execution_service/TARGETS +++ b/test/buildtool/execution_api/execution_service/TARGETS @@ -21,6 +21,7 @@ , ["@", "src", "src/buildtool/storage", "config"] , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "gsl", "", "gsl"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "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 8d68d9cb..af5a3d58 100644 --- a/test/buildtool/execution_api/execution_service/cas_server.test.cpp +++ b/test/buildtool/execution_api/execution_service/cas_server.test.cpp @@ -27,6 +27,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/test_hash_function_type.hpp" #include "test/utils/hermeticity/test_storage_config.hpp" namespace { @@ -48,7 +49,7 @@ namespace { TEST_CASE("CAS Service: upload incomplete tree", "[execution_service]") { // For compatible mode tree invariants aren't checked. - if (ProtocolTraits::Instance().IsCompatible()) { + if (not ProtocolTraits::IsNative(TestHashType::ReadFromEnvironment())) { return; } diff --git a/test/buildtool/execution_engine/executor/TARGETS b/test/buildtool/execution_engine/executor/TARGETS index 74247e49..bb86c6d8 100644 --- a/test/buildtool/execution_engine/executor/TARGETS +++ b/test/buildtool/execution_engine/executor/TARGETS @@ -7,7 +7,6 @@ , ["@", "src", "src/buildtool/common", "artifact_description"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/common", "artifact_digest_factory"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/execution_api/common", "common"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/execution_api/remote", "context"] @@ -21,6 +20,7 @@ , ["@", "gsl", "", "gsl"] , ["utils", "test_api_bundle"] , ["utils", "test_remote_config"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_engine", "executor"] } @@ -34,7 +34,6 @@ , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/common", "artifact_digest_factory"] , ["@", "src", "src/buildtool/common", "config"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/common/remote", "retry_config"] , ["@", "src", "src/buildtool/execution_api/common", "common"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] @@ -48,6 +47,7 @@ , ["@", "catch2", "", "catch2"] , ["@", "gsl", "", "gsl"] , ["utils", "test_api_bundle"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_engine", "executor"] } @@ -84,7 +84,6 @@ [ "executor_api_tests" , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/common", "config"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/common/remote", "retry_config"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] @@ -95,6 +94,7 @@ , ["utils", "test_auth_config"] , ["utils", "test_remote_config"] , ["@", "catch2", "", "catch2"] + , ["utils", "test_hash_function_type"] ] , "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 d0533f9c..48bcf082 100644 --- a/test/buildtool/execution_engine/executor/executor.test.cpp +++ b/test/buildtool/execution_engine/executor/executor.test.cpp @@ -29,7 +29,6 @@ #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/artifact_digest_factory.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/common/statistics.hpp" #include "src/buildtool/crypto/hash_function.hpp" @@ -40,6 +39,7 @@ #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/hermeticity/test_hash_function_type.hpp" /// \brief Mockup API test config. struct TestApiConfig { @@ -64,9 +64,7 @@ struct TestApiConfig { }; static auto NamedDigest(std::string const& str) -> ArtifactDigest { - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; return ArtifactDigestFactory::HashDataAs<ObjectType::File>(hash_function, str); } @@ -305,9 +303,7 @@ TEST_CASE("Executor: Process artifact", "[executor]") { DependencyGraph g; auto [config, repo_config] = CreateTest(&g, workspace_path); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto const local_cpp_id = ArtifactDescription::CreateLocal("local.cpp", "").Id(); @@ -383,9 +379,7 @@ TEST_CASE("Executor: Process action", "[executor]") { DependencyGraph g; auto [config, repo_config] = CreateTest(&g, workspace_path); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto const local_cpp_id = ArtifactDescription::CreateLocal("local.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 570c6e39..c323bde6 100644 --- a/test/buildtool/execution_engine/executor/executor_api.test.hpp +++ b/test/buildtool/execution_engine/executor/executor_api.test.hpp @@ -27,7 +27,6 @@ #include "src/buildtool/common/artifact.hpp" #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/common/artifact_digest_factory.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/common/statistics.hpp" @@ -41,6 +40,7 @@ #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/hermeticity/test_hash_function_type.hpp" #include "test/utils/remote_execution/test_remote_config.hpp" using ApiFactory = std::function<IExecutionApi::Ptr()>; @@ -56,9 +56,7 @@ static inline void RunBlobUpload(RepositoryConfig* repo_config, ApiFactory const& factory) { SetupConfig(repo_config); auto api = factory(); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; std::string const blob = "test"; CHECK(api->Upload(ArtifactBlobContainer{ @@ -144,9 +142,7 @@ static inline void RunHelloWorldCompilation( .retry_config = &retry_config, .exec_config = &*remote_config}; - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto api = factory(); auto const apis = CreateTestApiBundle(hash_function, api); @@ -279,9 +275,7 @@ static inline void RunGreeterCompilation( .retry_config = &retry_config, .exec_config = &*remote_config}; - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto api = factory(); auto const apis = CreateTestApiBundle(hash_function, api); @@ -420,9 +414,7 @@ static inline void TestUploadAndDownloadTrees( env.emplace("PATH", "/bin:/usr/bin"); } - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto foo = std::string{"foo"}; auto bar = std::string{"bar"}; @@ -576,9 +568,7 @@ static inline void TestRetrieveOutputDirectories( int /*expected_cached*/ = 0) { SetupConfig(repo_config); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto const make_tree_id = std::string{"make_tree"}; auto const* make_tree_cmd = 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 fd2167a7..f024941c 100644 --- a/test/buildtool/execution_engine/executor/executor_api_remote_bazel.test.cpp +++ b/test/buildtool/execution_engine/executor/executor_api_remote_bazel.test.cpp @@ -15,7 +15,6 @@ #include <optional> #include "catch2/catch_test_macros.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/common/statistics.hpp" @@ -25,6 +24,7 @@ #include "src/buildtool/execution_engine/executor/executor.hpp" #include "src/buildtool/progress_reporting/progress.hpp" #include "test/buildtool/execution_engine/executor/executor_api.test.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" #include "test/utils/remote_execution/test_remote_config.hpp" @@ -41,9 +41,7 @@ TEST_CASE("Executor<BazelApi>: Upload blob", "[executor]") { RetryConfig retry_config{}; // default retry config - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; TestBlobUpload(&repo_config, [&] { return BazelApi::Ptr{new BazelApi{"remote-execution", @@ -72,9 +70,7 @@ TEST_CASE("Executor<BazelApi>: Compile hello world", "[executor]") { RetryConfig retry_config{}; // default retry config - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; TestHelloWorldCompilation( &repo_config, @@ -110,9 +106,7 @@ TEST_CASE("Executor<BazelApi>: Compile greeter", "[executor]") { RetryConfig retry_config{}; // default retry config - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; TestGreeterCompilation( &repo_config, @@ -148,9 +142,7 @@ TEST_CASE("Executor<BazelApi>: Upload and download trees", "[executor]") { RetryConfig retry_config{}; // default retry config - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; TestUploadAndDownloadTrees( &repo_config, @@ -186,9 +178,7 @@ TEST_CASE("Executor<BazelApi>: Retrieve output directories", "[executor]") { RetryConfig retry_config{}; // default retry config - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; TestRetrieveOutputDirectories( &repo_config, diff --git a/test/buildtool/execution_engine/traverser/TARGETS b/test/buildtool/execution_engine/traverser/TARGETS index 7228b0af..72a7abea 100644 --- a/test/buildtool/execution_engine/traverser/TARGETS +++ b/test/buildtool/execution_engine/traverser/TARGETS @@ -7,11 +7,11 @@ , ["", "catch-main"] , ["utils", "container_matchers"] , ["@", "src", "src/buildtool/common", "common"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/common", "artifact_description"] , ["@", "src", "src/buildtool/execution_engine/dag", "dag"] , ["@", "src", "src/buildtool/execution_engine/traverser", "traverser"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_engine", "traverser"] } diff --git a/test/buildtool/execution_engine/traverser/traverser.test.cpp b/test/buildtool/execution_engine/traverser/traverser.test.cpp index 7b2e6293..cc5c22e9 100644 --- a/test/buildtool/execution_engine/traverser/traverser.test.cpp +++ b/test/buildtool/execution_engine/traverser/traverser.test.cpp @@ -24,10 +24,10 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_description.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_engine/dag/dag.hpp" #include "test/utils/container_matchers.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" namespace { @@ -184,9 +184,7 @@ class TestProject { auto inputs_desc = ActionDescription::inputs_t{}; if (not inputs.empty()) { command.emplace_back("FROM"); - auto const hash_type = ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1; + auto const hash_type = TestHashType::ReadFromEnvironment(); for (auto const& input_desc : inputs) { auto artifact = ArtifactDescription::FromJson(hash_type, input_desc); diff --git a/test/buildtool/file_system/TARGETS b/test/buildtool/file_system/TARGETS index eda8f376..8d1a5c0a 100644 --- a/test/buildtool/file_system/TARGETS +++ b/test/buildtool/file_system/TARGETS @@ -62,11 +62,11 @@ , ["@", "src", "src/buildtool/common", "artifact_description"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/common", "artifact_digest_factory"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/crypto", "hash_function"] , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["utils", "shell_quoting"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "file_system"] } diff --git a/test/buildtool/file_system/file_root.test.cpp b/test/buildtool/file_system/file_root.test.cpp index 1a27dd1b..94a2a552 100644 --- a/test/buildtool/file_system/file_root.test.cpp +++ b/test/buildtool/file_system/file_root.test.cpp @@ -25,10 +25,10 @@ #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/artifact_digest_factory.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "test/utils/container_matchers.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" #include "test/utils/shell_quoting.hpp" namespace { @@ -380,9 +380,7 @@ static void CheckGitRoot(HashFunction::Type hash_type, bool ignore_special) noexcept; TEST_CASE("Creating artifact descriptions", "[file_root]") { - auto const hash_type = ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1; + auto const hash_type = TestHashType::ReadFromEnvironment(); SECTION("local root") { CheckLocalRoot(hash_type, /*ignore_special=*/false); diff --git a/test/buildtool/graph_traverser/TARGETS b/test/buildtool/graph_traverser/TARGETS index d9dd7af6..b2791561 100644 --- a/test/buildtool/graph_traverser/TARGETS +++ b/test/buildtool/graph_traverser/TARGETS @@ -23,6 +23,7 @@ , ["@", "src", "src/buildtool/execution_api/common", "api_bundle"] , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "src", "src/buildtool/storage", "config"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "graph_traverser"] } @@ -55,10 +56,10 @@ , ["utils", "catch-main-remote-execution"] , ["utils", "test_auth_config"] , ["utils", "test_remote_config"] + , ["utils", "test_hash_function_type"] , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "src", "src/buildtool/storage", "config"] , ["@", "src", "src/buildtool/crypto", "hash_function"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] ] , "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 666b905f..cb9cb57c 100644 --- a/test/buildtool/graph_traverser/graph_traverser.test.hpp +++ b/test/buildtool/graph_traverser/graph_traverser.test.hpp @@ -47,6 +47,7 @@ #include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" #include "src/utils/cpp/json.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" // NOLINTNEXTLINE(google-build-namespaces) namespace { @@ -128,7 +129,8 @@ class TestProject { CommandLineArguments clargs{gtargs}; clargs.artifacts = entry_points; auto const comp_graph = root_dir_ / "graph_description_compatible"; - if (ProtocolTraits::Instance().IsCompatible() and + if (not ProtocolTraits::IsNative( + TestHashType::ReadFromEnvironment()) and FileSystemManager::Exists(comp_graph)) { clargs.graph_description = comp_graph; } diff --git a/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp b/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp index bf3dfe02..a7888ac4 100644 --- a/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp +++ b/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp @@ -13,12 +13,12 @@ // limitations under the License. #include "catch2/catch_test_macros.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/remote/config.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/test_hash_function_type.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" #include "test/utils/remote_execution/test_remote_config.hpp" @@ -35,9 +35,7 @@ StorageConfig::Builder builder; auto config = builder.SetBuildRoot(cache_dir) - .SetHashType(ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1) + .SetHashType(TestHashType::ReadFromEnvironment()) .SetRemoteExecutionArgs(remote_config.remote_address, remote_config.platform_properties, remote_config.dispatch) diff --git a/test/buildtool/storage/large_object_cas.test.cpp b/test/buildtool/storage/large_object_cas.test.cpp index cbc92038..e0e3c816 100644 --- a/test/buildtool/storage/large_object_cas.test.cpp +++ b/test/buildtool/storage/large_object_cas.test.cpp @@ -405,7 +405,8 @@ static void TestExternal(StorageConfig const& storage_config, REQUIRE(FileSystemManager::IsFile(path)); } - if (kIsTree and not ProtocolTraits::Instance().IsCompatible()) { + if (kIsTree and ProtocolTraits::IsTreeAllowed( + storage_config.hash_function.GetType())) { // Tree invariants check is omitted in compatible mode. SECTION("Tree invariants check fails") { // Check splice fails due to the tree invariants check. @@ -606,7 +607,8 @@ TEST_CASE("LargeObjectCAS: uplink nested large objects", "[storage]") { // However, in native mode they might be reconstructed on request because // their entries are in the latest generation: - if (not ProtocolTraits::Instance().IsCompatible()) { + if (ProtocolTraits::IsNative( + storage_config.Get().hash_function.GetType())) { auto split_nested_tree_2 = latest.CAS().SplitTree(*nested_tree_digest); REQUIRE(split_nested_tree_2); @@ -720,10 +722,10 @@ auto Tree::StoreRaw(LocalCAS<kDefaultDoGlobalUplink> const& cas, return cas.StoreBlob(content); }; - return ProtocolTraits::Instance().IsCompatible() - ? BazelMsgFactory::CreateDirectoryDigestFromLocalTree( + return ProtocolTraits::IsNative(cas.GetHashFunction().GetType()) + ? BazelMsgFactory::CreateGitTreeDigestFromLocalTree( directory, store_blob, store_tree, store_symlink) - : BazelMsgFactory::CreateGitTreeDigestFromLocalTree( + : BazelMsgFactory::CreateDirectoryDigestFromLocalTree( directory, store_blob, store_tree, store_symlink); } } // namespace LargeTestUtils |