Skip to content

Commit

Permalink
Merge pull request #24236 from IoannisRP/ik-bazel-tests-serde
Browse files Browse the repository at this point in the history
Ik bazel tests serde
  • Loading branch information
dotnwat authored Nov 21, 2024
2 parents 13843b5 + 5967185 commit 04211b2
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 8 deletions.
9 changes: 9 additions & 0 deletions bazel/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def _redpanda_cc_test(
memory,
cpu,
srcs = [],
defines = [],
deps = [],
extra_args = [],
custom_args = [],
Expand All @@ -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
Expand Down Expand Up @@ -114,6 +116,7 @@ def _redpanda_cc_test(
name = name,
timeout = timeout,
srcs = srcs,
defines = defines,
deps = deps,
copts = redpanda_copts(),
args = args,
Expand Down Expand Up @@ -147,6 +150,7 @@ def redpanda_cc_gtest(
name,
timeout,
srcs = [],
defines = [],
deps = [],
args = [],
env = {},
Expand All @@ -159,6 +163,7 @@ def redpanda_cc_gtest(
name = name,
timeout = timeout,
srcs = srcs,
defines = defines,
cpu = cpu,
memory = memory,
deps = deps,
Expand All @@ -173,6 +178,7 @@ def redpanda_cc_btest(
name,
timeout,
srcs = [],
defines = [],
deps = [],
args = [],
env = {},
Expand All @@ -186,6 +192,7 @@ def redpanda_cc_btest(
name = name,
timeout = timeout,
srcs = srcs,
defines = defines,
deps = deps,
cpu = cpu,
memory = memory,
Expand All @@ -200,6 +207,7 @@ def redpanda_cc_bench(
name,
timeout,
srcs = [],
defines = [],
deps = [],
args = [],
env = {},
Expand All @@ -215,6 +223,7 @@ def redpanda_cc_bench(
name = name,
timeout = timeout,
srcs = srcs,
defines = defines,
deps = deps,
custom_args = args,
tags = [
Expand Down
10 changes: 4 additions & 6 deletions src/v/serde/rw/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include "serde/type_str.h"
#include "ssx/sformat.h"

#include <cinttypes>
#include <limits>
#include <utility>

namespace serde {

Expand All @@ -26,9 +26,7 @@ requires(serde_is_enum_v<std::decay_t<T>>)
void tag_invoke(tag_t<write_tag>, iobuf& out, T t) {
using Type = std::decay_t<T>;
const auto val = static_cast<std::underlying_type_t<Type>>(t);
if (unlikely(
val > std::numeric_limits<serde_enum_serialized_t>::max()
|| val < std::numeric_limits<serde_enum_serialized_t>::min())) {
if (unlikely(!std::in_range<serde_enum_serialized_t>(val))) {
throw serde_exception{fmt_with_ctx(
ssx::sformat,
"serde: enum of type {} has value {} which is out of bounds for "
Expand All @@ -46,8 +44,8 @@ void tag_invoke(
using Type = std::decay_t<T>;

const auto val = read_nested<serde_enum_serialized_t>(in, bytes_left_limit);
if (unlikely(
val > std::numeric_limits<std::underlying_type_t<Type>>::max())) {
if (unlikely(std::cmp_greater(
val, std::numeric_limits<std::underlying_type_t<Type>>::max()))) {
throw serde_exception(fmt_with_ctx(
ssx::sformat,
"enum value {} too large for {}",
Expand Down
42 changes: 42 additions & 0 deletions src/v/serde/test/BUILD
Original file line number Diff line number Diff line change
@@ -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",
],
)
17 changes: 15 additions & 2 deletions src/v/serde/test/serde_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -36,6 +48,7 @@
#include <limits>
#include <optional>
#include <ratio>
#include <utility>

struct custom_read_write {
friend inline void read_nested(
Expand Down Expand Up @@ -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?",
Expand Down

0 comments on commit 04211b2

Please sign in to comment.