From 7f409d198f3fd1e256a6e7d1c0bdb2dcb1c20566 Mon Sep 17 00:00:00 2001 From: nsz Date: Aug 04 2011 23:23:17 +0000 Subject: add timeout in pthread, ldflags hack, nicer error formatting --- diff --git a/Makefile.inc b/Makefile.inc index ff5b5ff..9b97adb 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -20,7 +20,7 @@ AR=ar RANLIB=ranlib CFLAGS += -g -std=c99 -pipe -Wall -LDFLAGS += -g -lpthread +LDFLAGS += -g -lpthread -lrt -lm INC += -I$(ROOTDIR)/common ifeq ($(usemusl), yes) diff --git a/common/t.c b/common/t.c index f42054b..daf06fd 100644 --- a/common/t.c +++ b/common/t.c @@ -30,7 +30,7 @@ void error__(const char *n, int l, const char *s, ...) { va_list ap; failed = 1; - fprintf(stderr, "- ERROR %s at %s:%d: ", name, n, l); + fprintf(stderr, " ERROR %s %s:%d: ", name, n, l); va_start(ap, s); vfprintf(stderr, s, ap); va_end(ap); diff --git a/src/thread/pthread.c b/src/thread/pthread.c index 4c4e50e..642f772 100644 --- a/src/thread/pthread.c +++ b/src/thread/pthread.c @@ -5,16 +5,24 @@ #include #include #include +#include #include "test.h" #define TEST(r, f, x, m) ( \ - ((r) = (f)) == (x) || \ + msg = #f, ((r) = (f)) == (x) || \ (error("%s failed (" m ")\n", #f, r, x), 0) ) #define TEST_S(s, x, m) ( \ !strcmp((s),(x)) || \ (error("[%s] != [%s] (%s)\n", s, x, m), 0) ) +static volatile char *msg = ""; + +static void alarmhandler(int sig) { + error("timeout in %s\n", msg); + _Exit(1); +} + static pthread_key_t k1, k2; static void dtor(void *p) @@ -125,6 +133,9 @@ void test_pthread(void) pthread_mutex_t mtx; pthread_cond_t cond; + signal(SIGALRM, alarmhandler); + alarm(10); + TEST(r, pthread_barrier_init(&barrier2, 0, 2), 0, "creating barrier"); /* Test basic thread creation and joining */