summaryrefslogtreecommitdiffstats
path: root/tests/msgb
diff options
context:
space:
mode:
Diffstat (limited to 'tests/msgb')
-rw-r--r--tests/msgb/msgb_test.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/msgb/msgb_test.c b/tests/msgb/msgb_test.c
index 75925095..260aca54 100644
--- a/tests/msgb/msgb_test.c
+++ b/tests/msgb/msgb_test.c
@@ -23,6 +23,7 @@
#include <osmocom/core/logging.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/msgb.h>
+#include <setjmp.h>
#include <errno.h>
@@ -34,6 +35,36 @@
abort(); \
}
+static jmp_buf jmp_env;
+static int jmp_env_valid = 0;
+static void osmo_panic_raise(const char *fmt, va_list args)
+{
+ /*
+ * The args can include pointer values which are not suitable for
+ * regression testing. So just write the (hopefully constant) format
+ * string to stdout and write the full message to stderr.
+ */
+ printf("%s", fmt);
+ vfprintf(stderr, fmt, args);
+ if (!jmp_env_valid)
+ abort();
+ longjmp(jmp_env, 1);
+}
+
+/* Note that this does not nest */
+#define OSMO_PANIC_TRY(pE) (osmo_panic_try(pE, setjmp(jmp_env)))
+
+static int osmo_panic_try(volatile int *exception, int setjmp_result)
+{
+ jmp_env_valid = setjmp_result == 0;
+ *exception = setjmp_result;
+
+ if (setjmp_result)
+ fprintf(stderr, "Exception caught: %d\n", setjmp_result);
+
+ return *exception == 0;
+}
+
static void test_msgb_api()
{
struct msgb *msg = msgb_alloc_headroom(4096, 128, "data");