* tst-robust1.c: Add second mutex to check that the mutex list is

handled correctly.
This commit is contained in:
Ulrich Drepper 2006-02-18 08:41:57 +00:00
parent f1740bc4e3
commit a93317a17a
2 changed files with 97 additions and 22 deletions

View File

@ -1,3 +1,8 @@
2006-02-18 Ulrich Drepper <drepper@redhat.com>
* tst-robust1.c: Add second mutex to check that the mutex list is
handled correctly.
2006-02-17 Jakub Jelinek <jakub@redhat.com> 2006-02-17 Jakub Jelinek <jakub@redhat.com>
* sysdeps/unix/sysv/linux/alpha/lowlevellock.h (lll_robust_mutex_dead, * sysdeps/unix/sysv/linux/alpha/lowlevellock.h (lll_robust_mutex_dead,

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2005 Free Software Foundation, Inc. /* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2005. Contributed by Ulrich Drepper <drepper@redhat.com>, 2005.
@ -23,7 +23,8 @@
#include <stdlib.h> #include <stdlib.h>
static pthread_mutex_t m; static pthread_mutex_t m1;
static pthread_mutex_t m2;
static pthread_barrier_t b; static pthread_barrier_t b;
@ -43,10 +44,17 @@ tf (void *arg)
exit (1); exit (1);
} }
int e = LOCK (&m); int e = LOCK (&m1);
if (e != 0) if (e != 0)
{ {
printf ("%ld: child: mutex_lock failed with error %d\n", round, e); printf ("%ld: child: mutex_lock m1 failed with error %d\n", round, e);
exit (1);
}
e = LOCK (&m2);
if (e != 0)
{
printf ("%ld: child: mutex_lock m2 failed with error %d\n", round, e);
exit (1); exit (1);
} }
@ -90,9 +98,15 @@ do_test (void)
return 1; return 1;
} }
#ifndef NOT_CONSISTENT #ifndef NOT_CONSISTENT
if (pthread_mutex_init (&m, &a) != 0) if (pthread_mutex_init (&m1, &a) != 0)
{ {
puts ("mutex_init failed"); puts ("mutex_init m1 failed");
return 1;
}
if (pthread_mutex_init (&m2, &a) != 0)
{
puts ("mutex_init m2 failed");
return 1; return 1;
} }
#endif #endif
@ -106,9 +120,14 @@ do_test (void)
for (long int round = 1; round < 5; ++round) for (long int round = 1; round < 5; ++round)
{ {
#ifdef NOT_CONSISTENT #ifdef NOT_CONSISTENT
if (pthread_mutex_init (&m, &a) != 0) if (pthread_mutex_init (&m1 , &a) != 0)
{ {
puts ("mutex_init failed"); puts ("mutex_init m1 failed");
return 1;
}
if (pthread_mutex_init (&m2 , &a) != 0)
{
puts ("mutex_init m2 failed");
return 1; return 1;
} }
#endif #endif
@ -157,15 +176,27 @@ do_test (void)
} }
} }
e = LOCK (&m); e = LOCK (&m1);
if (e == 0) if (e == 0)
{ {
printf ("%ld: parent: mutex_lock succeeded\n", round); printf ("%ld: parent: mutex_lock m1 succeeded\n", round);
return 1; return 1;
} }
if (e != EOWNERDEAD) if (e != EOWNERDEAD)
{ {
printf ("%ld: parent: mutex_lock returned wrong code\n", round); printf ("%ld: parent: mutex_lock m1 returned wrong code\n", round);
return 1;
}
e = LOCK (&m2);
if (e == 0)
{
printf ("%ld: parent: mutex_lock m2 succeeded\n", round);
return 1;
}
if (e != EOWNERDEAD)
{
printf ("%ld: parent: mutex_lock m2 returned wrong code\n", round);
return 1; return 1;
} }
@ -187,47 +218,86 @@ do_test (void)
#endif #endif
#ifndef NOT_CONSISTENT #ifndef NOT_CONSISTENT
e = pthread_mutex_consistent_np (&m); e = pthread_mutex_consistent_np (&m1);
if (e != 0) if (e != 0)
{ {
printf ("%ld: mutex_consistent failed with error %d\n", round, e); printf ("%ld: mutex_consistent m1 failed with error %d\n", round, e);
return 1;
}
e = pthread_mutex_consistent_np (&m2);
if (e != 0)
{
printf ("%ld: mutex_consistent m2 failed with error %d\n", round, e);
return 1; return 1;
} }
#endif #endif
e = pthread_mutex_unlock (&m); e = pthread_mutex_unlock (&m1);
if (e != 0) if (e != 0)
{ {
printf ("%ld: mutex_unlocked failed\n", round); printf ("%ld: mutex_unlock m1 failed\n", round);
return 1;
}
e = pthread_mutex_unlock (&m2);
if (e != 0)
{
printf ("%ld: mutex_unlock m2 failed\n", round);
return 1; return 1;
} }
#ifdef NOT_CONSISTENT #ifdef NOT_CONSISTENT
e = LOCK (&m); e = LOCK (&m1);
if (e == 0) if (e == 0)
{ {
printf ("%ld: locking inconsistent mutex succeeded\n", round); printf ("%ld: locking inconsistent mutex m1 succeeded\n", round);
return 1; return 1;
} }
if (e != ENOTRECOVERABLE) if (e != ENOTRECOVERABLE)
{ {
printf ("%ld: locking inconsistent mutex failed with error %d\n", printf ("%ld: locking inconsistent mutex m1 failed with error %d\n",
round, e); round, e);
return 1; return 1;
} }
if (pthread_mutex_destroy (&m) != 0) if (pthread_mutex_destroy (&m1) != 0)
{ {
puts ("mutex_destroy failed"); puts ("mutex_destroy m1 failed");
return 1;
}
e = LOCK (&m2);
if (e == 0)
{
printf ("%ld: locking inconsistent mutex m2 succeeded\n", round);
return 1;
}
if (e != ENOTRECOVERABLE)
{
printf ("%ld: locking inconsistent mutex m2 failed with error %d\n",
round, e);
return 1;
}
if (pthread_mutex_destroy (&m2) != 0)
{
puts ("mutex_destroy m2 failed");
return 1; return 1;
} }
#endif #endif
} }
#ifndef NOT_CONSISTENT #ifndef NOT_CONSISTENT
if (pthread_mutex_destroy (&m) != 0) if (pthread_mutex_destroy (&m1) != 0)
{ {
puts ("mutex_destroy failed"); puts ("mutex_destroy m1 failed");
return 1;
}
if (pthread_mutex_destroy (&m2) != 0)
{
puts ("mutex_destroy m2 failed");
return 1; return 1;
} }
#endif #endif