c6d234
While the original upstream commit  adds several error-checked wrappers
c6d234
around pthread functions in test-skeleton.c, a later upstream change
c6d234
(c23de0aacb, containing the new support/ infrastructure for testing) removed
c6d234
these wrappers and replaced them with an include declaration that provides
c6d234
these functions (support/xthread.h). This backport does the same, because
c6d234
the same change (new support/ infrastructure) is already included in RHEL as
c6d234
well.
c6d234
c6d234
Also note: The correct sourceware bug number is 19946. The original upstream
c6d234
commit message refers to an incorrect one.
c6d234
c6d234
commit 7e625f7e85b4e88f10dbde35a0641742af581806
c6d234
Author: Florian Weimer <fweimer@redhat.com>
c6d234
Date:   Fri Aug 26 19:27:16 2016 +0200
c6d234
c6d234
    nptl: Avoid expected SIGALRM in most tests [BZ #20432]
c6d234
    
c6d234
    Before this change, several tests did not detect early deadlocks
c6d234
    because they used SIGALRM as the expected signal, and they ran
c6d234
    for the full default TIMEOUT seconds.
c6d234
    
c6d234
    This commit adds a new delayed_exit function to the test skeleton,
c6d234
    along with several error-checking wrappers to pthread functions.
c6d234
    Additional error checking is introduced into several tests.
c6d234
c6d234
Index: b/nptl/tst-cond3.c
c6d234
===================================================================
c6d234
--- a/nptl/tst-cond3.c
c6d234
+++ b/nptl/tst-cond3.c
c6d234
@@ -22,6 +22,10 @@
c6d234
 #include <string.h>
c6d234
 #include <unistd.h>
c6d234
 
c6d234
+static int do_test (void);
c6d234
+
c6d234
+#define TEST_FUNCTION do_test ()
c6d234
+#include "../test-skeleton.c"
c6d234
 
c6d234
 /* Note that this test requires more than the standard.  It is
c6d234
    required that there are no spurious wakeups if only more readers
c6d234
@@ -50,7 +54,8 @@ tf (void *arg)
c6d234
     }
c6d234
 
c6d234
   /* This call should never return.  */
c6d234
-  pthread_cond_wait (&cond, &mut;;
c6d234
+  xpthread_cond_wait (&cond, &mut;;
c6d234
+  puts ("error: pthread_cond_wait in tf returned");
c6d234
 
c6d234
   /* We should never get here.  */
c6d234
   exit (1);
c6d234
@@ -96,17 +101,11 @@ do_test (void)
c6d234
 	}
c6d234
     }
c6d234
 
c6d234
-  /* Set an alarm for 1 second.  The wrapper will expect this.  */
c6d234
-  alarm (1);
c6d234
+  delayed_exit (1);
c6d234
 
c6d234
   /* This call should never return.  */
c6d234
-  pthread_cond_wait (&cond, &mut;;
c6d234
+  xpthread_cond_wait (&cond, &mut;;
c6d234
 
c6d234
-  puts ("cond_wait returned");
c6d234
+  puts ("error: pthread_cond_wait in do_test returned");
c6d234
   return 1;
c6d234
 }
c6d234
-
c6d234
-
c6d234
-#define EXPECTED_SIGNAL SIGALRM
c6d234
-#define TEST_FUNCTION do_test ()
c6d234
-#include "../test-skeleton.c"
c6d234
Index: b/nptl/tst-eintr1.c
c6d234
===================================================================
c6d234
--- a/nptl/tst-eintr1.c
c6d234
+++ b/nptl/tst-eintr1.c
c6d234
@@ -23,6 +23,11 @@
c6d234
 #include <stdlib.h>
c6d234
 #include <string.h>
c6d234
 
c6d234
+static int do_test (void);
c6d234
+
c6d234
+#define TEST_FUNCTION do_test ()
c6d234
+#include "../test-skeleton.c"
c6d234
+
c6d234
 #include "eintr.c"
c6d234
 
c6d234
 
c6d234
@@ -92,13 +97,8 @@ do_test (void)
c6d234
 	}
c6d234
     }
c6d234
 
c6d234
+  delayed_exit (3);
c6d234
+  /* This call must never return.  */
c6d234
   (void) tf1 (NULL);
