summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-07-16 12:26:13 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-07-22 17:02:34 +0200
commit8f3a09e42d25f533e9d9a007125a7661cef3b653 (patch)
treecd384b19f0a1c95c0d01b3b43d6d93968518cbbc
parent7caf8d3fc009c34b6a1484eac4cbd1b697a2e3c4 (diff)
downloadjustbuild-8f3a09e42d25f533e9d9a007125a7661cef3b653.tar.gz
Remove singleton calls to HashFunction in tests
-rw-r--r--test/buildtool/execution_api/bazel/TARGETS3
-rw-r--r--test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp7
-rw-r--r--test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp27
-rw-r--r--test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp11
-rw-r--r--test/buildtool/execution_api/bazel/bytestream_client.test.cpp51
-rw-r--r--test/buildtool/execution_api/common/TARGETS1
-rw-r--r--test/buildtool/execution_api/common/api_test.hpp28
7 files changed, 86 insertions, 42 deletions
diff --git a/test/buildtool/execution_api/bazel/TARGETS b/test/buildtool/execution_api/bazel/TARGETS
index 972717c5..4cd01735 100644
--- a/test/buildtool/execution_api/bazel/TARGETS
+++ b/test/buildtool/execution_api/bazel/TARGETS
@@ -34,6 +34,7 @@
, ["@", "src", "src/buildtool/execution_api/remote", "config"]
, ["@", "src", "src/buildtool/file_system", "object_type"]
, ["@", "src", "src/buildtool/crypto", "hash_function"]
+ , ["@", "src", "src/buildtool/compatibility", "compatibility"]
]
, "stage": ["test", "buildtool", "execution_api", "bazel"]
}
@@ -53,6 +54,7 @@
, ["@", "src", "src/buildtool/execution_api/remote", "config"]
, ["@", "src", "src/buildtool/file_system", "object_type"]
, ["@", "src", "src/buildtool/crypto", "hash_function"]
+ , ["@", "src", "src/buildtool/compatibility", "compatibility"]
]
, "stage": ["test", "buildtool", "execution_api", "bazel"]
}
@@ -94,6 +96,7 @@
, ["@", "src", "src/buildtool/file_system", "object_type"]
, ["utils", "blob_creator"]
, ["@", "src", "src/buildtool/crypto", "hash_function"]
+ , ["@", "src", "src/buildtool/compatibility", "compatibility"]
]
, "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 498b0492..86cee26a 100644
--- a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp
+++ b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp
@@ -48,8 +48,11 @@ TEST_CASE("Bazel internals: CAS Client", "[execution_api]") {
SECTION("Valid digest and blob") {
// digest of "test"
- auto digest = ArtifactDigest::Create<ObjectType::File>(
- HashFunction::Instance(), content);
+ HashFunction const hash_function{
+ Compatibility::IsCompatible() ? HashFunction::JustHash::Compatible
+ : HashFunction::JustHash::Native};
+ auto digest =
+ ArtifactDigest::Create<ObjectType::File>(hash_function, 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 00da3636..87bf48cd 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/compatibility/compatibility.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"
@@ -28,9 +29,13 @@
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>(
- HashFunction::Instance(), content));
+
+ HashFunction const hash_function{Compatibility::IsCompatible()
+ ? HashFunction::JustHash::Compatible
+ : HashFunction::JustHash::Native};
+
+ auto test_digest = static_cast<bazel_re::Digest>(
+ ArtifactDigest::Create<ObjectType::File>(hash_function, content));
auto auth_config = TestAuthConfig::ReadFromEnvironment();
REQUIRE(auth_config);
@@ -54,7 +59,7 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") {
{"echo", "-n", content},
{},
remote_config->platform_properties,
- HashFunction::Instance());
+ hash_function);
REQUIRE(action_immediate);
auto response = execution_client.Execute(
@@ -74,7 +79,7 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") {
{"sh", "-c", "sleep 1s; echo -n test"},
{},
remote_config->platform_properties,
- HashFunction::Instance());
+ hash_function);
SECTION("Blocking, immediately obtain result") {
auto response = execution_client.Execute(
@@ -108,9 +113,13 @@ 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>(
- HashFunction::Instance(), content));
+
+ HashFunction const hash_function{Compatibility::IsCompatible()
+ ? HashFunction::JustHash::Compatible
+ : HashFunction::JustHash::Native};
+
+ auto test_digest = static_cast<bazel_re::Digest>(
+ ArtifactDigest::Create<ObjectType::File>(hash_function, content));
auto auth_config = TestAuthConfig::ReadFromEnvironment();
REQUIRE(auth_config);
@@ -133,7 +142,7 @@ TEST_CASE("Bazel internals: Execution Client using env variables",
{"/bin/sh", "-c", "set -e\necho -n ${MYTESTVAR}"},
{{"MYTESTVAR", content}},
remote_config->platform_properties,
- HashFunction::Instance());
+ hash_function);
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 233621e9..849f4485 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/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/bazel_msg/bazel_msg_factory.hpp"
@@ -36,10 +37,14 @@ TEST_CASE("Bazel internals: MessageFactory", "[execution_api]") {
std::filesystem::path link = subdir1 / "link";
REQUIRE(FileSystemManager::CreateSymlink("file1", link));
+ HashFunction const hash_function{Compatibility::IsCompatible()
+ ? HashFunction::JustHash::Compatible
+ : HashFunction::JustHash::Native};
+
// create the corresponding blobs
- auto file1_blob = CreateBlobFromPath(file1, HashFunction::Instance());
- auto file2_blob = CreateBlobFromPath(file2, HashFunction::Instance());
- auto link_blob = CreateBlobFromPath(link, HashFunction::Instance());
+ auto file1_blob = CreateBlobFromPath(file1, hash_function);
+ auto file2_blob = CreateBlobFromPath(file2, hash_function);
+ auto link_blob = CreateBlobFromPath(link, hash_function);
CHECK(file1_blob);
CHECK(file2_blob);
diff --git a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp
index fda769e1..aa08cc7f 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/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/common/execution_common.hpp"
@@ -43,14 +44,17 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") {
&*auth_config};
auto uuid = CreateUUIDVersion4(*CreateProcessUniqueId());
+ HashFunction const hash_function{Compatibility::IsCompatible()
+ ? HashFunction::JustHash::Compatible
+ : HashFunction::JustHash::Native};
+
SECTION("Upload small blob") {
std::string instance_name{"remote-execution"};
std::string content("foobar");
// digest of "foobar"
auto digest = static_cast<bazel_re::Digest>(
- ArtifactDigest::Create<ObjectType::File>(HashFunction::Instance(),
- content));
+ ArtifactDigest::Create<ObjectType::File>(hash_function, content));
CHECK(stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}",
instance_name,
@@ -79,8 +83,7 @@ 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>(HashFunction::Instance(),
- content));
+ ArtifactDigest::Create<ObjectType::File>(hash_function, content));
CHECK(stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}",
instance_name,
@@ -131,21 +134,25 @@ TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") {
&*auth_config};
auto uuid = CreateUUIDVersion4(*CreateProcessUniqueId());
+ HashFunction const hash_function{Compatibility::IsCompatible()
+ ? HashFunction::JustHash::Compatible
+ : HashFunction::JustHash::Native};
+
SECTION("Upload small blobs") {
std::string instance_name{"remote-execution"};
- BazelBlob foo{ArtifactDigest::Create<ObjectType::File>(
- HashFunction::Instance(), "foo"),
- "foo",
- /*is_exec=*/false};
- BazelBlob bar{ArtifactDigest::Create<ObjectType::File>(
- HashFunction::Instance(), "bar"),
- "bar",
- /*is_exec=*/false};
- BazelBlob baz{ArtifactDigest::Create<ObjectType::File>(
- HashFunction::Instance(), "baz"),
- "baz",
- /*is_exec=*/false};
+ BazelBlob foo{
+ ArtifactDigest::Create<ObjectType::File>(hash_function, "foo"),
+ "foo",
+ /*is_exec=*/false};
+ BazelBlob bar{
+ ArtifactDigest::Create<ObjectType::File>(hash_function, "bar"),
+ "bar",
+ /*is_exec=*/false};
+ BazelBlob baz{
+ ArtifactDigest::Create<ObjectType::File>(hash_function, "baz"),
+ "baz",
+ /*is_exec=*/false};
CHECK(stream.WriteMany<BazelBlob>(
{foo, bar, baz},
@@ -190,16 +197,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>(
- HashFunction::Instance(), content_foo),
+ BazelBlob foo{ArtifactDigest::Create<ObjectType::File>(hash_function,
+ content_foo),
content_foo,
/*is_exec=*/false};
- BazelBlob bar{ArtifactDigest::Create<ObjectType::File>(
- HashFunction::Instance(), content_bar),
+ BazelBlob bar{ArtifactDigest::Create<ObjectType::File>(hash_function,
+ content_bar),
content_bar,
/*is_exec=*/false};
- BazelBlob baz{ArtifactDigest::Create<ObjectType::File>(
- HashFunction::Instance(), content_baz),
+ BazelBlob baz{ArtifactDigest::Create<ObjectType::File>(hash_function,
+ content_baz),
content_baz,
/*is_exec=*/false};
diff --git a/test/buildtool/execution_api/common/TARGETS b/test/buildtool/execution_api/common/TARGETS
index 89da6ab8..c181447b 100644
--- a/test/buildtool/execution_api/common/TARGETS
+++ b/test/buildtool/execution_api/common/TARGETS
@@ -11,6 +11,7 @@
, ["@", "src", "src/buildtool/logging", "log_level"]
, ["@", "src", "src/buildtool/logging", "logging"]
, ["@", "src", "src/buildtool/crypto", "hash_function"]
+ , ["@", "src", "src/buildtool/compatibility", "compatibility"]
]
, "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 e00a3b32..81a11364 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/compatibility/compatibility.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"
@@ -129,8 +130,13 @@ 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>(
- HashFunction::Instance(), test_content);
+
+ HashFunction const hash_function{Compatibility::IsCompatible()
+ ? HashFunction::JustHash::Compatible
+ : HashFunction::JustHash::Native};
+
+ auto test_digest =
+ ArtifactDigest::Create<ObjectType::File>(hash_function, test_content);
std::string output_path{"output_file"};
@@ -207,8 +213,13 @@ 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>(
- HashFunction::Instance(), test_content);
+
+ HashFunction const hash_function{Compatibility::IsCompatible()
+ ? HashFunction::JustHash::Compatible
+ : HashFunction::JustHash::Native};
+
+ auto test_digest =
+ ArtifactDigest::Create<ObjectType::File>(hash_function, test_content);
auto input_artifact_opt =
ArtifactDescription::CreateKnown(test_digest, ObjectType::File)
@@ -292,8 +303,13 @@ 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>(
- HashFunction::Instance(), test_content);
+
+ HashFunction const hash_function{Compatibility::IsCompatible()
+ ? HashFunction::JustHash::Compatible
+ : HashFunction::JustHash::Native};
+
+ auto test_digest =
+ ArtifactDigest::Create<ObjectType::File>(hash_function, test_content);
std::string output_path{"output_file"};