From 7810516596f3a9f6013a78365199978c2b61dad1 Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Mon, 18 Nov 2024 15:33:41 +0100 Subject: [PATCH] Add equality check and error macro to NAS --- openair3/NAS/NR_UE/5GS/fgs_nas_utils.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h b/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h index 74f4d2ed7f..3082bc7daa 100644 --- a/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h +++ b/openair3/NAS/NR_UE/5GS/fgs_nas_utils.h @@ -24,6 +24,24 @@ #include +#define PRINT_NAS_ERROR(...) fprintf(stderr, ##__VA_ARGS__) + +#define _NAS_EQ_CHECK_GENERIC(condition, fmt, ...) \ + do { \ + if (!(condition)) { \ + PRINT_NAS_ERROR("NAS Equality Check failure: %s:%d: Condition '%s' failed: " fmt " != " fmt "\n", \ + __FILE__, \ + __LINE__, \ + #condition, \ + ##__VA_ARGS__); \ + return false; \ + } \ + } while (0) + +#define _NAS_EQ_CHECK_LONG(A, B) _NAS_EQ_CHECK_GENERIC(A == B, "%ld", A, B); +#define _NAS_EQ_CHECK_INT(A, B) _NAS_EQ_CHECK_GENERIC(A == B, "%d", A, B); +#define _NAS_EQ_CHECK_STR(A, B) _NAS_EQ_CHECK_GENERIC(strcmp(A, B) == 0, "'%s'", A, B); + /* Map task id to printable name. */ typedef struct { int id;