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

master
Francisco Paisana 3 years ago
parent 5c526a4895
commit 599fc978a5

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

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

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

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

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

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

@ -14,7 +14,7 @@
#define SRSRAN_MOVE_CALLBACK_H #define SRSRAN_MOVE_CALLBACK_H
#include "detail/type_storage.h" #include "detail/type_storage.h"
#include "srsran/common/srsran_assert.h" #include "support/srsran_assert.h"
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
@ -60,7 +60,7 @@ public:
constexpr empty_table_t() = default; constexpr empty_table_t() = default;
R call(void* src, Args... args) const final 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 move(void* src, void* dest) const final {}
void dtor(void* src) const final {} void dtor(void* src) const final {}

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

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

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

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

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

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

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

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

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

@ -34,7 +34,7 @@ phy_cfg_nr_default_t::reference_cfg_t::reference_cfg_t(const std::string& args)
// Skip if size is invalid // Skip if size is invalid
if (param.size() != 2) { 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") { 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()); srsran_assert(pdsch != R_PDSCH_COUNT, "Invalid PDSCH reference configuration '%s'", param.back().c_str());
} else { } 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; res3.periodicity.offset = 21;
res4.periodicity.offset = 21; res4.periodicity.offset = 21;
} else { } 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}; 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); make_carrier_custom_20MHz(carrier);
break; break;
case reference_cfg_t::R_CARRIER_COUNT: case reference_cfg_t::R_CARRIER_COUNT:
srsran_terminate("Invalid carrier reference"); srsran_assertion_failure("Invalid carrier reference");
} }
switch (reference_cfg.tdd) { 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); make_tdd_fr1_15_1(tdd);
break; break;
case reference_cfg_t::R_TDD_COUNT: case reference_cfg_t::R_TDD_COUNT:
srsran_terminate("Invalid TDD reference"); srsran_assertion_failure("Invalid TDD reference");
} }
switch (reference_cfg.pdcch) { 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); make_pdsch_2_1_1_tdd(carrier, pdsch);
break; break;
case reference_cfg_t::R_PDSCH_COUNT: case reference_cfg_t::R_PDSCH_COUNT:
srsran_terminate("Invalid PDSCH reference configuration"); srsran_assertion_failure("Invalid PDSCH reference configuration");
} }
switch (reference_cfg.pusch) { switch (reference_cfg.pusch) {

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

@ -18,11 +18,11 @@
#include "srsenb/hdr/stack/rrc/ue_rr_cfg.h" #include "srsenb/hdr/stack/rrc/ue_rr_cfg.h"
#include "srsran/asn1/rrc_utils.h" #include "srsran/asn1/rrc_utils.h"
#include "srsran/common/enb_events.h" #include "srsran/common/enb_events.h"
#include "srsran/common/srsran_assert.h"
#include "srsran/common/standard_streams.h" #include "srsran/common/standard_streams.h"
#include "srsran/interfaces/enb_pdcp_interfaces.h" #include "srsran/interfaces/enb_pdcp_interfaces.h"
#include "srsran/interfaces/enb_rlc_interfaces.h" #include "srsran/interfaces/enb_rlc_interfaces.h"
#include "srsran/interfaces/enb_s1ap_interfaces.h" #include "srsran/interfaces/enb_s1ap_interfaces.h"
#include "support/srsran_assert.h"
using namespace asn1::rrc; 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) { } else if (srb.srb_id == 2) {
srb_cfg = &parent->cfg.srb2_cfg; srb_cfg = &parent->cfg.srb2_cfg;
} else { } 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) { if (srb_cfg->rlc_cfg.type() == srb_to_add_mod_s::rlc_cfg_c_::types_opts::explicit_value) {

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

Loading…
Cancel
Save