|
From: <sv...@va...> - 2009-07-04 12:58:42
|
Author: bart
Date: 2009-07-04 13:20:04 +0100 (Sat, 04 Jul 2009)
New Revision: 10408
Log:
Added regression test for pthread cleanup handling.
Added:
trunk/drd/tests/pth_cleanup_handler.c
trunk/drd/tests/pth_cleanup_handler.stderr.exp
trunk/drd/tests/pth_cleanup_handler.vgtest
Modified:
trunk/drd/tests/Makefile.am
Modified: trunk/drd/tests/Makefile.am
===================================================================
--- trunk/drd/tests/Makefile.am 2009-07-04 12:17:58 UTC (rev 10407)
+++ trunk/drd/tests/Makefile.am 2009-07-04 12:20:04 UTC (rev 10408)
@@ -98,6 +98,8 @@
pth_broadcast.vgtest \
pth_cancel_locked.stderr.exp \
pth_cancel_locked.vgtest \
+ pth_cleanup_handler.stderr.exp \
+ pth_cleanup_handler.vgtest \
pth_cond_race.stderr.exp \
pth_cond_race.vgtest \
pth_cond_race2.stderr.exp \
@@ -228,6 +230,7 @@
new_delete \
pth_broadcast \
pth_cancel_locked \
+ pth_cleanup_handler \
pth_cond_race \
pth_create_chain \
pth_detached \
@@ -286,6 +289,8 @@
monitor_example_SOURCES = monitor_example.cpp
new_delete_SOURCES = new_delete.cpp
+pth_cleanup_handler_CFLAGS = @FLAG_W_NO_EMPTY_BODY@
+
tsan_unittest_SOURCES = tsan_unittest.cpp
tsan_unittest_CXXFLAGS = $(AM_CXXFLAGS) \
-DTHREAD_WRAPPERS='"tsan_thread_wrappers_pthread.h"'
Added: trunk/drd/tests/pth_cleanup_handler.c
===================================================================
--- trunk/drd/tests/pth_cleanup_handler.c (rev 0)
+++ trunk/drd/tests/pth_cleanup_handler.c 2009-07-04 12:20:04 UTC (rev 10408)
@@ -0,0 +1,66 @@
+/*
+ * Test program for verifying whether pthread cleanup handlers are invoked
+ * correctly.
+ */
+
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <stdlib.h>
+
+
+static pthread_rwlock_t rwl;
+
+
+static void cleanup_handler(void* param)
+{
+ fprintf(stderr, "Cleanup handler has been called.\n");
+ pthread_rwlock_unlock(&rwl);
+}
+
+static void* f(void *p)
+{
+ if (pthread_rwlock_rdlock(&rwl) != 0)
+ {
+ fprintf(stderr, "pthread_rwlock_rdlock()\n");
+ exit(1);
+ }
+
+ pthread_cleanup_push(cleanup_handler, NULL);
+ pthread_exit(0);
+ pthread_cleanup_pop(true);
+}
+
+
+int main()
+{
+ pthread_t pt1, pt2;
+
+ // Make sure the program exits in case a deadlock has been triggered.
+ alarm(2);
+
+ if (pthread_rwlock_init(&rwl, NULL) != 0)
+ {
+ fprintf(stderr, "pthread_rwlock_init()\n");
+ exit(1);
+ }
+ if (pthread_create(&pt1, NULL, f, NULL) != 0)
+ {
+ fprintf(stderr, "pthread_create()\n");
+ exit(1);
+ }
+ if (pthread_create(&pt2, NULL, f, NULL) != 0)
+ {
+ fprintf(stderr, "pthread_create()\n");
+ exit(1);
+ }
+
+ pthread_join(pt1, 0);
+ pthread_join(pt2, 0);
+
+ fprintf(stderr, "Test succeeded.\n");
+
+ return 0;
+}
Added: trunk/drd/tests/pth_cleanup_handler.stderr.exp
===================================================================
--- trunk/drd/tests/pth_cleanup_handler.stderr.exp (rev 0)
+++ trunk/drd/tests/pth_cleanup_handler.stderr.exp 2009-07-04 12:20:04 UTC (rev 10408)
@@ -0,0 +1,6 @@
+
+Cleanup handler has been called.
+Cleanup handler has been called.
+Test succeeded.
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Added: trunk/drd/tests/pth_cleanup_handler.vgtest
===================================================================
--- trunk/drd/tests/pth_cleanup_handler.vgtest (rev 0)
+++ trunk/drd/tests/pth_cleanup_handler.vgtest 2009-07-04 12:20:04 UTC (rev 10408)
@@ -0,0 +1,3 @@
+prereq: test -e pth_cleanup_handler && ./supported_libpthread
+vgopts: --var-info=yes --check-stack-var=yes
+prog: pth_cleanup_handler
|