Modified recursive_mutex regression test: improved portability by removing usage of alarm() / all output is now sent to stderr / full output is now compared instead of only a summary.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10425 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/drd/tests/recursive_mutex.c b/drd/tests/recursive_mutex.c
index 3ddfc25..7d8ff2d 100644
--- a/drd/tests/recursive_mutex.c
+++ b/drd/tests/recursive_mutex.c
@@ -10,26 +10,25 @@
#include "../../config.h"
-#if !defined(VGO_darwin)
static void lock_twice(pthread_mutex_t* const p)
{
- pthread_mutex_lock(p);
- pthread_mutex_lock(p);
- pthread_mutex_unlock(p);
- pthread_mutex_unlock(p);
+ if (pthread_mutex_trylock(p) != 0)
+ fprintf(stderr, "first lock call failed !\n");
+ if (pthread_mutex_trylock(p) != 0)
+ fprintf(stderr, "second lock call failed !\n");
+ if (pthread_mutex_unlock(p) != 0)
+ fprintf(stderr, "first unlock call failed !\n");
+ if (pthread_mutex_unlock(p) != 0)
+ fprintf(stderr, "second unlock call failed !\n");
}
-#endif
int main(int argc, char** argv)
{
- /* Let the program abort after 3 seconds instead of leaving it deadlocked. */
- alarm(3);
-
#if defined(HAVE_PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
{
pthread_mutex_t m = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
- printf("Recursive mutex (statically initialized).\n");
+ fprintf(stderr, "Recursive mutex (statically initialized).\n");
lock_twice(&m);
pthread_mutex_destroy(&m);
}
@@ -39,7 +38,7 @@
pthread_mutex_t m;
pthread_mutexattr_t attr;
- printf("Recursive mutex (initialized via mutex attributes).\n");
+ fprintf(stderr, "\nRecursive mutex (initialized via mutex attributes).\n");
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
pthread_mutex_init(&m, &attr);
@@ -53,7 +52,7 @@
pthread_mutex_t m;
pthread_mutexattr_t attr;
- printf("Error checking mutex.\n");
+ fprintf(stderr, "\nError checking mutex.\n");
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK_NP);
pthread_mutex_init(&m, &attr);
@@ -63,17 +62,14 @@
}
#endif
-// DDD: Darwin doesn't support signals yet, so the alarm() call doesn't kick
-// in, which causes it to hang.
-#if !defined(VGO_darwin)
{
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
- printf("Non-recursive mutex.\n");
- fflush(stdout);
+ fprintf(stderr, "\nNon-recursive mutex.\n");
lock_twice(&m);
}
- printf("Done.\n");
-#endif
+
+ fprintf(stderr, "\nDone.\n");
+
return 0;
}