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