summaryrefslogtreecommitdiff
path: root/test/utility/test_util.i
diff options
context:
space:
mode:
Diffstat (limited to 'test/utility/test_util.i')
-rw-r--r--test/utility/test_util.i37
1 files changed, 36 insertions, 1 deletions
diff --git a/test/utility/test_util.i b/test/utility/test_util.i
index 3b88d375381..c5cebadcb5c 100644
--- a/test/utility/test_util.i
+++ b/test/utility/test_util.i
@@ -42,25 +42,60 @@
#define DEFAULT_DIR "WT_TEST"
#define MKDIR_COMMAND "mkdir "
+/* Allow tests to add their own death handling. */
+extern void (*custom_die)(void);
+
+static void testutil_die(int, const char *, ...)
+#if defined(__GNUC__)
+__attribute__((__noreturn__))
+#endif
+;
+
/*
* die --
* Report an error and quit.
*/
-static inline void
+static void
testutil_die(int e, const char *fmt, ...)
{
va_list ap;
+ /* Allow test programs to cleanup on fatal error. */
+ if (custom_die != NULL)
+ (*custom_die)();
+
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
if (e != 0)
fprintf(stderr, ": %s", wiredtiger_strerror(e));
fprintf(stderr, "\n");
+
exit(EXIT_FAILURE);
}
/*
+ * testutil_check --
+ * Complain and quit if a function call fails.
+ */
+#define testutil_check(call) do { \
+ int __r; \
+ if ((__r = (call)) != 0) \
+ testutil_die(__r, "%s/%d: %s", __func__, __LINE__, #call);\
+} while (0)
+
+/*
+ * testutil_checkfmt --
+ * Complain and quit if a function call fails, with additional arguments.
+ */
+#define testutil_checkfmt(call, fmt, ...) do { \
+ int __r; \
+ if ((__r = (call)) != 0) \
+ testutil_die(__r, "%s/%d: %s: " fmt, \
+ __func__, __LINE__, #call, __VA_ARGS__); \
+} while (0)
+
+/*
* testutil_work_dir_from_path --
* Takes a buffer, its size and the intended work directory.
* Creates the full intended work directory in buffer.