Skip to content

Commit

Permalink
nptl: Avoid expected SIGALRM in most tests [BZ #20432]
Browse files Browse the repository at this point in the history
Before this change, several tests did not detect early deadlocks
because they used SIGALRM as the expected signal, and they ran
for the full default TIMEOUT seconds.

This commit adds a new delayed_exit function to the test skeleton,
along with several error-checking wrappers to pthread functions.
Additional error checking is introduced into several tests.
  • Loading branch information
fweimer-rh committed Aug 26, 2016
1 parent 0ac8ee5 commit 7e625f7
Show file tree
Hide file tree
Showing 15 changed files with 293 additions and 101 deletions.
42 changes: 42 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
2016-08-26 Florian Weimer <[email protected]>

[BZ #20432]
Avoid expected SIGALRM signals.
* test-skeleton.c (xpthread_sigmask, xpthread_mutex_lock)
(xpthread_spin_lock, xpthread_cond_wait, xpthread_barrier_wait)
(xpthread_create, xpthread_detach, xpthread_join)
(delayed_exit_thread, delayed_exit): New functions.
* nptl/tst-cond3 (EXPECTED_SIGNAL): Remove.
(tf): Use xpthread_cond_wait.
(do_test): Likewise. Replace alarm with delayed_exit.
* nptl/tst-eintr1.c (EXPECTED_SIGNAL, TIMEOUT): Remove.
(do_test): Call delayed_exit. Report failure.
* nptl/tst-eintr2.c (EXPECTED_SIGNAL, TIMEOUT): Remove.
(do_test): Call delayed_exit.
* nptl/tst-eintr3.c (EXPECTED_SIGNAL, TIMEOUT): Remove.
(do_test): Call delayed_exit. Use xpthread_join. Report error.
* nptl/tst-eintr4.c (EXPECTED_SIGNAL, TIMEOUT): Remove.
(do_test): Call delayed_exit. Use xpthread_barrier_wait. Report
error.
* nptl/tst-eintr5.c (EXPECTED_SIGNAL, TIMEOUT): Remove.
(do_test): Call delayed_exit. Use xpthread_cond_wait. Report
error.
* nptl/tst-exit2.c (EXPECTED_SIGNAL): Remove.
(do_test): Call delayed_exit.
* nptl/tst-exit3.c (EXPECTED_SIGNAL): Remove.
(do_test): Call delayed_exit.
* nptl/tst-mutex6.c (EXPECTED_SIGNAL): Remove.
(do_test): Call delayed_exit instead of alarm. Use
xpthread_mutex_lock.
* nptl/tst-rwlock5.c (EXPECTED_SIGNAL): Remove.
(do_test): Call delayed_exit instead of alarm. Use
xpthread_mutex_lock.
* nptl/tst-sem2.c (EXPECTED_SIGNAL): Remove.
(do_test): Call delayed_exit instead of alarm.
* nptl/tst-spin3.c (EXPECTED_SIGNAL): Remove.
(do_test): Call delayed_exit instead of alarm. Use
xpthread_spin_lock.
* nptl/tst-stdio1.c (EXPECTED_SIGNAL): Remove.
(do_test): Call delayed_exit instead of alarm. Use
xpthread_join.

2016-08-26 H.J. Lu <[email protected]>

* sysdeps/x86_64/dl-trampoline.h (_dl_runtime_resolve): Don't
Expand Down
19 changes: 9 additions & 10 deletions nptl/tst-cond3.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <string.h>
#include <unistd.h>

static int do_test (void);

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"

/* Note that this test requires more than the standard. It is
required that there are no spurious wakeups if only more readers
Expand Down Expand Up @@ -50,7 +54,8 @@ tf (void *arg)
}

/* This call should never return. */
pthread_cond_wait (&cond, &mut);
xpthread_cond_wait (&cond, &mut);
puts ("error: pthread_cond_wait in tf returned");

/* We should never get here. */
exit (1);
Expand Down Expand Up @@ -96,17 +101,11 @@ do_test (void)
}
}

/* Set an alarm for 1 second. The wrapper will expect this. */
alarm (1);
delayed_exit (1);

/* This call should never return. */
pthread_cond_wait (&cond, &mut);
xpthread_cond_wait (&cond, &mut);

puts ("cond_wait returned");
puts ("error: pthread_cond_wait in do_test returned");
return 1;
}


#define EXPECTED_SIGNAL SIGALRM
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
16 changes: 8 additions & 8 deletions nptl/tst-eintr1.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#include <stdlib.h>
#include <string.h>

static int do_test (void);

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"

#include "eintr.c"


Expand Down Expand Up @@ -92,13 +97,8 @@ do_test (void)
}
}

delayed_exit (3);
/* This call must never return. */
(void) tf1 (NULL);
/* NOTREACHED */

return 0;
return 1;
}

#define EXPECTED_SIGNAL SIGALRM
#define TIMEOUT 3
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
11 changes: 6 additions & 5 deletions nptl/tst-eintr2.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
#include <string.h>
#include <sys/time.h>

static int do_test (void);

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"

