@@ -1,13 +1,17 @@
+#include <atomic.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+static int reached;
static void *
tf (void *arg)
{
+ atomic_increment (&reached);
while (1)
sleep (100);
@@ -15,6 +19,11 @@ tf (void *arg)
return NULL;
}
+static int
+timeout_check (void)
+{
+ return (reached == 2) ? 0 : 1;
+}
static int
do_test (void)
@@ -28,6 +37,9 @@ do_test (void)
return 1;
}
+ atomic_increment (&reached);
+ alarm (3);
+
/* Terminate only this thread. */
pthread_exit (NULL);
@@ -35,6 +47,6 @@ do_test (void)
return 1;
}
-#define EXPECTED_SIGNAL SIGALRM
#define TEST_FUNCTION do_test ()
+#define TIMEOUT_CHECK timeout_check()
#include "../test-skeleton.c"
@@ -219,6 +219,20 @@ signal_handler (int sig __attribute__ ((unused)))
exit (1);
}
+#ifdef TIMEOUT_CHECK
+static void
+__attribute__ ((noreturn))
+child_timeout_handler (int sig __attribute__ ((unused)))
+{
+ if (TIMEOUT_CHECK == 0)
+ exit (0);
+
+ /* If the check returns, use a generic diagnosis. */
+ puts ("Timeout check failed");
+ exit (1);
+}
+#endif
+
/* Avoid all the buffer overflow messages on stderr. */
static void
__attribute__ ((unused))
@@ -451,6 +465,10 @@ main (int argc, char *argv[])
if (setpgid (0, 0) != 0)
printf ("Failed to set the process group ID: %m\n");
+#ifdef TIMEOUT_CHECK
+ signal (SIGALRM, child_timeout_handler);
+#endif
+
/* Execute the test function and exit with the return value. */
exit (TEST_FUNCTION);
}