c6d234
-  /* NOTREACHED */
c6d234
-
c6d234
-  return 0;
c6d234
+  return 1;
c6d234
 }
c6d234
-
c6d234
-#define EXPECTED_SIGNAL SIGALRM
c6d234
-#define TIMEOUT 3
c6d234
-#define TEST_FUNCTION do_test ()
c6d234
-#include "../test-skeleton.c"
c6d234
Index: b/nptl/tst-eintr2.c
c6d234
===================================================================
c6d234
--- a/nptl/tst-eintr2.c
c6d234
+++ b/nptl/tst-eintr2.c
c6d234
@@ -24,6 +24,11 @@
c6d234
 #include <string.h>
c6d234
 #include <sys/time.h>
c6d234
 
c6d234
+static int do_test (void);
c6d234
+
c6d234
+#define TEST_FUNCTION do_test ()
c6d234
+#include "../test-skeleton.c"
c6d234
+
c6d234
 #include "eintr.c"
c6d234
 
c6d234
 
c6d234
@@ -103,6 +108,7 @@ do_test (void)
c6d234
       exit (1);
c6d234
     }
c6d234
 
c6d234
+  delayed_exit (3);
c6d234
   /* This call must never return.  */
c6d234
   e = pthread_mutex_lock (&m1;;
c6d234
   printf ("main: mutex_lock returned: %s\n",
c6d234
@@ -110,8 +116,3 @@ do_test (void)
c6d234
 
c6d234
   return 1;
c6d234
 }
c6d234
-
c6d234
-#define EXPECTED_SIGNAL SIGALRM
c6d234
-#define TIMEOUT 3
c6d234
-#define TEST_FUNCTION do_test ()
c6d234
-#include "../test-skeleton.c"
c6d234
Index: b/nptl/tst-eintr3.c
c6d234
===================================================================
c6d234
--- a/nptl/tst-eintr3.c
c6d234
+++ b/nptl/tst-eintr3.c
c6d234
@@ -23,6 +23,11 @@
c6d234
 #include <stdlib.h>
c6d234
 #include <string.h>
c6d234
 
c6d234
+static int do_test (void);
c6d234
+
c6d234
+#define TEST_FUNCTION do_test ()
c6d234
+#include "../test-skeleton.c"
c6d234
+
c6d234
 #include "eintr.c"
c6d234
 
c6d234
 
c6d234
@@ -56,16 +61,9 @@ do_test (void)
c6d234
       exit (1);
c6d234
     }
c6d234
 
c6d234
+  delayed_exit (1);
c6d234
   /* This call must never return.  */
c6d234
-  e = pthread_join (th, NULL);
c6d234
-
c6d234
-  if (e == EINTR)
c6d234
-    puts ("pthread_join returned with EINTR");
c6d234
-
c6d234
-  return 0;
c6d234
+  xpthread_join (th);
c6d234
+  puts ("error: pthread_join returned");
c6d234
+  return 1;
c6d234
 }
c6d234
-
c6d234
-#define EXPECTED_SIGNAL SIGALRM
c6d234
-#define TIMEOUT 1
c6d234
-#define TEST_FUNCTION do_test ()
c6d234
-#include "../test-skeleton.c"
c6d234
Index: b/nptl/tst-eintr4.c
c6d234
===================================================================
c6d234
--- a/nptl/tst-eintr4.c
c6d234
+++ b/nptl/tst-eintr4.c
c6d234
@@ -23,6 +23,11 @@
c6d234
 #include <stdlib.h>
c6d234
 #include <string.h>
c6d234
 
c6d234
+static int do_test (void);
c6d234
+
c6d234
+#define TEST_FUNCTION do_test ()
c6d234
+#include "../test-skeleton.c"
c6d234
+
c6d234
 #include "eintr.c"
c6d234
 
c6d234
 
c6d234
@@ -40,16 +45,9 @@ do_test (void)
c6d234
       exit (1);
c6d234
     }
c6d234
 
c6d234
+  delayed_exit (1);
c6d234
   /* This call must never return.  */