#include "eintr.c"


Expand Down Expand Up @@ -103,15 +108,11 @@ do_test (void)
exit (1);
}

delayed_exit (3);
/* This call must never return. */
e = pthread_mutex_lock (&m1);
printf ("main: mutex_lock returned: %s\n",
strerror_r (e, buf, sizeof (buf)));

return 1;
}

#define EXPECTED_SIGNAL SIGALRM
#define TIMEOUT 3
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
20 changes: 9 additions & 11 deletions nptl/tst-eintr3.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#include <stdlib.h>
#include <string.h>

static int do_test (void);

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"

#include "eintr.c"


Expand Down Expand Up @@ -56,16 +61,9 @@ do_test (void)
exit (1);
}

delayed_exit (1);
/* This call must never return. */
e = pthread_join (th, NULL);

if (e == EINTR)
puts ("pthread_join returned with EINTR");

return 0;
xpthread_join (th);
puts ("error: pthread_join returned");
return 1;
}

#define EXPECTED_SIGNAL SIGALRM
#define TIMEOUT 1
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
20 changes: 9 additions & 11 deletions nptl/tst-eintr4.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#include <stdlib.h>
#include <string.h>

static int do_test (void);

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"

#include "eintr.c"


Expand All @@ -40,16 +45,9 @@ do_test (void)
exit (1);
}

delayed_exit (1);
/* This call must never return. */
int e = pthread_barrier_wait (&b);

if (e == EINTR)
puts ("pthread_join returned with EINTR");

return 0;
xpthread_barrier_wait (&b);
puts ("error: pthread_barrier_wait returned");
return 1;
}

#define EXPECTED_SIGNAL SIGALRM
#define TIMEOUT 1
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
19 changes: 9 additions & 10 deletions nptl/tst-eintr5.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
#include <string.h>
#include <sys/time.h>

static int do_test (void);

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"

#include "eintr.c"


Expand Down Expand Up @@ -66,15 +71,9 @@ do_test (void)
exit (1);
}

delayed_exit (3);
/* This call must never return. */
e = pthread_cond_wait (&c, &m);
printf ("main: cond_wait returned: %s\n",
strerror_r (e, buf, sizeof (buf)));

return 0;
xpthread_cond_wait (&c, &m);
puts ("error: pthread_cond_wait returned");
return 1;
}

#define EXPECTED_SIGNAL SIGALRM
#define TIMEOUT 3
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
10 changes: 6 additions & 4 deletions nptl/tst-exit2.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <string.h>
#include <unistd.h>

static int do_test (void);

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"

static void *
tf (void *arg)
Expand All @@ -28,13 +32,11 @@ do_test (void)
return 1;
}

delayed_exit (1);

/* Terminate only this thread. */
pthread_exit (NULL);

/* NOTREACHED */
return 1;
}

#define EXPECTED_SIGNAL SIGALRM
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
10 changes: 6 additions & 4 deletions nptl/tst-exit3.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <string.h>
#include <unistd.h>

static int do_test (void);

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"

static pthread_barrier_t b;

Expand Down Expand Up @@ -69,13 +73,11 @@ do_test (void)
exit (1);
}

delayed_exit (3);

/* Terminate only this thread. */
pthread_exit (NULL);

/* NOTREACHED */
return 1;
}

#define EXPECTED_SIGNAL SIGALRM
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
17 changes: 7 additions & 10 deletions nptl/tst-mutex6.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#include <errno.h>
#include <stdbool.h>

#ifndef TEST_FUNCTION
static int do_test (void);
# define TEST_FUNCTION do_test ()
#endif
#include "../test-skeleton.c"

#ifndef ATTR
pthread_mutexattr_t *attr;
Expand Down Expand Up @@ -62,18 +67,10 @@ do_test (void)
return 1;
}

/* Set an alarm for 1 second. The wrapper will expect this. */
alarm (1);

delayed_exit (1);
/* This call should never return. */
pthread_mutex_lock (&m);
xpthread_mutex_lock (&m);

puts ("2nd mutex_lock returned");
return 1;
}

#define EXPECTED_SIGNAL SIGALRM
#ifndef TEST_FUNCTION
# define TEST_FUNCTION do_test ()
#endif
#include "../test-skeleton.c"
14 changes: 6 additions & 8 deletions nptl/tst-rwlock5.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <stdlib.h>
#include <unistd.h>

static int do_test (void);

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"

static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
static pthread_rwlock_t r;
Expand Down Expand Up @@ -65,22 +69,16 @@ do_test (void)
return 1;
}

/* Set an alarm for 1 second. The wrapper will expect this. */
alarm (1);

if (pthread_create (&th, NULL, tf, NULL) != 0)
{
puts ("create failed");
return 1;
}

delayed_exit (1);
/* This call should never return. */
pthread_mutex_lock (&m);
xpthread_mutex_lock (&m);

puts ("2nd mutex_lock returned");
return 1;
}

#define EXPECTED_SIGNAL SIGALRM
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
Loading

0 comments on commit 7e625f7

Please sign in to comment.