summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/test/utility/test_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/wiredtiger/test/utility/test_util.h')
-rw-r--r--src/third_party/wiredtiger/test/utility/test_util.h68
1 files changed, 66 insertions, 2 deletions
diff --git a/src/third_party/wiredtiger/test/utility/test_util.h b/src/third_party/wiredtiger/test/utility/test_util.h
index 3c1d0e2630a..f6a9cd68e02 100644
--- a/src/third_party/wiredtiger/test/utility/test_util.h
+++ b/src/third_party/wiredtiger/test/utility/test_util.h
@@ -68,10 +68,8 @@ typedef struct {
* resources.
*/
WT_CONNECTION *conn;
- char *conn_config;
WT_SESSION *session;
bool running;
- char *table_config;
char *uri;
volatile uint64_t next_threadid;
uint64_t max_inserted_id;
@@ -87,6 +85,16 @@ typedef struct {
} while (0)
/*
+ * testutil_assertfmt --
+ * Complain and quit if something isn't true.
+ */
+#define testutil_assertfmt(a, fmt, ...) do { \
+ if (!(a)) \
+ testutil_die(0, "%s/%d: %s: " fmt, \
+ __func__, __LINE__, #a, __VA_ARGS__); \
+} while (0)
+
+/*
* testutil_check --
* Complain and quit if a function call fails.
*/
@@ -108,6 +116,62 @@ typedef struct {
__func__, __LINE__, #call, __VA_ARGS__); \
} while (0)
+/*
+ * u64_to_string --
+ * Convert a uint64_t to a text string.
+ *
+ * Algorithm from Andrei Alexandrescu's talk: "Three Optimization Tips for C++"
+ */
+static inline void
+u64_to_string(uint64_t n, char **pp)
+{
+ static const char hundred_lookup[201] =
+ "0001020304050607080910111213141516171819"
+ "2021222324252627282930313233343536373839"
+ "4041424344454647484950515253545556575859"
+ "6061626364656667686970717273747576777879"
+ "8081828384858687888990919293949596979899";
+ u_int i;
+ char *p;
+
+ /*
+ * The argument pointer references the last element of a buffer (which
+ * must be large enough to hold any possible value).
+ *
+ * Nul-terminate the buffer.
+ */
+ for (p = *pp, *p-- = '\0'; n >= 100; n /= 100) {
+ i = (n % 100) * 2;
+ *p-- = hundred_lookup[i + 1];
+ *p-- = hundred_lookup[i];
+ }
+
+ /* Handle the last two digits. */
+ i = (u_int)n * 2;
+ *p = hundred_lookup[i + 1];
+ if (n >= 10)
+ *--p = hundred_lookup[i];
+
+ /* Return a pointer to the first byte of the text string. */
+ *pp = p;
+}
+
+/*
+ * u64_to_string_zf --
+ * Convert a uint64_t to a text string, zero-filling the buffer.
+ */
+static inline void
+u64_to_string_zf(uint64_t n, char *buf, size_t len)
+{
+ char *p;
+
+ p = buf + (len - 1);
+ u64_to_string(n, &p);
+
+ while (p > buf)
+ *--p = '0';
+}
+
/* Allow tests to add their own death handling. */
extern void (*custom_die)(void);