diff --git a/bazel/test.bzl b/bazel/test.bzl index f0f86be2acda..96c40310ffb1 100644 --- a/bazel/test.bzl +++ b/bazel/test.bzl @@ -58,6 +58,7 @@ def _redpanda_cc_test( memory, cpu, srcs = [], + defines = [], deps = [], extra_args = [], custom_args = [], @@ -74,6 +75,7 @@ def _redpanda_cc_test( timeout: same as native cc_test dash_dash_protocol: false for google test, true for boost test srcs: test source files + defines: definitions of object-like macros deps: test dependencies memory: seastar memory as a string ("1GB" or "512MiB" or "256M") cpu: seastar cores @@ -114,6 +116,7 @@ def _redpanda_cc_test( name = name, timeout = timeout, srcs = srcs, + defines = defines, deps = deps, copts = redpanda_copts(), args = args, @@ -147,6 +150,7 @@ def redpanda_cc_gtest( name, timeout, srcs = [], + defines = [], deps = [], args = [], env = {}, @@ -159,6 +163,7 @@ def redpanda_cc_gtest( name = name, timeout = timeout, srcs = srcs, + defines = defines, cpu = cpu, memory = memory, deps = deps, @@ -173,6 +178,7 @@ def redpanda_cc_btest( name, timeout, srcs = [], + defines = [], deps = [], args = [], env = {}, @@ -186,6 +192,7 @@ def redpanda_cc_btest( name = name, timeout = timeout, srcs = srcs, + defines = defines, deps = deps, cpu = cpu, memory = memory, @@ -200,6 +207,7 @@ def redpanda_cc_bench( name, timeout, srcs = [], + defines = [], deps = [], args = [], env = {}, @@ -215,6 +223,7 @@ def redpanda_cc_bench( name = name, timeout = timeout, srcs = srcs, + defines = defines, deps = deps, custom_args = args, tags = [ diff --git a/src/v/serde/rw/enum.h b/src/v/serde/rw/enum.h index f2e43e07bdf2..976771adf7ed 100644 --- a/src/v/serde/rw/enum.h +++ b/src/v/serde/rw/enum.h @@ -16,8 +16,8 @@ #include "serde/type_str.h" #include "ssx/sformat.h" -#include #include +#include namespace serde { @@ -26,9 +26,7 @@ requires(serde_is_enum_v>) void tag_invoke(tag_t, iobuf& out, T t) { using Type = std::decay_t; const auto val = static_cast>(t); - if (unlikely( - val > std::numeric_limits::max() - || val < std::numeric_limits::min())) { + if (unlikely(!std::in_range(val))) { throw serde_exception{fmt_with_ctx( ssx::sformat, "serde: enum of type {} has value {} which is out of bounds for " @@ -46,8 +44,8 @@ void tag_invoke( using Type = std::decay_t; const auto val = read_nested(in, bytes_left_limit); - if (unlikely( - val > std::numeric_limits>::max())) { + if (unlikely(std::cmp_greater( + val, std::numeric_limits>::max()))) { throw serde_exception(fmt_with_ctx( ssx::sformat, "enum value {} too large for {}", diff --git a/src/v/serde/test/BUILD b/src/v/serde/test/BUILD new file mode 100644 index 000000000000..df1c7a007b8f --- /dev/null +++ b/src/v/serde/test/BUILD @@ -0,0 +1,42 @@ +load("//bazel:test.bzl", "redpanda_cc_btest") + +redpanda_cc_btest( + name = "serde_test", + timeout = "short", + srcs = [ + "serde_test.cc", + ], + defines = [ + "SERDE_TEST", + ], + deps = [ + "//src/v/bytes:random", + "//src/v/container:fragmented_vector", + "//src/v/hashing:crc32c", + "//src/v/model", + "//src/v/random:generators", + "//src/v/serde", + "//src/v/serde:array", + "//src/v/serde:bool_class", + "//src/v/serde:bytes", + "//src/v/serde:chrono", + "//src/v/serde:enum", + "//src/v/serde:inet_address", + "//src/v/serde:iobuf", + "//src/v/serde:map", + "//src/v/serde:set", + "//src/v/serde:sstring", + "//src/v/serde:variant", + "//src/v/test_utils:random", + "//src/v/test_utils:seastar_boost", + "//src/v/utils:tristate", + "@abseil-cpp//absl/container:btree", + "@abseil-cpp//absl/container:flat_hash_map", + "@abseil-cpp//absl/container:node_hash_map", + "@abseil-cpp//absl/container:node_hash_set", + "@boost//:container_hash", + "@boost//:test", + "@seastar", + "@seastar//:testing", + ], +) diff --git a/src/v/serde/test/serde_test.cc b/src/v/serde/test/serde_test.cc index dd2a9628519f..a7578e937369 100644 --- a/src/v/serde/test/serde_test.cc +++ b/src/v/serde/test/serde_test.cc @@ -13,9 +13,21 @@ #include "model/fundamental.h" #include "model/metadata.h" #include "random/generators.h" +#include "serde/async.h" +#include "serde/peek.h" +#include "serde/rw/array.h" +#include "serde/rw/bool_class.h" +#include "serde/rw/bytes.h" +#include "serde/rw/chrono.h" +#include "serde/rw/enum.h" +#include "serde/rw/envelope.h" +#include "serde/rw/inet_address.h" +#include "serde/rw/iobuf.h" +#include "serde/rw/map.h" #include "serde/rw/rw.h" +#include "serde/rw/set.h" +#include "serde/rw/sstring.h" #include "serde/rw/variant.h" -#include "serde/serde.h" #include "test_utils/randoms.h" #include "utils/tristate.h" @@ -36,6 +48,7 @@ #include #include #include +#include struct custom_read_write { friend inline void read_nested( @@ -468,7 +481,7 @@ ss::future<> test_snapshot_header::serde_async_read( crc.extend(ss::cpu_to_le(version)); crc.extend(ss::cpu_to_le(metadata_size)); - if (header_crc != crc.value()) { + if (std::cmp_not_equal(header_crc, crc.value())) { throw std::runtime_error(fmt::format( "Corrupt snapshot. Failed to verify header crc: {} != " "{}: path?",