diff --git a/regressions/ck_backoff/validate/validate.c b/regressions/ck_backoff/validate/validate.c index 46d42ed..d4688a2 100644 --- a/regressions/ck_backoff/validate/validate.c +++ b/regressions/ck_backoff/validate/validate.c @@ -37,23 +37,20 @@ main(void) const ck_backoff_t ceiling = CK_BACKOFF_CEILING + 1; unsigned int i = 0; - fprintf(stderr, "Ceiling is: %u (%#x)\n", CK_BACKOFF_CEILING, CK_BACKOFF_CEILING); + ck_error("Ceiling is: %u (%#x)\n", CK_BACKOFF_CEILING, CK_BACKOFF_CEILING); for (;;) { ck_backoff_t previous = backoff; ck_backoff_gb(&backoff); if (previous == ceiling) { - if (backoff != ceiling) { - fprintf(stderr, "[C] GB: expected %u, got %u\n", ceiling, backoff); - exit(EXIT_FAILURE); - } + if (backoff != ceiling) + ck_error("[C] GB: expected %u, got %u\n", ceiling, backoff); if (i++ >= 1) break; } else if (previous != backoff >> 1) { - fprintf(stderr, "[N] GB: expected %u (%u), got %u\n", previous << 1, previous, backoff); - exit(EXIT_FAILURE); + ck_error("[N] GB: expected %u (%u), got %u\n", previous << 1, previous, backoff); } } @@ -66,8 +63,7 @@ main(void) if (i++ >= 3) break; } else if (previous * previous >= backoff) { - fprintf(stderr, "[N] EB: expected %u (%u), got %u\n", previous * previous, previous, backoff); - exit(EXIT_FAILURE); + ck_error("[N] EB: expected %u (%u), got %u\n", previous * previous, previous, backoff); } } diff --git a/regressions/ck_bag/validate/order.c b/regressions/ck_bag/validate/order.c index 6773c39..94a8822 100644 --- a/regressions/ck_bag/validate/order.c +++ b/regressions/ck_bag/validate/order.c @@ -124,16 +124,12 @@ reader(void *arg) curr = (uintptr_t)(curr_ptr); if (curr < prev) { /* Ascending order within block violated */ - fprintf(stderr, "%p: %p: %ju\n", (void *)&epoch_record, (void *)iterator.block, (uintmax_t)curr); - fprintf(stderr, "ERROR: %ju < %ju \n", - (uintmax_t)curr, (uintmax_t)prev); - exit(EXIT_FAILURE); + ck_error("%p: %p: %ju\nERROR: %ju < %ju\n", + (void *)&epoch_record, (void *)iterator.block, (uintmax_t)curr, (uintmax_t)curr, (uintmax_t)prev); } else if (prev_max != -1 && curr > prev_max) { /* Max of prev block > max of current block */ - fprintf(stderr, "%p: %p: %ju\n", (void *)&epoch_record, (void *)iterator.block, (uintmax_t)curr); - fprintf(stderr, "ERROR: %ju > prev_max: %ju\n", - (uintmax_t)curr, (uintmax_t)prev_max); - exit(EXIT_FAILURE); + ck_error("%p: %p: %ju\nERROR: %ju > %ju\n", + (void *)&epoch_record, (void *)iterator.block, (uintmax_t)curr, (uintmax_t)curr, (uintmax_t)prev_max); } curr_max = curr; @@ -148,7 +144,7 @@ reader(void *arg) break; } - fprintf(stderr, "Read %llu entries in %llu iterations.\n", n_entries, iterations); + ck_error("Read %llu entries in %llu iterations.\n", n_entries, iterations); ck_pr_inc_uint(&barrier); while (ck_pr_load_uint(&barrier) != NUM_READER_THREADS + 1) @@ -175,8 +171,7 @@ writer_thread(void *unused) } if (ck_bag_member_spmc(&bag, (void *)(uintptr_t)i) == false) { - fprintf(stderr, "ck_bag_put_spmc [%u]: %u\n", iteration, i); - exit(EXIT_FAILURE); + ck_error("ck_bag_put_spmc [%u]: %u\n", iteration, i); } } @@ -186,28 +181,25 @@ writer_thread(void *unused) for (i = 1; i < writer_max; i++) { void *replace = (void *)(uintptr_t)i; if (ck_bag_set_spmc(&bag, (void *)(uintptr_t)i, replace) == false) { - fprintf(stderr, "ERROR: set %ju != %ju", + ck_error("ERROR: set %ju != %ju", (uintmax_t)(uintptr_t)replace, (uintmax_t)i); - exit(EXIT_FAILURE); } } for (i = writer_max; i > 0; i--) { if (ck_bag_member_spmc(&bag, (void *)(uintptr_t)i) == false) { - fprintf(stderr, "ck_bag_member_spmc [%u]: %u\n", iteration, i); - exit(EXIT_FAILURE); + ck_error("ck_bag_member_spmc [%u]: %u\n", iteration, i); } if (ck_bag_remove_spmc(&bag, (void *)(uintptr_t)i) == false) { - fprintf(stderr, "ck_bag_remove_spmc [%u]: %u\n", iteration, i); - exit(EXIT_FAILURE); + ck_error("ck_bag_remove_spmc [%u]: %u\n", iteration, i); } } ck_epoch_poll(&epoch_bag, &epoch_wr); } - fprintf(stderr, "Writer %u iterations, %u writes per iteration.\n", iteration, writer_max); + ck_error("Writer %u iterations, %u writes per iteration.\n", iteration, writer_max); while (ck_pr_load_uint(&barrier) != NUM_READER_THREADS) ck_pr_stall(); @@ -228,8 +220,7 @@ main(int argc, char **argv) if (argc >= 2) { int r = atoi(argv[1]); if (r <= 0) { - fprintf(stderr, "# entries in block must be > 0\n"); - exit(EXIT_FAILURE); + ck_error("# entries in block must be > 0\n"); } b = (size_t)r; @@ -238,8 +229,7 @@ main(int argc, char **argv) if (argc >= 3) { int r = atoi(argv[2]); if (r < 16) { - fprintf(stderr, "# entries must be >= 16\n"); - exit(EXIT_FAILURE); + ck_error("# entries must be >= 16\n"); } writer_max = (unsigned int)r; @@ -249,10 +239,9 @@ main(int argc, char **argv) ck_epoch_register(&epoch_bag, &epoch_wr); ck_bag_allocator_set(&allocator, sizeof(struct bag_epoch)); if (ck_bag_init(&bag, b, CK_BAG_ALLOCATE_GEOMETRIC) == false) { - fprintf(stderr, "Error: failed ck_bag_init()."); - exit(EXIT_FAILURE); + ck_error("Error: failed ck_bag_init()."); } - fprintf(stderr, "Configuration: %u entries, %zu bytes/block, %zu entries/block\n", writer_max, bag.info.bytes, bag.info.max); + ck_error("Configuration: %u entries, %zu bytes/block, %zu entries/block\n", writer_max, bag.info.bytes, bag.info.max); i = 1; /* Basic Test */ @@ -277,7 +266,7 @@ main(int argc, char **argv) while (ck_bag_next(&bag_it, &curr_ptr)) { curr = (uintptr_t)(curr_ptr); if (curr > (uintptr_t)i) - fprintf(stderr, "ERROR: %ju != %u\n", (uintmax_t)curr, i); + ck_error("ERROR: %ju != %u\n", (uintmax_t)curr, i); ck_bag_remove_spmc(&bag, curr_ptr); } @@ -289,16 +278,16 @@ main(int argc, char **argv) pthread_create(&readers[i], NULL, reader, NULL); } - fprintf(stderr, "Waiting..."); + ck_error("Waiting..."); sleep(30); - fprintf(stderr, "done\n"); + ck_error("done\n"); ck_pr_store_int(&leave, 1); for (i = 0; i < NUM_READER_THREADS; i++) pthread_join(readers[i], NULL); pthread_join(writer, NULL); - fprintf(stderr, "Current entries: %u\n", ck_bag_count(&bag)); + ck_error("Current entries: %u\n", ck_bag_count(&bag)); ck_bag_destroy(&bag); return 0; } diff --git a/regressions/ck_barrier/benchmark/throughput.c b/regressions/ck_barrier/benchmark/throughput.c index cb771a2..aa1f01f 100644 --- a/regressions/ck_barrier/benchmark/throughput.c +++ b/regressions/ck_barrier/benchmark/throughput.c @@ -86,38 +86,33 @@ main(int argc, char *argv[]) int i; if (argc != 3) { - fprintf(stderr, "Correct usage: \n"); - exit(EXIT_FAILURE); + ck_error("Correct usage: \n"); } nthr = atoi(argv[1]); if (nthr <= 0) { - fprintf(stderr, "ERROR: Number of threads must be greater than 0\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of threads must be greater than 0\n"); } threads = malloc(sizeof(pthread_t) * nthr); if (threads == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate thread structures\n"); } counters = calloc(sizeof(struct counter), nthr); if (counters == NULL) { - fprintf(stderr, "ERROR: Could not allocate counters\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate counters\n"); } a.delta = atoi(argv[2]); - fprintf(stderr, "Creating threads (barrier)..."); + ck_error("Creating threads (barrier)..."); for (i = 0; i < nthr; ++i) { if (pthread_create(&threads[i], NULL, thread, NULL)) { - fprintf(stderr, "ERROR: Could not create thread %d\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not create thread %d\n", i); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); sleep(10); diff --git a/regressions/ck_barrier/validate/barrier_centralized.c b/regressions/ck_barrier/validate/barrier_centralized.c index abb41b1..c57813e 100644 --- a/regressions/ck_barrier/validate/barrier_centralized.c +++ b/regressions/ck_barrier/validate/barrier_centralized.c @@ -73,8 +73,7 @@ thread(void *null CK_CC_UNUSED) ck_barrier_centralized(&barrier, &state, nthr); counter = ck_pr_load_int(&counters[i]); if (counter != nthr * (j / ENTRIES + 1)) { - fprintf(stderr, "FAILED [%d:%d]: %d != %d\n", i, j - 1, counter, nthr); - exit(EXIT_FAILURE); + ck_error("FAILED [%d:%d]: %d != %d\n", i, j - 1, counter, nthr); } } @@ -88,37 +87,33 @@ main(int argc, char *argv[]) int i; if (argc < 3) { - fprintf(stderr, "Usage: correct \n"); - exit(EXIT_FAILURE); + ck_error("Usage: correct \n"); } nthr = atoi(argv[1]); if (nthr <= 0) { - fprintf(stderr, "ERROR: Number of threads must be greater than 0\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of threads must be greater than 0\n"); } threads = malloc(sizeof(pthread_t) * nthr); if (threads == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate thread structures\n"); } a.delta = atoi(argv[2]); - fprintf(stderr, "Creating threads (barrier)..."); + ck_error("Creating threads (barrier)..."); for (i = 0; i < nthr; i++) { if (pthread_create(&threads[i], NULL, thread, NULL)) { - fprintf(stderr, "ERROR: Could not create thread %d\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not create thread %d\n", i); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); - fprintf(stderr, "Waiting for threads to finish correctness regression..."); + ck_error("Waiting for threads to finish correctness regression..."); for (i = 0; i < nthr; i++) pthread_join(threads[i], NULL); - fprintf(stderr, "done (passed)\n"); + ck_error("done (passed)\n"); return (0); diff --git a/regressions/ck_barrier/validate/barrier_combining.c b/regressions/ck_barrier/validate/barrier_combining.c index 9204697..1978b00 100644 --- a/regressions/ck_barrier/validate/barrier_combining.c +++ b/regressions/ck_barrier/validate/barrier_combining.c @@ -75,8 +75,7 @@ thread(void *group) ck_barrier_combining(&barrier, group, &state); counter = ck_pr_load_int(&counters[i]); if (counter != nthr * ngroups * (j / ENTRIES + 1)) { - fprintf(stderr, "FAILED [%d:%d]: %d != %d\n", i, j - 1, counter, nthr * ngroups); - exit(EXIT_FAILURE); + ck_error("FAILED [%d:%d]: %d != %d\n", i, j - 1, counter, nthr * ngroups); } } @@ -93,38 +92,32 @@ main(int argc, char *argv[]) init_root = malloc(sizeof(ck_barrier_combining_group_t)); if (init_root == NULL) { - fprintf(stderr, "ERROR: Could not allocate initial barrier structure\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate initial barrier structure\n"); } ck_barrier_combining_init(&barrier, init_root); if (argc < 4) { - fprintf(stderr, "Usage: correct \n"); - exit(EXIT_FAILURE); + ck_error("Usage: correct \n"); } ngroups = atoi(argv[1]); if (ngroups <= 0) { - fprintf(stderr, "ERROR: Number of groups must be greater than 0\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of groups must be greater than 0\n"); } nthr = atoi(argv[2]); if (nthr <= 0) { - fprintf(stderr, "ERROR: Number of threads must be greater than 0\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of threads must be greater than 0\n"); } groupings = malloc(sizeof(ck_barrier_combining_group_t) * ngroups); if (groupings == NULL) { - fprintf(stderr, "Could not allocate thread barrier grouping structures\n"); - exit(EXIT_FAILURE); + ck_error("Could not allocate thread barrier grouping structures\n"); } threads = malloc(sizeof(pthread_t) * nthr * ngroups); if (threads == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate thread structures\n"); } a.delta = atoi(argv[3]); @@ -132,19 +125,18 @@ main(int argc, char *argv[]) for (i = 0; i < ngroups; i++) ck_barrier_combining_group_init(&barrier, groupings + i, nthr); - fprintf(stderr, "Creating threads (barrier)..."); + ck_error("Creating threads (barrier)..."); for (i = 0; i < (nthr * ngroups); i++) { if (pthread_create(&threads[i], NULL, thread, groupings + (i % ngroups))) { - fprintf(stderr, "ERROR: Could not create thread %d\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not create thread %d\n", i); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); - fprintf(stderr, "Waiting for threads to finish correctness regression..."); + ck_error("Waiting for threads to finish correctness regression..."); for (i = 0; i < (nthr * ngroups); i++) pthread_join(threads[i], NULL); - fprintf(stderr, "done (passed)\n"); + ck_error("done (passed)\n"); return (0); } diff --git a/regressions/ck_barrier/validate/barrier_dissemination.c b/regressions/ck_barrier/validate/barrier_dissemination.c index a46f277..fe3ac5e 100644 --- a/regressions/ck_barrier/validate/barrier_dissemination.c +++ b/regressions/ck_barrier/validate/barrier_dissemination.c @@ -75,8 +75,7 @@ thread(void *b) ck_barrier_dissemination(barrier, &state); counter = ck_pr_load_int(&counters[i]); if (counter != nthr * (j / ENTRIES + 1)) { - fprintf(stderr, "FAILED [%d:%d]: %d != %d\n", i, j - 1, counter, nthr); - exit(EXIT_FAILURE); + ck_error("FAILED [%d:%d]: %d != %d\n", i, j - 1, counter, nthr); } } @@ -92,59 +91,52 @@ main(int argc, char *argv[]) int i, size; if (argc < 3) { - fprintf(stderr, "Usage: correct \n"); - exit(EXIT_FAILURE); + ck_error("Usage: correct \n"); } nthr = atoi(argv[1]); if (nthr <= 0) { - fprintf(stderr, "ERROR: Number of threads must be greater than 0\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of threads must be greater than 0\n"); } threads = malloc(sizeof(pthread_t) * nthr); if (threads == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate thread structures\n"); } a.delta = atoi(argv[2]); barrier = malloc(sizeof(ck_barrier_dissemination_t) * nthr); if (barrier == NULL) { - fprintf(stderr, "ERROR: Could not allocate barrier structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate barrier structures\n"); } barrier_internal = malloc(sizeof(ck_barrier_dissemination_flag_t *) * nthr); if (barrier_internal == NULL) { - fprintf(stderr, "ERROR: Could not allocate barrier structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate barrier structures\n"); } size = ck_barrier_dissemination_size(nthr); for (i = 0; i < nthr; ++i) { barrier_internal[i] = malloc(sizeof(ck_barrier_dissemination_flag_t) * size); if (barrier_internal[i] == NULL) { - fprintf(stderr, "ERROR: Could not allocate barrier structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate barrier structures\n"); } } ck_barrier_dissemination_init(barrier, barrier_internal, nthr); - fprintf(stderr, "Creating threads (barrier)..."); + ck_error("Creating threads (barrier)..."); for (i = 0; i < nthr; i++) { if (pthread_create(&threads[i], NULL, thread, barrier)) { - fprintf(stderr, "ERROR: Could not create thread %d\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not create thread %d\n", i); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); - fprintf(stderr, "Waiting for threads to finish correctness regression..."); + ck_error("Waiting for threads to finish correctness regression..."); for (i = 0; i < nthr; i++) pthread_join(threads[i], NULL); - fprintf(stderr, "done (passed)\n"); + ck_error("done (passed)\n"); return (0); diff --git a/regressions/ck_barrier/validate/barrier_mcs.c b/regressions/ck_barrier/validate/barrier_mcs.c index a47c367..c5ac262 100644 --- a/regressions/ck_barrier/validate/barrier_mcs.c +++ b/regressions/ck_barrier/validate/barrier_mcs.c @@ -76,8 +76,7 @@ thread(void *b) ck_barrier_mcs(barrier, &state); counter = ck_pr_load_int(&counters[i]); if (counter != nthr * (j / ENTRIES + 1)) { - fprintf(stderr, "FAILED [%d:%d]: %d != %d\n", i, j - 1, counter, nthr); - exit(EXIT_FAILURE); + ck_error("FAILED [%d:%d]: %d != %d\n", i, j - 1, counter, nthr); } } @@ -92,44 +91,39 @@ main(int argc, char *argv[]) int i; if (argc < 3) { - fprintf(stderr, "Usage: correct \n"); - exit(EXIT_FAILURE); + ck_error("Usage: correct \n"); } nthr = atoi(argv[1]); if (nthr <= 0) { - fprintf(stderr, "ERROR: Number of threads must be greater than 0\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of threads must be greater than 0\n"); } threads = malloc(sizeof(pthread_t) * nthr); if (threads == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate thread structures\n"); } barrier = malloc(sizeof(ck_barrier_mcs_t) * nthr); if (barrier == NULL) { - fprintf(stderr, "ERROR: Could not allocate barrier structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate barrier structures\n"); } ck_barrier_mcs_init(barrier, nthr); a.delta = atoi(argv[2]); - fprintf(stderr, "Creating threads (barrier)..."); + ck_error("Creating threads (barrier)..."); for (i = 0; i < nthr; i++) { if (pthread_create(&threads[i], NULL, thread, barrier)) { - fprintf(stderr, "ERROR: Could not create thread %d\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not create thread %d\n", i); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); - fprintf(stderr, "Waiting for threads to finish correctness regression..."); + ck_error("Waiting for threads to finish correctness regression..."); for (i = 0; i < nthr; i++) pthread_join(threads[i], NULL); - fprintf(stderr, "done (passed)\n"); + ck_error("done (passed)\n"); return (0); diff --git a/regressions/ck_barrier/validate/barrier_tournament.c b/regressions/ck_barrier/validate/barrier_tournament.c index 4ec204a..2e9eacd 100644 --- a/regressions/ck_barrier/validate/barrier_tournament.c +++ b/regressions/ck_barrier/validate/barrier_tournament.c @@ -75,8 +75,7 @@ thread(CK_CC_UNUSED void *unused) ck_barrier_tournament(&barrier, &state); counter = ck_pr_load_int(&counters[i]); if (counter != nthr * (j / ENTRIES + 1)) { - fprintf(stderr, "FAILED [%d:%d]: %d != %d\n", i, j - 1, counter, nthr); - exit(EXIT_FAILURE); + ck_error("FAILED [%d:%d]: %d != %d\n", i, j - 1, counter, nthr); } } @@ -96,53 +95,47 @@ main(int argc, char *argv[]) unsigned int size; if (argc < 3) { - fprintf(stderr, "Usage: correct \n"); - exit(EXIT_FAILURE); + ck_error("Usage: correct \n"); } nthr = atoi(argv[1]); if (nthr <= 0) { - fprintf(stderr, "ERROR: Number of threads must be greater than 0\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of threads must be greater than 0\n"); } a.delta = atoi(argv[2]); threads = malloc(sizeof(pthread_t) * nthr); if (threads == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate thread structures\n"); } rounds = malloc(sizeof(ck_barrier_tournament_round_t *) * nthr); if (rounds == NULL) { - fprintf(stderr, "ERROR: Could not allocate barrier structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate barrier structures\n"); } size = ck_barrier_tournament_size(nthr); for (i = 0; i < nthr; ++i) { rounds[i] = malloc(sizeof(ck_barrier_tournament_round_t) * size); if (rounds[i] == NULL) { - fprintf(stderr, "ERROR: Could not allocate barrier structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate barrier structures\n"); } } ck_barrier_tournament_init(&barrier, rounds, nthr); - fprintf(stderr, "Creating threads (barrier)..."); + ck_error("Creating threads (barrier)..."); for (i = 0; i < nthr; i++) { if (pthread_create(&threads[i], NULL, thread, NULL)) { - fprintf(stderr, "ERROR: Could not create thread %d\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not create thread %d\n", i); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); - fprintf(stderr, "Waiting for threads to finish correctness regression..."); + ck_error("Waiting for threads to finish correctness regression..."); for (i = 0; i < nthr; i++) pthread_join(threads[i], NULL); - fprintf(stderr, "done (passed)\n"); + ck_error("done (passed)\n"); return (0); } diff --git a/regressions/ck_bitmap/validate/serial.c b/regressions/ck_bitmap/validate/serial.c index 46b7737..3d1f005 100644 --- a/regressions/ck_bitmap/validate/serial.c +++ b/regressions/ck_bitmap/validate/serial.c @@ -31,6 +31,8 @@ #include #include +#include "../../common.h" + #ifndef STATIC_LENGTH #define STATIC_LENGTH 256 #endif @@ -57,13 +59,11 @@ check_iteration(ck_bitmap_t *bits, unsigned int len, bool initial) if (i == j) continue; - fprintf(stderr, "[4] ERROR: Expected bit %u, got bit %u\n", j, i); - exit(EXIT_FAILURE); + ck_error("[4] ERROR: Expected bit %u, got bit %u\n", j, i); } if (j != len) { - fprintf(stderr, "[5] ERROR: Expected length %u, got length %u\n", len, j); - exit(EXIT_FAILURE); + ck_error("[5] ERROR: Expected length %u, got length %u\n", len, j); } return; @@ -76,28 +76,24 @@ test(ck_bitmap_t *bits, unsigned int n_length, bool initial) for (i = 0; i < n_length; i++) { if (ck_bitmap_test(bits, i) == !initial) { - fprintf(stderr, "[0] ERROR [%u]: Expected %u got %u\n", i, + ck_error("[0] ERROR [%u]: Expected %u got %u\n", i, initial, !initial); - exit(EXIT_FAILURE); } } for (i = 0; i < n_length; i++) { ck_bitmap_set_mpmc(bits, i); if (ck_bitmap_test(bits, i) == false) { - fprintf(stderr, "[1] ERROR: Expected bit to be set: %u\n", i); - exit(EXIT_FAILURE); + ck_error("[1] ERROR: Expected bit to be set: %u\n", i); } ck_bitmap_reset_mpmc(bits, i); if (ck_bitmap_test(bits, i) == true) { - fprintf(stderr, "[2] ERROR: Expected bit to be cleared: %u\n", i); - exit(EXIT_FAILURE); + ck_error("[2] ERROR: Expected bit to be cleared: %u\n", i); } ck_bitmap_set_mpmc(bits, i); if (ck_bitmap_test(bits, i) == false) { - fprintf(stderr, "[3] ERROR: Expected bit to be set: %u\n", i); - exit(EXIT_FAILURE); + ck_error("[3] ERROR: Expected bit to be set: %u\n", i); } check_iteration(bits, i, initial); @@ -105,8 +101,7 @@ test(ck_bitmap_t *bits, unsigned int n_length, bool initial) for (i = 0; i < n_length; i++) { if (ck_bitmap_test(bits, i) == false) { - fprintf(stderr, "[4] ERROR: Expected bit to be set: %u\n", i); - exit(EXIT_FAILURE); + ck_error("[4] ERROR: Expected bit to be set: %u\n", i); } } @@ -114,8 +109,7 @@ test(ck_bitmap_t *bits, unsigned int n_length, bool initial) for (i = 0; i < n_length; i++) { if (ck_bitmap_test(bits, i) == true) { - fprintf(stderr, "[4] ERROR: Expected bit to be reset: %u\n", i); - exit(EXIT_FAILURE); + ck_error("[4] ERROR: Expected bit to be reset: %u\n", i); } } @@ -133,7 +127,7 @@ main(int argc, char *argv[]) base = ck_bitmap_base(length); bytes = ck_bitmap_size(length); - fprintf(stderr, "Configuration: %u bytes\n", + ck_error("Configuration: %u bytes\n", bytes); g_bits = malloc(bytes); @@ -148,7 +142,7 @@ main(int argc, char *argv[]) ck_bitmap_test(g_bits, length - 1); CK_BITMAP_INSTANCE(STATIC_LENGTH) sb; - fprintf(stderr, "Static configuration: %zu bytes\n", + ck_error("Static configuration: %zu bytes\n", sizeof(sb)); memset(CK_BITMAP_BUFFER(&sb), 0xFF, ck_bitmap_base(STATIC_LENGTH)); CK_BITMAP_INIT(&sb, STATIC_LENGTH, false); @@ -159,20 +153,17 @@ main(int argc, char *argv[]) CK_BITMAP_CLEAR(&sb); if (CK_BITMAP_TEST(&sb, 1) == true) { - fprintf(stderr, "ERROR: Expected bit to be reset.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Expected bit to be reset.\n"); } CK_BITMAP_SET_MPMC(&sb, 1); if (CK_BITMAP_TEST(&sb, 1) == false) { - fprintf(stderr, "ERROR: Expected bit to be set.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Expected bit to be set.\n"); } CK_BITMAP_RESET_MPMC(&sb, 1); if (CK_BITMAP_TEST(&sb, 1) == true) { - fprintf(stderr, "ERROR: Expected bit to be reset.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Expected bit to be reset.\n"); } return 0; diff --git a/regressions/ck_brlock/benchmark/throughput.c b/regressions/ck_brlock/benchmark/throughput.c index 726aed7..45e7939 100644 --- a/regressions/ck_brlock/benchmark/throughput.c +++ b/regressions/ck_brlock/benchmark/throughput.c @@ -119,47 +119,42 @@ main(int argc, char *argv[]) uint64_t *latency; if (argc != 3) { - fprintf(stderr, "Usage: throughput \n"); - exit(EXIT_FAILURE); + ck_error("Usage: throughput \n"); } threads = atoi(argv[2]); if (threads <= 0) { - fprintf(stderr, "ERROR: Threads must be a value > 0.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Threads must be a value > 0.\n"); } p = malloc(sizeof(pthread_t) * threads); if (p == NULL) { - fprintf(stderr, "ERROR: Failed to initialize thread.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to initialize thread.\n"); } latency = malloc(sizeof(uint64_t) * threads); if (latency == NULL) { - fprintf(stderr, "ERROR: Failed to create latency buffer.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to create latency buffer.\n"); } affinity.delta = atoi(argv[1]); affinity.request = 0; - fprintf(stderr, "Creating threads (brlock)..."); + ck_error("Creating threads (brlock)..."); for (t = 0; t < threads; t++) { if (pthread_create(&p[t], NULL, thread_brlock, latency + t) != 0) { - fprintf(stderr, "ERROR: Could not create thread %d\n", t); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not create thread %d\n", t); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); sleep(10); ck_pr_store_uint(&flag, 1); - fprintf(stderr, "Waiting for threads to finish acquisition regression..."); + ck_error("Waiting for threads to finish acquisition regression..."); for (t = 0; t < threads; t++) pthread_join(p[t], NULL); - fprintf(stderr, "done\n\n"); + ck_error("done\n\n"); for (t = 1; t <= threads; t++) printf("%10u %20" PRIu64 "\n", t, latency[t - 1]); diff --git a/regressions/ck_brlock/validate/validate.c b/regressions/ck_brlock/validate/validate.c index c11e384..64009f2 100644 --- a/regressions/ck_brlock/validate/validate.c +++ b/regressions/ck_brlock/validate/validate.c @@ -68,8 +68,7 @@ thread(void *null CK_CC_UNUSED) { l = ck_pr_load_uint(&locked); if (l != 0) { - fprintf(stderr, "ERROR [WR:%d]: %u != 0\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l); } ck_pr_inc_uint(&locked); @@ -83,8 +82,7 @@ thread(void *null CK_CC_UNUSED) l = ck_pr_load_uint(&locked); if (l != 8) { - fprintf(stderr, "ERROR [WR:%d]: %u != 2\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [WR:%d]: %u != 2\n", __LINE__, l); } ck_pr_dec_uint(&locked); @@ -98,8 +96,7 @@ thread(void *null CK_CC_UNUSED) l = ck_pr_load_uint(&locked); if (l != 0) { - fprintf(stderr, "ERROR [WR:%d]: %u != 0\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l); } } ck_brlock_write_unlock(&lock); @@ -108,8 +105,7 @@ thread(void *null CK_CC_UNUSED) { l = ck_pr_load_uint(&locked); if (l != 0) { - fprintf(stderr, "ERROR [RD:%d]: %u != 0\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [RD:%d]: %u != 0\n", __LINE__, l); } } ck_brlock_read_unlock(&r); @@ -126,37 +122,33 @@ main(int argc, char *argv[]) int i; if (argc != 3) { - fprintf(stderr, "Usage: validate \n"); - exit(EXIT_FAILURE); + ck_error("Usage: validate \n"); } nthr = atoi(argv[1]); if (nthr <= 0) { - fprintf(stderr, "ERROR: Number of threads must be greater than 0\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of threads must be greater than 0\n"); } threads = malloc(sizeof(pthread_t) * nthr); if (threads == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate thread structures\n"); } a.delta = atoi(argv[2]); - fprintf(stderr, "Creating threads (mutual exclusion)..."); + ck_error("Creating threads (mutual exclusion)..."); for (i = 0; i < nthr; i++) { if (pthread_create(&threads[i], NULL, thread, NULL)) { - fprintf(stderr, "ERROR: Could not create thread %d\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not create thread %d\n", i); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); - fprintf(stderr, "Waiting for threads to finish correctness regression..."); + ck_error("Waiting for threads to finish correctness regression..."); for (i = 0; i < nthr; i++) pthread_join(threads[i], NULL); - fprintf(stderr, "done (passed)\n"); + ck_error("done (passed)\n"); return (0); } diff --git a/regressions/ck_bytelock/validate/validate.c b/regressions/ck_bytelock/validate/validate.c index cf900a0..4324761 100644 --- a/regressions/ck_bytelock/validate/validate.c +++ b/regressions/ck_bytelock/validate/validate.c @@ -70,8 +70,7 @@ thread(void *null) { l = ck_pr_load_uint(&locked); if (l != 0) { - fprintf(stderr, "ERROR [WR:%d]: %u != 0\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l); } ck_pr_inc_uint(&locked); @@ -85,8 +84,7 @@ thread(void *null) l = ck_pr_load_uint(&locked); if (l != 8) { - fprintf(stderr, "ERROR [WR:%d]: %u != 2\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [WR:%d]: %u != 2\n", __LINE__, l); } ck_pr_dec_uint(&locked); @@ -100,8 +98,7 @@ thread(void *null) l = ck_pr_load_uint(&locked); if (l != 0) { - fprintf(stderr, "ERROR [WR:%d]: %u != 0\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l); } } ck_bytelock_write_unlock(&lock); @@ -110,8 +107,7 @@ thread(void *null) { l = ck_pr_load_uint(&locked); if (l != 0) { - fprintf(stderr, "ERROR [RD:%d]: %u != 0\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [RD:%d]: %u != 0\n", __LINE__, l); } } ck_bytelock_read_unlock(&lock, context->tid); @@ -128,44 +124,39 @@ main(int argc, char *argv[]) int i; if (argc != 3) { - fprintf(stderr, "Usage: correct \n"); - exit(EXIT_FAILURE); + ck_error("Usage: correct \n"); } nthr = atoi(argv[1]); if (nthr <= 0) { - fprintf(stderr, "ERROR: Number of threads must be greater than 0\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of threads must be greater than 0\n"); } threads = malloc(sizeof(pthread_t) * nthr); if (threads == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate thread structures\n"); } context = malloc(sizeof(struct block) * nthr); if (context == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread contexts\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate thread contexts\n"); } a.delta = atoi(argv[2]); - fprintf(stderr, "Creating threads (mutual exclusion)..."); + ck_error("Creating threads (mutual exclusion)..."); for (i = 0; i < nthr; i++) { context[i].tid = i + 1; if (pthread_create(&threads[i], NULL, thread, context + i)) { - fprintf(stderr, "ERROR: Could not create thread %d\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not create thread %d\n", i); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); - fprintf(stderr, "Waiting for threads to finish correctness regression..."); + ck_error("Waiting for threads to finish correctness regression..."); for (i = 0; i < nthr; i++) pthread_join(threads[i], NULL); - fprintf(stderr, "done (passed)\n"); + ck_error("done (passed)\n"); return (0); } diff --git a/regressions/ck_epoch/validate/ck_epoch_poll.c b/regressions/ck_epoch/validate/ck_epoch_poll.c index 26652d1..dd2e8da 100644 --- a/regressions/ck_epoch/validate/ck_epoch_poll.c +++ b/regressions/ck_epoch/validate/ck_epoch_poll.c @@ -138,7 +138,7 @@ read_thread(void *unused CK_CC_UNUSED) ck_pr_inc_uint(&e_barrier); while (ck_pr_load_uint(&e_barrier) < n_threads); - fprintf(stderr, "[R] Observed entries: %u\n", j); + ck_error("[R] Observed entries: %u\n", j); return (NULL); } @@ -163,16 +163,14 @@ write_thread(void *unused CK_CC_UNUSED) entry = malloc(sizeof(struct node *) * PAIRS_S); if (entry == NULL) { - fprintf(stderr, "Failed allocation.\n"); - exit(EXIT_FAILURE); + ck_error("Failed allocation.\n"); } for (j = 0; j < ITERATE_S; j++) { for (i = 0; i < PAIRS_S; i++) { entry[i] = malloc(sizeof(struct node)); if (entry == NULL) { - fprintf(stderr, "Failed individual allocation\n"); - exit(EXIT_FAILURE); + ck_error("Failed individual allocation\n"); } } @@ -184,7 +182,7 @@ write_thread(void *unused CK_CC_UNUSED) ck_pr_stall(); if (tid == 0) { - fprintf(stderr, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b[W] %2.2f: %c", + ck_error("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b[W] %2.2f: %c", (double)j / ITERATE_S, animate[i % strlen(animate)]); } @@ -202,7 +200,7 @@ write_thread(void *unused CK_CC_UNUSED) ck_epoch_synchronize(&stack_epoch, &record); if (tid == 0) { - fprintf(stderr, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b[W] Peak: %u (%2.2f%%)\n Reclamations: %lu\n\n", + ck_error("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b[W] Peak: %u (%2.2f%%)\n Reclamations: %lu\n\n", record.n_peak, (double)record.n_peak / ((double)PAIRS_S * ITERATE_S) * 100, record.n_dispatch); @@ -220,8 +218,7 @@ main(int argc, char *argv[]) pthread_t *threads; if (argc != 4) { - fprintf(stderr, "Usage: stack <#readers> <#writers> \n"); - exit(EXIT_FAILURE); + ck_error("Usage: stack <#readers> <#writers> \n"); } n_rd = atoi(argv[1]); diff --git a/regressions/ck_epoch/validate/ck_epoch_synchronize.c b/regressions/ck_epoch/validate/ck_epoch_synchronize.c index 4fbc1b4..72f7c05 100644 --- a/regressions/ck_epoch/validate/ck_epoch_synchronize.c +++ b/regressions/ck_epoch/validate/ck_epoch_synchronize.c @@ -138,7 +138,7 @@ read_thread(void *unused CK_CC_UNUSED) ck_pr_inc_uint(&e_barrier); while (ck_pr_load_uint(&e_barrier) < n_threads); - fprintf(stderr, "[R] Observed entries: %u\n", j); + ck_error("[R] Observed entries: %u\n", j); return (NULL); } @@ -163,16 +163,14 @@ write_thread(void *unused CK_CC_UNUSED) entry = malloc(sizeof(struct node *) * PAIRS_S); if (entry == NULL) { - fprintf(stderr, "Failed allocation.\n"); - exit(EXIT_FAILURE); + ck_error("Failed allocation.\n"); } for (j = 0; j < ITERATE_S; j++) { for (i = 0; i < PAIRS_S; i++) { entry[i] = malloc(sizeof(struct node)); if (entry == NULL) { - fprintf(stderr, "Failed individual allocation\n"); - exit(EXIT_FAILURE); + ck_error("Failed individual allocation\n"); } } @@ -184,7 +182,7 @@ write_thread(void *unused CK_CC_UNUSED) ck_pr_stall(); if (tid == 0) { - fprintf(stderr, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b[W] %2.2f: %c", + ck_error("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b[W] %2.2f: %c", (double)j / ITERATE_S, animate[i % strlen(animate)]); } @@ -200,7 +198,7 @@ write_thread(void *unused CK_CC_UNUSED) ck_epoch_call(&stack_epoch, &record, &e->epoch_entry, destructor); } else { if (tid == 0 && i % 8192) - fprintf(stderr, "\b%c", animate[i % strlen(animate)]); + ck_error("\b%c", animate[i % strlen(animate)]); destructor(&e->epoch_entry); } @@ -210,7 +208,7 @@ write_thread(void *unused CK_CC_UNUSED) ck_epoch_synchronize(&stack_epoch, &record); if (tid == 0) { - fprintf(stderr, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b[W] Peak: %u (%2.2f%%)\n Reclamations: %lu\n\n", + ck_error("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b[W] Peak: %u (%2.2f%%)\n Reclamations: %lu\n\n", record.n_peak, (double)record.n_peak / ((double)PAIRS_S * ITERATE_S) * 100, record.n_dispatch); @@ -228,8 +226,7 @@ main(int argc, char *argv[]) pthread_t *threads; if (argc != 4) { - fprintf(stderr, "Usage: stack <#readers> <#writers> \n"); - exit(EXIT_FAILURE); + ck_error("Usage: stack <#readers> <#writers> \n"); } n_rd = atoi(argv[1]); diff --git a/regressions/ck_epoch/validate/ck_stack.c b/regressions/ck_epoch/validate/ck_stack.c index 5a8c740..15c1c83 100644 --- a/regressions/ck_epoch/validate/ck_stack.c +++ b/regressions/ck_epoch/validate/ck_stack.c @@ -90,15 +90,13 @@ thread(void *unused CK_CC_UNUSED) entry = malloc(sizeof(struct node *) * PAIRS); if (entry == NULL) { - fprintf(stderr, "Failed allocation.\n"); - exit(EXIT_FAILURE); + ck_error("Failed allocation.\n"); } for (i = 0; i < PAIRS; i++) { entry[i] = malloc(sizeof(struct node)); if (entry == NULL) { - fprintf(stderr, "Failed individual allocation\n"); - exit(EXIT_FAILURE); + ck_error("Failed individual allocation\n"); } } @@ -119,8 +117,8 @@ thread(void *unused CK_CC_UNUSED) ck_pr_inc_uint(&e_barrier); while (ck_pr_load_uint(&e_barrier) < n_threads); - fprintf(stderr, "Deferrals: %lu (%2.2f)\n", smr, (double)smr / PAIRS); - fprintf(stderr, "Peak: %u (%2.2f%%), %u pending\nReclamations: %lu\n\n", + ck_error("Deferrals: %lu (%2.2f)\n", smr, (double)smr / PAIRS); + ck_error("Peak: %u (%2.2f%%), %u pending\nReclamations: %lu\n\n", record.n_peak, (double)record.n_peak / PAIRS * 100, record.n_pending, @@ -131,9 +129,8 @@ thread(void *unused CK_CC_UNUSED) while (ck_pr_load_uint(&e_barrier) < (n_threads << 1)); if (record.n_pending != 0) { - fprintf(stderr, "ERROR: %u pending, expecting none.\n", + ck_error("ERROR: %u pending, expecting none.\n", record.n_pending); - exit(EXIT_FAILURE); } return (NULL); @@ -146,8 +143,7 @@ main(int argc, char *argv[]) pthread_t *threads; if (argc != 3) { - fprintf(stderr, "Usage: stack \n"); - exit(EXIT_FAILURE); + ck_error("Usage: stack \n"); } n_threads = atoi(argv[1]); diff --git a/regressions/ck_fifo/validate/ck_fifo_mpmc.c b/regressions/ck_fifo/validate/ck_fifo_mpmc.c index 8a210d4..01f4b4a 100644 --- a/regressions/ck_fifo/validate/ck_fifo_mpmc.c +++ b/regressions/ck_fifo/validate/ck_fifo_mpmc.c @@ -82,13 +82,11 @@ test(void *c) entry->tid = context->tid; ck_fifo_mpmc_enqueue(&fifo, fifo_entry, entry); if (ck_fifo_mpmc_dequeue(&fifo, &entry, &garbage) == false) { - fprintf(stderr, "ERROR [%u] Queue should never be empty.\n", context->tid); - exit(EXIT_FAILURE); + ck_error("ERROR [%u] Queue should never be empty.\n", context->tid); } if (entry->tid < 0 || entry->tid >= nthr) { - fprintf(stderr, "ERROR [%u] Incorrect value in entry.\n", entry->tid); - exit(EXIT_FAILURE); + ck_error("ERROR [%u] Incorrect value in entry.\n", entry->tid); } } } @@ -105,8 +103,7 @@ test(void *c) ck_pr_stall(); if (entry->tid < 0 || entry->tid >= nthr) { - fprintf(stderr, "ERROR [%u] Incorrect value in entry when using try interface.\n", entry->tid); - exit(EXIT_FAILURE); + ck_error("ERROR [%u] Incorrect value in entry when using try interface.\n", entry->tid); } } } @@ -123,8 +120,7 @@ main(int argc, char *argv[]) pthread_t *thread; if (argc != 4) { - fprintf(stderr, "Usage: validate \n"); - exit(EXIT_FAILURE); + ck_error("Usage: validate \n"); } a.request = 0; @@ -158,7 +154,7 @@ main(int argc, char *argv[]) int main(void) { - fprintf(stderr, "Unsupported.\n"); + ck_error("Unsupported.\n"); return 0; } #endif diff --git a/regressions/ck_fifo/validate/ck_fifo_spsc.c b/regressions/ck_fifo/validate/ck_fifo_spsc.c index 017f493..e7d1cac 100644 --- a/regressions/ck_fifo/validate/ck_fifo_spsc.c +++ b/regressions/ck_fifo/validate/ck_fifo_spsc.c @@ -68,7 +68,7 @@ test(void *c) } #ifdef DEBUG - fprintf(stderr, "%p %u: %u -> %u\n", fifo+context->tid, context->tid, context->previous, context->tid); + ck_error("%p %u: %u -> %u\n", fifo+context->tid, context->tid, context->previous, context->tid); #endif if (context->tid == 0) { @@ -93,15 +93,13 @@ test(void *c) for (j = 0; j < size; j++) { while (ck_fifo_spsc_dequeue(fifo + context->previous, &entry) == false); if (context->previous != (unsigned int)entry->tid) { - fprintf(stderr, "T [%u:%p] %u != %u\n", + ck_error("T [%u:%p] %u != %u\n", context->tid, (void *)entry, entry->tid, context->previous); - exit(EXIT_FAILURE); } if (entry->value != j) { - fprintf(stderr, "V [%u:%p] %u != %u\n", + ck_error("V [%u:%p] %u != %u\n", context->tid, (void *)entry, entry->value, j); - exit(EXIT_FAILURE); } entry->tid = context->tid; @@ -124,8 +122,7 @@ main(int argc, char *argv[]) pthread_t *thread; if (argc != 4) { - fprintf(stderr, "Usage: validate \n"); - exit(EXIT_FAILURE); + ck_error("Usage: validate \n"); } a.request = 0; diff --git a/regressions/ck_hp/benchmark/fifo_latency.c b/regressions/ck_hp/benchmark/fifo_latency.c index fec18c6..970b785 100644 --- a/regressions/ck_hp/benchmark/fifo_latency.c +++ b/regressions/ck_hp/benchmark/fifo_latency.c @@ -59,8 +59,7 @@ main(void) r = malloc(CK_HP_FIFO_SLOTS_SIZE); if (r == NULL) { - fprintf(stderr, "ERROR: Failed to allocate slots.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to allocate slots.\n"); } ck_hp_register(&fifo_hp, &record, r); diff --git a/regressions/ck_hp/benchmark/stack_latency.c b/regressions/ck_hp/benchmark/stack_latency.c index 8b65064..5779609 100644 --- a/regressions/ck_hp/benchmark/stack_latency.c +++ b/regressions/ck_hp/benchmark/stack_latency.c @@ -58,8 +58,7 @@ main(void) ck_hp_init(&stack_hp, CK_HP_STACK_SLOTS_COUNT, 1000000, NULL); r = malloc(CK_HP_STACK_SLOTS_SIZE); if (r == NULL) { - fprintf(stderr, "ERROR: Failed to allocate slots.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to allocate slots.\n"); } ck_hp_register(&stack_hp, &record, (void *)r); diff --git a/regressions/ck_hp/validate/ck_hp_fifo.c b/regressions/ck_hp/validate/ck_hp_fifo.c index 9882798..47e2f97 100644 --- a/regressions/ck_hp/validate/ck_hp_fifo.c +++ b/regressions/ck_hp/validate/ck_hp_fifo.c @@ -85,15 +85,13 @@ test(void *c) fifo_entry = ck_hp_fifo_dequeue_mpmc(&record, &fifo, &entry); if (fifo_entry == NULL) { - fprintf(stderr, "ERROR [%u] Queue should never be empty.\n", context->tid); - exit(EXIT_FAILURE); + ck_error("ERROR [%u] Queue should never be empty.\n", context->tid); } ck_pr_barrier(); if (entry->tid < 0 || entry->tid >= nthr) { - fprintf(stderr, "ERROR [%u] Incorrect value in entry.\n", entry->tid); - exit(EXIT_FAILURE); + ck_error("ERROR [%u] Incorrect value in entry.\n", entry->tid); } ck_hp_free(&record, &fifo_entry->hazard, fifo_entry, fifo_entry); @@ -113,8 +111,7 @@ test(void *c) ck_pr_stall(); if (entry->tid < 0 || entry->tid >= nthr) { - fprintf(stderr, "ERROR [%u] Incorrect value in entry.\n", entry->tid); - exit(EXIT_FAILURE); + ck_error("ERROR [%u] Incorrect value in entry.\n", entry->tid); } ck_hp_free(&record, &fifo_entry->hazard, fifo_entry, fifo_entry); @@ -144,8 +141,7 @@ main(int argc, char *argv[]) int threshold; if (argc != 5) { - fprintf(stderr, "Usage: validate \n"); - exit(EXIT_FAILURE); + ck_error("Usage: validate \n"); } a.delta = atoi(argv[2]); diff --git a/regressions/ck_hp/validate/ck_hp_fifo_donner.c b/regressions/ck_hp/validate/ck_hp_fifo_donner.c index 693328f..0866729 100644 --- a/regressions/ck_hp/validate/ck_hp_fifo_donner.c +++ b/regressions/ck_hp/validate/ck_hp_fifo_donner.c @@ -34,6 +34,7 @@ #include #include #include +#include "../../common.h" /* FIFO queue */ static ck_hp_fifo_t fifo; @@ -149,8 +150,7 @@ main(int argc, char** argv) pthread_t *thr; if (argc != 3) { - fprintf(stderr, "Usage: cktest \n"); - exit(EXIT_FAILURE); + ck_error("Usage: cktest \n"); } /* Get element count from argument */ diff --git a/regressions/ck_hp/validate/ck_hp_stack.c b/regressions/ck_hp/validate/ck_hp_stack.c index 4cc74df..667a440 100644 --- a/regressions/ck_hp/validate/ck_hp_stack.c +++ b/regressions/ck_hp/validate/ck_hp_stack.c @@ -84,15 +84,13 @@ thread(void *unused CK_CC_UNUSED) entry = malloc(sizeof(struct node *) * PAIRS); if (entry == NULL) { - fprintf(stderr, "Failed allocation.\n"); - exit(EXIT_FAILURE); + ck_error("Failed allocation.\n"); } for (i = 0; i < PAIRS; i++) { entry[i] = malloc(sizeof(struct node)); if (entry == NULL) { - fprintf(stderr, "Failed individual allocation\n"); - exit(EXIT_FAILURE); + ck_error("Failed individual allocation\n"); } } @@ -109,7 +107,7 @@ thread(void *unused CK_CC_UNUSED) ck_pr_inc_uint(&e_barrier); while (ck_pr_load_uint(&e_barrier) < n_threads); - fprintf(stderr, "Peak: %u (%2.2f%%)\nReclamations: %" PRIu64 "\n\n", + ck_error("Peak: %u (%2.2f%%)\nReclamations: %" PRIu64 "\n\n", record.n_peak, (double)record.n_peak / PAIRS * 100, record.n_reclamations); @@ -121,9 +119,8 @@ thread(void *unused CK_CC_UNUSED) while (ck_pr_load_uint(&e_barrier) < (n_threads << 1)); if (record.n_pending != 0) { - fprintf(stderr, "ERROR: %u pending, expecting none.\n", + ck_error("ERROR: %u pending, expecting none.\n", record.n_pending); - exit(EXIT_FAILURE); } return (NULL); @@ -144,8 +141,7 @@ main(int argc, char *argv[]) pthread_t *threads; if (argc != 4) { - fprintf(stderr, "Usage: stack \n"); - exit(EXIT_FAILURE); + ck_error("Usage: stack \n"); } n_threads = atoi(argv[1]); diff --git a/regressions/ck_hp/validate/nbds_haz_test.c b/regressions/ck_hp/validate/nbds_haz_test.c index 2f8d3d4..1ce9479 100644 --- a/regressions/ck_hp/validate/nbds_haz_test.c +++ b/regressions/ck_hp/validate/nbds_haz_test.c @@ -201,8 +201,7 @@ main(int argc, char *argv[]) pthread_t *threads; if (argc != 4) { - fprintf(stderr, "Usage: stack \n"); - exit(EXIT_FAILURE); + ck_error("Usage: stack \n"); } n_threads = atoi(argv[1]); @@ -220,6 +219,6 @@ main(int argc, char *argv[]) for (i = 0; i < n_threads; i++) pthread_join(threads[i], NULL); - fprintf(stderr, "Push: %u\nPop: %u\n", pushs, pops); + ck_error("Push: %u\nPop: %u\n", pushs, pops); return (0); } diff --git a/regressions/ck_hp/validate/serial.c b/regressions/ck_hp/validate/serial.c index ab4614e..7d6456c 100644 --- a/regressions/ck_hp/validate/serial.c +++ b/regressions/ck_hp/validate/serial.c @@ -38,6 +38,8 @@ #include #include +#include "../../common.h" + struct entry { unsigned int value; ck_hp_hazard_t hazard; @@ -47,7 +49,7 @@ static void destructor(void *pointer) { - fprintf(stderr, "Free %p\n", pointer); + ck_error("Free %p\n", pointer); free(pointer); return; } @@ -67,8 +69,7 @@ main(int argc, char *argv[]) pointers = malloc(sizeof(void *)); if (pointers == NULL) { - fprintf(stderr, "ERROR: Failed to allocate slot.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to allocate slot.\n"); } ck_hp_register(&state, &record[0], pointers); ck_hp_reclaim(&record[0]); @@ -91,8 +92,7 @@ main(int argc, char *argv[]) pointers = malloc(sizeof(void *)); if (pointers == NULL) { - fprintf(stderr, "ERROR: Failed to allocate slot.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to allocate slot.\n"); } ck_hp_register(&state, &record[1], pointers); ck_hp_reclaim(&record[1]); diff --git a/regressions/ck_hs/benchmark/parallel_bytestring.c b/regressions/ck_hs/benchmark/parallel_bytestring.c index f48c0a7..f2e6acd 100644 --- a/regressions/ck_hs/benchmark/parallel_bytestring.c +++ b/regressions/ck_hs/benchmark/parallel_bytestring.c @@ -227,8 +227,7 @@ reader(void *unused) r = set_get(keys[i]); if (r == NULL) { if (n_state == HS_STATE_STRICT_REPLACEMENT) { - fprintf(stderr, "ERROR: Did not find during replacement: %s\n", keys[i]); - exit(EXIT_FAILURE); + ck_error("ERROR: Did not find during replacement: %s\n", keys[i]); } continue; @@ -237,8 +236,7 @@ reader(void *unused) if (strcmp(r, keys[i]) == 0) continue; - fprintf(stderr, "ERROR: Found invalid value: [%s] but expected [%s]\n", (char *)r, keys[i]); - exit(EXIT_FAILURE); + ck_error("ERROR: Found invalid value: [%s] but expected [%s]\n", (char *)r, keys[i]); } a += rdtsc() - s; ck_epoch_end(&epoch_hs, &epoch_record); @@ -277,9 +275,8 @@ main(int argc, char *argv[]) n_threads = CORES - 1; if (argc < 2) { - fprintf(stderr, "Usage: parallel [ \n" + ck_error("Usage: parallel [ \n" " ]\n"); - exit(EXIT_FAILURE); } if (argc >= 3) @@ -291,24 +288,21 @@ main(int argc, char *argv[]) if (argc >= 5) { n_threads = atoi(argv[4]); if (n_threads < 1) { - fprintf(stderr, "ERROR: Number of readers must be >= 1.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of readers must be >= 1.\n"); } } if (argc >= 6) { p_r = atof(argv[5]) / 100.00; if (p_r < 0) { - fprintf(stderr, "ERROR: Probability of replacement must be >= 0 and <= 100.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Probability of replacement must be >= 0 and <= 100.\n"); } } if (argc >= 7) { p_d = atof(argv[6]) / 100.00; if (p_d < 0) { - fprintf(stderr, "ERROR: Probability of deletion must be >= 0 and <= 100.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Probability of deletion must be >= 0 and <= 100.\n"); } } @@ -342,25 +336,23 @@ main(int argc, char *argv[]) for (i = 0; i < (size_t)n_threads; i++) { if (pthread_create(&readers[i], NULL, reader, NULL) != 0) { - fprintf(stderr, "ERROR: Failed to create thread %zu.\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to create thread %zu.\n", i); } } for (i = 0; i < keys_length; i++) d += set_insert(keys[i]) == false; - fprintf(stderr, " [S] %d readers, 1 writer.\n", n_threads); - fprintf(stderr, " [S] %zu entries stored and %u duplicates.\n\n", + ck_error(" [S] %d readers, 1 writer.\n", n_threads); + ck_error(" [S] %zu entries stored and %u duplicates.\n\n", set_count(), d); - fprintf(stderr, " ,- BASIC TEST\n"); - fprintf(stderr, " | Executing SMR test..."); + ck_error(" ,- BASIC TEST\n"); + ck_error(" | Executing SMR test..."); a = 0; for (j = 0; j < r; j++) { if (set_reset() == false) { - fprintf(stderr, "ERROR: Failed to reset hash table.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to reset hash table.\n"); } s = rdtsc(); @@ -369,9 +361,9 @@ main(int argc, char *argv[]) e = rdtsc(); a += e - s; } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); - fprintf(stderr, " | Executing replacement test..."); + ck_error(" | Executing replacement test..."); a = 0; for (j = 0; j < r; j++) { s = rdtsc(); @@ -380,25 +372,24 @@ main(int argc, char *argv[]) e = rdtsc(); a += e - s; } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); - fprintf(stderr, " | Executing get test..."); + ck_error(" | Executing get test..."); a = 0; for (j = 0; j < r; j++) { s = rdtsc(); for (i = 0; i < keys_length; i++) { if (set_get(keys[i]) == NULL) { - fprintf(stderr, "ERROR: Unexpected NULL value.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Unexpected NULL value.\n"); } } e = rdtsc(); a += e - s; } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); a = 0; - fprintf(stderr, " | Executing removal test..."); + ck_error(" | Executing removal test..."); for (j = 0; j < r; j++) { s = rdtsc(); for (i = 0; i < keys_length; i++) @@ -409,9 +400,9 @@ main(int argc, char *argv[]) for (i = 0; i < keys_length; i++) set_insert(keys[i]); } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); - fprintf(stderr, " | Executing negative look-up test..."); + ck_error(" | Executing negative look-up test..."); a = 0; for (j = 0; j < r; j++) { s = rdtsc(); @@ -421,18 +412,18 @@ main(int argc, char *argv[]) e = rdtsc(); a += e - s; } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); ck_epoch_record_t epoch_temporary = epoch_wr; ck_epoch_synchronize(&epoch_hs, &epoch_wr); - fprintf(stderr, " '- Summary: %u pending, %u peak, %lu reclamations -> " + ck_error(" '- Summary: %u pending, %u peak, %lu reclamations -> " "%u pending, %u peak, %lu reclamations\n\n", epoch_temporary.n_pending, epoch_temporary.n_peak, epoch_temporary.n_dispatch, epoch_wr.n_pending, epoch_wr.n_peak, epoch_wr.n_dispatch); - fprintf(stderr, " ,- READER CONCURRENCY\n"); - fprintf(stderr, " | Executing reader test..."); + ck_error(" ,- READER CONCURRENCY\n"); + ck_error(" | Executing reader test..."); ck_pr_store_int(&state, HS_STATE_GET); while (ck_pr_load_int(&barrier[HS_STATE_STOP]) != n_threads) @@ -442,10 +433,10 @@ main(int argc, char *argv[]) ck_pr_store_int(&state, HS_STATE_STRICT_REPLACEMENT); while (ck_pr_load_int(&barrier[HS_STATE_GET]) != n_threads) ck_pr_stall(); - fprintf(stderr, "done (reader = %" PRIu64 " ticks)\n", + ck_error("done (reader = %" PRIu64 " ticks)\n", accumulator[HS_STATE_GET] / n_threads); - fprintf(stderr, " | Executing strict replacement test..."); + ck_error(" | Executing strict replacement test..."); a = repeated = 0; signal(SIGALRM, alarm_handler); @@ -471,13 +462,13 @@ main(int argc, char *argv[]) ck_pr_stall(); set_reset(); ck_epoch_synchronize(&epoch_hs, &epoch_wr); - fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", + ck_error("done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), accumulator[HS_STATE_STRICT_REPLACEMENT] / n_threads); signal(SIGALRM, alarm_handler); alarm(r); - fprintf(stderr, " | Executing deletion test (%.2f)...", p_d * 100); + ck_error(" | Executing deletion test (%.2f)...", p_d * 100); a = repeated = 0; ck_pr_inc_int(&barrier[HS_STATE_STRICT_REPLACEMENT]); for (;;) { @@ -507,13 +498,13 @@ main(int argc, char *argv[]) set_reset(); ck_epoch_synchronize(&epoch_hs, &epoch_wr); - fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", + ck_error("done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), accumulator[HS_STATE_DELETION] / n_threads); signal(SIGALRM, alarm_handler); alarm(r); - fprintf(stderr, " | Executing replacement test (%.2f)...", p_r * 100); + ck_error(" | Executing replacement test (%.2f)...", p_r * 100); a = repeated = 0; ck_pr_inc_int(&barrier[HS_STATE_DELETION]); for (;;) { @@ -547,14 +538,14 @@ main(int argc, char *argv[]) ck_pr_stall(); set_reset(); ck_epoch_synchronize(&epoch_hs, &epoch_wr); - fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", + ck_error("done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), accumulator[HS_STATE_REPLACEMENT] / n_threads); ck_pr_inc_int(&barrier[HS_STATE_REPLACEMENT]); epoch_temporary = epoch_wr; ck_epoch_synchronize(&epoch_hs, &epoch_wr); - fprintf(stderr, " '- Summary: %u pending, %u peak, %lu reclamations -> " + ck_error(" '- Summary: %u pending, %u peak, %lu reclamations -> " "%u pending, %u peak, %lu reclamations\n\n", epoch_temporary.n_pending, epoch_temporary.n_peak, epoch_temporary.n_dispatch, epoch_wr.n_pending, epoch_wr.n_peak, epoch_wr.n_dispatch); diff --git a/regressions/ck_hs/benchmark/serial.c b/regressions/ck_hs/benchmark/serial.c index 712df01..97f621b 100644 --- a/regressions/ck_hs/benchmark/serial.c +++ b/regressions/ck_hs/benchmark/serial.c @@ -187,8 +187,7 @@ main(int argc, char *argv[]) srand(time(NULL)); if (argc < 2) { - fprintf(stderr, "Usage: ck_hs [ ]\n"); - exit(EXIT_FAILURE); + ck_error("Usage: ck_hs [ ]\n"); } if (argc >= 3) @@ -224,16 +223,15 @@ main(int argc, char *argv[]) d += set_insert(keys[i]) == false; ck_hs_stat(&hs, &st); - fprintf(stderr, "# %zu entries stored, %u duplicates, %u probe.\n", + ck_error("# %zu entries stored, %u duplicates, %u probe.\n", set_count(), d, st.probe_maximum); - fprintf(stderr, "# reverse_insertion serial_insertion random_insertion serial_replace reverse_get serial_get random_get serial_remove negative_get\n\n"); + ck_error("# reverse_insertion serial_insertion random_insertion serial_replace reverse_get serial_get random_get serial_remove negative_get\n\n"); a = 0; for (j = 0; j < r; j++) { if (set_reset() == false) { - fprintf(stderr, "ERROR: Failed to reset hash table.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to reset hash table.\n"); } s = rdtsc(); @@ -247,8 +245,7 @@ main(int argc, char *argv[]) a = 0; for (j = 0; j < r; j++) { if (set_reset() == false) { - fprintf(stderr, "ERROR: Failed to reset hash table.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to reset hash table.\n"); } s = rdtsc(); @@ -264,8 +261,7 @@ main(int argc, char *argv[]) keys_shuffle(keys); if (set_reset() == false) { - fprintf(stderr, "ERROR: Failed to reset hash table.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to reset hash table.\n"); } s = rdtsc(); @@ -295,8 +291,7 @@ main(int argc, char *argv[]) s = rdtsc(); for (i = keys_length; i > 0; i--) { if (set_get(keys[i - 1]) == NULL) { - fprintf(stderr, "ERROR: Unexpected NULL value.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Unexpected NULL value.\n"); } } e = rdtsc(); @@ -309,8 +304,7 @@ main(int argc, char *argv[]) s = rdtsc(); for (i = 0; i < keys_length; i++) { if (set_get(keys[i]) == NULL) { - fprintf(stderr, "ERROR: Unexpected NULL value.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Unexpected NULL value.\n"); } } e = rdtsc(); @@ -325,8 +319,7 @@ main(int argc, char *argv[]) s = rdtsc(); for (i = 0; i < keys_length; i++) { if (set_get(keys[i]) == NULL) { - fprintf(stderr, "ERROR: Unexpected NULL value.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Unexpected NULL value.\n"); } } e = rdtsc(); diff --git a/regressions/ck_hs/validate/serial.c b/regressions/ck_hs/validate/serial.c index 13fc053..26f237b 100644 --- a/regressions/ck_hs/validate/serial.c +++ b/regressions/ck_hs/validate/serial.c @@ -33,6 +33,8 @@ #include #include +#include "../../common.h" + static void * hs_malloc(size_t r) { @@ -100,8 +102,7 @@ main(void) h = test[i][0]; ck_hs_put(&hs, h, test[i]); if (ck_hs_put(&hs, h, test[i]) == true) { - fprintf(stderr, "ERROR [1]: put must fail on collision.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR [1]: put must fail on collision.\n"); } } @@ -110,25 +111,21 @@ main(void) for (i = 0; i < sizeof(test) / sizeof(*test); i++) { h = test[i][0]; if (ck_hs_put(&hs, h, test[i]) == true) { - fprintf(stderr, "ERROR [2]: put must fail on collision.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR [2]: put must fail on collision.\n"); } if (ck_hs_get(&hs, h, test[i]) == NULL) { - fprintf(stderr, "ERROR: get must not fail\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: get must not fail\n"); } } h = ULONG_MAX; if (ck_hs_put(&hs, h, blob) == false) { - fprintf(stderr, "ERROR: Duplicate put failed.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Duplicate put failed.\n"); } if (ck_hs_put(&hs, h, blob) == true) { - fprintf(stderr, "ERROR: Duplicate put succeeded.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Duplicate put succeeded.\n"); } /* Grow set and check get semantics. */ @@ -136,8 +133,7 @@ main(void) for (i = 0; i < sizeof(test) / sizeof(*test); i++) { h = test[i][0]; if (ck_hs_get(&hs, h, test[i]) == NULL) { - fprintf(stderr, "ERROR: get must not fail\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: get must not fail\n"); } } @@ -150,13 +146,11 @@ main(void) continue; if (r = ck_hs_remove(&hs, h, test[i]), r == NULL) { - fprintf(stderr, "ERROR: remove must not fail\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: remove must not fail\n"); } if (strcmp(r, test[i]) != 0) { - fprintf(stderr, "ERROR: Removed incorrect node (%s != %s)\n", (char *)r, test[i]); - exit(EXIT_FAILURE); + ck_error("ERROR: Removed incorrect node (%s != %s)\n", (char *)r, test[i]); } } @@ -168,24 +162,21 @@ main(void) h = test[i][0]; d = ck_hs_get(&hs, h, test[i]) != NULL; if (ck_hs_set(&hs, h, test[i], &r) == false) { - fprintf(stderr, "ERROR: Failed to set\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to set\n"); } /* Expected replacement. */ if (d == true && (r == NULL || strcmp(r, test[i]) != 0)) { - fprintf(stderr, "ERROR: Incorrect previous value: %s != %s\n", + ck_error("ERROR: Incorrect previous value: %s != %s\n", test[i], (char *)r); } if (ck_hs_set(&hs, h, test[i], &r) == false) { - fprintf(stderr, "ERROR: Failed to set [1]\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to set [1]\n"); } if (strcmp(r, test[i]) != 0) { - fprintf(stderr, "ERROR: Invalid pointer: %s != %s\n", (char *)r, test[i]); - exit(EXIT_FAILURE); + ck_error("ERROR: Invalid pointer: %s != %s\n", (char *)r, test[i]); } } diff --git a/regressions/ck_ht/benchmark/parallel_bytestring.c b/regressions/ck_ht/benchmark/parallel_bytestring.c index dbbabf4..735a5e3 100644 --- a/regressions/ck_ht/benchmark/parallel_bytestring.c +++ b/regressions/ck_ht/benchmark/parallel_bytestring.c @@ -231,8 +231,7 @@ reader(void *unused) if (strcmp(r, keys[i]) == 0) continue; - fprintf(stderr, "ERROR: Found invalid value: [%s] but expected [%s]\n", r, keys[i]); - exit(EXIT_FAILURE); + ck_error("ERROR: Found invalid value: [%s] but expected [%s]\n", r, keys[i]); } a += rdtsc() - s; ck_epoch_end(&epoch_ht, &epoch_record); @@ -271,9 +270,8 @@ main(int argc, char *argv[]) n_threads = CORES - 1; if (argc < 2) { - fprintf(stderr, "Usage: parallel [ \n" + ck_error("Usage: parallel [ \n" " ]\n"); - exit(EXIT_FAILURE); } if (argc >= 3) @@ -285,24 +283,21 @@ main(int argc, char *argv[]) if (argc >= 5) { n_threads = atoi(argv[4]); if (n_threads < 1) { - fprintf(stderr, "ERROR: Number of readers must be >= 1.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of readers must be >= 1.\n"); } } if (argc >= 6) { p_r = atof(argv[5]) / 100.00; if (p_r < 0) { - fprintf(stderr, "ERROR: Probability of replacement must be >= 0 and <= 100.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Probability of replacement must be >= 0 and <= 100.\n"); } } if (argc >= 7) { p_d = atof(argv[6]) / 100.00; if (p_d < 0) { - fprintf(stderr, "ERROR: Probability of deletion must be >= 0 and <= 100.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Probability of deletion must be >= 0 and <= 100.\n"); } } @@ -336,25 +331,23 @@ main(int argc, char *argv[]) for (i = 0; i < (size_t)n_threads; i++) { if (pthread_create(&readers[i], NULL, reader, NULL) != 0) { - fprintf(stderr, "ERROR: Failed to create thread %zu.\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to create thread %zu.\n", i); } } for (i = 0; i < keys_length; i++) d += table_insert(keys[i]) == false; - fprintf(stderr, " [S] %d readers, 1 writer.\n", n_threads); - fprintf(stderr, " [S] %zu entries stored and %u duplicates.\n\n", + ck_error(" [S] %d readers, 1 writer.\n", n_threads); + ck_error(" [S] %zu entries stored and %u duplicates.\n\n", table_count(), d); - fprintf(stderr, " ,- BASIC TEST\n"); - fprintf(stderr, " | Executing SMR test..."); + ck_error(" ,- BASIC TEST\n"); + ck_error(" | Executing SMR test..."); a = 0; for (j = 0; j < r; j++) { if (table_reset() == false) { - fprintf(stderr, "ERROR: Failed to reset hash table.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to reset hash table.\n"); } s = rdtsc(); @@ -363,9 +356,9 @@ main(int argc, char *argv[]) e = rdtsc(); a += e - s; } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); - fprintf(stderr, " | Executing replacement test..."); + ck_error(" | Executing replacement test..."); a = 0; for (j = 0; j < r; j++) { s = rdtsc(); @@ -374,25 +367,24 @@ main(int argc, char *argv[]) e = rdtsc(); a += e - s; } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); - fprintf(stderr, " | Executing get test..."); + ck_error(" | Executing get test..."); a = 0; for (j = 0; j < r; j++) { s = rdtsc(); for (i = 0; i < keys_length; i++) { if (table_get(keys[i]) == NULL) { - fprintf(stderr, "ERROR: Unexpected NULL value.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Unexpected NULL value.\n"); } } e = rdtsc(); a += e - s; } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); a = 0; - fprintf(stderr, " | Executing removal test..."); + ck_error(" | Executing removal test..."); for (j = 0; j < r; j++) { s = rdtsc(); for (i = 0; i < keys_length; i++) @@ -403,9 +395,9 @@ main(int argc, char *argv[]) for (i = 0; i < keys_length; i++) table_insert(keys[i]); } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); - fprintf(stderr, " | Executing negative look-up test..."); + ck_error(" | Executing negative look-up test..."); a = 0; for (j = 0; j < r; j++) { s = rdtsc(); @@ -415,18 +407,18 @@ main(int argc, char *argv[]) e = rdtsc(); a += e - s; } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); ck_epoch_record_t epoch_temporary = epoch_wr; ck_epoch_synchronize(&epoch_ht, &epoch_wr); - fprintf(stderr, " '- Summary: %u pending, %u peak, %lu reclamations -> " + ck_error(" '- Summary: %u pending, %u peak, %lu reclamations -> " "%u pending, %u peak, %lu reclamations\n\n", epoch_temporary.n_pending, epoch_temporary.n_peak, epoch_temporary.n_dispatch, epoch_wr.n_pending, epoch_wr.n_peak, epoch_wr.n_dispatch); - fprintf(stderr, " ,- READER CONCURRENCY\n"); - fprintf(stderr, " | Executing reader test..."); + ck_error(" ,- READER CONCURRENCY\n"); + ck_error(" | Executing reader test..."); ck_pr_store_int(&state, HT_STATE_GET); while (ck_pr_load_int(&barrier[HT_STATE_STOP]) != n_threads) @@ -436,10 +428,10 @@ main(int argc, char *argv[]) ck_pr_store_int(&state, HT_STATE_STRICT_REPLACEMENT); while (ck_pr_load_int(&barrier[HT_STATE_GET]) != n_threads) ck_pr_stall(); - fprintf(stderr, "done (reader = %" PRIu64 " ticks)\n", + ck_error("done (reader = %" PRIu64 " ticks)\n", accumulator[HT_STATE_GET] / n_threads); - fprintf(stderr, " | Executing strict replacement test..."); + ck_error(" | Executing strict replacement test..."); a = repeated = 0; signal(SIGALRM, alarm_handler); @@ -465,13 +457,13 @@ main(int argc, char *argv[]) ck_pr_stall(); table_reset(); ck_epoch_synchronize(&epoch_ht, &epoch_wr); - fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", + ck_error("done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), accumulator[HT_STATE_STRICT_REPLACEMENT] / n_threads); signal(SIGALRM, alarm_handler); alarm(r); - fprintf(stderr, " | Executing deletion test (%.2f)...", p_d * 100); + ck_error(" | Executing deletion test (%.2f)...", p_d * 100); a = repeated = 0; ck_pr_inc_int(&barrier[HT_STATE_STRICT_REPLACEMENT]); for (;;) { @@ -501,13 +493,13 @@ main(int argc, char *argv[]) table_reset(); ck_epoch_synchronize(&epoch_ht, &epoch_wr); - fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", + ck_error("done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), accumulator[HT_STATE_DELETION] / n_threads); signal(SIGALRM, alarm_handler); alarm(r); - fprintf(stderr, " | Executing replacement test (%.2f)...", p_r * 100); + ck_error(" | Executing replacement test (%.2f)...", p_r * 100); a = repeated = 0; ck_pr_inc_int(&barrier[HT_STATE_DELETION]); for (;;) { @@ -541,14 +533,14 @@ main(int argc, char *argv[]) ck_pr_stall(); table_reset(); ck_epoch_synchronize(&epoch_ht, &epoch_wr); - fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", + ck_error("done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), accumulator[HT_STATE_REPLACEMENT] / n_threads); ck_pr_inc_int(&barrier[HT_STATE_REPLACEMENT]); epoch_temporary = epoch_wr; ck_epoch_synchronize(&epoch_ht, &epoch_wr); - fprintf(stderr, " '- Summary: %u pending, %u peak, %lu reclamations -> " + ck_error(" '- Summary: %u pending, %u peak, %lu reclamations -> " "%u pending, %u peak, %lu reclamations\n\n", epoch_temporary.n_pending, epoch_temporary.n_peak, epoch_temporary.n_dispatch, epoch_wr.n_pending, epoch_wr.n_peak, epoch_wr.n_dispatch); diff --git a/regressions/ck_ht/benchmark/parallel_direct.c b/regressions/ck_ht/benchmark/parallel_direct.c index cd19187..cede2c0 100644 --- a/regressions/ck_ht/benchmark/parallel_direct.c +++ b/regressions/ck_ht/benchmark/parallel_direct.c @@ -237,9 +237,8 @@ ht_reader(void *unused) if (r == keys[i]) continue; - fprintf(stderr, "ERROR: Found invalid value: [%ju]\n", + ck_error("ERROR: Found invalid value: [%ju]\n", (uintmax_t)r); - exit(EXIT_FAILURE); } a += rdtsc() - s; ck_epoch_end(&epoch_ht, &epoch_record); @@ -275,9 +274,8 @@ main(int argc, char *argv[]) n_threads = CORES - 1; if (argc < 2) { - fprintf(stderr, "Usage: parallel <#entries> [ \n" + ck_error("Usage: parallel <#entries> [ \n" " ]\n"); - exit(EXIT_FAILURE); } if (argc >= 3) @@ -289,24 +287,21 @@ main(int argc, char *argv[]) if (argc >= 5) { n_threads = atoi(argv[4]); if (n_threads < 1) { - fprintf(stderr, "ERROR: Number of readers must be >= 1.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of readers must be >= 1.\n"); } } if (argc >= 6) { p_r = atof(argv[5]) / 100.00; if (p_r < 0) { - fprintf(stderr, "ERROR: Probability of replacement must be >= 0 and <= 100.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Probability of replacement must be >= 0 and <= 100.\n"); } } if (argc >= 7) { p_d = atof(argv[6]) / 100.00; if (p_d < 0) { - fprintf(stderr, "ERROR: Probability of deletion must be >= 0 and <= 100.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Probability of deletion must be >= 0 and <= 100.\n"); } } @@ -328,24 +323,22 @@ main(int argc, char *argv[]) for (i = 0; i < (size_t)n_threads; i++) { if (pthread_create(&readers[i], NULL, ht_reader, NULL) != 0) { - fprintf(stderr, "ERROR: Failed to create thread %zu.\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to create thread %zu.\n", i); } } for (i = 0; i < keys_length; i++) d += table_insert(keys[i]) == false; - fprintf(stderr, " [S] %zu entries stored and %u duplicates.\n\n", + ck_error(" [S] %zu entries stored and %u duplicates.\n\n", table_count(), d); - fprintf(stderr, " ,- BASIC TEST\n"); - fprintf(stderr, " | Executing SMR test..."); + ck_error(" ,- BASIC TEST\n"); + ck_error(" | Executing SMR test..."); a = 0; for (j = 0; j < r; j++) { if (table_reset() == false) { - fprintf(stderr, "ERROR: Failed to reset hash table.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to reset hash table.\n"); } s = rdtsc(); @@ -354,9 +347,9 @@ main(int argc, char *argv[]) e = rdtsc(); a += e - s; } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); - fprintf(stderr, " | Executing replacement test..."); + ck_error(" | Executing replacement test..."); a = 0; for (j = 0; j < r; j++) { s = rdtsc(); @@ -365,25 +358,24 @@ main(int argc, char *argv[]) e = rdtsc(); a += e - s; } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); - fprintf(stderr, " | Executing get test..."); + ck_error(" | Executing get test..."); a = 0; for (j = 0; j < r; j++) { s = rdtsc(); for (i = 0; i < keys_length; i++) { if (table_get(keys[i]) == 0) { - fprintf(stderr, "ERROR: Unexpected 0 value.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Unexpected 0 value.\n"); } } e = rdtsc(); a += e - s; } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); a = 0; - fprintf(stderr, " | Executing removal test..."); + ck_error(" | Executing removal test..."); for (j = 0; j < r; j++) { s = rdtsc(); for (i = 0; i < keys_length; i++) @@ -394,9 +386,9 @@ main(int argc, char *argv[]) for (i = 0; i < keys_length; i++) table_insert(keys[i]); } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); - fprintf(stderr, " | Executing negative look-up test..."); + ck_error(" | Executing negative look-up test..."); a = 0; for (j = 0; j < r; j++) { s = rdtsc(); @@ -406,18 +398,18 @@ main(int argc, char *argv[]) e = rdtsc(); a += e - s; } - fprintf(stderr, "done (%" PRIu64 " ticks)\n", a / (r * keys_length)); + ck_error("done (%" PRIu64 " ticks)\n", a / (r * keys_length)); ck_epoch_record_t epoch_temporary = epoch_wr; ck_epoch_synchronize(&epoch_ht, &epoch_wr); - fprintf(stderr, " '- Summary: %u pending, %u peak, %lu reclamations -> " + ck_error(" '- Summary: %u pending, %u peak, %lu reclamations -> " "%u pending, %u peak, %lu reclamations\n\n", epoch_temporary.n_pending, epoch_temporary.n_peak, epoch_temporary.n_dispatch, epoch_wr.n_pending, epoch_wr.n_peak, epoch_wr.n_dispatch); - fprintf(stderr, " ,- READER CONCURRENCY\n"); - fprintf(stderr, " | Executing reader test..."); + ck_error(" ,- READER CONCURRENCY\n"); + ck_error(" | Executing reader test..."); ck_pr_store_int(&state, HT_STATE_GET); while (ck_pr_load_int(&barrier[HT_STATE_STOP]) != n_threads) @@ -427,10 +419,10 @@ main(int argc, char *argv[]) ck_pr_store_int(&state, HT_STATE_STRICT_REPLACEMENT); while (ck_pr_load_int(&barrier[HT_STATE_GET]) != n_threads) ck_pr_stall(); - fprintf(stderr, "done (reader = %" PRIu64 " ticks)\n", + ck_error("done (reader = %" PRIu64 " ticks)\n", accumulator[HT_STATE_GET] / n_threads); - fprintf(stderr, " | Executing strict replacement test..."); + ck_error(" | Executing strict replacement test..."); a = repeated = 0; signal(SIGALRM, alarm_handler); @@ -456,13 +448,13 @@ main(int argc, char *argv[]) ck_pr_stall(); table_reset(); ck_epoch_synchronize(&epoch_ht, &epoch_wr); - fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", + ck_error("done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), accumulator[HT_STATE_STRICT_REPLACEMENT] / n_threads); signal(SIGALRM, alarm_handler); alarm(r); - fprintf(stderr, " | Executing deletion test (%.2f)...", p_d * 100); + ck_error(" | Executing deletion test (%.2f)...", p_d * 100); a = repeated = 0; ck_pr_inc_int(&barrier[HT_STATE_STRICT_REPLACEMENT]); for (;;) { @@ -492,13 +484,13 @@ main(int argc, char *argv[]) table_reset(); ck_epoch_synchronize(&epoch_ht, &epoch_wr); - fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", + ck_error("done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), accumulator[HT_STATE_DELETION] / n_threads); signal(SIGALRM, alarm_handler); alarm(r); - fprintf(stderr, " | Executing replacement test (%.2f)...", p_r * 100); + ck_error(" | Executing replacement test (%.2f)...", p_r * 100); a = repeated = 0; ck_pr_inc_int(&barrier[HT_STATE_DELETION]); for (;;) { @@ -532,14 +524,14 @@ main(int argc, char *argv[]) ck_pr_stall(); table_reset(); ck_epoch_synchronize(&epoch_ht, &epoch_wr); - fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", + ck_error("done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), accumulator[HT_STATE_REPLACEMENT] / n_threads); ck_pr_inc_int(&barrier[HT_STATE_REPLACEMENT]); epoch_temporary = epoch_wr; ck_epoch_synchronize(&epoch_ht, &epoch_wr); - fprintf(stderr, " '- Summary: %u pending, %u peak, %lu reclamations -> " + ck_error(" '- Summary: %u pending, %u peak, %lu reclamations -> " "%u pending, %u peak, %lu reclamations\n\n", epoch_temporary.n_pending, epoch_temporary.n_peak, epoch_temporary.n_dispatch, epoch_wr.n_pending, epoch_wr.n_peak, epoch_wr.n_dispatch); diff --git a/regressions/ck_ht/benchmark/serial.c b/regressions/ck_ht/benchmark/serial.c index df0b05f..0a4bf8e 100644 --- a/regressions/ck_ht/benchmark/serial.c +++ b/regressions/ck_ht/benchmark/serial.c @@ -183,8 +183,7 @@ main(int argc, char *argv[]) srand(time(NULL)); if (argc < 2) { - fprintf(stderr, "Usage: ck_ht [ ]\n"); - exit(EXIT_FAILURE); + ck_error("Usage: ck_ht [ ]\n"); } if (argc >= 3) @@ -221,16 +220,15 @@ main(int argc, char *argv[]) d += table_insert(keys[i]) == false; ck_ht_stat(&ht, &st); - fprintf(stderr, "# %zu entries stored, %u duplicates, %" PRIu64 " probe.\n", + ck_error("# %zu entries stored, %u duplicates, %" PRIu64 " probe.\n", table_count(), d, st.probe_maximum); - fprintf(stderr, "# reverse_insertion serial_insertion random_insertion serial_replace reverse_get serial_get random_get serial_remove negative_get\n\n"); + ck_error("# reverse_insertion serial_insertion random_insertion serial_replace reverse_get serial_get random_get serial_remove negative_get\n\n"); a = 0; for (j = 0; j < r; j++) { if (table_reset() == false) { - fprintf(stderr, "ERROR: Failed to reset hash table.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to reset hash table.\n"); } s = rdtsc(); @@ -244,8 +242,7 @@ main(int argc, char *argv[]) a = 0; for (j = 0; j < r; j++) { if (table_reset() == false) { - fprintf(stderr, "ERROR: Failed to reset hash table.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to reset hash table.\n"); } s = rdtsc(); @@ -261,8 +258,7 @@ main(int argc, char *argv[]) keys_shuffle(keys); if (table_reset() == false) { - fprintf(stderr, "ERROR: Failed to reset hash table.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to reset hash table.\n"); } s = rdtsc(); @@ -292,8 +288,7 @@ main(int argc, char *argv[]) s = rdtsc(); for (i = keys_length; i > 0; i--) { if (table_get(keys[i - 1]) == NULL) { - fprintf(stderr, "ERROR: Unexpected NULL value.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Unexpected NULL value.\n"); } } e = rdtsc(); @@ -306,8 +301,7 @@ main(int argc, char *argv[]) s = rdtsc(); for (i = 0; i < keys_length; i++) { if (table_get(keys[i]) == NULL) { - fprintf(stderr, "ERROR: Unexpected NULL value.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Unexpected NULL value.\n"); } } e = rdtsc(); @@ -322,8 +316,7 @@ main(int argc, char *argv[]) s = rdtsc(); for (i = 0; i < keys_length; i++) { if (table_get(keys[i]) == NULL) { - fprintf(stderr, "ERROR: Unexpected NULL value.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Unexpected NULL value.\n"); } } e = rdtsc(); diff --git a/regressions/ck_ht/validate/serial.c b/regressions/ck_ht/validate/serial.c index 9278927..482452b 100644 --- a/regressions/ck_ht/validate/serial.c +++ b/regressions/ck_ht/validate/serial.c @@ -33,6 +33,7 @@ #include #include #include +#include "../../common.h" static void * ht_malloc(size_t r) @@ -99,7 +100,7 @@ main(void) ck_ht_hash(&h, &ht, test[i], l); ck_ht_entry_key_set(&entry, test[i], l); if (ck_ht_get_spmc(&ht, h, &entry) == false) { - fprintf(stderr, "ERROR (put): Failed to find [%s]\n", test[i]); + ck_error("ERROR (put): Failed to find [%s]\n", test[i]); } else { void *k, *v; @@ -107,7 +108,7 @@ main(void) v = ck_ht_entry_value(&entry); if (strcmp(k, test[i]) || strcmp(v, test[i])) { - fprintf(stderr, "ERROR: Mismatch: (%s, %s) != (%s, %s)\n", + ck_error("ERROR: Mismatch: (%s, %s) != (%s, %s)\n", (char *)k, (char *)v, test[i], test[i]); } } @@ -116,7 +117,7 @@ main(void) ck_ht_hash(&h, &ht, negative, strlen(negative)); ck_ht_entry_key_set(&entry, negative, strlen(negative)); if (ck_ht_get_spmc(&ht, h, &entry) == true) { - fprintf(stderr, "ERROR: Found non-existing entry.\n"); + ck_error("ERROR: Found non-existing entry.\n"); } for (i = 0; i < sizeof(test) / sizeof(*test); i++) { @@ -128,27 +129,24 @@ main(void) continue; if (ck_ht_remove_spmc(&ht, h, &entry) == false) { - fprintf(stderr, "ERROR: Failed to delete existing entry\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to delete existing entry\n"); } if (ck_ht_get_spmc(&ht, h, &entry) == true) - fprintf(stderr, "ERROR: Able to find [%s] after delete\n", test[i]); + ck_error("ERROR: Able to find [%s] after delete\n", test[i]); ck_ht_entry_set(&entry, h, test[i], l, test[i]); if (ck_ht_put_spmc(&ht, h, &entry) == false) - fprintf(stderr, "ERROR: Failed to insert [%s]\n", test[i]); + ck_error("ERROR: Failed to insert [%s]\n", test[i]); if (ck_ht_remove_spmc(&ht, h, &entry) == false) { - fprintf(stderr, "ERROR: Failed to delete existing entry\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to delete existing entry\n"); } } ck_ht_reset_spmc(&ht); if (ck_ht_count(&ht) != 0) { - fprintf(stderr, "ERROR: Map was not reset.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Map was not reset.\n"); } for (i = 0; i < sizeof(test) / sizeof(*test); i++) { @@ -160,8 +158,7 @@ main(void) for (i = 0; ck_ht_next(&ht, &iterator, &cursor) == true; i++); if (i != 42) { - fprintf(stderr, "ERROR: Incorrect number of entries in table.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Incorrect number of entries in table.\n"); } for (i = 0; i < sizeof(test) / sizeof(*test); i++) { @@ -176,7 +173,7 @@ main(void) ck_ht_hash(&h, &ht, test[i], l); ck_ht_entry_key_set(&entry, test[i], l); if (ck_ht_get_spmc(&ht, h, &entry) == false) { - fprintf(stderr, "ERROR (set): Failed to find [%s]\n", test[i]); + ck_error("ERROR (set): Failed to find [%s]\n", test[i]); } else { void *k, *v; @@ -184,7 +181,7 @@ main(void) v = ck_ht_entry_value(&entry); if (strcmp(k, test[i]) || strcmp(v, test[i])) { - fprintf(stderr, "ERROR: Mismatch: (%s, %s) != (%s, %s)\n", + ck_error("ERROR: Mismatch: (%s, %s) != (%s, %s)\n", (char *)k, (char *)v, test[i], test[i]); } } @@ -203,19 +200,17 @@ main(void) continue; if (strcmp(ck_ht_entry_value(&entry), test[i]) != 0) { - fprintf(stderr, "Mismatch detected: %s, expected %s\n", + ck_error("Mismatch detected: %s, expected %s\n", (char *)ck_ht_entry_value(&entry), test[i]); - exit(EXIT_FAILURE); } } ck_ht_iterator_init(&iterator); while (ck_ht_next(&ht, &iterator, &cursor) == true) { if (strcmp(ck_ht_entry_value(cursor), "REPLACED") != 0) { - fprintf(stderr, "Mismatch detected: %s, expected REPLACED\n", + ck_error("Mismatch detected: %s, expected REPLACED\n", (char *)ck_ht_entry_value(cursor)); - exit(EXIT_FAILURE); } } @@ -228,20 +223,18 @@ main(void) continue; if (ck_ht_remove_spmc(&ht, h, &entry) == false) { - fprintf(stderr, "ERROR: Failed to delete existing entry\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to delete existing entry\n"); } if (ck_ht_get_spmc(&ht, h, &entry) == true) - fprintf(stderr, "ERROR: Able to find [%s] after delete\n", test[i]); + ck_error("ERROR: Able to find [%s] after delete\n", test[i]); ck_ht_entry_set(&entry, h, test[i], l, test[i]); if (ck_ht_put_spmc(&ht, h, &entry) == false) - fprintf(stderr, "ERROR: Failed to insert [%s]\n", test[i]); + ck_error("ERROR: Failed to insert [%s]\n", test[i]); if (ck_ht_remove_spmc(&ht, h, &entry) == false) { - fprintf(stderr, "ERROR: Failed to delete existing entry\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to delete existing entry\n"); } } @@ -259,8 +252,7 @@ main(void) } if (l != 7) { - fprintf(stderr, "ERROR: Got %zu failures rather than 7\n", l); - exit(EXIT_FAILURE); + ck_error("ERROR: Got %zu failures rather than 7\n", l); } for (i = 0; i < sizeof(direct) / sizeof(*direct); i++) { @@ -272,9 +264,8 @@ main(void) ck_ht_iterator_init(&iterator); while (ck_ht_next(&ht, &iterator, &cursor) == true) { if (strcmp(ck_ht_entry_value(cursor), "REPLACED") != 0) { - fprintf(stderr, "Mismatch detected: %s, expected REPLACED\n", + ck_error("Mismatch detected: %s, expected REPLACED\n", (char *)ck_ht_entry_value(cursor)); - exit(EXIT_FAILURE); } } diff --git a/regressions/ck_pr/benchmark/benchmark.h b/regressions/ck_pr/benchmark/benchmark.h index 26559cf..9314335 100644 --- a/regressions/ck_pr/benchmark/benchmark.h +++ b/regressions/ck_pr/benchmark/benchmark.h @@ -60,25 +60,25 @@ main(int argc, char *argv[]) struct block *context; if (argc != 3) { - fprintf(stderr, "Usage: " ATOMIC_STRING " \n"); + ck_error("Usage: " ATOMIC_STRING " \n"); exit(EXIT_FAILURE); } nthr = atoi(argv[1]); if (nthr <= 0) { - fprintf(stderr, "ERROR: Number of threads must be greater than 0\n"); + ck_error("ERROR: Number of threads must be greater than 0\n"); exit(EXIT_FAILURE); } threads = malloc(sizeof(pthread_t) * nthr); if (threads == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread structures\n"); + ck_error("ERROR: Could not allocate thread structures\n"); exit(EXIT_FAILURE); } context = malloc(sizeof(struct block) * nthr); if (context == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread contexts\n"); + ck_error("ERROR: Could not allocate thread contexts\n"); exit(EXIT_FAILURE); } @@ -87,29 +87,29 @@ main(int argc, char *argv[]) count = malloc(sizeof(uint64_t) * nthr); if (count == NULL) { - fprintf(stderr, "ERROR: Could not create acquisition buffer\n"); + ck_error("ERROR: Could not create acquisition buffer\n"); exit(EXIT_FAILURE); } memset(count, 0, sizeof(uint64_t) * nthr); - fprintf(stderr, "Creating threads (fairness)..."); + ck_error("Creating threads (fairness)..."); for (i = 0; i < nthr; i++) { context[i].tid = i; if (pthread_create(&threads[i], NULL, fairness, context + i)) { - fprintf(stderr, "ERROR: Could not create thread %d\n", i); + ck_error("ERROR: Could not create thread %d\n", i); exit(EXIT_FAILURE); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); ck_pr_store_uint(&ready, 1); sleep(10); ck_pr_store_uint(&ready, 0); - fprintf(stderr, "Waiting for threads to finish acquisition regression..."); + ck_error("Waiting for threads to finish acquisition regression..."); for (i = 0; i < nthr; i++) pthread_join(threads[i], NULL); - fprintf(stderr, "done\n\n"); + ck_error("done\n\n"); for (i = 0, v = 0; i < nthr; i++) { printf("%d %15" PRIu64 "\n", i, count[i]); diff --git a/regressions/ck_pr/benchmark/ck_pr_fas_64.c b/regressions/ck_pr/benchmark/ck_pr_fas_64.c index b12a522..facd759 100644 --- a/regressions/ck_pr/benchmark/ck_pr_fas_64.c +++ b/regressions/ck_pr/benchmark/ck_pr_fas_64.c @@ -11,6 +11,7 @@ int main(void) { - exit(EXIT_FAILURE); + + return 0; } #endif diff --git a/regressions/ck_queue/validate/ck_list.c b/regressions/ck_queue/validate/ck_list.c index bbf45c9..abcfd86 100644 --- a/regressions/ck_queue/validate/ck_list.c +++ b/regressions/ck_queue/validate/ck_list.c @@ -57,16 +57,14 @@ test_foreach(void) s = s - 1; if (n->value != s) { - fprintf(stderr, "\nExpected %d, but got %d.\n", + ck_error("\nExpected %d, but got %d.\n", s, n->value); - exit(EXIT_FAILURE); } next = CK_LIST_NEXT(n, list_entry); if (next != NULL && next->value != s - 1) { - fprintf(stderr, "\nExpected %d, but got %d.\n", + ck_error("\nExpected %d, but got %d.\n", s, next->value); - exit(EXIT_FAILURE); } i--; @@ -85,16 +83,14 @@ test_foreach(void) s = s - 1; if (n->value != s) { - fprintf(stderr, "\nExpected %d, but got %d.\n", + ck_error("\nExpected %d, but got %d.\n", s, n->value); - exit(EXIT_FAILURE); } next = CK_LIST_NEXT(n, list_entry); if (next != NULL && next->value != s - 1) { - fprintf(stderr, "\nExpected %d, but got %d.\n", + ck_error("\nExpected %d, but got %d.\n", s, next->value); - exit(EXIT_FAILURE); } i--; @@ -104,7 +100,7 @@ test_foreach(void) break; } - fprintf(stderr, "(%d, %d) ", j, k); + ck_error("(%d, %d) ", j, k); return; } @@ -126,14 +122,12 @@ main(int argc, char *argv[]) int n_threads, i; if (argc != 3) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(EXIT_FAILURE); + ck_error("Usage: %s \n", argv[0]); } n_threads = atoi(argv[1]); if (n_threads < 1) { - fprintf(stderr, "ERROR: Number of threads must be >= 1.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of threads must be >= 1.\n"); } thread = malloc(sizeof(pthread_t) * n_threads); @@ -141,11 +135,10 @@ main(int argc, char *argv[]) goal = atoi(argv[2]); if (goal < 4) { - fprintf(stderr, "ERROR: Number of entries must be >= 4.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of entries must be >= 4.\n"); } - fprintf(stderr, "Beginning serial test..."); + ck_error("Beginning serial test..."); CK_LIST_INIT(&head); for (i = 1; i <= goal; i++) { @@ -164,13 +157,12 @@ main(int argc, char *argv[]) } if (CK_LIST_EMPTY(&head) == false) { - fprintf(stderr, "List is not empty after bulk removal.\n"); - exit(EXIT_FAILURE); + ck_error("List is not empty after bulk removal.\n"); } - fprintf(stderr, "done (success)\n"); + ck_error("done (success)\n"); - fprintf(stderr, "Beginning parallel traversal..."); + ck_error("Beginning parallel traversal..."); n = malloc(sizeof *n); assert(n != NULL); @@ -216,7 +208,7 @@ main(int argc, char *argv[]) for (i = 0; i < n_threads; i++) pthread_join(thread[i], NULL); - fprintf(stderr, "done (success)\n"); + ck_error("done (success)\n"); return (0); } diff --git a/regressions/ck_queue/validate/ck_slist.c b/regressions/ck_queue/validate/ck_slist.c index 6391ae3..687e2f2 100644 --- a/regressions/ck_queue/validate/ck_slist.c +++ b/regressions/ck_queue/validate/ck_slist.c @@ -57,16 +57,14 @@ test_foreach(void) s = s - 1; if (n->value != s) { - fprintf(stderr, "\nExpected %d, but got %d.\n", + ck_error("\nExpected %d, but got %d.\n", s, n->value); - exit(EXIT_FAILURE); } next = CK_SLIST_NEXT(n, list_entry); if (next != NULL && next->value != s - 1) { - fprintf(stderr, "\nExpected %d, but got %d.\n", + ck_error("\nExpected %d, but got %d.\n", s, next->value); - exit(EXIT_FAILURE); } i--; @@ -85,16 +83,14 @@ test_foreach(void) s = s - 1; if (n->value != s) { - fprintf(stderr, "\nExpected %d, but got %d.\n", + ck_error("\nExpected %d, but got %d.\n", s, n->value); - exit(EXIT_FAILURE); } next = CK_SLIST_NEXT(n, list_entry); if (next != NULL && next->value != s - 1) { - fprintf(stderr, "\nExpected %d, but got %d.\n", + ck_error("\nExpected %d, but got %d.\n", s, next->value); - exit(EXIT_FAILURE); } i--; @@ -104,7 +100,7 @@ test_foreach(void) break; } - fprintf(stderr, "(%d, %d) ", j, k); + ck_error("(%d, %d) ", j, k); return; } @@ -126,14 +122,12 @@ main(int argc, char *argv[]) int n_threads, i; if (argc != 3) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(EXIT_FAILURE); + ck_error("Usage: %s \n", argv[0]); } n_threads = atoi(argv[1]); if (n_threads < 1) { - fprintf(stderr, "ERROR: Number of threads must be >= 1.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of threads must be >= 1.\n"); } thread = malloc(sizeof(pthread_t) * n_threads); @@ -141,11 +135,10 @@ main(int argc, char *argv[]) goal = atoi(argv[2]); if (goal < 4) { - fprintf(stderr, "ERROR: Number of entries must be >= 4.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of entries must be >= 4.\n"); } - fprintf(stderr, "Beginning serial test..."); + ck_error("Beginning serial test..."); CK_SLIST_INIT(&head); for (i = 1; i <= goal; i++) { @@ -164,13 +157,12 @@ main(int argc, char *argv[]) } if (CK_SLIST_EMPTY(&head) == false) { - fprintf(stderr, "List is not empty after bulk removal.\n"); - exit(EXIT_FAILURE); + ck_error("List is not empty after bulk removal.\n"); } - fprintf(stderr, "done (success)\n"); + ck_error("done (success)\n"); - fprintf(stderr, "Beginning parallel traversal..."); + ck_error("Beginning parallel traversal..."); n = malloc(sizeof *n); assert(n != NULL); @@ -219,7 +211,7 @@ main(int argc, char *argv[]) for (i = 0; i < n_threads; i++) pthread_join(thread[i], NULL); - fprintf(stderr, "done (success)\n"); + ck_error("done (success)\n"); return (0); } diff --git a/regressions/ck_ring/benchmark/latency.c b/regressions/ck_ring/benchmark/latency.c index eb3ed85..5901806 100644 --- a/regressions/ck_ring/benchmark/latency.c +++ b/regressions/ck_ring/benchmark/latency.c @@ -26,20 +26,17 @@ main(int argc, char *argv[]) struct entry entry = {0, 0}; if (argc != 2) { - fprintf(stderr, "Usage: latency \n"); - exit(EXIT_FAILURE); + ck_error("Usage: latency \n"); } size = atoi(argv[1]); if (size <= 4 || (size & (size - 1))) { - fprintf(stderr, "ERROR: Size must be a power of 2 greater than 4.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Size must be a power of 2 greater than 4.\n"); } buffer = malloc(sizeof(struct entry) * size); if (buffer == NULL) { - fprintf(stderr, "ERROR: Failed to allocate buffer\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to allocate buffer\n"); } CK_RING_INIT(entry_ring, &ring, buffer, size); diff --git a/regressions/ck_ring/validate/ck_ring_spmc.c b/regressions/ck_ring/validate/ck_ring_spmc.c index 39c062a..10a03ec 100644 --- a/regressions/ck_ring/validate/ck_ring_spmc.c +++ b/regressions/ck_ring/validate/ck_ring_spmc.c @@ -89,9 +89,8 @@ test_spmc(void *c) || o->value != o->tid || o->magic != 0xdead || (previous != 0 && previous >= o->value_long)) { - fprintf(stderr, "[0x%p] (%x) (%d, %d) >< (0, %d)\n", + ck_error("[0x%p] (%x) (%d, %d) >< (0, %d)\n", (void *)o, o->magic, o->tid, o->value, size); - exit(EXIT_FAILURE); } o->magic = 0xbeef; @@ -100,15 +99,14 @@ test_spmc(void *c) previous = o->value_long; if (ck_pr_faa_uint(&o->ref, 1) != 0) { - fprintf(stderr, "[%p] We dequeued twice.\n", (void *)o); - exit(EXIT_FAILURE); + ck_error("[%p] We dequeued twice.\n", (void *)o); } free(o); } } - fprintf(stderr, "[%d] Observed %u\n", tid, observed); + ck_error("[%d] Observed %u\n", tid, observed); return NULL; } @@ -132,9 +130,8 @@ test(void *c) assert(entries != NULL); if (ck_ring_size(ring) != 0) { - fprintf(stderr, "More entries than expected: %u > 0\n", + ck_error("More entries than expected: %u > 0\n", ck_ring_size(ring)); - exit(EXIT_FAILURE); } for (i = 0; i < size; i++) { @@ -146,15 +143,13 @@ test(void *c) } if (ck_ring_size(ring) != (unsigned int)size) { - fprintf(stderr, "Less entries than expected: %u < %d\n", + ck_error("Less entries than expected: %u < %d\n", ck_ring_size(ring), size); - exit(EXIT_FAILURE); } if (ck_ring_capacity(ring) != ck_ring_size(ring) + 1) { - fprintf(stderr, "Capacity less than expected: %u < %u\n", + ck_error("Capacity less than expected: %u < %u\n", ck_ring_size(ring), ck_ring_capacity(ring)); - exit(EXIT_FAILURE); } barrier = 1; @@ -167,15 +162,13 @@ test(void *c) while (ck_ring_dequeue_spmc(ring + context->previous, &entry) == false); if (context->previous != (unsigned int)entry->tid) { - fprintf(stderr, "[%u:%p] %u != %u\n", + ck_error("[%u:%p] %u != %u\n", context->tid, (void *)entry, entry->tid, context->previous); - exit(EXIT_FAILURE); } if (entry->value < 0 || entry->value >= size) { - fprintf(stderr, "[%u:%p] %u %u\n", + ck_error("[%u:%p] %u %u\n", context->tid, (void *)entry, entry->tid, context->previous); - exit(EXIT_FAILURE); } entry->tid = context->tid; @@ -197,8 +190,7 @@ main(int argc, char *argv[]) pthread_t *thread; if (argc != 4) { - fprintf(stderr, "Usage: validate \n"); - exit(EXIT_FAILURE); + ck_error("Usage: validate \n"); } a.request = 0; @@ -220,7 +212,7 @@ main(int argc, char *argv[]) thread = malloc(sizeof(pthread_t) * nthr); assert(thread); - fprintf(stderr, "SPSC test:"); + ck_error("SPSC test:"); for (i = 0; i < nthr; i++) { context[i].tid = i; if (i == 0) { @@ -244,9 +236,9 @@ main(int argc, char *argv[]) for (i = 0; i < nthr; i++) pthread_join(thread[i], NULL); - fprintf(stderr, " done\n"); + ck_error(" done\n"); - fprintf(stderr, "SPMC test:\n"); + ck_error("SPMC test:\n"); buffer = malloc(sizeof(void *) * (size + 1)); assert(buffer); memset(buffer, 0, sizeof(void *) * (size + 1)); diff --git a/regressions/ck_ring/validate/ck_ring_spmc_template.c b/regressions/ck_ring/validate/ck_ring_spmc_template.c index da64f97..324e23d 100644 --- a/regressions/ck_ring/validate/ck_ring_spmc_template.c +++ b/regressions/ck_ring/validate/ck_ring_spmc_template.c @@ -90,9 +90,8 @@ test_spmc(void *c) || o.value != o.tid || o.magic != 0xdead || (previous != 0 && previous >= o.value_long)) { - fprintf(stderr, "(%x) (%d, %d) >< (0, %d)\n", + ck_error("(%x) (%d, %d) >< (0, %d)\n", o.magic, o.tid, o.value, size); - exit(EXIT_FAILURE); } o.magic = 0xbeef; @@ -101,13 +100,12 @@ test_spmc(void *c) previous = o.value_long; if (ck_pr_faa_uint(&o.ref, 1) != 0) { - fprintf(stderr, "We dequeued twice.\n"); - exit(EXIT_FAILURE); + ck_error("We dequeued twice.\n"); } } } - fprintf(stderr, "[%d] Observed %u\n", tid, observed); + ck_error("[%d] Observed %u\n", tid, observed); return NULL; } @@ -126,9 +124,8 @@ test(void *c) if (context->tid == 0) { if (CK_RING_SIZE(spmc_ring, ring) != 0) { - fprintf(stderr, "More entries than expected: %u > 0\n", + ck_error("More entries than expected: %u > 0\n", CK_RING_SIZE(spmc_ring, ring)); - exit(EXIT_FAILURE); } for (i = 0; i < size; i++) { @@ -140,15 +137,13 @@ test(void *c) } if (CK_RING_SIZE(spmc_ring, ring) != (unsigned int)size) { - fprintf(stderr, "Less entries than expected: %u < %d\n", + ck_error("Less entries than expected: %u < %d\n", CK_RING_SIZE(spmc_ring, ring), size); - exit(EXIT_FAILURE); } if (CK_RING_CAPACITY(spmc_ring, ring) != CK_RING_SIZE(spmc_ring, ring) + 1) { - fprintf(stderr, "Capacity less than expected: %u < %u\n", + ck_error("Capacity less than expected: %u < %u\n", CK_RING_SIZE(spmc_ring, ring), CK_RING_CAPACITY(spmc_ring, ring)); - exit(EXIT_FAILURE); } barrier = 1; @@ -161,15 +156,13 @@ test(void *c) while (CK_RING_DEQUEUE_SPMC(spmc_ring, ring + context->previous, &entry) == false); if (context->previous != (unsigned int)entry.tid) { - fprintf(stderr, "[%u] %u != %u\n", + ck_error("[%u] %u != %u\n", context->tid, entry.tid, context->previous); - exit(EXIT_FAILURE); } if (entry.value < 0 || entry.value >= size) { - fprintf(stderr, "[%u] %u %u\n", + ck_error("[%u] %u %u\n", context->tid, entry.tid, context->previous); - exit(EXIT_FAILURE); } entry.tid = context->tid; @@ -191,8 +184,7 @@ main(int argc, char *argv[]) pthread_t *thread; if (argc != 4) { - fprintf(stderr, "Usage: validate \n"); - exit(EXIT_FAILURE); + ck_error("Usage: validate \n"); } a.request = 0; @@ -214,7 +206,7 @@ main(int argc, char *argv[]) thread = malloc(sizeof(pthread_t) * nthr); assert(thread); - fprintf(stderr, "SPSC test:"); + ck_error("SPSC test:"); for (i = 0; i < nthr; i++) { context[i].tid = i; if (i == 0) { @@ -238,9 +230,9 @@ main(int argc, char *argv[]) for (i = 0; i < nthr; i++) pthread_join(thread[i], NULL); - fprintf(stderr, " done\n"); + ck_error(" done\n"); - fprintf(stderr, "SPMC test:\n"); + ck_error("SPMC test:\n"); buffer = malloc(sizeof(struct entry) * (size + 1)); assert(buffer); memset(buffer, 0, sizeof(struct entry) * (size + 1)); diff --git a/regressions/ck_ring/validate/ck_ring_spsc.c b/regressions/ck_ring/validate/ck_ring_spsc.c index 884ad01..65e8b65 100644 --- a/regressions/ck_ring/validate/ck_ring_spsc.c +++ b/regressions/ck_ring/validate/ck_ring_spsc.c @@ -73,9 +73,8 @@ test(void *c) assert(entries != NULL); if (ck_ring_size(ring) != 0) { - fprintf(stderr, "More entries than expected: %u > 0\n", + ck_error("More entries than expected: %u > 0\n", ck_ring_size(ring)); - exit(EXIT_FAILURE); } for (i = 0; i < size; i++) { @@ -87,15 +86,13 @@ test(void *c) } if (ck_ring_size(ring) != (unsigned int)size) { - fprintf(stderr, "Less entries than expected: %u < %d\n", + ck_error("Less entries than expected: %u < %d\n", ck_ring_size(ring), size); - exit(EXIT_FAILURE); } if (ck_ring_capacity(ring) != ck_ring_size(ring) + 1) { - fprintf(stderr, "Capacity less than expected: %u < %u\n", + ck_error("Capacity less than expected: %u < %u\n", ck_ring_size(ring), ck_ring_capacity(ring)); - exit(EXIT_FAILURE); } barrier = 1; @@ -108,15 +105,13 @@ test(void *c) while (ck_ring_dequeue_spsc(ring + context->previous, &entry) == false); if (context->previous != (unsigned int)entry->tid) { - fprintf(stderr, "[%u:%p] %u != %u\n", + ck_error("[%u:%p] %u != %u\n", context->tid, (void *)entry, entry->tid, context->previous); - exit(EXIT_FAILURE); } if (entry->value != j) { - fprintf(stderr, "[%u:%p] %u != %u\n", + ck_error("[%u:%p] %u != %u\n", context->tid, (void *)entry, entry->tid, context->previous); - exit(EXIT_FAILURE); } entry->tid = context->tid; @@ -137,8 +132,7 @@ main(int argc, char *argv[]) pthread_t *thread; if (argc != 4) { - fprintf(stderr, "Usage: validate \n"); - exit(EXIT_FAILURE); + ck_error("Usage: validate \n"); } a.request = 0; diff --git a/regressions/ck_ring/validate/ck_ring_spsc_template.c b/regressions/ck_ring/validate/ck_ring_spsc_template.c index 659e756..c4a6c9d 100644 --- a/regressions/ck_ring/validate/ck_ring_spsc_template.c +++ b/regressions/ck_ring/validate/ck_ring_spsc_template.c @@ -74,9 +74,8 @@ test(void *c) assert(entries != NULL); if (CK_RING_SIZE(entry_ring, ring) != 0) { - fprintf(stderr, "Ring should be empty: %u\n", + ck_error("Ring should be empty: %u\n", CK_RING_SIZE(entry_ring, ring)); - exit(EXIT_FAILURE); } for (i = 0; i < size; i++) { @@ -88,10 +87,9 @@ test(void *c) if (CK_RING_SIZE(entry_ring, ring) != CK_RING_CAPACITY(entry_ring, ring) - 1) { - fprintf(stderr, "Ring has incorrect size or capacity: %u != %u\n", + ck_error("Ring has incorrect size or capacity: %u != %u\n", CK_RING_SIZE(entry_ring, ring), CK_RING_CAPACITY(entry_ring, ring)); - exit(EXIT_FAILURE); } barrier = 1; @@ -104,15 +102,13 @@ test(void *c) while (CK_RING_DEQUEUE_SPSC(entry_ring, ring + context->previous, &entry) == false); if (context->previous != (unsigned int)entry.tid) { - fprintf(stderr, "[%u] %u != %u\n", + ck_error("[%u] %u != %u\n", context->tid, entry.tid, context->previous); - exit(EXIT_FAILURE); } if (entry.value != j) { - fprintf(stderr, "[%u] %u != %u\n", + ck_error("[%u] %u != %u\n", context->tid, entry.tid, context->previous); - exit(EXIT_FAILURE); } entry.tid = context->tid; @@ -133,8 +129,7 @@ main(int argc, char *argv[]) pthread_t *thread; if (argc != 4) { - fprintf(stderr, "Usage: validate \n"); - exit(EXIT_FAILURE); + ck_error("Usage: validate \n"); } a.request = 0; diff --git a/regressions/ck_rwlock/benchmark/throughput.c b/regressions/ck_rwlock/benchmark/throughput.c index b9f3e26..260383e 100644 --- a/regressions/ck_rwlock/benchmark/throughput.c +++ b/regressions/ck_rwlock/benchmark/throughput.c @@ -117,47 +117,42 @@ main(int argc, char *argv[]) uint64_t *latency; if (argc != 3) { - fprintf(stderr, "Usage: throughput \n"); - exit(EXIT_FAILURE); + ck_error("Usage: throughput \n"); } threads = atoi(argv[2]); if (threads <= 0) { - fprintf(stderr, "ERROR: Threads must be a value > 0.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Threads must be a value > 0.\n"); } p = malloc(sizeof(pthread_t) * threads); if (p == NULL) { - fprintf(stderr, "ERROR: Failed to initialize thread.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to initialize thread.\n"); } latency = malloc(sizeof(uint64_t) * threads); if (latency == NULL) { - fprintf(stderr, "ERROR: Failed to create latency buffer.\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to create latency buffer.\n"); } affinity.delta = atoi(argv[1]); affinity.request = 0; - fprintf(stderr, "Creating threads (rwlock)..."); + ck_error("Creating threads (rwlock)..."); for (t = 0; t < threads; t++) { if (pthread_create(&p[t], NULL, thread_rwlock, latency + t) != 0) { - fprintf(stderr, "ERROR: Could not create thread %d\n", t); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not create thread %d\n", t); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); sleep(10); ck_pr_store_uint(&flag, 1); - fprintf(stderr, "Waiting for threads to finish acquisition regression..."); + ck_error("Waiting for threads to finish acquisition regression..."); for (t = 0; t < threads; t++) pthread_join(p[t], NULL); - fprintf(stderr, "done\n\n"); + ck_error("done\n\n"); for (t = 1; t <= threads; t++) printf("%10u %20" PRIu64 "\n", t, latency[t - 1]); diff --git a/regressions/ck_rwlock/validate/validate.c b/regressions/ck_rwlock/validate/validate.c index 8910a00..27e44d8 100644 --- a/regressions/ck_rwlock/validate/validate.c +++ b/regressions/ck_rwlock/validate/validate.c @@ -74,8 +74,7 @@ thread_recursive(void *null CK_CC_UNUSED) { l = ck_pr_load_uint(&locked); if (l != 0) { - fprintf(stderr, "ERROR [WR:%d]: %u != 0\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l); } ck_pr_inc_uint(&locked); @@ -89,8 +88,7 @@ thread_recursive(void *null CK_CC_UNUSED) l = ck_pr_load_uint(&locked); if (l != 8) { - fprintf(stderr, "ERROR [WR:%d]: %u != 2\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [WR:%d]: %u != 2\n", __LINE__, l); } ck_pr_dec_uint(&locked); @@ -104,8 +102,7 @@ thread_recursive(void *null CK_CC_UNUSED) l = ck_pr_load_uint(&locked); if (l != 0) { - fprintf(stderr, "ERROR [WR:%d]: %u != 0\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l); } } ck_rwlock_recursive_write_unlock(&r_lock); @@ -117,8 +114,7 @@ thread_recursive(void *null CK_CC_UNUSED) { l = ck_pr_load_uint(&locked); if (l != 0) { - fprintf(stderr, "ERROR [RD:%d]: %u != 0\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [RD:%d]: %u != 0\n", __LINE__, l); } } ck_rwlock_recursive_read_unlock(&r_lock); @@ -143,8 +139,7 @@ thread(void *null CK_CC_UNUSED) { l = ck_pr_load_uint(&locked); if (l != 0) { - fprintf(stderr, "ERROR [WR:%d]: %u != 0\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l); } ck_pr_inc_uint(&locked); @@ -158,8 +153,7 @@ thread(void *null CK_CC_UNUSED) l = ck_pr_load_uint(&locked); if (l != 8) { - fprintf(stderr, "ERROR [WR:%d]: %u != 2\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [WR:%d]: %u != 2\n", __LINE__, l); } ck_pr_dec_uint(&locked); @@ -173,8 +167,7 @@ thread(void *null CK_CC_UNUSED) l = ck_pr_load_uint(&locked); if (l != 0) { - fprintf(stderr, "ERROR [WR:%d]: %u != 0\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l); } } ck_rwlock_write_unlock(&lock); @@ -183,8 +176,7 @@ thread(void *null CK_CC_UNUSED) { l = ck_pr_load_uint(&locked); if (l != 0) { - fprintf(stderr, "ERROR [RD:%d]: %u != 0\n", __LINE__, l); - exit(EXIT_FAILURE); + ck_error("ERROR [RD:%d]: %u != 0\n", __LINE__, l); } } ck_rwlock_read_unlock(&lock); @@ -200,51 +192,46 @@ main(int argc, char *argv[]) int i; if (argc != 3) { - fprintf(stderr, "Usage: validate \n"); - exit(EXIT_FAILURE); + ck_error("Usage: validate \n"); } nthr = atoi(argv[1]); if (nthr <= 0) { - fprintf(stderr, "ERROR: Number of threads must be greater than 0\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of threads must be greater than 0\n"); } threads = malloc(sizeof(pthread_t) * nthr); if (threads == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread structures\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate thread structures\n"); } a.delta = atoi(argv[2]); - fprintf(stderr, "Creating threads (mutual exclusion)..."); + ck_error("Creating threads (mutual exclusion)..."); for (i = 0; i < nthr; i++) { if (pthread_create(&threads[i], NULL, thread, NULL)) { - fprintf(stderr, "ERROR: Could not create thread %d\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not create thread %d\n", i); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); - fprintf(stderr, "Waiting for threads to finish correctness regression..."); + ck_error("Waiting for threads to finish correctness regression..."); for (i = 0; i < nthr; i++) pthread_join(threads[i], NULL); - fprintf(stderr, "done (passed)\n"); + ck_error("done (passed)\n"); - fprintf(stderr, "Creating threads (mutual exclusion, recursive)..."); + ck_error("Creating threads (mutual exclusion, recursive)..."); for (i = 0; i < nthr; i++) { if (pthread_create(&threads[i], NULL, thread_recursive, NULL)) { - fprintf(stderr, "ERROR: Could not create thread %d\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not create thread %d\n", i); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); - fprintf(stderr, "Waiting for threads to finish correctness regression..."); + ck_error("Waiting for threads to finish correctness regression..."); for (i = 0; i < nthr; i++) pthread_join(threads[i], NULL); - fprintf(stderr, "done (passed)\n"); + ck_error("done (passed)\n"); return (0); } diff --git a/regressions/ck_sequence/validate/ck_sequence.c b/regressions/ck_sequence/validate/ck_sequence.c index e121acc..497fd29 100644 --- a/regressions/ck_sequence/validate/ck_sequence.c +++ b/regressions/ck_sequence/validate/ck_sequence.c @@ -79,17 +79,15 @@ consumer(void *unused CK_CC_UNUSED) } while (ck_sequence_read_retry(&seqlock, version) == true); if (copy.b != copy.a + 1000) { - fprintf(stderr, "ERROR: Failed regression: copy.b (%u != %u + %u / %u)\n", copy.b, copy.a, 1000, copy.a + 1000); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed regression: copy.b (%u != %u + %u / %u)\n", copy.b, copy.a, 1000, copy.a + 1000); } if (copy.c != copy.a + copy.b) { - fprintf(stderr, "ERROR: Failed regression: copy.c (%u != %u + %u / %u)\n", copy.c, copy.a, copy.b, copy.a + copy.b); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed regression: copy.c (%u != %u + %u / %u)\n", copy.c, copy.a, copy.b, copy.a + copy.b); } } - fprintf(stderr, "%u retries.\n", retries - STEPS); + ck_error("%u retries.\n", retries - STEPS); ck_pr_dec_uint(&barrier); return (NULL); } @@ -102,20 +100,17 @@ main(int argc, char *argv[]) int n_threads, i; if (argc != 3) { - fprintf(stderr, "Usage: ck_sequence \n"); - exit(EXIT_FAILURE); + ck_error("Usage: ck_sequence \n"); } n_threads = atoi(argv[1]); if (n_threads <= 0) { - fprintf(stderr, "ERROR: Number of threads must be greater than 0\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Number of threads must be greater than 0\n"); } threads = malloc(sizeof(pthread_t) * n_threads); if (threads == NULL) { - fprintf(stderr, "ERROR: Could not allocate memory for threads\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: Could not allocate memory for threads\n"); } affinerator.delta = atoi(argv[2]); @@ -123,8 +118,7 @@ main(int argc, char *argv[]) for (i = 0; i < n_threads; i++) { if (pthread_create(&threads[i], NULL, consumer, NULL)) { - fprintf(stderr, "ERROR: Failed to create thread %d\n", i); - exit(EXIT_FAILURE); + ck_error("ERROR: Failed to create thread %d\n", i); } } diff --git a/regressions/ck_spinlock/benchmark/throughput.h b/regressions/ck_spinlock/benchmark/throughput.h index d0f72c0..fe371c4 100644 --- a/regressions/ck_spinlock/benchmark/throughput.h +++ b/regressions/ck_spinlock/benchmark/throughput.h @@ -136,13 +136,13 @@ main(int argc, char *argv[]) struct block *context; if (argc != 4) { - fprintf(stderr, "Usage: " LOCK_NAME " \n"); + ck_error("Usage: " LOCK_NAME " \n"); exit(EXIT_FAILURE); } nthr = atoi(argv[1]); if (nthr <= 0) { - fprintf(stderr, "ERROR: Number of threads must be greater than 0\n"); + ck_error("ERROR: Number of threads must be greater than 0\n"); exit(EXIT_FAILURE); } @@ -152,19 +152,19 @@ main(int argc, char *argv[]) critical = atoi(argv[3]); if (critical < 0) { - fprintf(stderr, "ERROR: critical section cannot be negative\n"); + ck_error("ERROR: critical section cannot be negative\n"); exit(EXIT_FAILURE); } threads = malloc(sizeof(pthread_t) * nthr); if (threads == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread structures\n"); + ck_error("ERROR: Could not allocate thread structures\n"); exit(EXIT_FAILURE); } context = malloc(sizeof(struct block) * nthr); if (context == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread contexts\n"); + ck_error("ERROR: Could not allocate thread contexts\n"); exit(EXIT_FAILURE); } @@ -173,29 +173,29 @@ main(int argc, char *argv[]) count = malloc(sizeof(*count) * nthr); if (count == NULL) { - fprintf(stderr, "ERROR: Could not create acquisition buffer\n"); + ck_error("ERROR: Could not create acquisition buffer\n"); exit(EXIT_FAILURE); } memset(count, 0, sizeof(*count) * nthr); - fprintf(stderr, "Creating threads (fairness)..."); + ck_error("Creating threads (fairness)..."); for (i = 0; i < nthr; i++) { context[i].tid = i; if (pthread_create(&threads[i], NULL, fairness, context + i)) { - fprintf(stderr, "ERROR: Could not create thread %d\n", i); + ck_error("ERROR: Could not create thread %d\n", i); exit(EXIT_FAILURE); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); ck_pr_store_uint(&ready, 1); sleep(10); ck_pr_store_uint(&ready, 0); - fprintf(stderr, "Waiting for threads to finish acquisition regression..."); + ck_error("Waiting for threads to finish acquisition regression..."); for (i = 0; i < nthr; i++) pthread_join(threads[i], NULL); - fprintf(stderr, "done\n\n"); + ck_error("done\n\n"); for (i = 0, v = 0; i < nthr; i++) { printf("%d %15" PRIu64 "\n", i, count[i].value); diff --git a/regressions/ck_spinlock/validate/validate.h b/regressions/ck_spinlock/validate/validate.h index 1fa8440..1bc466b 100644 --- a/regressions/ck_spinlock/validate/validate.h +++ b/regressions/ck_spinlock/validate/validate.h @@ -81,7 +81,7 @@ thread(void *null CK_CC_UNUSED) j = ck_pr_load_uint(&locked); if (j != 5) { - fprintf(stderr, "ERROR (WR): Race condition (%u)\n", j); + ck_error("ERROR (WR): Race condition (%u)\n", j); exit(EXIT_FAILURE); } @@ -96,7 +96,7 @@ thread(void *null CK_CC_UNUSED) j = ck_pr_load_uint(&locked); if (j != 0) { - fprintf(stderr, "ERROR (RD): Race condition (%u)\n", j); + ck_error("ERROR (RD): Race condition (%u)\n", j); exit(EXIT_FAILURE); } UNLOCK; @@ -112,13 +112,13 @@ main(int argc, char *argv[]) pthread_t *threads; if (argc != 3) { - fprintf(stderr, "Usage: " LOCK_NAME " \n"); + ck_error("Usage: " LOCK_NAME " \n"); exit(EXIT_FAILURE); } nthr = atoi(argv[1]); if (nthr <= 0) { - fprintf(stderr, "ERROR: Number of threads must be greater than 0\n"); + ck_error("ERROR: Number of threads must be greater than 0\n"); exit(EXIT_FAILURE); } @@ -128,26 +128,26 @@ main(int argc, char *argv[]) threads = malloc(sizeof(pthread_t) * nthr); if (threads == NULL) { - fprintf(stderr, "ERROR: Could not allocate thread structures\n"); + ck_error("ERROR: Could not allocate thread structures\n"); exit(EXIT_FAILURE); } a.delta = atoi(argv[2]); a.request = 0; - fprintf(stderr, "Creating threads (mutual exclusion)..."); + ck_error("Creating threads (mutual exclusion)..."); for (i = 0; i < nthr; i++) { if (pthread_create(&threads[i], NULL, thread, NULL)) { - fprintf(stderr, "ERROR: Could not create thread %" PRIu64 "\n", i); + ck_error("ERROR: Could not create thread %" PRIu64 "\n", i); exit(EXIT_FAILURE); } } - fprintf(stderr, "done\n"); + ck_error("done\n"); - fprintf(stderr, "Waiting for threads to finish correctness regression..."); + ck_error("Waiting for threads to finish correctness regression..."); for (i = 0; i < nthr; i++) pthread_join(threads[i], NULL); - fprintf(stderr, "done (passed)\n"); + ck_error("done (passed)\n"); return (0); } diff --git a/regressions/ck_stack/validate/pair.c b/regressions/ck_stack/validate/pair.c index 8261070..26c8dbe 100644 --- a/regressions/ck_stack/validate/pair.c +++ b/regressions/ck_stack/validate/pair.c @@ -178,8 +178,7 @@ main(int argc, char *argv[]) #endif if (argc != 4) { - fprintf(stderr, "Usage: stack \n"); - exit(EXIT_FAILURE); + ck_error("Usage: stack \n"); } { @@ -190,8 +189,7 @@ main(int argc, char *argv[]) perror("ERROR: too many threads"); exit(EXIT_FAILURE); } else if (*e != '\0') { - fprintf(stderr, "ERROR: input format is incorrect\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: input format is incorrect\n"); } d = strtol(argv[2], &e, 10); @@ -199,8 +197,7 @@ main(int argc, char *argv[]) perror("ERROR: delta is too large"); exit(EXIT_FAILURE); } else if (*e != '\0') { - fprintf(stderr, "ERROR: input format is incorrect\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: input format is incorrect\n"); } critical = strtoul(argv[3], &e, 10); @@ -208,8 +205,7 @@ main(int argc, char *argv[]) perror("ERROR: critical section is too large"); exit(EXIT_FAILURE); } else if (*e != '\0') { - fprintf(stderr, "ERROR: input format is incorrect\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: input format is incorrect\n"); } } diff --git a/regressions/ck_stack/validate/pop.c b/regressions/ck_stack/validate/pop.c index 0b5af13..193a704 100644 --- a/regressions/ck_stack/validate/pop.c +++ b/regressions/ck_stack/validate/pop.c @@ -198,8 +198,7 @@ main(int argc, char *argv[]) #endif if (argc != 4) { - fprintf(stderr, "Usage: stack \n"); - exit(EXIT_FAILURE); + ck_error("Usage: stack \n"); } { @@ -210,8 +209,7 @@ main(int argc, char *argv[]) perror("ERROR: too many threads"); exit(EXIT_FAILURE); } else if (*e != '\0') { - fprintf(stderr, "ERROR: input format is incorrect\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: input format is incorrect\n"); } d = strtol(argv[2], &e, 10); @@ -219,8 +217,7 @@ main(int argc, char *argv[]) perror("ERROR: delta is too large"); exit(EXIT_FAILURE); } else if (*e != '\0') { - fprintf(stderr, "ERROR: input format is incorrect\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: input format is incorrect\n"); } critical = strtoul(argv[3], &e, 10); @@ -228,8 +225,7 @@ main(int argc, char *argv[]) perror("ERROR: critical section is too large"); exit(EXIT_FAILURE); } else if (*e != '\0') { - fprintf(stderr, "ERROR: input format is incorrect\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: input format is incorrect\n"); } } diff --git a/regressions/ck_stack/validate/push.c b/regressions/ck_stack/validate/push.c index e704806..afd939b 100644 --- a/regressions/ck_stack/validate/push.c +++ b/regressions/ck_stack/validate/push.c @@ -164,8 +164,7 @@ main(int argc, char *argv[]) struct timeval stv, etv; if (argc != 4) { - fprintf(stderr, "Usage: stack \n"); - exit(EXIT_FAILURE); + ck_error("Usage: stack \n"); } { @@ -176,8 +175,7 @@ main(int argc, char *argv[]) perror("ERROR: too many threads"); exit(EXIT_FAILURE); } else if (*e != '\0') { - fprintf(stderr, "ERROR: input format is incorrect\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: input format is incorrect\n"); } d = strtol(argv[2], &e, 10); @@ -185,8 +183,7 @@ main(int argc, char *argv[]) perror("ERROR: delta is too large"); exit(EXIT_FAILURE); } else if (*e != '\0') { - fprintf(stderr, "ERROR: input format is incorrect\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: input format is incorrect\n"); } critical = strtoul(argv[3], &e, 10); @@ -194,8 +191,7 @@ main(int argc, char *argv[]) perror("ERROR: critical section is too large"); exit(EXIT_FAILURE); } else if (*e != '\0') { - fprintf(stderr, "ERROR: input format is incorrect\n"); - exit(EXIT_FAILURE); + ck_error("ERROR: input format is incorrect\n"); } } diff --git a/regressions/common.h b/regressions/common.h index b8a158d..acc484f 100644 --- a/regressions/common.h +++ b/regressions/common.h @@ -26,6 +26,8 @@ #include #include +#include +#include #ifdef __linux__ #include @@ -147,3 +149,14 @@ rdtsc(void) #endif } +CK_CC_USED static void +ck_error(const char *message, ...) +{ + va_list ap; + + va_start(ap, message); + vfprintf(stderr, message, ap); + va_end(ap); + exit(EXIT_FAILURE); +} +