summaryrefslogtreecommitdiff
path: root/malloc
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2016-12-09 08:18:27 +0100
committerFlorian Weimer <fweimer@redhat.com>2016-12-09 08:18:27 +0100
commitc23de0aacbeaa7a091609b35764bed931475a16d (patch)
treebe4396f71292ee7a509912d70e74323d1587d227 /malloc
parentc03073774f915fe7841c2b551fe304544143470f (diff)
support: Introduce new subdirectory for test infrastructure
The new test driver in <support/test-driver.c> 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). <test-skeleton.c> 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.
Diffstat (limited to 'malloc')
-rw-r--r--malloc/tst-malloc-backtrace.c14
-rw-r--r--malloc/tst-malloc-fork-deadlock.c32
-rw-r--r--malloc/tst-malloc-thread-exit.c121
3 files changed, 35 insertions, 132 deletions
diff --git a/malloc/tst-malloc-backtrace.c b/malloc/tst-malloc-backtrace.c
index 3aee7fdb28..1f1f0e803c 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
<http://www.gnu.org/licenses/>. */
-
+#include <signal.h>
#include <stdlib.h>
+#include <support/support.h>
+
#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 <support/test-driver.c>
diff --git a/malloc/tst-malloc-fork-deadlock.c b/malloc/tst-malloc-fork-deadlock.c
index 94549ca459..cdef2257d2 100644
--- a/malloc/tst-malloc-fork-deadlock.c
+++ b/malloc/tst-malloc-fork-deadlock.c
@@ -28,9 +28,9 @@
#include <string.h>
#include <signal.h>
-static int do_test (void);
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/xthread.h>
+#include <support/temp_file.h>
+#include <support/test-driver.h>
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 <support/test-driver.c>
diff --git a/malloc/tst-malloc-thread-exit.c b/malloc/tst-malloc-thread-exit.c
index fa6ebf98bf..9f92318c8d 100644
--- a/malloc/tst-malloc-thread-exit.c
+++ b/malloc/tst-malloc-thread-exit.c
@@ -33,10 +33,9 @@
#include <stdlib.h>
#include <unistd.h>
-static int do_test (void);
-
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/support.h>
+#include <support/xthread.h>
+#include <support/test-driver.h>
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 <support/test-driver.c>