Author: sewardj
Date: 2007-11-05 02:26:31 +0000 (Mon, 05 Nov 2007)
New Revision: 7092

Log:
Add a test for detection of passing bogus mutex values to
pthread_cond_wait.

Added:
   branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.c
   branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.stderr.exp-glibc25-amd64
   branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.stdout.exp
   branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.vgtest
Modified:
   branches/THRCHECK/thrcheck/tests/Makefile.am


Modified: branches/THRCHECK/thrcheck/tests/Makefile.am
===================================================================
--- branches/THRCHECK/thrcheck/tests/Makefile.am        2007-11-05 02:11:57 UTC 
(rev 7091)
+++ branches/THRCHECK/thrcheck/tests/Makefile.am        2007-11-05 02:26:31 UTC 
(rev 7092)
@@ -77,7 +77,9 @@
                tc21_pthonce.stderr.exp-glibc25-amd64 \
                tc21_pthonce.stderr.exp-glibc25-x86 \
        tc22_exit_w_lock.vgtest tc22_exit_w_lock.stdout.exp \
-               tc22_exit_w_lock.stderr.exp-glibc25-amd64
+               tc22_exit_w_lock.stderr.exp-glibc25-amd64 \
+       tc23_bogus_condwait.vgtest tc23_bogus_condwait.stdout.exp \
+               tc23_bogus_condwait.stderr.exp-glibc25-amd64
 
 check_PROGRAMS = \
        hg01_all_ok \
@@ -107,7 +109,8 @@
        tc19_shadowmem \
        tc20_verifywrap \
        tc21_pthonce \
-       tc22_exit_w_lock
+       tc22_exit_w_lock \
+       tc23_bogus_condwait
 
 AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include \
                 -I$(top_srcdir)/coregrind -I$(top_builddir)/include \

Added: branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.c
===================================================================
--- branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.c                      
        (rev 0)
+++ branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.c      2007-11-05 
02:26:31 UTC (rev 7092)
@@ -0,0 +1,78 @@
+
+/* Expect 5 errors total (4 re cvs, 1 re exiting w/lock.).
+   Tests passing bogus mutexes to pthread_cond_wait. */
+
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+
+pthread_mutex_t mx[4];
+pthread_cond_t cv;
+pthread_rwlock_t rwl;
+
+void* rescue_me ( void* uu )
+{
+  /* wait for, and unblock, the first wait */
+  sleep(1);
+  pthread_cond_signal( &cv );
+
+  /* wait for, and unblock, the second wait */
+  sleep(1);
+  pthread_cond_signal( &cv );
+
+  /* wait for, and unblock, the third wait */
+  sleep(1);
+  pthread_cond_signal( &cv );
+
+  /* wait for grabber and main, then unblock the fourth wait */
+  sleep(1+1);
+  pthread_cond_signal( &cv );
+
+  return NULL;
+}
+
+void* grab_the_lock ( void* uu )
+{
+   int r= pthread_mutex_lock( &mx[2] ); assert(!r);
+   /* tc correctly complains that the thread is exiting whilst still
+      holding a lock.  A bit tricky to fix - we just live with it. */
+   return NULL;
+}
+
+int main ( void )
+{
+  int r;
+  pthread_t my_rescuer, grabber;
+
+  r= pthread_mutex_init(&mx[0], NULL); assert(!r);
+  r= pthread_mutex_init(&mx[1], NULL); assert(!r);
+  r= pthread_mutex_init(&mx[2], NULL); assert(!r);
+  r= pthread_mutex_init(&mx[3], NULL); assert(!r);
+
+  r= pthread_cond_init(&cv, NULL); assert(!r);
+  r= pthread_rwlock_init(&rwl, NULL); assert(!r);
+
+  r= pthread_create( &my_rescuer, NULL, rescue_me, NULL );
+  assert(!r);
+
+  /* Do stupid things and hope that rescue_me gets us out of
+     trouble */
+
+  /* mx is bogus */
+  r= pthread_cond_wait(&cv, (pthread_mutex_t*)(1 + (char*)&mx[0]) );
+
+  /* mx is not locked */
+  r= pthread_cond_wait(&cv, &mx[0]);
+
+  /* wrong flavour of lock */
+  r= pthread_cond_wait(&cv, (pthread_mutex_t*)&rwl );
+
+  /* mx is held by someone else. */
+  r= pthread_create( &grabber, NULL, grab_the_lock, NULL ); assert(!r);
+  sleep(1); /* let the grabber get there first */
+  r= pthread_cond_wait(&cv, &mx[2] );
+
+  r= pthread_join( my_rescuer, NULL ); assert(!r);
+  r= pthread_join( grabber, NULL ); assert(!r);
+  return 0;
+}

Added: 
branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.stderr.exp-glibc25-amd64
===================================================================
--- 
branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.stderr.exp-glibc25-amd64   
                            (rev 0)
+++ 
branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.stderr.exp-glibc25-amd64   
    2007-11-05 02:26:31 UTC (rev 7092)
@@ -0,0 +1,31 @@
+
+Thread #1 is the program's root thread
+
+Thread #1: pthread_cond_wait called with invalid mutex
+   at 0x........: [EMAIL PROTECTED] (tc_intercepts.c:...)
+   by 0x........: main (tc23_bogus_condwait.c:62)
+
+Thread #1: pthread_cond_wait called with un-held mutex
+   at 0x........: [EMAIL PROTECTED] (tc_intercepts.c:...)
+   by 0x........: main (tc23_bogus_condwait.c:65)
+
+Thread #1: pthread_cond_wait called with mutex of type pthread_rwlock_t*
+   at 0x........: [EMAIL PROTECTED] (tc_intercepts.c:...)
+   by 0x........: main (tc23_bogus_condwait.c:68)
+
+Thread #3 was created
+   at 0x........: clone (in /...libc...)
+   by 0x........: ...
+   by 0x........: [EMAIL PROTECTED] (in /lib/libpthread...)
+   by 0x........: [EMAIL PROTECTED] (tc_intercepts.c:...)
+   by 0x........: main (tc23_bogus_condwait.c:71)
+
+Thread #3: Exiting thread still holds 1 lock
+   at 0x........: start_thread (in /lib/libpthread...)
+   by 0x........: ...
+
+Thread #1: pthread_cond_wait called with mutex held by a different thread
+   at 0x........: [EMAIL PROTECTED] (tc_intercepts.c:...)
+   by 0x........: main (tc23_bogus_condwait.c:73)
+
+ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 0 from 0)

Added: branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.stdout.exp
===================================================================

Added: branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.vgtest
===================================================================
--- branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.vgtest                 
        (rev 0)
+++ branches/THRCHECK/thrcheck/tests/tc23_bogus_condwait.vgtest 2007-11-05 
02:26:31 UTC (rev 7092)
@@ -0,0 +1 @@
+prog: tc23_bogus_condwait


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to