From c23de0aacbeaa7a091609b35764bed931475a16d Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Fri, 9 Dec 2016 08:18:27 +0100 Subject: support: Introduce new subdirectory for test infrastructure The new test driver in has feature parity with the old one. The main difference is that its hooking mechanism is based on functions and function pointers instead of macros. This commit also implements a new environment variable, TEST_COREDUMPS, which disables the code which disables coredumps (that is, it enables them if the invocation environment has not disabled them). defines wrapper functions so that it is possible to use existing macros with the new-style hook functionality. This commit changes only a few test cases to the new test driver, to make sure that it works as expected. --- malloc/tst-malloc-backtrace.c | 14 ++--- malloc/tst-malloc-fork-deadlock.c | 32 +++------- malloc/tst-malloc-thread-exit.c | 121 +++++++------------------------------- 3 files changed, 35 insertions(+), 132 deletions(-) (limited to 'malloc') diff --git a/malloc/tst-malloc-backtrace.c b/malloc/tst-malloc-backtrace.c index 3aee7fd..1f1f0e8 100644 --- a/malloc/tst-malloc-backtrace.c +++ b/malloc/tst-malloc-backtrace.c @@ -16,9 +16,11 @@ License along with the GNU C Library; if not, see . */ - +#include #include +#include + #define SIZE 4096 /* Wrap free with a function to prevent gcc from optimizing it out. */ @@ -30,13 +32,6 @@ call_free (void *ptr) *(size_t *)(ptr - sizeof (size_t)) = 1; } -int do_test (void); - -#define TEST_FUNCTION do_test () -#define EXPECTED_SIGNAL SIGABRT - -#include "../test-skeleton.c" - int do_test (void) { @@ -53,3 +48,6 @@ do_test (void) doesn't optimize out that malloc call. */ return (ptr1 == ptr2); } + +#define EXPECTED_SIGNAL SIGABRT +#include diff --git a/malloc/tst-malloc-fork-deadlock.c b/malloc/tst-malloc-fork-deadlock.c index 94549ca..cdef225 100644 --- a/malloc/tst-malloc-fork-deadlock.c +++ b/malloc/tst-malloc-fork-deadlock.c @@ -28,9 +28,9 @@ #include #include -static int do_test (void); -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include +#include +#include enum { /* Number of threads which call fork. */ @@ -117,30 +117,14 @@ static void create_threads (pthread_t *threads, size_t count, void *(*func) (void *)) { for (size_t i = 0; i < count; ++i) - { - int ret = pthread_create (threads + i, NULL, func, NULL); - if (ret != 0) - { - errno = ret; - printf ("error: pthread_create: %m\n"); - abort (); - } - } + threads[i] = xpthread_create (NULL, func, NULL); } static void join_threads (pthread_t *threads, size_t count) { for (size_t i = 0; i < count; ++i) - { - int ret = pthread_join (threads[i], NULL); - if (ret != 0) - { - errno = ret; - printf ("error: pthread_join: %m\n"); - abort (); - } - } + xpthread_join (threads[i]); } /* Create a file which consists of a single long line, and assigns @@ -189,8 +173,8 @@ do_test (void) /* Leave some room for shutting down all threads gracefully. */ int timeout = 3; - if (timeout > TIMEOUT) - timeout = TIMEOUT - 1; + if (timeout > DEFAULT_TIMEOUT) + timeout = DEFAULT_TIMEOUT - 1; create_file_with_large_line (); @@ -218,3 +202,5 @@ do_test (void) return 0; } + +#include diff --git a/malloc/tst-malloc-thread-exit.c b/malloc/tst-malloc-thread-exit.c index fa6ebf9..9f92318 100644 --- a/malloc/tst-malloc-thread-exit.c +++ b/malloc/tst-malloc-thread-exit.c @@ -33,10 +33,9 @@ #include #include -static int do_test (void); - -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include +#include +#include static bool termination_requested; static int inner_thread_count = 4; @@ -53,19 +52,8 @@ static void * malloc_first_thread (void * closure) { pthread_barrier_t *barrier = closure; - void *ptr = malloc (malloc_size); - if (ptr == NULL) - { - printf ("error: malloc: %m\n"); - abort (); - } - int ret = pthread_barrier_wait (barrier); - if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) - { - errno = ret; - printf ("error: pthread_barrier_wait: %m\n"); - abort (); - } + void *ptr = xmalloc (malloc_size); + xpthread_barrier_wait (barrier); unoptimized_free (ptr); return NULL; } @@ -74,19 +62,8 @@ static void * wait_first_thread (void * closure) { pthread_barrier_t *barrier = closure; - int ret = pthread_barrier_wait (barrier); - if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) - { - errno = ret; - printf ("error: pthread_barrier_wait: %m\n"); - abort (); - } - void *ptr = malloc (malloc_size); - if (ptr == NULL) - { - printf ("error: malloc: %m\n"); - abort (); - } + xpthread_barrier_wait (barrier); + void *ptr = xmalloc (malloc_size); unoptimized_free (ptr); return NULL; } @@ -94,23 +71,11 @@ wait_first_thread (void * closure) static void * outer_thread (void *closure) { - pthread_t *threads = calloc (sizeof (*threads), inner_thread_count); - if (threads == NULL) - { - printf ("error: calloc: %m\n"); - abort (); - } - + pthread_t *threads = xcalloc (sizeof (*threads), inner_thread_count); while (!__atomic_load_n (&termination_requested, __ATOMIC_RELAXED)) { pthread_barrier_t barrier; - int ret = pthread_barrier_init (&barrier, NULL, inner_thread_count + 1); - if (ret != 0) - { - errno = ret; - printf ("pthread_barrier_init: %m\n"); - abort (); - } + xpthread_barrier_init (&barrier, NULL, inner_thread_count + 1); for (int i = 0; i < inner_thread_count; ++i) { void *(*func) (void *); @@ -118,38 +83,12 @@ outer_thread (void *closure) func = malloc_first_thread; else func = wait_first_thread; - ret = pthread_create (threads + i, NULL, func, &barrier); - if (ret != 0) - { - errno = ret; - printf ("error: pthread_create: %m\n"); - abort (); - } - } - ret = pthread_barrier_wait (&barrier); - if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) - { - errno = ret; - printf ("pthread_wait: %m\n"); - abort (); + threads[i] = xpthread_create (NULL, func, &barrier); } + xpthread_barrier_wait (&barrier); for (int i = 0; i < inner_thread_count; ++i) - { - ret = pthread_join (threads[i], NULL); - if (ret != 0) - { - ret = errno; - printf ("error: pthread_join: %m\n"); - abort (); - } - } - ret = pthread_barrier_destroy (&barrier); - if (ret != 0) - { - ret = errno; - printf ("pthread_barrier_destroy: %m\n"); - abort (); - } + xpthread_join (threads[i]); + xpthread_barrier_destroy (&barrier); } free (threads); @@ -172,26 +111,12 @@ do_test (void) /* Leave some room for shutting down all threads gracefully. */ int timeout = 3; - if (timeout > TIMEOUT) - timeout = TIMEOUT - 1; - - pthread_t *threads = calloc (sizeof (*threads), outer_thread_count); - if (threads == NULL) - { - printf ("error: calloc: %m\n"); - abort (); - } + if (timeout > DEFAULT_TIMEOUT) + timeout = DEFAULT_TIMEOUT - 1; + pthread_t *threads = xcalloc (sizeof (*threads), outer_thread_count); for (long i = 0; i < outer_thread_count; ++i) - { - int ret = pthread_create (threads + i, NULL, outer_thread, NULL); - if (ret != 0) - { - errno = ret; - printf ("error: pthread_create: %m\n"); - abort (); - } - } + threads[i] = xpthread_create (NULL, outer_thread, NULL); struct timespec ts = {timeout, 0}; if (nanosleep (&ts, NULL)) @@ -203,16 +128,10 @@ do_test (void) __atomic_store_n (&termination_requested, true, __ATOMIC_RELAXED); for (long i = 0; i < outer_thread_count; ++i) - { - int ret = pthread_join (threads[i], NULL); - if (ret != 0) - { - errno = ret; - printf ("error: pthread_join: %m\n"); - abort (); - } - } + xpthread_join (threads[i]); free (threads); return 0; } + +#include -- cgit v1.1