improvement of srsran_assert design, with specializations to enable/disable assertions based on compile flags other than ASSERTS_ENABLED. Creation of the support/ folder

This commit is contained in:
Francisco Paisana 2021-08-19 15:52:21 +02:00
parent 5c526a4895
commit 599fc978a5
20 changed files with 71 additions and 51 deletions

View File

@ -13,8 +13,8 @@
#ifndef SRSRAN_DYN_BITSET_H
#define SRSRAN_DYN_BITSET_H
#include "srsran/common/srsran_assert.h"
#include "srsran/srslog/bundled/fmt/format.h"
#include "support/srsran_assert.h"
#include <cstdint>
#include <inttypes.h>
#include <string>

View File

@ -14,7 +14,7 @@
#define SRSRAN_BOUNDED_VECTOR_H
#include "srsran/adt/detail/type_storage.h"
#include "srsran/common/srsran_assert.h"
#include "support/srsran_assert.h"
#include <iterator>
#include <memory>
#include <type_traits>

View File

@ -16,7 +16,7 @@
#include "srsran/adt/detail/type_storage.h"
#include "srsran/adt/expected.h"
#include "srsran/adt/pool/pool_utils.h"
#include "srsran/common/srsran_assert.h"
#include "support/srsran_assert.h"
#include <array>
#include <cassert>

View File

