From 11df3c743f2c106150ac19a39b71891cfa0bf07f Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Wed, 29 May 2024 12:25:51 +0200 Subject: [PATCH] Introduce new macros to improve debugging capabilities in F1AP library * _F1_EQ_CHECK_GENERIC can be used to check the equality of two different members of F1AP structs and return `false` if the condition is not met. When the condition fails, the macros will print a debug message to the standard error stream, including the function name, line number, and the provided format string and arguments. --- openair2/F1AP/lib/f1ap_lib_common.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/openair2/F1AP/lib/f1ap_lib_common.h b/openair2/F1AP/lib/f1ap_lib_common.h index fa1b6246d0..97e4f7eac4 100644 --- a/openair2/F1AP/lib/f1ap_lib_common.h +++ b/openair2/F1AP/lib/f1ap_lib_common.h @@ -26,6 +26,28 @@ #include #include +#ifdef ENABLE_TESTS + #define PRINT_ERROR(...) fprintf(stderr, ##__VA_ARGS__) +#else + #define PRINT_ERROR(...) // Do nothing +#endif + +#define _F1_EQ_CHECK_GENERIC(condition, fmt, ...) \ + do { \ + if (!(condition)) { \ + PRINT_ERROR("F1 Equality Check failure: %s:%d: Condition '%s' failed: " fmt " != " fmt "\n", \ + __FILE__, \ + __LINE__, \ + #condition, \ + ##__VA_ARGS__); \ + return false; \ + } \ + } while (0) + +#define _F1_EQ_CHECK_LONG(A, B) _F1_EQ_CHECK_GENERIC(A == B, "%ld", A, B); +#define _F1_EQ_CHECK_INT(A, B) _F1_EQ_CHECK_GENERIC(A == B, "%d", A, B); +#define _F1_EQ_CHECK_STR(A, B) _F1_EQ_CHECK_GENERIC(strcmp(A, B) == 0, "'%s'", A, B); + /* macro to look up IE. If mandatory and not found, macro will print * descriptive debug message to stderr and force exit in calling function */ #define F1AP_LIB_FIND_IE(IE_TYPE, ie, container, IE_ID, mandatory) \