diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-12 11:52:55 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-13 14:41:00 +0200 |
commit | 0be15127f1ecbd4010c657e908e62ed5f4b737dc (patch) | |
tree | 1e2897dc587018f4903e3e0c0783ffee0a158ac4 /test | |
parent | 74498f0633d9039bbb7971efa33d4242cd724812 (diff) | |
download | justbuild-0be15127f1ecbd4010c657e908e62ed5f4b737dc.tar.gz |
Pass HashFunction::Type to SourceTargetMap
...that is to be used by FileRoot::ToArtifactDescription.
Diffstat (limited to 'test')
4 files changed, 111 insertions, 67 deletions
diff --git a/test/buildtool/build_engine/base_maps/TARGETS b/test/buildtool/build_engine/base_maps/TARGETS index 2c5f4029..bb145bac 100644 --- a/test/buildtool/build_engine/base_maps/TARGETS +++ b/test/buildtool/build_engine/base_maps/TARGETS @@ -68,6 +68,7 @@ , ["@", "src", "src/buildtool/build_engine/base_maps", "source_map"] , ["@", "src", "src/buildtool/build_engine/base_maps", "entity_name_data"] , ["@", "src", "src/buildtool/file_system", "file_root"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "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 b6c7f1c1..bd1e71ba 100644 --- a/test/buildtool/build_engine/base_maps/source_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/source_map.test.cpp @@ -27,6 +27,7 @@ #include "src/buildtool/build_engine/base_maps/entity_name_data.hpp" #include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/common/repository_config.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/multithreading/async_map_consumer.hpp" #include "src/buildtool/multithreading/task_system.hpp" @@ -60,13 +61,14 @@ auto SetupConfig(bool use_git) -> RepositoryConfig { auto ReadSourceTarget(EntityName const& id, SourceTargetMap::Consumer consumer, + HashFunction::Type hash_type, bool use_git = false, std::optional<SourceTargetMap::FailureFunction> fail_func = std::nullopt) -> bool { auto repo_config = SetupConfig(use_git); auto directory_entries = CreateDirectoryEntriesMap(&repo_config); auto source_artifacts = - CreateSourceTargetMap(&directory_entries, &repo_config); + CreateSourceTargetMap(&directory_entries, &repo_config, hash_type); std::string error_msg; bool success{true}; { @@ -93,14 +95,18 @@ TEST_CASE("from file") { 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, /*use_git=*/false)); + CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); CHECK(artifacts["file"]["type"] == "LOCAL"); CHECK(artifacts["file"]["data"]["path"] == "file"); } SECTION("via git tree") { - CHECK(ReadSourceTarget(name, consumer, /*use_git=*/true)); + CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); CHECK(artifacts["file"]["type"] == "KNOWN"); CHECK(artifacts["file"]["data"]["id"] == (ProtocolTraits::Instance().IsCompatible() ? kEmptySha256 @@ -116,16 +122,20 @@ TEST_CASE("not present at all") { 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, /*use_git=*/false, fail_func)); + CHECK_FALSE(ReadSourceTarget( + name, consumer, hash_type, /*use_git=*/false, fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } SECTION("via git tree") { - CHECK_FALSE( - ReadSourceTarget(name, consumer, /*use_git=*/true, fail_func)); + CHECK_FALSE(ReadSourceTarget( + name, consumer, hash_type, /*use_git=*/true, fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } @@ -138,16 +148,20 @@ TEST_CASE("malformed 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, /*use_git=*/false, fail_func)); + CHECK_FALSE(ReadSourceTarget( + name, consumer, hash_type, /*use_git=*/false, fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } SECTION("via git tree") { - CHECK_FALSE( - ReadSourceTarget(name, consumer, /*use_git=*/true, fail_func)); + CHECK_FALSE(ReadSourceTarget( + name, consumer, hash_type, /*use_git=*/true, fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } @@ -160,14 +174,18 @@ TEST_CASE("subdir file") { 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, /*use_git=*/false)); + CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); CHECK(artifacts["bar/file"]["type"] == "LOCAL"); CHECK(artifacts["bar/file"]["data"]["path"] == "foo/bar/file"); } SECTION("via git tree") { - CHECK(ReadSourceTarget(name, consumer, /*use_git=*/true)); + 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 @@ -183,14 +201,18 @@ TEST_CASE("subdir symlink") { 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, /*use_git=*/false)); + CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); CHECK(artifacts["link"]["type"] == "LOCAL"); CHECK(artifacts["link"]["data"]["path"] == "foo/link"); } SECTION("via git tree") { - CHECK(ReadSourceTarget(name, consumer, /*use_git=*/true)); + CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); CHECK(artifacts["link"]["type"] == "KNOWN"); CHECK(artifacts["link"]["data"]["id"] == (ProtocolTraits::Instance().IsCompatible() ? kSrcLinkIdSha256 diff --git a/test/buildtool/build_engine/target_map/target_map.test.cpp b/test/buildtool/build_engine/target_map/target_map.test.cpp index cb8aa230..99fe1d4e 100644 --- a/test/buildtool/build_engine/target_map/target_map.test.cpp +++ b/test/buildtool/build_engine/target_map/target_map.test.cpp @@ -93,8 +93,10 @@ TEST_CASE("simple targets", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -720,8 +722,10 @@ TEST_CASE("configuration deduplication", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -830,8 +834,10 @@ TEST_CASE("generator functions in string arguments", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -952,8 +958,10 @@ TEST_CASE("built-in rules", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -1186,8 +1194,10 @@ TEST_CASE("target reference", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -1351,8 +1361,10 @@ TEST_CASE("trees", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -1480,8 +1492,10 @@ TEST_CASE("RESULT error reporting", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -1668,8 +1682,10 @@ TEST_CASE("wrong arguments", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); diff --git a/test/buildtool/file_system/file_root.test.cpp b/test/buildtool/file_system/file_root.test.cpp index 1e7b9e7b..1a27dd1b 100644 --- a/test/buildtool/file_system/file_root.test.cpp +++ b/test/buildtool/file_system/file_root.test.cpp @@ -374,89 +374,94 @@ TEST_CASE("Reading blob type", "[file_root]") { } } -static void CheckLocalRoot(bool ignore_special) noexcept; -static void CheckGitRoot(bool ignore_special) noexcept; +static void CheckLocalRoot(HashFunction::Type hash_type, + bool ignore_special) noexcept; +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; + SECTION("local root") { - CheckLocalRoot(/*ignore_special=*/false); + CheckLocalRoot(hash_type, /*ignore_special=*/false); } SECTION("git root") { - CheckGitRoot(/*ignore_special=*/false); + CheckGitRoot(hash_type, /*ignore_special=*/false); } SECTION("local root ignore-special") { - CheckLocalRoot(/*ignore_special=*/true); + CheckLocalRoot(hash_type, /*ignore_special=*/true); } SECTION("git root ignore-special") { - CheckGitRoot(/*ignore_special=*/true); + CheckGitRoot(hash_type, /*ignore_special=*/true); } } -static void CheckLocalRoot(bool ignore_special) noexcept { +static void CheckLocalRoot(HashFunction::Type hash_type, + bool ignore_special) noexcept { auto const root_path = CreateTestRepoSymlinks(true); REQUIRE(root_path); auto const root = FileRoot{*root_path, ignore_special}; - auto const desc = root.ToArtifactDescription("baz/foo", "repo"); + auto const desc = root.ToArtifactDescription(hash_type, "baz/foo", "repo"); REQUIRE(desc); CHECK(*desc == ArtifactDescription::CreateLocal( std::filesystem::path{"baz/foo"}, "repo")); - CHECK(root.ToArtifactDescription("does_not_exist", "repo")); + CHECK(root.ToArtifactDescription(hash_type, "does_not_exist", "repo")); } -static void CheckGitRoot(bool ignore_special) noexcept { +static void CheckGitRoot(HashFunction::Type hash_type, + bool ignore_special) noexcept { auto const repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); auto const root = FileRoot::FromGit(*repo_path, kTreeSymId, ignore_special); REQUIRE(root); - auto const foo = root->ToArtifactDescription("baz/foo", "repo"); + auto const foo = root->ToArtifactDescription(hash_type, "baz/foo", "repo"); REQUIRE(foo); - if (ProtocolTraits::Instance().IsCompatible()) { - auto const digest = - ArtifactDigestFactory::Create(HashFunction::Type::PlainSHA256, - kFooIdSha256, - kFooContentLength, - /*is_tree=*/false); + if (not ProtocolTraits::IsNative(hash_type)) { + auto const digest = ArtifactDigestFactory::Create(hash_type, + kFooIdSha256, + kFooContentLength, + /*is_tree=*/false); REQUIRE(digest); CHECK(*foo == ArtifactDescription::CreateKnown(*digest, ObjectType::File)); } else { - auto const digest = - ArtifactDigestFactory::Create(HashFunction::Type::GitSHA1, - kFooIdGitSha1, - kFooContentLength, - /*is_tree=*/false); + auto const digest = ArtifactDigestFactory::Create(hash_type, + kFooIdGitSha1, + kFooContentLength, + /*is_tree=*/false); REQUIRE(digest); CHECK(*foo == ArtifactDescription::CreateKnown( *digest, ObjectType::File, "repo")); } - auto const bar = root->ToArtifactDescription("baz/bar", "repo"); + auto const bar = root->ToArtifactDescription(hash_type, "baz/bar", "repo"); REQUIRE(bar); - if (ProtocolTraits::Instance().IsCompatible()) { - auto const digest = - ArtifactDigestFactory::Create(HashFunction::Type::PlainSHA256, - kBarIdSha256, - kBarContentLength, - /*is_tree=*/false); + if (not ProtocolTraits::IsNative(hash_type)) { + auto const digest = ArtifactDigestFactory::Create(hash_type, + kBarIdSha256, + kBarContentLength, + /*is_tree=*/false); REQUIRE(digest); CHECK(*bar == ArtifactDescription::CreateKnown(*digest, ObjectType::Executable)); } else { - auto const digest = - ArtifactDigestFactory::Create(HashFunction::Type::GitSHA1, - kBarIdGitSha1, - kBarContentLength, - /*is_tree=*/false); + auto const digest = ArtifactDigestFactory::Create(hash_type, + kBarIdGitSha1, + kBarContentLength, + /*is_tree=*/false); REQUIRE(digest); CHECK(*bar == ArtifactDescription::CreateKnown( *digest, ObjectType::Executable, "repo")); } - CHECK_FALSE(root->ToArtifactDescription("baz", "repo")); - CHECK_FALSE(root->ToArtifactDescription("does_not_exist", "repo")); + CHECK_FALSE(root->ToArtifactDescription(hash_type, "baz", "repo")); + CHECK_FALSE( + root->ToArtifactDescription(hash_type, "does_not_exist", "repo")); } |