add timeout in pthread, ldflags hack, nicer error formatting
authornsz <nsz@port70.net>
Thu, 4 Aug 2011 23:23:17 +0000 (01:23 +0200)
committernsz <nsz@port70.net>
Thu, 4 Aug 2011 23:23:17 +0000 (01:23 +0200)
Makefile.inc
common/t.c
src/thread/pthread.c

index ff5b5ff..9b97adb 100644 (file)
@@ -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)
index f42054b..daf06fd 100644 (file)
@@ -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);
index 4c4e50e..642f772 100644 (file)
@@ -5,16 +5,24 @@
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
+#include <signal.h>
 #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 */