@ -15,7 +15,7 @@
#include "detail/type_storage.h"
#include "expected.h"
#include "srsran/common/srsran_assert.h"
#include "support/srsran_assert.h"
#include <array>
namespace srsran {

View File

@ -13,7 +13,7 @@
#ifndef SRSRAN_EXPECTED_H
#define SRSRAN_EXPECTED_H
#include "srsran/common/srsran_assert.h"
#include "support/srsran_assert.h"
#include <memory>
#include <system_error>

View File

@ -13,8 +13,8 @@
#ifndef SRSRAN_INTERVAL_H
#define SRSRAN_INTERVAL_H
#include "srsran/common/srsran_assert.h"
#include "srsran/srslog/bundled/fmt/format.h"
#include "support/srsran_assert.h"
#include <cassert>
#include <string>
#include <type_traits>

View File

@ -14,7 +14,7 @@
#define SRSRAN_MOVE_CALLBACK_H
#include "detail/type_storage.h"
#include "srsran/common/srsran_assert.h"
#include "support/srsran_assert.h"
#include <cstddef>
#include <cstdint>
#include <cstdio>
@ -60,7 +60,7 @@ public:
constexpr empty_table_t() = default;
R call(void* src, Args... args) const final
{
srsran_terminate("ERROR: bad function call (cause: function ptr is empty)");
srsran_assertion_failure("bad function call (cause: function ptr is empty)");
}
void move(void* src, void* dest) const final {}
void dtor(void* src) const final {}

View File

@ -14,7 +14,7 @@
#define SRSRAN_OPTIONAL_H
#include "detail/type_storage.h"
#include "srsran/common/srsran_assert.h"
#include "support/srsran_assert.h"
namespace srsran {

View File

@ -15,8 +15,8 @@
#include "memblock_cache.h"
#include "pool_utils.h"
#include "srsran/common/srsran_assert.h"
#include "srsran/common/thread_pool.h"
#include "support/srsran_assert.h"
#include <memory>
#include <mutex>

View File

@ -14,7 +14,7 @@
#define SRSRAN_LINEAR_ALLOCATOR_H
#include "pool_utils.h"
#include "srsran/common/srsran_assert.h"
#include "support/srsran_assert.h"
namespace srsran {

View File

@ -13,8 +13,8 @@
#ifndef SRSASN_COMMON_UTILS_H
#define SRSASN_COMMON_UTILS_H
#include "srsran/common/srsran_assert.h"
#include "srsran/srslog/srslog.h"
#include "support/srsran_assert.h"
#include <algorithm>
#include <array>
#include <cmath>

View File

@ -14,7 +14,7 @@
#define SRSRAN_SLOT_POINT_H
#include "srsran/adt/interval.h"
#include "srsran/common/srsran_assert.h"
#include "support/srsran_assert.h"
namespace srsran {

View File

@ -19,9 +19,9 @@
#include "srsran/common/buffer_pool.h"
#include "srsran/common/crash_handler.h"
#include "srsran/common/srsran_assert.h"
#include "srsran/common/standard_streams.h"
#include "srsran/srslog/srslog.h"
#include "support/srsran_assert.h"
#include <atomic>
#include <cstdio>

View File

@ -15,8 +15,8 @@
#include "srsran/adt/interval.h"
#include "srsran/common/common.h"
#include "srsran/common/srsran_assert.h"
#include "srsran/srslog/srslog.h"
#include "support/srsran_assert.h"
#include <cstdint>
#include <limits>

View File

@ -19,13 +19,13 @@
#include "srsran/adt/intrusive_list.h"
#include "srsran/common/buffer_pool.h"
#include "srsran/common/common.h"
#include "srsran/common/srsran_assert.h"
#include "srsran/common/task_scheduler.h"
#include "srsran/common/timeout.h"
#include "srsran/interfaces/pdcp_interface_types.h"
#include "srsran/rlc/rlc_am_base.h"
#include "srsran/rlc/rlc_common.h"
#include "srsran/upper/byte_buffer_queue.h"
#include "support/srsran_assert.h"
#include <deque>
#include <list>
#include <map>

View File

@ -13,38 +13,54 @@
#ifndef SRSRAN_ASSERT_H
#define SRSRAN_ASSERT_H
#ifdef __cplusplus
#include "srsran/srslog/srslog.h"
#include <cstdio>
#include <stdarg.h>
#define srsran_unlikely(expr) __builtin_expect(!!(expr), 0)
#define srsran_terminate(fmt, ...) \
srslog::flush(); \
std::fprintf(stderr, "%s:%d: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
std::abort()
/**
* Command to terminate srsRAN application with an error message, ensuring first that the log is flushed
*/
[[gnu::noinline, noreturn]] inline bool srsran_terminate(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
srslog::flush();
vfprintf(stderr, fmt, args);
va_end(args);
std::abort();
}
#ifdef ASSERTS_ENABLED
#define srsran_assertion_failure(fmt, ...) \
srsran_terminate("%s:%d: Assertion Failure: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)
/**
* Macro that asserts condition is true. If false, it logs the remaining parameters, prints the backtrace and closes
* the application
* Macro that asserts condition is true. If false, it logs the remaining macro args, flushes the log,
* prints the backtrace (if it was activated) and closes the application.
*/
#define srsran_assert(condition, fmt, ...) \
do { \
if (srsran_unlikely(not(condition))) { \
srsran_terminate(fmt, ##__VA_ARGS__); \
} \
} while (0)
#define srsran_always_assert(condition, fmt, ...) (void)((condition) || srsran_assertion_failure(fmt, ##__VA_ARGS__))
#define SRSRAN_IS_DEFINED(x) SRSRAN_IS_DEFINED2(x)
#define SRSRAN_IS_DEFINED2(x) (#x[0] == 0 || (#x[0] >= '1' && #x[0] <= '9'))
/**
* Same as "srsran_always_assert" but it is only active when "enable_check" flag is defined
*/
#define srsran_assert_ifdef(enable_check, condition, fmt, ...) \
(void)((not SRSRAN_IS_DEFINED(enable_check)) || (srsran_always_assert(condition, fmt, ##__VA_ARGS__), 0))
/**
* Specialization of "srsran_assert_ifdef" for the ASSERTS_ENABLED flag
*/
#define srsran_assert(condition, fmt, ...) srsran_assert_ifdef(ASSERTS_ENABLED, condition, fmt, ##__VA_ARGS__)
#ifdef STOP_ON_WARNING
/**
* Macro that verifies if condition is true. If false, and STOP_ON_WARNING is true, it behaves like srsran_assert.
* If STOP_ON_WARNING is false, it logs a warning.
*/
#define srsran_expect(condition, fmt, ...) srsran_assert(condition, fmt, ##__VA_ARGS__)
#else // STOP_ON_WARNING
#else
#define srsran_expect(condition, fmt, ...) \
do { \
@ -53,16 +69,20 @@
} \
} while (0)
#endif // STOP_ON_WARNING
#endif
#else // ASSERTS_ENABLED
#else // __ifcplusplus
#include <cassert>
#ifdef ASSERTS_ENABLED
#define srsran_assert(condition, fmt, ...) (void)((condition) || (__assert(#condition, __FILE__, __FLAG__), 0))
#else
#define srsran_assert(condition, fmt, ...) \
do { \
} while (0)
#define srsran_expect(condition, fmt, ...) srsran_assert(condition, fmt, ##__VA_ARGS__)
#endif
#endif // __ifcplusplus
#endif // SRSRAN_ASSERT_H

View File

@ -34,7 +34,7 @@ phy_cfg_nr_default_t::reference_cfg_t::reference_cfg_t(const std::string& args)
// Skip if size is invalid
if (param.size() != 2) {
srsran_terminate("Invalid reference argument '%s'", e.c_str());
srsran_assertion_failure("Invalid reference argument '%s'", e.c_str());
}
if (param.front() == "carrier") {
@ -59,7 +59,7 @@ phy_cfg_nr_default_t::reference_cfg_t::reference_cfg_t(const std::string& args)
}
srsran_assert(pdsch != R_PDSCH_COUNT, "Invalid PDSCH reference configuration '%s'", param.back().c_str());
} else {
srsran_terminate("Invalid %s reference component", param.front().c_str());
srsran_assertion_failure("Invalid %s reference component", param.front().c_str());
}
}
}
@ -212,7 +212,7 @@ void make_nzp_csi_rs_ts38101_table_5_2_1(const srsran_carrier_nr_t& carrier, srs
res3.periodicity.offset = 21;
res4.periodicity.offset = 21;
} else {
srsran_terminate("Invalid subcarrier spacing %d kHz", 15U << (uint32_t)carrier.scs);
srsran_assertion_failure("Invalid subcarrier spacing %d kHz", 15U << (uint32_t)carrier.scs);
}
res1.resource_mapping.freq_band = {0, carrier.nof_prb};
@ -370,7 +370,7 @@ phy_cfg_nr_default_t::phy_cfg_nr_default_t(const reference_cfg_t& reference_cfg)
make_carrier_custom_20MHz(carrier);
break;
case reference_cfg_t::R_CARRIER_COUNT:
srsran_terminate("Invalid carrier reference");
srsran_assertion_failure("Invalid carrier reference");
}
switch (reference_cfg.tdd) {
@ -381,7 +381,7 @@ phy_cfg_nr_default_t::phy_cfg_nr_default_t(const reference_cfg_t& reference_cfg)
make_tdd_fr1_15_1(tdd);
break;
case reference_cfg_t::R_TDD_COUNT:
srsran_terminate("Invalid TDD reference");
srsran_assertion_failure("Invalid TDD reference");
}
switch (reference_cfg.pdcch) {
@ -398,7 +398,7 @@ phy_cfg_nr_default_t::phy_cfg_nr_default_t(const reference_cfg_t& reference_cfg)
make_pdsch_2_1_1_tdd(carrier, pdsch);
break;
case reference_cfg_t::R_PDSCH_COUNT:
srsran_terminate("Invalid PDSCH reference configuration");
srsran_assertion_failure("Invalid PDSCH reference configuration");
}
switch (reference_cfg.pusch) {

View File

@ -15,7 +15,7 @@
#include "srsran/adt/bounded_bitset.h"
#include "srsran/adt/interval.h"
#include "srsran/common/srsran_assert.h"
#include "support/srsran_assert.h"
extern "C" {
#include "srsran/phy/phch/ra.h"
}
@ -46,7 +46,7 @@ inline uint32_t cell_nof_prb_to_rbg(uint32_t nof_prbs)
case 100:
return 25;
default:
srsran_terminate("Provided nof PRBs not valid");
srsran_assertion_failure("Provided nof PRBs not valid");
}
return 0;
}
@ -68,7 +68,7 @@ inline uint32_t cell_nof_rbg_to_prb(uint32_t nof_rbgs)
case 25:
return 100;
default:
srsran_terminate("Provided nof PRBs not valid");
srsran_assertion_failure("Provided nof PRBs not valid");
}
return 0;
}

View File

@ -18,11 +18,11 @@
#include "srsenb/hdr/stack/rrc/ue_rr_cfg.h"
#include "srsran/asn1/rrc_utils.h"
#include "srsran/common/enb_events.h"
#include "srsran/common/srsran_assert.h"
#include "srsran/common/standard_streams.h"
#include "srsran/interfaces/enb_pdcp_interfaces.h"
#include "srsran/interfaces/enb_rlc_interfaces.h"
#include "srsran/interfaces/enb_s1ap_interfaces.h"
#include "support/srsran_assert.h"
using namespace asn1::rrc;
@ -1420,7 +1420,7 @@ void rrc::ue::apply_rlc_rb_updates(const rr_cfg_ded_s& pending_rr_cfg)
} else if (srb.srb_id == 2) {
srb_cfg = &parent->cfg.srb2_cfg;
} else {
srsran_terminate("Invalid LTE SRB id=%d", srb.srb_id);
srsran_assertion_failure("Invalid LTE SRB id=%d", srb.srb_id);
}
if (srb_cfg->rlc_cfg.type() == srb_to_add_mod_s::rlc_cfg_c_::types_opts::explicit_value) {

View File

@ -13,11 +13,11 @@
#include "srsran/upper/gtpu.h"
#include "srsenb/hdr/stack/upper/gtpu.h"
#include "srsran/common/network_utils.h"
#include "srsran/common/srsran_assert.h"
#include "srsran/common/standard_streams.h"
#include "srsran/common/string_helpers.h"
#include "srsran/interfaces/enb_interfaces.h"
#include "srsran/interfaces/enb_pdcp_interfaces.h"
#include "support/srsran_assert.h"
#include <errno.h>
#include <linux/ip.h>