@@ -19,6 +19,7 @@ cflatobjs := \
lib/argv.o \
lib/printf.o \
lib/string.o \
+ lib/abort.o \
lib/report.o
# libfdt paths
new file mode 100644
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2014, Red Hat Inc, Andrew Jones <drjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include "libcflat.h"
+
+/*
+ * When exit(code) is invoked, qemu will exit with ((code << 1) | 1),
+ * leaving us 128 exit status codes. To avoid confusion with signal
+ * status, we further limit exit codes to those resulting in qemu
+ * exiting with a status < 128. We give abort() the highest (127),
+ * leaving the lower status codes for unit tests.
+ */
+#define ABORT_EXIT_STATUS 63 /* 127 exit status from qemu */
+
+void abort(void)
+{
+ exit(ABORT_EXIT_STATUS);
+}
@@ -44,6 +44,7 @@ typedef _Bool bool;
#define false 0
extern void exit(int code);
+extern void abort(void);
extern int printf(const char *fmt, ...);
extern int snprintf(char *buf, int size, const char *fmt, ...);
@@ -61,4 +62,12 @@ extern long atol(const char *ptr);
void report(const char *msg_fmt, bool pass, ...);
void report_xfail(const char *msg_fmt, bool xfail, bool pass, ...);
int report_summary(void);
+
+#define assert(cond) \
+do { \
+ if (!(cond)) \
+ printf("%s:%d: assert failed\n", __FILE__, __LINE__), \
+ abort(); \
+} while (0)
+
#endif