Skip to content

Commit

Permalink
treewide: replace assert with SEASTAR_ASSERT
Browse files Browse the repository at this point in the history
This prevents the need to undefined NDEBUG in seastar source and
prevents headers from conditionally excluding these checks.
  • Loading branch information
rockwotj authored and avikivity committed Feb 17, 2025
1 parent a3a22eb commit 7a91062
Show file tree
Hide file tree
Showing 109 changed files with 495 additions and 391 deletions.
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,6 @@ target_include_directories (seastar

set (Seastar_PRIVATE_CXX_FLAGS
-fno-semantic-interposition
-UNDEBUG
-Wall
-Werror
-Wimplicit-fallthrough
Expand Down Expand Up @@ -904,11 +903,6 @@ endif ()
set( MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1 --leak-check=no --trace-children=yes" )
include (CTest)

#
# We want asserts enabled on all modes, but cmake defaults to passing
# -DNDEBUG in some modes. We add -UNDEBUG to our private options to
# reenable it. To force asserts off pass -DNDEBUG in
# Seastar_CXX_FLAGS.
#
# To disable -Werror, pass -Wno-error to Seastar_CXX_FLAGS.
#
Expand Down
3 changes: 2 additions & 1 deletion apps/io_tester/io_tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <seastar/core/with_scheduling_group.hh>
#include <seastar/core/metrics_api.hh>
#include <seastar/core/io_intent.hh>
#include <seastar/util/assert.hh>
#include <seastar/util/later.hh>
#include <chrono>
#include <optional>
Expand Down Expand Up @@ -640,7 +641,7 @@ class io_class_data : public class_data {
void emit_one_metrics(YAML::Emitter& out, sstring m_name) {
const auto& values = seastar::metrics::impl::get_value_map();
const auto& mf = values.find(m_name);
assert(mf != values.end());
SEASTAR_ASSERT(mf != values.end());
for (auto&& mi : mf->second) {
auto&& cname = mi.first.labels().find("class");
if (cname != mi.first.labels().end() && cname->second == name()) {
Expand Down
11 changes: 6 additions & 5 deletions apps/memcached/memcache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <seastar/core/print.hh>
#include <seastar/net/api.hh>
#include <seastar/net/packet-data-source.hh>
#include <seastar/util/assert.hh>
#include <seastar/util/std-compat.hh>
#include <seastar/util/log.hh>
#include "ascii.hh"
Expand Down Expand Up @@ -162,8 +163,8 @@ class item : public slab_item_base {
, _key_size(key.key().size())
, _ascii_prefix_size(ascii_prefix.size())
{
assert(_key_size <= std::numeric_limits<uint8_t>::max());
assert(_ascii_prefix_size <= std::numeric_limits<uint8_t>::max());
SEASTAR_ASSERT(_key_size <= std::numeric_limits<uint8_t>::max());
SEASTAR_ASSERT(_ascii_prefix_size <= std::numeric_limits<uint8_t>::max());
// storing key
memcpy(_data, key.key().c_str(), _key_size);
// storing ascii_prefix
Expand Down Expand Up @@ -255,7 +256,7 @@ class item : public slab_item_base {
}

friend inline void intrusive_ptr_add_ref(item* it) {
assert(it->_ref_count >= 0);
SEASTAR_ASSERT(it->_ref_count >= 0);
++it->_ref_count;
if (it->_ref_count == 2) {
slab->lock_item(it);
Expand All @@ -269,7 +270,7 @@ class item : public slab_item_base {
} else if (it->_ref_count == 0) {
slab->free(it);
}
assert(it->_ref_count >= 0);
SEASTAR_ASSERT(it->_ref_count >= 0);
}

friend struct item_key_cmp;
Expand Down Expand Up @@ -469,7 +470,7 @@ class cache {
intrusive_ptr_add_ref(new_item);

auto insert_result = _cache.insert(*new_item);
assert(insert_result.second);
SEASTAR_ASSERT(insert_result.second);
if (insertion.expiry.ever_expires() && _alive.insert(*new_item)) {
_timer.rearm(new_item->get_timeout());
}
Expand Down
3 changes: 2 additions & 1 deletion apps/rpc_tester/rpc_tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <seastar/core/with_scheduling_group.hh>
#include <seastar/core/sleep.hh>
#include <seastar/rpc/rpc.hh>
#include <seastar/util/assert.hh>

using namespace seastar;
using namespace boost::accumulators;
Expand Down Expand Up @@ -388,7 +389,7 @@ class job_rpc : public job {

future<> call_write(unsigned dummy, const payload_t& pl) {
return _rpc.make_client<uint64_t(payload_t)>(rpc_verb::WRITE)(*_client, pl).then([exp = pl.size()] (auto res) {
assert(res == exp);
SEASTAR_ASSERT(res == exp);
return make_ready_future<>();
});
}
Expand Down
3 changes: 2 additions & 1 deletion demos/block_discard_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <seastar/core/reactor.hh>
#include <seastar/core/seastar.hh>
#include <seastar/core/semaphore.hh>
#include <seastar/util/assert.hh>
#include <iostream>

using namespace seastar;
Expand Down Expand Up @@ -53,7 +54,7 @@ int main(int ac, char** av) {

// Discard asynchronously, siganl when done.
(void)ft->f.stat().then([ft] (struct stat st) mutable {
assert(S_ISBLK(st.st_mode));
SEASTAR_ASSERT(S_ISBLK(st.st_mode));
auto offset = 0;
auto length = max * 4096;
return ft->f.discard(offset, length).then([ft] () mutable {
Expand Down
15 changes: 8 additions & 7 deletions demos/file_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <seastar/core/temporary_buffer.hh>
#include <seastar/core/loop.hh>
#include <seastar/core/io_intent.hh>
#include <seastar/util/assert.hh>
#include <seastar/util/log.hh>
#include <seastar/util/tmp_file.hh>

Expand All @@ -45,17 +46,17 @@ constexpr size_t aligned_size = 4096;

future<> verify_data_file(file& f, temporary_buffer<char>& rbuf, const temporary_buffer<char>& wbuf) {
return f.dma_read(0, rbuf.get_write(), aligned_size).then([&rbuf, &wbuf] (size_t count) {
assert(count == aligned_size);
SEASTAR_ASSERT(count == aligned_size);
fmt::print(" verifying {} bytes\n", count);
assert(!memcmp(rbuf.get(), wbuf.get(), aligned_size));
SEASTAR_ASSERT(!memcmp(rbuf.get(), wbuf.get(), aligned_size));
});
}

future<file> open_data_file(sstring meta_filename, temporary_buffer<char>& rbuf) {
fmt::print(" retrieving data filename from {}\n", meta_filename);
return with_file(open_file_dma(meta_filename, open_flags::ro), [&rbuf] (file& f) {
return f.dma_read(0, rbuf.get_write(), aligned_size).then([&rbuf] (size_t count) {
assert(count == aligned_size);
SEASTAR_ASSERT(count == aligned_size);
auto data_filename = sstring(rbuf.get());
fmt::print(" opening {}\n", data_filename);
return open_file_dma(data_filename, open_flags::ro);
Expand All @@ -77,7 +78,7 @@ future<> demo_with_file() {
auto count = with_file(open_file_dma(filename, open_flags::rw | open_flags::create), [&wbuf] (file& f) {
return f.dma_write(0, wbuf.get(), aligned_size);
}).get();
assert(count == aligned_size);
SEASTAR_ASSERT(count == aligned_size);
};

// print the data_filename into the write buffer
Expand Down Expand Up @@ -213,14 +214,14 @@ future<> demo_with_io_intent() {
f.dma_read(0, rbuf.get(), aligned_size).get();

// First part of the buffer must coincide with the overwritten data
assert(!memcmp(rbuf.get(), wbuf_n.get(), half_aligned_size));
SEASTAR_ASSERT(!memcmp(rbuf.get(), wbuf_n.get(), half_aligned_size));

if (cancelled) {
// Second part -- with the old data ...
assert(!memcmp(rbuf.get() + half_aligned_size, wbuf.get() + half_aligned_size, half_aligned_size));
SEASTAR_ASSERT(!memcmp(rbuf.get() + half_aligned_size, wbuf.get() + half_aligned_size, half_aligned_size));
} else {
// ... or with new if the cancellation didn't happen
assert(!memcmp(rbuf.get() + half_aligned_size, wbuf.get() + half_aligned_size, half_aligned_size));
SEASTAR_ASSERT(!memcmp(rbuf.get() + half_aligned_size, wbuf.get() + half_aligned_size, half_aligned_size));
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions demos/sharded_parameter_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <seastar/core/sharded.hh>
#include <seastar/core/app-template.hh>
#include <seastar/core/thread.hh>
#include <seastar/util/assert.hh>
#include <seastar/util/closeable.hh>
#include <cassert>

// This is some service that we wish to run on all shards.
class service_one {
Expand Down Expand Up @@ -71,7 +71,7 @@ int main(int ac, char** av) {
auto stop_s2 = seastar::deferred_stop(s2);

s2.invoke_on_all([] (service_two& s2) {
assert(s2.get_resource_allocation() == 3);
SEASTAR_ASSERT(s2.get_resource_allocation() == 3);
}).get();
});
});
Expand Down
5 changes: 3 additions & 2 deletions demos/udp_zero_copy_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <seastar/core/units.hh>
#include <seastar/core/timer.hh>
#include <seastar/net/api.hh>
#include <seastar/util/assert.hh>
#include <random>
#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -101,7 +102,7 @@ class server {

_chunk_distribution = std::uniform_int_distribution<size_t>(0, _mem_size - _chunk_size * 3);

assert(3 * _chunk_size <= _packet_size);
SEASTAR_ASSERT(3 * _chunk_size <= _packet_size);

// Run sender in background.
(void)keep_doing([this] {
Expand All @@ -117,7 +118,7 @@ class server {
chunk += _chunk_size;
(void)_out->write(chunk, _chunk_size);
(void)_out->flush();
assert(_packets.size() == 1);
SEASTAR_ASSERT(_packets.size() == 1);
return send(dgram.get_src(), std::move(_packets[0]));
} else {
auto chunk = next_chunk();
Expand Down
3 changes: 2 additions & 1 deletion include/seastar/core/abort_source.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#pragma once

#include <seastar/util/assert.hh>
#include <seastar/util/modules.hh>
#include <seastar/util/noncopyable_function.hh>
#include <seastar/util/optimized_optional.hh>
Expand Down Expand Up @@ -132,7 +133,7 @@ private:
return;
}
_ex = ex.value_or(get_default_exception());
assert(_ex);
SEASTAR_ASSERT(_ex);
auto subs = std::move(_subscriptions);
while (!subs.empty()) {
subscription& s = subs.front();
Expand Down
5 changes: 3 additions & 2 deletions include/seastar/core/abortable_fifo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <seastar/core/abort_source.hh>
#include <seastar/core/future.hh>
#include <seastar/core/chunked_fifo.hh>
#include <seastar/util/assert.hh>
#include <seastar/util/modules.hh>

#ifndef SEASTAR_MODULE
Expand Down Expand Up @@ -111,7 +112,7 @@ public:
abortable_fifo(abortable_fifo&& o) noexcept
: abortable_fifo(std::move(o._on_abort)) {
// entry objects hold a reference to this so non-empty containers cannot be moved.
assert(o._size == 0);
SEASTAR_ASSERT(o._size == 0);
}

abortable_fifo& operator=(abortable_fifo&& o) noexcept {
Expand Down Expand Up @@ -236,7 +237,7 @@ public:
if (!_list.empty()) {
e = &_list.back();
}
assert(!e->sub);
SEASTAR_ASSERT(!e->sub);
auto aborter = [this, e] (const std::optional<std::exception_ptr>& ex_opt) noexcept {
if constexpr (aborter_ex<OnAbort, T>) {
_on_abort(*e->payload, ex_opt);
Expand Down
3 changes: 2 additions & 1 deletion include/seastar/core/chunked_fifo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <algorithm>
#include <cassert>
#include <type_traits>
#include <seastar/util/assert.hh>
#include <seastar/util/modules.hh>
#endif

Expand Down Expand Up @@ -342,7 +343,7 @@ void chunked_fifo<T, items_per_chunk>::clear() noexcept {
template <typename T, size_t items_per_chunk>
void chunked_fifo<T, items_per_chunk>::pop_front_n(size_t n) noexcept {
while (n) {
assert(_front_chunk && "pop_front_n n too large");
SEASTAR_ASSERT(_front_chunk && "pop_front_n n too large");

auto target = _front_chunk;
unsigned delete_count = std::min(target->size(), n);
Expand Down
3 changes: 2 additions & 1 deletion include/seastar/core/expiring_fifo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <seastar/core/timer.hh>
#include <seastar/core/lowres_clock.hh>
#include <seastar/core/timed_out_error.hh>
#include <seastar/util/assert.hh>
#include <seastar/util/modules.hh>
#endif

Expand Down Expand Up @@ -108,7 +109,7 @@ public:
expiring_fifo(expiring_fifo&& o) noexcept
: expiring_fifo(std::move(o._on_expiry)) {
// entry objects hold a reference to this so non-empty containers cannot be moved.
assert(o._size == 0);
SEASTAR_ASSERT(o._size == 0);
}

expiring_fifo& operator=(expiring_fifo&& o) noexcept {
Expand Down
3 changes: 2 additions & 1 deletion include/seastar/core/fair_queue.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <seastar/core/shared_ptr.hh>
#include <seastar/core/circular_buffer.hh>
#include <seastar/core/metrics_registration.hh>
#include <seastar/util/assert.hh>
#include <seastar/util/shared_token_bucket.hh>

#include <chrono>
Expand Down Expand Up @@ -318,7 +319,7 @@ private:
}

void assert_enough_capacity() const noexcept {
assert(c.size() < c.capacity());
SEASTAR_ASSERT(c.size() < c.capacity());
}
};

Expand Down
Loading

0 comments on commit 7a91062

Please sign in to comment.