diff options
Diffstat (limited to 'test')
19 files changed, 116 insertions, 55 deletions
diff --git a/test/buildtool/execution_api/bazel/TARGETS b/test/buildtool/execution_api/bazel/TARGETS index eb888328..4bb08931 100644 --- a/test/buildtool/execution_api/bazel/TARGETS +++ b/test/buildtool/execution_api/bazel/TARGETS @@ -14,6 +14,7 @@ , ["@", "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"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -32,6 +33,7 @@ , ["@", "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"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -50,6 +52,7 @@ , ["@", "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"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -70,6 +73,7 @@ , ["@", "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"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -89,6 +93,7 @@ ] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["utils", "blob_creator"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } 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 5c906b44..498b0492 100644 --- a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp @@ -20,6 +20,7 @@ #include "gsl/gsl" #include "src/buildtool/common/artifact_digest.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_cas_client.hpp" #include "src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp" @@ -47,7 +48,8 @@ TEST_CASE("Bazel internals: CAS Client", "[execution_api]") { SECTION("Valid digest and blob") { // digest of "test" - auto digest = ArtifactDigest::Create<ObjectType::File>(content); + auto digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content); // Valid blob BazelBlob blob{digest, content, /*is_exec=*/false}; 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 57967957..00da3636 100755..100644 --- a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp @@ -17,6 +17,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/remote/retry_config.hpp" +#include "src/buildtool/crypto/hash_function.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" @@ -27,8 +28,9 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { std::string instance_name{"remote-execution"}; std::string content("test"); - auto test_digest = static_cast<bazel_re::Digest>( - ArtifactDigest::Create<ObjectType::File>(content)); + auto test_digest = + static_cast<bazel_re::Digest>(ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content)); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); @@ -48,11 +50,11 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { config.skip_cache_lookup = false; SECTION("Immediate execution and response") { - auto action_immediate = - CreateAction(instance_name, - {"echo", "-n", content}, - {}, - remote_config->platform_properties); + auto action_immediate = CreateAction(instance_name, + {"echo", "-n", content}, + {}, + remote_config->platform_properties, + HashFunction::Instance()); REQUIRE(action_immediate); auto response = execution_client.Execute( @@ -71,7 +73,8 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { CreateAction(instance_name, {"sh", "-c", "sleep 1s; echo -n test"}, {}, - remote_config->platform_properties); + remote_config->platform_properties, + HashFunction::Instance()); SECTION("Blocking, immediately obtain result") { auto response = execution_client.Execute( @@ -105,8 +108,9 @@ TEST_CASE("Bazel internals: Execution Client using env variables", "[execution_api]") { std::string instance_name{"remote-execution"}; std::string content("contents of env variable"); - auto test_digest = static_cast<bazel_re::Digest>( - ArtifactDigest::Create<ObjectType::File>(content)); + auto test_digest = + static_cast<bazel_re::Digest>(ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content)); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); @@ -128,7 +132,8 @@ TEST_CASE("Bazel internals: Execution Client using env variables", CreateAction(instance_name, {"/bin/sh", "-c", "set -e\necho -n ${MYTESTVAR}"}, {{"MYTESTVAR", content}}, - remote_config->platform_properties); + remote_config->platform_properties, + HashFunction::Instance()); REQUIRE(action); auto response = 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 b56021c8..233621e9 100644 --- a/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp @@ -17,6 +17,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_description.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" @@ -36,9 +37,9 @@ TEST_CASE("Bazel internals: MessageFactory", "[execution_api]") { REQUIRE(FileSystemManager::CreateSymlink("file1", link)); // create the corresponding blobs - auto file1_blob = CreateBlobFromPath(file1); - auto file2_blob = CreateBlobFromPath(file2); - auto link_blob = CreateBlobFromPath(link); + auto file1_blob = CreateBlobFromPath(file1, HashFunction::Instance()); + auto file2_blob = CreateBlobFromPath(file2, HashFunction::Instance()); + auto link_blob = CreateBlobFromPath(link, HashFunction::Instance()); CHECK(file1_blob); CHECK(file2_blob); diff --git a/test/buildtool/execution_api/bazel/bazel_network.test.cpp b/test/buildtool/execution_api/bazel/bazel_network.test.cpp index d60af9fc..ff05eefb 100644 --- a/test/buildtool/execution_api/bazel/bazel_network.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_network.test.cpp @@ -22,6 +22,7 @@ #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/compatibility/compatibility.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/bazel/bazel_network.hpp" @@ -55,13 +56,16 @@ TEST_CASE("Bazel network: write/read blobs", "[execution_api]") { std::string content_bar("bar"); std::string content_baz(kLargeSize, 'x'); // single larger blob - BazelBlob foo{ArtifactDigest::Create<ObjectType::File>(content_foo), + BazelBlob foo{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_foo), content_foo, /*is_exec=*/false}; - BazelBlob bar{ArtifactDigest::Create<ObjectType::File>(content_bar), + BazelBlob bar{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_bar), content_bar, /*is_exec=*/false}; - BazelBlob baz{ArtifactDigest::Create<ObjectType::File>(content_baz), + BazelBlob baz{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_baz), content_baz, /*is_exec=*/false}; @@ -113,10 +117,12 @@ TEST_CASE("Bazel network: read blobs with unknown size", "[execution_api]") { std::string content_foo("foo"); std::string content_bar(kLargeSize, 'x'); // single larger blob - BazelBlob foo{ArtifactDigest::Create<ObjectType::File>(content_foo), + BazelBlob foo{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_foo), content_foo, /*is_exec=*/false}; - BazelBlob bar{ArtifactDigest::Create<ObjectType::File>(content_bar), + BazelBlob bar{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_bar), content_bar, /*is_exec=*/false}; diff --git a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp index 293d2c45..fda769e1 100644 --- a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp @@ -19,6 +19,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/common/artifact_digest.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/bazel/bytestream_client.hpp" @@ -48,7 +49,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { // digest of "foobar" auto digest = static_cast<bazel_re::Digest>( - ArtifactDigest::Create<ObjectType::File>(content)); + ArtifactDigest::Create<ObjectType::File>(HashFunction::Instance(), + content)); CHECK(stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}", instance_name, @@ -77,7 +79,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { // digest of "instance_nameinstance_nameinstance_..." auto digest = static_cast<bazel_re::Digest>( - ArtifactDigest::Create<ObjectType::File>(content)); + ArtifactDigest::Create<ObjectType::File>(HashFunction::Instance(), + content)); CHECK(stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}", instance_name, @@ -131,13 +134,16 @@ TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") { SECTION("Upload small blobs") { std::string instance_name{"remote-execution"}; - BazelBlob foo{ArtifactDigest::Create<ObjectType::File>("foo"), + BazelBlob foo{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "foo"), "foo", /*is_exec=*/false}; - BazelBlob bar{ArtifactDigest::Create<ObjectType::File>("bar"), + BazelBlob bar{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "bar"), "bar", /*is_exec=*/false}; - BazelBlob baz{ArtifactDigest::Create<ObjectType::File>("baz"), + BazelBlob baz{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "baz"), "baz", /*is_exec=*/false}; @@ -184,13 +190,16 @@ TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") { content_baz[i] = instance_name[(i + 2) % instance_name.size()]; } - BazelBlob foo{ArtifactDigest::Create<ObjectType::File>(content_foo), + BazelBlob foo{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_foo), content_foo, /*is_exec=*/false}; - BazelBlob bar{ArtifactDigest::Create<ObjectType::File>(content_bar), + BazelBlob bar{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_bar), content_bar, /*is_exec=*/false}; - BazelBlob baz{ArtifactDigest::Create<ObjectType::File>(content_baz), + BazelBlob baz{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_baz), content_baz, /*is_exec=*/false}; diff --git a/test/buildtool/execution_api/common/TARGETS b/test/buildtool/execution_api/common/TARGETS index b4e2c4a9..89da6ab8 100644 --- a/test/buildtool/execution_api/common/TARGETS +++ b/test/buildtool/execution_api/common/TARGETS @@ -10,6 +10,7 @@ , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["@", "src", "src/buildtool/logging", "log_level"] , ["@", "src", "src/buildtool/logging", "logging"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "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 e2d8a17d..e00a3b32 100644 --- a/test/buildtool/execution_api/common/api_test.hpp +++ b/test/buildtool/execution_api/common/api_test.hpp @@ -21,6 +21,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_description.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" #include "src/buildtool/execution_api/common/execution_response.hpp" @@ -128,7 +129,8 @@ using ExecProps = std::map<std::string, std::string>; ExecProps const& props, bool is_hermetic = false) { std::string test_content("test"); - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_content); std::string output_path{"output_file"}; @@ -205,7 +207,8 @@ using ExecProps = std::map<std::string, std::string>; ExecProps const& props, bool is_hermetic = false) { std::string test_content("test"); - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_content); auto input_artifact_opt = ArtifactDescription::CreateKnown(test_digest, ObjectType::File) @@ -289,7 +292,8 @@ using ExecProps = std::map<std::string, std::string>; ApiFactory const& api_factory, ExecProps const& props) { std::string test_content("test"); - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_content); std::string output_path{"output_file"}; diff --git a/test/buildtool/execution_api/execution_service/TARGETS b/test/buildtool/execution_api/execution_service/TARGETS index 754615d5..f50057c7 100644 --- a/test/buildtool/execution_api/execution_service/TARGETS +++ b/test/buildtool/execution_api/execution_service/TARGETS @@ -17,6 +17,7 @@ , ["@", "src", "src/buildtool/storage", "config"] , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "gsl", "", "gsl"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "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 f0fcf949..845d94aa 100644 --- a/test/buildtool/execution_api/execution_service/cas_server.test.cpp +++ b/test/buildtool/execution_api/execution_service/cas_server.test.cpp @@ -17,6 +17,7 @@ #include "catch2/catch_test_macros.hpp" #include "gsl/gsl" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/execution_service/cas_server.hpp" #include "src/buildtool/file_system/git_repo.hpp" #include "src/buildtool/file_system/object_type.hpp" @@ -57,15 +58,16 @@ TEST_CASE("CAS Service: upload incomplete tree", "[execution_service]") { auto empty_entries = GitRepo::tree_entries_t{}; auto empty_tree = GitRepo::CreateShallowTree(empty_entries); REQUIRE(empty_tree); - auto empty_tree_digest = - ArtifactDigest::Create<ObjectType::Tree>(empty_tree->second); + auto empty_tree_digest = ArtifactDigest::Create<ObjectType::Tree>( + HashFunction::Instance(), empty_tree->second); // Create a tree containing the empty tree. auto entries = GitRepo::tree_entries_t{}; entries[empty_tree->first].emplace_back("empty_tree", ObjectType::Tree); auto tree = GitRepo::CreateShallowTree(entries); REQUIRE(tree); - auto tree_digest = ArtifactDigest::Create<ObjectType::Tree>(tree->second); + auto tree_digest = ArtifactDigest::Create<ObjectType::Tree>( + HashFunction::Instance(), tree->second); // Upload tree. The tree invariant is violated, thus, a negative answer is // expected. diff --git a/test/buildtool/execution_api/local/TARGETS b/test/buildtool/execution_api/local/TARGETS index 41870428..212bf0b6 100644 --- a/test/buildtool/execution_api/local/TARGETS +++ b/test/buildtool/execution_api/local/TARGETS @@ -15,6 +15,7 @@ , ["utils", "test_storage_config"] , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "src", "src/buildtool/storage", "config"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "execution_api", "local"] } diff --git a/test/buildtool/execution_api/local/local_execution.test.cpp b/test/buildtool/execution_api/local/local_execution.test.cpp index 72db2800..cac83b2a 100644 --- a/test/buildtool/execution_api/local/local_execution.test.cpp +++ b/test/buildtool/execution_api/local/local_execution.test.cpp @@ -21,6 +21,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/common/repository_config.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/local/config.hpp" #include "src/buildtool/execution_api/local/local_api.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" @@ -172,7 +173,8 @@ TEST_CASE("LocalExecution: No input, create output", "[execution_api]") { &storage_config.Get(), &storage, &local_exec_config, &repo_config); std::string test_content("test"); - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_content); std::string output_path{"output_file"}; std::vector<std::string> const cmdline = { @@ -231,7 +233,8 @@ TEST_CASE("LocalExecution: One input copied to output", "[execution_api]") { &storage_config.Get(), &storage, &local_exec_config, &repo_config); std::string test_content("test"); - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_content); REQUIRE(api.Upload(ArtifactBlobContainer{{ArtifactBlob{ test_digest, test_content, /*is_exec=*/false}}}, false)); diff --git a/test/buildtool/file_system/object_cas.test.cpp b/test/buildtool/file_system/object_cas.test.cpp index be9ba709..df72d038 100644 --- a/test/buildtool/file_system/object_cas.test.cpp +++ b/test/buildtool/file_system/object_cas.test.cpp @@ -30,7 +30,8 @@ TEST_CASE("ObjectCAS", "[file_system]") { auto gen_config = storage_config.Get().CreateGenerationConfig(0); std::string test_content{"test"}; - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_content); SECTION("CAS for files") { ObjectCAS<ObjectType::File> cas{gen_config.cas_f}; diff --git a/test/buildtool/storage/TARGETS b/test/buildtool/storage/TARGETS index 4a2881c3..a2b0b0d2 100644 --- a/test/buildtool/storage/TARGETS +++ b/test/buildtool/storage/TARGETS @@ -24,6 +24,7 @@ , ["utils", "blob_creator"] , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "src", "src/buildtool/storage", "config"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "storage"] } @@ -41,6 +42,7 @@ , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "src", "src/buildtool/storage", "config"] , ["utils", "test_storage_config"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "storage"] } diff --git a/test/buildtool/storage/local_ac.test.cpp b/test/buildtool/storage/local_ac.test.cpp index fdd8eec6..b3a4fcd1 100644 --- a/test/buildtool/storage/local_ac.test.cpp +++ b/test/buildtool/storage/local_ac.test.cpp @@ -18,6 +18,7 @@ #include "gsl/gsl" #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/bazel_types.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/storage/config.hpp" @@ -36,7 +37,8 @@ TEST_CASE("LocalAC: Single action, single result", "[storage]") { auto const& ac = storage.ActionCache(); auto const& cas = storage.CAS(); - auto action_id = ArtifactDigest::Create<ObjectType::File>("action"); + auto action_id = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "action"); CHECK(not ac.CachedResult(action_id)); CHECK(RunDummyExecution(&ac, &cas, action_id, "result")); auto ac_result = ac.CachedResult(action_id); @@ -50,8 +52,10 @@ TEST_CASE("LocalAC: Two different actions, two different results", auto const& ac = storage.ActionCache(); auto const& cas = storage.CAS(); - auto action_id1 = ArtifactDigest::Create<ObjectType::File>("action1"); - auto action_id2 = ArtifactDigest::Create<ObjectType::File>("action2"); + auto action_id1 = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "action1"); + auto action_id2 = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "action2"); CHECK(not ac.CachedResult(action_id1)); CHECK(not ac.CachedResult(action_id2)); @@ -79,8 +83,10 @@ TEST_CASE("LocalAC: Two different actions, same two results", "[storage]") { auto const& ac = storage.ActionCache(); auto const& cas = storage.CAS(); - auto action_id1 = ArtifactDigest::Create<ObjectType::File>("action1"); - auto action_id2 = ArtifactDigest::Create<ObjectType::File>("action2"); + auto action_id1 = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "action1"); + auto action_id2 = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "action2"); CHECK(not ac.CachedResult(action_id1)); CHECK(not ac.CachedResult(action_id2)); @@ -108,7 +114,8 @@ TEST_CASE("LocalAC: Same two actions, two different results", "[storage]") { auto const& ac = storage.ActionCache(); auto const& cas = storage.CAS(); - auto action_id = ArtifactDigest::Create<ObjectType::File>("same action"); + auto action_id = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "same action"); CHECK(not ac.CachedResult(action_id)); std::string result_content1{}; diff --git a/test/buildtool/storage/local_cas.test.cpp b/test/buildtool/storage/local_cas.test.cpp index ef77a6a1..c1d65b8e 100644 --- a/test/buildtool/storage/local_cas.test.cpp +++ b/test/buildtool/storage/local_cas.test.cpp @@ -17,6 +17,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_type.hpp" @@ -32,7 +33,8 @@ TEST_CASE("LocalCAS: Add blob to storage from bytes", "[storage]") { std::string test_bytes("test"); - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_bytes); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_bytes); // check blob not in storage CHECK(not cas.BlobPath(test_digest, true)); @@ -82,7 +84,8 @@ TEST_CASE("LocalCAS: Add blob to storage from non-executable file", std::filesystem::path non_exec_file{ "test/buildtool/storage/data/non_executable_file"}; - auto test_blob = CreateBlobFromPath(non_exec_file); + auto test_blob = + CreateBlobFromPath(non_exec_file, HashFunction::Instance()); REQUIRE(test_blob); // check blob not in storage @@ -132,7 +135,7 @@ TEST_CASE("LocalCAS: Add blob to storage from executable file", "[storage]") { std::filesystem::path exec_file{ "test/buildtool/storage/data/executable_file"}; - auto test_blob = CreateBlobFromPath(exec_file); + auto test_blob = CreateBlobFromPath(exec_file, HashFunction::Instance()); REQUIRE(test_blob); // check blob not in storage diff --git a/test/utils/TARGETS b/test/utils/TARGETS index b7a4db53..13ad7626 100644 --- a/test/utils/TARGETS +++ b/test/utils/TARGETS @@ -17,6 +17,7 @@ , "test_env" , "test_auth_config" , "test_remote_config" + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "utils"] } @@ -167,6 +168,7 @@ , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] } , "TESTS": diff --git a/test/utils/blob_creator.hpp b/test/utils/blob_creator.hpp index baa7cc86..944fb9d2 100644 --- a/test/utils/blob_creator.hpp +++ b/test/utils/blob_creator.hpp @@ -20,6 +20,7 @@ #include <string> #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_type.hpp" @@ -27,7 +28,8 @@ /// \brief Create a blob from the content found in file or symlink pointed to by /// given path. [[nodiscard]] static inline auto CreateBlobFromPath( - std::filesystem::path const& fpath) noexcept -> std::optional<BazelBlob> { + std::filesystem::path const& fpath, + HashFunction hash_function) noexcept -> std::optional<BazelBlob> { auto const type = FileSystemManager::Type(fpath, /*allow_upwards=*/true); if (not type) { return std::nullopt; @@ -36,9 +38,10 @@ if (not content.has_value()) { return std::nullopt; } - return BazelBlob{ArtifactDigest::Create<ObjectType::File>(*content), - *content, - IsExecutableObject(*type)}; + return BazelBlob{ + ArtifactDigest::Create<ObjectType::File>(hash_function, *content), + *content, + IsExecutableObject(*type)}; } #endif // INCLUDED_SRC_TEST_UTILS_BLOB_CREATOR_HPP diff --git a/test/utils/remote_execution/bazel_action_creator.hpp b/test/utils/remote_execution/bazel_action_creator.hpp index d915cda1..7b92428d 100644 --- a/test/utils/remote_execution/bazel_action_creator.hpp +++ b/test/utils/remote_execution/bazel_action_creator.hpp @@ -36,8 +36,8 @@ std::string const& instance_name, std::vector<std::string> const& args, std::map<std::string, std::string> const& env_vars, - std::map<std::string, std::string> const& properties) noexcept - -> std::unique_ptr<bazel_re::Digest> { + std::map<std::string, std::string> const& properties, + HashFunction hash_function) noexcept -> std::unique_ptr<bazel_re::Digest> { auto platform = std::make_unique<bazel_re::Platform>(); for (auto const& [name, value] : properties) { bazel_re::Platform_Property property; @@ -64,12 +64,14 @@ }); auto cmd_data = cmd.SerializeAsString(); - auto cmd_id = ArtifactDigest::Create<ObjectType::File>(cmd_data); + auto cmd_id = + ArtifactDigest::Create<ObjectType::File>(hash_function, cmd_data); blobs.emplace_back(cmd_id, cmd_data, /*is_exec=*/false); bazel_re::Directory empty_dir; auto dir_data = empty_dir.SerializeAsString(); - auto dir_id = ArtifactDigest::Create<ObjectType::Tree>(dir_data); + auto dir_id = + ArtifactDigest::Create<ObjectType::Tree>(hash_function, dir_data); blobs.emplace_back(dir_id, dir_data, /*is_exec=*/false); bazel_re::Action action; @@ -80,7 +82,8 @@ gsl::owner<bazel_re::Digest*>{new bazel_re::Digest{dir_id}}); auto action_data = action.SerializeAsString(); - auto action_id = ArtifactDigest::Create<ObjectType::File>(action_data); + auto action_id = + ArtifactDigest::Create<ObjectType::File>(hash_function, action_data); blobs.emplace_back(action_id, action_data, /*is_exec=*/false); auto auth_config = TestAuthConfig::ReadFromEnvironment(); |