diff options
author | Alex Gorrod <alexg@wiredtiger.com> | 2016-02-19 01:54:23 +0000 |
---|---|---|
committer | Alex Gorrod <alexg@wiredtiger.com> | 2016-02-19 01:54:23 +0000 |
commit | 2b4cd8de33de080348eaac967609dd6ace44f0d0 (patch) | |
tree | d511761944ec4b234278242d3ed32317dc134809 | |
parent | ec9a4510252a85e4d243d5025a4e2d5e5384981e (diff) | |
download | mongo-2b4cd8de33de080348eaac967609dd6ace44f0d0.tar.gz |
WT-2405 Switch new testing error handler to be shared in test util
-rw-r--r-- | test/format/backup.c | 10 | ||||
-rw-r--r-- | test/format/bulk.c | 10 | ||||
-rw-r--r-- | test/format/compact.c | 4 | ||||
-rw-r--r-- | test/format/format.h | 13 | ||||
-rw-r--r-- | test/format/lrt.c | 14 | ||||
-rw-r--r-- | test/format/ops.c | 59 | ||||
-rw-r--r-- | test/format/rebalance.c | 4 | ||||
-rw-r--r-- | test/format/salvage.c | 4 | ||||
-rw-r--r-- | test/format/t.c | 10 | ||||
-rw-r--r-- | test/format/wts.c | 23 | ||||
-rw-r--r-- | test/utility/test_util.i | 10 |
11 files changed, 85 insertions, 76 deletions
diff --git a/test/format/backup.c b/test/format/backup.c index 8e2ad1b4883..ea6306ccb27 100644 --- a/test/format/backup.c +++ b/test/format/backup.c @@ -97,7 +97,7 @@ backup(void *arg) return (NULL); /* Open a session. */ - check(conn->open_session(conn, NULL, NULL, &session)); + testutil_check(conn->open_session(conn, NULL, NULL, &session)); /* * Perform a backup at somewhere under 10 seconds (so we get at @@ -113,7 +113,7 @@ backup(void *arg) break; /* Lock out named checkpoints */ - check(pthread_rwlock_wrlock(&g.backup_lock)); + testutil_check(pthread_rwlock_wrlock(&g.backup_lock)); /* Re-create the backup directory. */ if ((ret = system(g.home_backup_init)) != 0) @@ -136,13 +136,13 @@ backup(void *arg) copy_file(key); } - check(backup_cursor->close(backup_cursor)); - check(pthread_rwlock_unlock(&g.backup_lock)); + testutil_check(backup_cursor->close(backup_cursor)); + testutil_check(pthread_rwlock_unlock(&g.backup_lock)); check_copy(); } - check(session->close(session, NULL)); + testutil_check(session->close(session, NULL)); return (NULL); } diff --git a/test/format/bulk.c b/test/format/bulk.c index b344403f06f..64b005d294f 100644 --- a/test/format/bulk.c +++ b/test/format/bulk.c @@ -41,7 +41,7 @@ wts_load(void) conn = g.wts_conn; keybuf = valbuf = NULL; - check(conn->open_session(conn, NULL, NULL, &session)); + testutil_check(conn->open_session(conn, NULL, NULL, &session)); if (g.logging != 0) (void)g.wt_api->msg_printf(g.wt_api, session, @@ -59,7 +59,7 @@ wts_load(void) if (g.c_reverse) is_bulk = false; - check(session->open_cursor(session, g.uri, NULL, + testutil_check(session->open_cursor(session, g.uri, NULL, is_bulk ? "bulk,append" : NULL, &cursor)); /* Set up the key/value buffers. */ @@ -117,7 +117,7 @@ wts_load(void) break; } - check(cursor->insert(cursor)); + testutil_check(cursor->insert(cursor)); #ifdef HAVE_BERKELEY_DB if (SINGLETHREADED) @@ -125,13 +125,13 @@ wts_load(void) #endif } - check(cursor->close(cursor)); + testutil_check(cursor->close(cursor)); if (g.logging != 0) (void)g.wt_api->msg_printf(g.wt_api, session, "=============== bulk load stop ==============="); - check(session->close(session, NULL)); + testutil_check(session->close(session, NULL)); free(keybuf); free(valbuf); diff --git a/test/format/compact.c b/test/format/compact.c index a3a67a35464..a75ee4f2adf 100644 --- a/test/format/compact.c +++ b/test/format/compact.c @@ -48,7 +48,7 @@ compact(void *arg) /* Open a session. */ conn = g.wts_conn; - check(conn->open_session(conn, NULL, NULL, &session)); + testutil_check(conn->open_session(conn, NULL, NULL, &session)); /* * Perform compaction at somewhere under 15 seconds (so we get at @@ -68,7 +68,7 @@ compact(void *arg) testutil_die(ret, "session.compact"); } - check(session->close(session, NULL)); + testutil_check(session->close(session, NULL)); return (NULL); } diff --git a/test/format/format.h b/test/format/format.h index 19b2e71d1ec..b32877636c8 100644 --- a/test/format/format.h +++ b/test/format/format.h @@ -310,6 +310,7 @@ void config_single(const char *, int); void *dmalloc(size_t); char *dstrdup(const char *); void fclose_and_clear(FILE **); +void format_die(void); void key_gen(uint8_t *, size_t *, uint64_t); void key_gen_insert(WT_RAND_STATE *, uint8_t *, size_t *, uint64_t); void key_gen_setup(uint8_t **); @@ -334,18 +335,6 @@ void wts_salvage(void); void wts_stats(void); void wts_verify(const char *); -void format_die(void); - -/* - * check -- - * Complain and quit if a function call fails. - */ -#define check(call) do { \ - int __r; \ - if ((__r = (call)) != 0) \ - testutil_die(__r, "%s/%d: %s", __func__, __LINE__, #call);\ -} while (0) - /* * mmrand -- * Return a random value between a min/max pair. diff --git a/test/format/lrt.c b/test/format/lrt.c index 57d4119b62d..451d2f4fa3c 100644 --- a/test/format/lrt.c +++ b/test/format/lrt.c @@ -60,8 +60,9 @@ lrt(void *arg) /* Open a session and cursor. */ conn = g.wts_conn; - check(conn->open_session(conn, NULL, NULL, &session)); - check(session->open_cursor(session, g.uri, NULL, NULL, &cursor)); + testutil_check(conn->open_session(conn, NULL, NULL, &session)); + testutil_check(session->open_cursor( + session, g.uri, NULL, NULL, &cursor)); for (pinned = 0;;) { if (pinned) { @@ -89,10 +90,11 @@ lrt(void *arg) testutil_die(0, "mismatched start/stop values"); /* End the transaction. */ - check(session->commit_transaction(session, NULL)); + testutil_check( + session->commit_transaction(session, NULL)); /* Reset the cursor, releasing our pin. */ - check(cursor->reset(cursor)); + testutil_check(cursor->reset(cursor)); pinned = 0; } else { /* @@ -101,7 +103,7 @@ lrt(void *arg) * positioned. As soon as the cursor loses its position * a new snapshot will be allocated. */ - check(session->begin_transaction( + testutil_check(session->begin_transaction( session, "isolation=snapshot")); /* Read a record at the end of the table. */ @@ -161,7 +163,7 @@ lrt(void *arg) break; } - check(session->close(session, NULL)); + testutil_check(session->close(session, NULL)); free(keybuf); free(buf); diff --git a/test/format/ops.c b/test/format/ops.c index bafe20e7afd..d248736bb57 100644 --- a/test/format/ops.c +++ b/test/format/ops.c @@ -97,7 +97,7 @@ wts_ops(int lastrun) /* Open a session. */ if (g.logging != 0) { - check(conn->open_session(conn, NULL, NULL, &session)); + testutil_check(conn->open_session(conn, NULL, NULL, &session)); (void)g.wt_api->msg_printf(g.wt_api, session, "=============== thread ops start ==============="); } @@ -108,7 +108,8 @@ wts_ops(int lastrun) for (i = 0; i < g.c_threads; ++i) { tinfo[i].id = (int)i + 1; tinfo[i].state = TINFO_RUNNING; - check(pthread_create(&tinfo[i].tid, NULL, ops, &tinfo[i])); + testutil_check( + pthread_create(&tinfo[i].tid, NULL, ops, &tinfo[i])); } /* @@ -116,11 +117,12 @@ wts_ops(int lastrun) * long-running reader threads. */ if (g.c_backups) - check(pthread_create(&backup_tid, NULL, backup, NULL)); + testutil_check(pthread_create(&backup_tid, NULL, backup, NULL)); if (g.c_compact) - check(pthread_create(&compact_tid, NULL, compact, NULL)); + testutil_check( + pthread_create(&compact_tid, NULL, compact, NULL)); if (!SINGLETHREADED && g.c_long_running_txn) - check(pthread_create(&lrt_tid, NULL, lrt, NULL)); + testutil_check(pthread_create(&lrt_tid, NULL, lrt, NULL)); /* Spin on the threads, calculating the totals. */ for (;;) { @@ -186,7 +188,7 @@ wts_ops(int lastrun) if (g.logging != 0) { (void)g.wt_api->msg_printf(g.wt_api, session, "=============== thread ops stop ==============="); - check(session->close(session, NULL)); + testutil_check(session->close(session, NULL)); } } @@ -262,7 +264,8 @@ ops(void *arg) */ if (intxn && (tinfo->ops == ckpt_op || tinfo->ops == session_op)) { - check(session->commit_transaction(session, NULL)); + testutil_check( + session->commit_transaction(session, NULL)); ++tinfo->commit; intxn = 0; } @@ -271,9 +274,9 @@ ops(void *arg) if (tinfo->ops == session_op || session == NULL || cursor == NULL) { if (session != NULL) - check(session->close(session, NULL)); + testutil_check(session->close(session, NULL)); - check(conn->open_session(conn, NULL, + testutil_check(conn->open_session(conn, NULL, ops_session_config(&tinfo->rnd), &session)); /* @@ -289,7 +292,7 @@ ops(void *arg) */ if (!SINGLETHREADED && !DATASOURCE("lsm") && ckpt_available && mmrand(&tinfo->rnd, 1, 10) == 1) { - check(session->open_cursor(session, + testutil_check(session->open_cursor(session, g.uri, NULL, ckpt_name, &cursor)); /* Pick the next session/cursor close/open. */ @@ -311,10 +314,10 @@ ops(void *arg) * want to have to specify the record number, * which requires an append configuration. */ - check(session->open_cursor(session, + testutil_check(session->open_cursor(session, g.uri, NULL, "overwrite", &cursor)); if (g.type == FIX || g.type == VAR) - check(session->open_cursor( + testutil_check(session->open_cursor( session, g.uri, NULL, "append", &cursor_insert)); @@ -346,7 +349,8 @@ ops(void *arg) /* Named checkpoints lock out backups */ if (ckpt_config != NULL) - check(pthread_rwlock_wrlock(&g.backup_lock)); + testutil_check( + pthread_rwlock_wrlock(&g.backup_lock)); if ((ret = session->checkpoint(session, ckpt_config)) != 0) @@ -355,7 +359,8 @@ ops(void *arg) ckpt_config == NULL ? "" : ckpt_config); if (ckpt_config != NULL) - check(pthread_rwlock_unlock(&g.backup_lock)); + testutil_check( + pthread_rwlock_unlock(&g.backup_lock)); /* Rephrase the checkpoint name for cursor open. */ if (ckpt_config == NULL) @@ -376,7 +381,7 @@ ops(void *arg) * have to do the reset outside of a transaction. */ if (tinfo->ops > reset_op && !intxn) { - check(session->reset(session)); + testutil_check(session->reset(session)); /* Pick the next reset operation. */ reset_op += mmrand(&tinfo->rnd, 20000, 50000); @@ -388,7 +393,8 @@ ops(void *arg) */ if (!SINGLETHREADED && !intxn && mmrand(&tinfo->rnd, 1, 10) >= 8) { - check(session->begin_transaction(session, NULL)); + testutil_check( + session->begin_transaction(session, NULL)); intxn = 1; } @@ -446,7 +452,8 @@ ops(void *arg) if (col_insert(tinfo, cursor_insert, &key, &value, &keyno)) goto deadlock; - check(cursor_insert->reset(cursor_insert)); + testutil_check( + cursor_insert->reset(cursor_insert)); insert = 1; break; @@ -496,7 +503,7 @@ skip_insert: if (col_update(tinfo, goto deadlock; /* Reset the cursor: there is no reason to keep pages pinned. */ - check(cursor->reset(cursor)); + testutil_check(cursor->reset(cursor)); /* * If we're in the transaction, commit 40% of the time and @@ -505,7 +512,7 @@ skip_insert: if (col_update(tinfo, if (intxn) switch (mmrand(&tinfo->rnd, 1, 10)) { case 1: case 2: case 3: case 4: /* 40% */ - check(session->commit_transaction( + testutil_check(session->commit_transaction( session, NULL)); ++tinfo->commit; intxn = 0; @@ -514,7 +521,7 @@ skip_insert: if (col_update(tinfo, if (0) { deadlock: ++tinfo->deadlock; } - check(session->rollback_transaction( + testutil_check(session->rollback_transaction( session, NULL)); ++tinfo->rollback; intxn = 0; @@ -525,7 +532,7 @@ deadlock: ++tinfo->deadlock; } if (session != NULL) - check(session->close(session, NULL)); + testutil_check(session->close(session, NULL)); free(keybuf); free(valbuf); @@ -555,9 +562,9 @@ wts_read_scan(void) key_gen_setup(&keybuf); /* Open a session and cursor pair. */ - check(conn->open_session( + testutil_check(conn->open_session( conn, NULL, ops_session_config(NULL), &session)); - check(session->open_cursor( + testutil_check(session->open_cursor( session, g.uri, NULL, NULL, &cursor)); /* Check a random subset of the records using the key. */ @@ -575,7 +582,7 @@ wts_read_scan(void) testutil_die(ret, "read_scan"); } - check(session->close(session, NULL)); + testutil_check(session->close(session, NULL)); free(keybuf); } @@ -951,7 +958,7 @@ table_append(uint64_t keyno) * and we find a slot. */ for (done = 0;;) { - check(pthread_rwlock_wrlock(&g.append_lock)); + testutil_check(pthread_rwlock_wrlock(&g.append_lock)); /* * If this is the thread we've been waiting for, and its record @@ -988,7 +995,7 @@ table_append(uint64_t keyno) break; } - check(pthread_rwlock_unlock(&g.append_lock)); + testutil_check(pthread_rwlock_unlock(&g.append_lock)); if (done) break; diff --git a/test/format/rebalance.c b/test/format/rebalance.c index c448413fd00..eea4735a530 100644 --- a/test/format/rebalance.c +++ b/test/format/rebalance.c @@ -51,7 +51,7 @@ wts_rebalance(void) /* Rebalance, then verify the object. */ wts_reopen(); conn = g.wts_conn; - check(conn->open_session(conn, NULL, NULL, &session)); + testutil_check(conn->open_session(conn, NULL, NULL, &session)); if (g.logging != 0) (void)g.wt_api->msg_printf(g.wt_api, session, "=============== rebalance start ==============="); @@ -62,7 +62,7 @@ wts_rebalance(void) if (g.logging != 0) (void)g.wt_api->msg_printf(g.wt_api, session, "=============== rebalance stop ==============="); - check(session->close(session, NULL)); + testutil_check(session->close(session, NULL)); wts_verify("post-rebalance verify"); wts_close(); diff --git a/test/format/salvage.c b/test/format/salvage.c index 6036f25df39..526e1563390 100644 --- a/test/format/salvage.c +++ b/test/format/salvage.c @@ -42,10 +42,10 @@ salvage(void) conn = g.wts_conn; track("salvage", 0ULL, NULL); - check(conn->open_session(conn, NULL, NULL, &session)); + testutil_check(conn->open_session(conn, NULL, NULL, &session)); if ((ret = session->salvage(session, g.uri, "force=true")) != 0) testutil_die(ret, "session.salvage: %s", g.uri); - check(session->close(session, NULL)); + testutil_check(session->close(session, NULL)); } /* diff --git a/test/format/t.c b/test/format/t.c index f2409290acb..b9dfdaabb33 100644 --- a/test/format/t.c +++ b/test/format/t.c @@ -178,9 +178,9 @@ main(int argc, char *argv[]) * Initialize locks to single-thread named checkpoints and backups, last * last-record updates, and failures. */ - check(pthread_rwlock_init(&g.append_lock, NULL)); - check(pthread_rwlock_init(&g.backup_lock, NULL)); - check(pthread_rwlock_init(&g.death_lock, NULL)); + testutil_check(pthread_rwlock_init(&g.append_lock, NULL)); + testutil_check(pthread_rwlock_init(&g.backup_lock, NULL)); + testutil_check(pthread_rwlock_init(&g.death_lock, NULL)); printf("%s: process %" PRIdMAX "\n", g.progname, (intmax_t)getpid()); while (++g.run_cnt <= g.c_runs || g.c_runs == 0 ) { @@ -272,8 +272,8 @@ main(int argc, char *argv[]) config_print(0); - check(pthread_rwlock_destroy(&g.append_lock)); - check(pthread_rwlock_destroy(&g.backup_lock)); + testutil_check(pthread_rwlock_destroy(&g.append_lock)); + testutil_check(pthread_rwlock_destroy(&g.backup_lock)); config_clear(); diff --git a/test/format/wts.c b/test/format/wts.c index 3c3d03195fa..f1b8eaff3c3 100644 --- a/test/format/wts.c +++ b/test/format/wts.c @@ -438,10 +438,10 @@ wts_create(void) /* * Create the underlying store. */ - check(conn->open_session(conn, NULL, NULL, &session)); + testutil_check(conn->open_session(conn, NULL, NULL, &session)); if ((ret = session->create(session, g.uri, config)) != 0) testutil_die(ret, "session.create: %s", g.uri); - check(session->close(session, NULL)); + testutil_check(session->close(session, NULL)); } void @@ -454,7 +454,7 @@ wts_close(void) config = g.c_leak_memory ? "leak_memory" : NULL; - check(conn->close(conn, config)); + testutil_check(conn->close(conn, config)); g.wts_conn = NULL; g.wt_api = NULL; } @@ -511,7 +511,7 @@ wts_verify(const char *tag) conn = g.wts_conn; track("verify", 0ULL, NULL); - check(conn->open_session(conn, NULL, NULL, &session)); + testutil_check(conn->open_session(conn, NULL, NULL, &session)); if (g.logging != 0) (void)g.wt_api->msg_printf(g.wt_api, session, "=============== verify start ==============="); @@ -524,7 +524,7 @@ wts_verify(const char *tag) if (g.logging != 0) (void)g.wt_api->msg_printf(g.wt_api, session, "=============== verify stop ==============="); - check(session->close(session, NULL)); + testutil_check(session->close(session, NULL)); } /* @@ -554,14 +554,14 @@ wts_stats(void) conn = g.wts_conn; track("stat", 0ULL, NULL); - check(conn->open_session(conn, NULL, NULL, &session)); + testutil_check(conn->open_session(conn, NULL, NULL, &session)); if ((fp = fopen(g.home_stats, "w")) == NULL) testutil_die(errno, "fopen: %s", g.home_stats); /* Connection statistics. */ fprintf(fp, "====== Connection statistics:\n"); - check(session->open_cursor( + testutil_check(session->open_cursor( session, "statistics:", NULL, NULL, &cursor)); while ((ret = cursor->next(cursor)) == 0 && @@ -571,13 +571,14 @@ wts_stats(void) if (ret != WT_NOTFOUND) testutil_die(ret, "cursor.next"); - check(cursor->close(cursor)); + testutil_check(cursor->close(cursor)); /* Data source statistics. */ fprintf(fp, "\n\n====== Data source statistics:\n"); stat_name = dmalloc(strlen("statistics:") + strlen(g.uri) + 1); sprintf(stat_name, "statistics:%s", g.uri); - check(session->open_cursor(session, stat_name, NULL, NULL, &cursor)); + testutil_check(session->open_cursor( + session, stat_name, NULL, NULL, &cursor)); free(stat_name); while ((ret = cursor->next(cursor)) == 0 && @@ -587,9 +588,9 @@ wts_stats(void) if (ret != WT_NOTFOUND) testutil_die(ret, "cursor.next"); - check(cursor->close(cursor)); + testutil_check(cursor->close(cursor)); fclose_and_clear(&fp); - check(session->close(session, NULL)); + testutil_check(session->close(session, NULL)); } diff --git a/test/utility/test_util.i b/test/utility/test_util.i index de9424115d0..f1f0768dfcf 100644 --- a/test/utility/test_util.i +++ b/test/utility/test_util.i @@ -76,6 +76,16 @@ testutil_die(int e, const char *fmt, ...) } /* + * 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_work_dir_from_path -- * Takes a buffer, its size and the intended work directory. * Creates the full intended work directory in buffer. |