From 20890f7c942008d16920bdb0f1bf8b9091d2b9bd Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Tue, 8 Apr 2014 22:00:32 +0200 Subject: [PATCH] mpsc_queue: Make tests more verbose in case of failure Signed-off-by: Pawel Dziepak --- test/mpsc_queue_m.c | 35 ++++++++++++++++++++++++++++------- test/mpsc_queue_s.c | 7 ++++--- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/test/mpsc_queue_m.c b/test/mpsc_queue_m.c index 8fe5d91..6151a42 100644 --- a/test/mpsc_queue_m.c +++ b/test/mpsc_queue_m.c @@ -16,7 +16,8 @@ along with this program. If not, see . */ -#include +#include +#include #include #include @@ -42,8 +43,11 @@ void* thread_func(void* ptr) for (i = 1; i < ITERATIONS; i++) { error = mpsc_queue_enqueue(&queue, (void*)(i + offset)); - if (error) + if (error) { + printf("Failed to enqueue a value %#" PRIxPTR ": %s (%d)\n", + i + offset, strerror(error), error); exit(1); + } } return NULL; @@ -64,11 +68,17 @@ int main(int argc, char** argv) memcpy(last_val, offsets, sizeof(last_val)); error = mpsc_queue_init(&queue); - if (error) + if (error) { + printf("Failed to init queue: %s (%d)\n", strerror(error), error); return 1; + } - if (mpsc_queue_dequeue(&queue)) + val = (uintptr_t)mpsc_queue_dequeue(&queue); + if (val) { + printf("Dequeued a value %#" PRIxPTR "from empty queue. (after init)\n", + val); return 1; + } pthread_barrier_init(&start, NULL, THREADS + 1); @@ -83,18 +93,29 @@ int main(int argc, char** argv) } while (!val); idx = val >> 28; - if (idx >= THREADS) + if (idx >= THREADS) { + printf("Received invalid value %#" PRIxPTR " (index: %" PRIuPTR + ", max: %u)\n", val, idx, THREADS); return 1; - if (last_val[idx] + 1 != val) + } + if (last_val[idx] + 1 != val) { + printf("Received invalid value %#" PRIxPTR ", expected: %#" PRIxPTR + " (index: %" PRIuPTR ", max: %u)\n", val, last_val[idx] + 1, + idx, THREADS); return 1; + } last_val[idx]++; } for (i = 0; i < THREADS; i++) pthread_join(threads[i], NULL); - if (mpsc_queue_dequeue(&queue)) + val = (uintptr_t)mpsc_queue_dequeue(&queue); + if (val) { + printf("Dequeued a value %#" PRIxPTR "from empty queue. (after test)\n", + val); return 1; + } mpsc_queue_destroy(&queue); } diff --git a/test/mpsc_queue_s.c b/test/mpsc_queue_s.c index 68baf36..0702715 100644 --- a/test/mpsc_queue_s.c +++ b/test/mpsc_queue_s.c @@ -26,7 +26,7 @@ struct mpsc_queue queue; int main(int argc, char** argv) { - uintptr_t i; + uintptr_t i, val; int error; (void)argc; @@ -46,7 +46,8 @@ int main(int argc, char** argv) } for (i = 1; i < SIZE; i++) { - if ((uintptr_t)mpsc_queue_dequeue(&queue) != i) + val = (uintptr_t)mpsc_queue_dequeue(&queue); + if (val != i) return 1; } @@ -54,7 +55,7 @@ int main(int argc, char** argv) return 1; for (i = 1; i < SIZE; i++) { - mpsc_queue_enqueue(&queue, (void*)i); + mpsc_queue_enqueue(&queue,(void*)i); if ((uintptr_t)mpsc_queue_dequeue(&queue) != i) return 1; } -- 2.11.4.GIT