c6d234
-  int e = pthread_barrier_wait (&b);
c6d234
-
c6d234
-  if (e == EINTR)
c6d234
-    puts ("pthread_join returned with EINTR");
c6d234
-
c6d234
-  return 0;
c6d234
+  xpthread_barrier_wait (&b);
c6d234
+  puts ("error: pthread_barrier_wait returned");
c6d234
+  return 1;
c6d234
 }
c6d234
-
c6d234
-#define EXPECTED_SIGNAL SIGALRM
c6d234
-#define TIMEOUT 1
c6d234
-#define TEST_FUNCTION do_test ()
c6d234
-#include "../test-skeleton.c"
c6d234
Index: b/nptl/tst-eintr5.c
c6d234
===================================================================
c6d234
--- a/nptl/tst-eintr5.c
c6d234
+++ b/nptl/tst-eintr5.c
c6d234
@@ -24,6 +24,11 @@
c6d234
 #include <string.h>
c6d234
 #include <sys/time.h>
c6d234
 
c6d234
+static int do_test (void);
c6d234
+
c6d234
+#define TEST_FUNCTION do_test ()
c6d234
+#include "../test-skeleton.c"
c6d234
+
c6d234
 #include "eintr.c"
c6d234
 
c6d234
 
c6d234
@@ -66,15 +71,9 @@ do_test (void)
c6d234
       exit (1);
c6d234
     }
c6d234
 
c6d234
+  delayed_exit (3);
c6d234
   /* This call must never return.  */
c6d234
-  e = pthread_cond_wait (&c, &m);
c6d234
-  printf ("main: cond_wait returned: %s\n",
c6d234
-	  strerror_r (e, buf, sizeof (buf)));
c6d234
-
c6d234
-  return 0;
c6d234
+  xpthread_cond_wait (&c, &m);
c6d234
+  puts ("error: pthread_cond_wait returned");
c6d234
+  return 1;
c6d234
 }
c6d234
-
c6d234
-#define EXPECTED_SIGNAL SIGALRM
c6d234
-#define TIMEOUT 3
c6d234
-#define TEST_FUNCTION do_test ()
c6d234
-#include "../test-skeleton.c"
c6d234
Index: b/nptl/tst-exit2.c
c6d234
===================================================================
c6d234
--- a/nptl/tst-exit2.c
c6d234
+++ b/nptl/tst-exit2.c
c6d234
@@ -4,6 +4,10 @@
c6d234
 #include <string.h>
c6d234
 #include <unistd.h>
c6d234
 
c6d234
+static int do_test (void);
c6d234
+
c6d234
+#define TEST_FUNCTION do_test ()
c6d234
+#include "../test-skeleton.c"
c6d234
 
c6d234
 static void *
c6d234
 tf (void *arg)
c6d234
@@ -28,13 +32,11 @@ do_test (void)
c6d234
       return 1;
c6d234
     }
c6d234
 
c6d234
+  delayed_exit (1);
c6d234
+
c6d234
   /* Terminate only this thread.  */
c6d234
   pthread_exit (NULL);
c6d234
 
c6d234
   /* NOTREACHED */
c6d234
   return 1;
c6d234
 }
c6d234
-
c6d234
-#define EXPECTED_SIGNAL SIGALRM
c6d234
-#define TEST_FUNCTION do_test ()
c6d234
-#include "../test-skeleton.c"
c6d234
Index: b/nptl/tst-exit3.c
c6d234
===================================================================
c6d234
--- a/nptl/tst-exit3.c
c6d234
+++ b/nptl/tst-exit3.c
c6d234
@@ -5,6 +5,10 @@
c6d234
 #include <string.h>
c6d234
 #include <unistd.h>
c6d234
 
c6d234
+static int do_test (void);
c6d234
+
c6d234
+#define TEST_FUNCTION do_test ()
c6d234
+#include "../test-skeleton.c"
c6d234
 
c6d234
 static pthread_barrier_t b;
c6d234
 
c6d234
@@ -69,13 +73,11 @@ do_test (void)
c6d234
       exit (1);
c6d234
     }
c6d234
 
c6d234
+  delayed_exit (3);
c6d234
+
c6d234
   /* Terminate only this thread.  */
c6d234
   pthread_exit (NULL);
c6d234
 
