Skip to content

Commit 8e4d1ba

Browse files
authored
Warnings in tests are errors (#7951)
1 parent e7002df commit 8e4d1ba

39 files changed

Lines changed: 391 additions & 401 deletions

cmake/common.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function(add_unit_test name)
3636
enable_coverage(${name})
3737
target_link_libraries(${name} PRIVATE ccfcrypto -pthread)
3838
add_san(${name})
39+
add_warning_checks(${name})
3940

4041
add_test(NAME ${name} COMMAND ${name})
4142
set_property(TEST ${name} APPEND PROPERTY LABELS unit)

include/ccf/ds/contiguous_set.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ namespace ccf::ds
257257
auto next_it = std::next(it);
258258
if (next_it != ranges.end())
259259
{
260-
if (it->first + it->second + 1 == next_it->first)
260+
if (it->first + static_cast<T>(it->second) + 1 == next_it->first)
261261
{
262262
it->second = it->second + 1 + next_it->second;
263263
ranges.erase(next_it);
@@ -463,7 +463,7 @@ namespace ccf::ds
463463
{
464464
for (auto n = from; n <= from + additional; ++n)
465465
{
466-
const auto b = insert(n);
466+
insert(n);
467467
}
468468
}
469469

src/consensus/aft/test/committable_suffix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ DOCTEST_TEST_CASE_TEMPLATE("Multi-term divergence", T, WorstCase, RandomCase)
646646
channels_primary->messages.clear();
647647
};
648648

649-
const auto num_terms = rand() % 30 + 5;
649+
const size_t num_terms = rand() % 30 + 5;
650650
if constexpr (is_worst_case)
651651
{
652652
std::cout << fmt::format("Worst case construction with {} terms", num_terms)

src/consensus/aft/test/logging_stub.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ namespace aft
2828

2929
LedgerStubProxy(const ccf::NodeId& id) : _id(id) {}
3030

31+
virtual ~LedgerStubProxy() = default;
32+
3133
virtual void init(Index, Index) {}
3234

3335
virtual void put_entry(
@@ -45,7 +47,7 @@ namespace aft
4547
// (to mirror the deserialisation in LoggingStubStore::ExecutionWrapper).
4648
// We also size-prefix, so in a buffer of multiple of these messages we
4749
// can extract each with get_entry
48-
const size_t idx = ledger.size() + 1;
50+
[[maybe_unused]] const size_t idx = ledger.size() + 1;
4951
assert(idx == index);
5052
auto additional_size =
5153
sizeof(size_t) /* size-prefix */ + ADDITIONAL_METADATA_SIZE;
@@ -341,6 +343,8 @@ namespace aft
341343
public:
342344
LoggingStubStore(ccf::NodeId id) : _id(id) {}
343345

346+
virtual ~LoggingStubStore() = default;
347+
344348
virtual void set_set_retired_committed_hook(
345349
RCHook set_retired_committed_hook_)
346350
{
@@ -523,7 +527,7 @@ namespace aft
523527
// Read wrapping term and version
524528
auto data_ = data.data();
525529
auto size = data.size();
526-
const auto committable = serialized::read<bool>(data_, size);
530+
serialized::read<bool>(data_, size);
527531
serialized::read<aft::Term>(data_, size);
528532
auto version = serialized::read<ccf::kv::Version>(data_, size);
529533
ReplicatedData r = nlohmann::json::parse(std::span{data_, size});

src/consensus/aft/test/main.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ DOCTEST_TEST_CASE("Single node commit" * doctest::test_suite("single"))
7777
entry->push_back(2);
7878
entry->push_back(3);
7979

80-
auto hooks = std::make_shared<ccf::kv::ConsensusHookPtrs>();
81-
8280
r0.replicate(ccf::kv::BatchVector{{i, entry, true, hooks}}, 1);
8381
DOCTEST_REQUIRE(r0.get_last_idx() == i);
8482
DOCTEST_REQUIRE(r0.get_committed_seqno() == i);
@@ -430,7 +428,6 @@ DOCTEST_TEST_CASE(
430428
DOCTEST_INFO("Try to replicate on a follower, and fail");
431429
std::vector<uint8_t> entry = {1, 2, 3};
432430
auto data = std::make_shared<std::vector<uint8_t>>(entry);
433-
auto hooks = std::make_shared<ccf::kv::ConsensusHookPtrs>();
434431
DOCTEST_REQUIRE_FALSE(
435432
r1.replicate(ccf::kv::BatchVector{{1, data, true, hooks}}, 1));
436433

@@ -551,7 +548,6 @@ DOCTEST_TEST_CASE("Multiple nodes late join" * doctest::test_suite("multiple"))
551548

552549
std::vector<uint8_t> first_entry = {1, 2, 3};
553550
auto data = std::make_shared<std::vector<uint8_t>>(first_entry);
554-
auto hooks = std::make_shared<ccf::kv::ConsensusHookPtrs>();
555551
DOCTEST_REQUIRE(
556552
r0.replicate(ccf::kv::BatchVector{{1, data, true, hooks}}, 1));
557553
r0.periodic(request_timeout);
@@ -625,7 +621,6 @@ DOCTEST_TEST_CASE("Recv append entries logic" * doctest::test_suite("multiple"))
625621
std::make_shared<aft::ChannelStubProxy>(),
626622
std::make_shared<aft::State>(node_id1),
627623
nullptr);
628-
auto hooks = std::make_shared<ccf::kv::ConsensusHookPtrs>();
629624

630625
aft::Configuration::Nodes config0;
631626
config0[node_id0] = {};
@@ -939,14 +934,13 @@ DOCTEST_TEST_CASE("Exceed append entries limit")
939934
// send_append_entries() triggered or not
940935
bool expected_ae = false;
941936

942-
for (size_t i = 1; i <= num_big_entries; ++i)
937+
for (size_t i = 1; i <= static_cast<size_t>(num_big_entries); ++i)
943938
{
944-
auto hooks = std::make_shared<ccf::kv::ConsensusHookPtrs>();
945939
DOCTEST_REQUIRE(
946940
r0.replicate(ccf::kv::BatchVector{{i, data, true, hooks}}, 1));
947941
const auto received_ae =
948942
dispatch_all_and_DOCTEST_CHECK<aft::AppendEntries>(
949-
nodes, node_id0, r0c->messages, [&i](const auto& msg) {
943+
nodes, node_id0, r0c->messages, [](const auto& msg) {
950944
DOCTEST_REQUIRE(msg.term == 1);
951945
}) > 0;
952946
DOCTEST_REQUIRE(received_ae == expected_ae);
@@ -957,9 +951,10 @@ DOCTEST_TEST_CASE("Exceed append entries limit")
957951
(individual_entries - num_big_entries);
958952
auto smaller_data = std::make_shared<std::vector<uint8_t>>(data_size, 1);
959953

960-
for (size_t i = num_big_entries + 1; i <= individual_entries; ++i)
954+
for (size_t i = num_big_entries + 1;
955+
i <= static_cast<size_t>(individual_entries);
956+
++i)
961957
{
962-
auto hooks = std::make_shared<ccf::kv::ConsensusHookPtrs>();
963958
DOCTEST_REQUIRE(
964959
r0.replicate(ccf::kv::BatchVector{{i, smaller_data, true, hooks}}, 1));
965960
dispatch_all(nodes, node_id0, r0c->messages);

0 commit comments

Comments
 (0)