c6d234
   /* NOTREACHED */
c6d234
   return 1;
c6d234
 }
c6d234
-
c6d234
-#define EXPECTED_SIGNAL SIGALRM
c6d234
-#define TEST_FUNCTION do_test ()
c6d234
-#include "../test-skeleton.c"
c6d234
Index: b/nptl/tst-mutex6.c
c6d234
===================================================================
c6d234
--- a/nptl/tst-mutex6.c
c6d234
+++ b/nptl/tst-mutex6.c
c6d234
@@ -22,6 +22,11 @@
c6d234
 #include <unistd.h>
c6d234
 #include <errno.h>
c6d234
 
c6d234
+#ifndef TEST_FUNCTION
c6d234
+static int do_test (void);
c6d234
+# define TEST_FUNCTION do_test ()
c6d234
+#endif
c6d234
+#include "../test-skeleton.c"
c6d234
 
c6d234
 #ifndef ATTR
c6d234
 pthread_mutexattr_t *attr;
c6d234
@@ -58,18 +63,10 @@ do_test (void)
c6d234
       return 1;
c6d234
     }
c6d234
 
c6d234
-  /* Set an alarm for 1 second.  The wrapper will expect this.  */
c6d234
-  alarm (1);
c6d234
-
c6d234
+  delayed_exit (1);
c6d234
   /* This call should never return.  */
c6d234
-  pthread_mutex_lock (&m);
c6d234
+  xpthread_mutex_lock (&m);
c6d234
 
c6d234
   puts ("2nd mutex_lock returned");
c6d234
   return 1;
c6d234
 }
c6d234
-
c6d234
-#define EXPECTED_SIGNAL SIGALRM
c6d234
-#ifndef TEST_FUNCTION
c6d234
-# define TEST_FUNCTION do_test ()
c6d234
-#endif
c6d234
-#include "../test-skeleton.c"
c6d234
Index: b/nptl/tst-rwlock5.c
c6d234
===================================================================
c6d234
--- a/nptl/tst-rwlock5.c
c6d234
+++ b/nptl/tst-rwlock5.c
c6d234
@@ -22,6 +22,10 @@
c6d234
 #include <stdlib.h>
c6d234
 #include <unistd.h>
c6d234
 
c6d234
+static int do_test (void);
c6d234
+
c6d234
+#define TEST_FUNCTION do_test ()
c6d234
+#include "../test-skeleton.c"
c6d234
 
c6d234
 static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
c6d234
 static pthread_rwlock_t r;
c6d234
@@ -65,22 +69,16 @@ do_test (void)
c6d234
       return 1;
c6d234
     }
c6d234
 
c6d234
-  /* Set an alarm for 1 second.  The wrapper will expect this.  */
c6d234
-  alarm (1);
c6d234
-
c6d234
   if (pthread_create (&th, NULL, tf, NULL) != 0)
c6d234
     {
c6d234
       puts ("create failed");
c6d234
       return 1;
c6d234
     }
c6d234
 
c6d234
+  delayed_exit (1);
c6d234
   /* This call should never return.  */
c6d234
-  pthread_mutex_lock (&m);
c6d234
+  xpthread_mutex_lock (&m);
c6d234
 
c6d234
   puts ("2nd mutex_lock returned");
c6d234
   return 1;
c6d234
 }
c6d234
-
c6d234
-#define EXPECTED_SIGNAL SIGALRM
c6d234
-#define TEST_FUNCTION do_test ()
c6d234
-#include "../test-skeleton.c"
c6d234
Index: b/nptl/tst-sem2.c
c6d234
===================================================================
c6d234
--- a/nptl/tst-sem2.c
c6d234
+++ b/nptl/tst-sem2.c
c6d234
@@ -17,11 +17,16 @@
c6d234
    <http://www.gnu.org/licenses/>.  */
c6d234
 
c6d234
 #include <errno.h>
c6d234
+#include <pthread.h>
c6d234
 #include <semaphore.h>
c6d234
 #include <signal.h>
c6d234
 #include <stdio.h>
c6d234
 #include <unistd.h>
c6d234
 
c6d234
+static int do_test (void);
c6d234
+
c6d234
+#define TEST_FUNCTION do_test ()
c6d234
+#include "../test-skeleton.c"
c6d234
 
c6d234
 static int
c6d234
 do_test (void)
c6d234
@@ -34,8 +39,7 @@ do_test (void)
c6d234
       return 1;
c6d234
     }
c6d234
 
c6d234
-  /* Set an alarm for 1 second.  The wrapper will expect this.  */
c6d234
-  alarm (1);
c6d234
+  delayed_exit (1);
c6d234
 
c6d234
   if (TEMP_FAILURE_RETRY (sem_wait (&s)) == -1)
c6d234
     {
c6d234
@@ -47,7 +51,3 @@ do_test (void)
c6d234
   puts ("wait succeeded");
c6d234
   return 1;
c6d234
 }
c6d234
-
c6d234
-#define EXPECTED_SIGNAL SIGALRM
c6d234
-#define TEST_FUNCTION do_test ()
c6d234
-#include "../test-skeleton.c"
c6d234
Index: b/nptl/tst-spin3.c
c6d234
===================================================================
c6d234
--- a/nptl/tst-spin3.c
c6d234
+++ b/nptl/tst-spin3.c
c6d234
@@ -21,6 +21,10 @@
c6d234
 #include <stdio.h>
c6d234
 #include <unistd.h>
c6d234
 
c6d234
+static int do_test (void);
c6d234
+
c6d234
+#define TEST_FUNCTION do_test ()
c6d234
+#include "../test-skeleton.c"
c6d234
 
c6d234
 static int
c6d234
 do_test (void)
c6d234
@@ -39,16 +43,11 @@ do_test (void)
c6d234
       return 1;
c6d234
     }
c6d234
 
c6d234
-  /* Set an alarm for 1 second.  The wrapper will expect this.  */
c6d234
-  alarm (1);
c6d234
+  delayed_exit (1);
c6d234
 
c6d234
   /* This call should never return.  */
c6d234
-  pthread_spin_lock (&s);
c6d234
+  xpthread_spin_lock (&s);
c6d234
 
c6d234
   puts ("2nd spin_lock returned");
c6d234
   return 1;
c6d234
 }
c6d234
-
c6d234
-#define EXPECTED_SIGNAL SIGALRM
c6d234
-#define TEST_FUNCTION do_test ()
c6d234
-#include "../test-skeleton.c"
c6d234
Index: b/nptl/tst-stdio1.c
c6d234
===================================================================
c6d234
--- a/nptl/tst-stdio1.c
c6d234
+++ b/nptl/tst-stdio1.c
c6d234
@@ -21,6 +21,10 @@
c6d234
 #include <stdio.h>
c6d234
 #include <unistd.h>
c6d234
 
c6d234
+static int do_test (void);
c6d234
+
c6d234
+#define TEST_FUNCTION do_test ()
c6d234
+#include "../test-skeleton.c"
c6d234
 
c6d234
 static void *tf (void *a)
c6d234
 {
c6d234
@@ -43,14 +47,10 @@ do_test (void)
c6d234
       _exit (1);
c6d234
     }
c6d234
 
c6d234
-  pthread_join (th, NULL);
c6d234
+  delayed_exit (1);
c6d234
+  xpthread_join (th);
c6d234
 
c6d234
   puts ("join returned");
c6d234
 
c6d234
-  return 0;
c6d234
+  return 1;
c6d234
 }
c6d234
-
c6d234
-
c6d234
-#define EXPECTED_SIGNAL SIGALRM
c6d234
-#define TEST_FUNCTION do_test ()
c6d234
-#include "../test-skeleton.c"
c6d234
Index: b/test-skeleton.c
c6d234
===================================================================
c6d234
--- a/test-skeleton.c
c6d234
+++ b/test-skeleton.c
c6d234
@@ -427,3 +427,9 @@ main (int argc, char *argv[])
c6d234
   return 0;
c6d234
 #endif
c6d234
 }
c6d234
+
c6d234
+/* The following functionality is only available if <pthread.h> was
c6d234
+   included before this file.  */
c6d234
+#ifdef _PTHREAD_H
c6d234
+# include <support/xthread.h>
c6d234
+#endif	/* _PTHREAD_H */