Author: sewardj Date: 2007-10-03 21:34:03 +0100 (Wed, 03 Oct 2007) New Revision: 6933
Log: More regression tests. Added: branches/THRCHECK/thrcheck/tests/tc11_XCHG.vgtest branches/THRCHECK/thrcheck/tests/tc12_rwl_trivial.c branches/THRCHECK/thrcheck/tests/tc12_rwl_trivial.stderr.exp branches/THRCHECK/thrcheck/tests/tc12_rwl_trivial.stdout.exp branches/THRCHECK/thrcheck/tests/tc12_rwl_trivial.vgtest branches/THRCHECK/thrcheck/tests/tc13_laog1.c branches/THRCHECK/thrcheck/tests/tc13_laog1.stderr.exp branches/THRCHECK/thrcheck/tests/tc13_laog1.stdout.exp branches/THRCHECK/thrcheck/tests/tc13_laog1.vgtest branches/THRCHECK/thrcheck/tests/tc14_laog_dinphils.c branches/THRCHECK/thrcheck/tests/tc14_laog_dinphils.stderr.exp branches/THRCHECK/thrcheck/tests/tc14_laog_dinphils.stdout.exp branches/THRCHECK/thrcheck/tests/tc14_laog_dinphils.vgtest branches/THRCHECK/thrcheck/tests/tc15_laog_lockdel.c branches/THRCHECK/thrcheck/tests/tc15_laog_lockdel.stderr.exp branches/THRCHECK/thrcheck/tests/tc15_laog_lockdel.stdout.exp branches/THRCHECK/thrcheck/tests/tc15_laog_lockdel.vgtest Modified: branches/THRCHECK/thrcheck/tests/Makefile.am Modified: branches/THRCHECK/thrcheck/tests/Makefile.am =================================================================== --- branches/THRCHECK/thrcheck/tests/Makefile.am 2007-10-03 20:18:28 UTC (rev 6932) +++ branches/THRCHECK/thrcheck/tests/Makefile.am 2007-10-03 20:34:03 UTC (rev 6933) @@ -32,7 +32,15 @@ tc10_rec_lock.vgtest tc10_rec_lock.stderr.exp \ tc10_rec_lock.stdout.exp \ tc11_XCHG.vgtest tc11_XCHG.stderr.exp \ - tc11_XCHG.stdout.exp + tc11_XCHG.stdout.exp \ + tc12_rwl_trivial.vgtest tc12_rwl_trivial.stderr.exp \ + tc12_rwl_trivial.stdout.exp \ + tc13_laog1.vgtest tc13_laog1.stderr.exp \ + tc13_laog1.stdout.exp \ + tc14_laog_dinphils.vgtest tc14_laog_dinphils.stderr.exp \ + tc14_laog_dinphils.stdout.exp \ + tc15_laog_lockdel.vgtest tc15_laog_lockdel.stderr.exp \ + tc15_laog_lockdel.stdout.exp check_PROGRAMS = \ hg01_all_ok \ @@ -51,7 +59,11 @@ tc08_hbl2 \ tc09_bad_unlock \ tc10_rec_lock \ - tc11_XCHG + tc11_XCHG \ + tc12_rwl_trivial \ + tc13_laog1 \ + tc14_laog_dinphils \ + tc15_laog_lockdel # is this necessary? AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -g $(AM_FLAG_M3264_PRI) Added: branches/THRCHECK/thrcheck/tests/tc11_XCHG.vgtest =================================================================== --- branches/THRCHECK/thrcheck/tests/tc11_XCHG.vgtest (rev 0) +++ branches/THRCHECK/thrcheck/tests/tc11_XCHG.vgtest 2007-10-03 20:34:03 UTC (rev 6933) @@ -0,0 +1 @@ +prog: tc11_XCHG Added: branches/THRCHECK/thrcheck/tests/tc12_rwl_trivial.c =================================================================== --- branches/THRCHECK/thrcheck/tests/tc12_rwl_trivial.c (rev 0) +++ branches/THRCHECK/thrcheck/tests/tc12_rwl_trivial.c 2007-10-03 20:34:03 UTC (rev 6933) @@ -0,0 +1,29 @@ + +#include <stdio.h> +#include <pthread.h> +#include <assert.h> + +/* Do trivial stuff with a reader-writer lock. */ + +int main ( void ) +{ + int r; + pthread_rwlock_t rwl; + + r = pthread_rwlock_init( &rwl, NULL ); assert(r == 0); + + r = pthread_rwlock_wrlock( &rwl ); assert(r == 0); + r = pthread_rwlock_unlock( &rwl ); assert(r == 0); + + r = pthread_rwlock_rdlock( &rwl ); assert(r == 0); + r = pthread_rwlock_rdlock( &rwl ); assert(r == 0); + r = pthread_rwlock_unlock( &rwl ); assert(r == 0); + r = pthread_rwlock_unlock( &rwl ); assert(r == 0); + + /* this should fail - lock is unowned now */ + r = pthread_rwlock_unlock( &rwl ); assert(r == 0); + + r = pthread_rwlock_destroy( &rwl ); assert(r == 0); + + return 0; +} Added: branches/THRCHECK/thrcheck/tests/tc12_rwl_trivial.stderr.exp =================================================================== Added: branches/THRCHECK/thrcheck/tests/tc12_rwl_trivial.stdout.exp =================================================================== Added: branches/THRCHECK/thrcheck/tests/tc12_rwl_trivial.vgtest =================================================================== --- branches/THRCHECK/thrcheck/tests/tc12_rwl_trivial.vgtest (rev 0) +++ branches/THRCHECK/thrcheck/tests/tc12_rwl_trivial.vgtest 2007-10-03 20:34:03 UTC (rev 6933) @@ -0,0 +1 @@ +prog: tc12_rwl_trivial Added: branches/THRCHECK/thrcheck/tests/tc13_laog1.c =================================================================== --- branches/THRCHECK/thrcheck/tests/tc13_laog1.c (rev 0) +++ branches/THRCHECK/thrcheck/tests/tc13_laog1.c 2007-10-03 20:34:03 UTC (rev 6933) @@ -0,0 +1,33 @@ + +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> + +/* The simplest possible test that triggers a lock order acquisition + error. */ + +int main ( void ) +{ + int r; + pthread_mutex_t mx1, mx2; + r = pthread_mutex_init( &mx1, NULL ); assert(r==0); + r = pthread_mutex_init( &mx2, NULL ); assert(r==0); + + r = pthread_mutex_lock( &mx1 ); assert(r==0); + r = pthread_mutex_lock( &mx2 ); assert(r==0); + + r = pthread_mutex_unlock( &mx1 ); assert(r==0); + r = pthread_mutex_unlock( &mx2 ); assert(r==0); + + r = pthread_mutex_lock( &mx2 ); assert(r==0); /* error */ + r = pthread_mutex_lock( &mx1 ); assert(r==0); + + r = pthread_mutex_unlock( &mx1 ); assert(r==0); + r = pthread_mutex_unlock( &mx2 ); assert(r==0); + + r = pthread_mutex_destroy( &mx1 ); + r = pthread_mutex_destroy( &mx2 ); + + return 0; +} Added: branches/THRCHECK/thrcheck/tests/tc13_laog1.stderr.exp =================================================================== Added: branches/THRCHECK/thrcheck/tests/tc13_laog1.stdout.exp =================================================================== Added: branches/THRCHECK/thrcheck/tests/tc13_laog1.vgtest =================================================================== --- branches/THRCHECK/thrcheck/tests/tc13_laog1.vgtest (rev 0) +++ branches/THRCHECK/thrcheck/tests/tc13_laog1.vgtest 2007-10-03 20:34:03 UTC (rev 6933) @@ -0,0 +1 @@ +prog: tc13_laog1 Added: branches/THRCHECK/thrcheck/tests/tc14_laog_dinphils.c =================================================================== --- branches/THRCHECK/thrcheck/tests/tc14_laog_dinphils.c (rev 0) +++ branches/THRCHECK/thrcheck/tests/tc14_laog_dinphils.c 2007-10-03 20:34:03 UTC (rev 6933) @@ -0,0 +1,42 @@ + +#include <pthread.h> +#include <stdlib.h> +#include <unistd.h> + +/* Naive dining philosophers with inconsistent lock acquisition + ordering. */ + +static pthread_t phil[5]; +static pthread_mutex_t chop[5]; + +void* dine ( void* arg ) +{ + int i; + long left = (long)arg; + long right = (left + 1) % 5; + for (i = 0; i < 1000/*arbitrary*/; i++) { + pthread_mutex_lock(&chop[left]); + pthread_mutex_lock(&chop[right]); + /* eating */ + pthread_mutex_unlock(&chop[left]); + pthread_mutex_unlock(&chop[right]); + } + return NULL; +} + +int main ( void ) +{ + long i; + for (i = 0; i < 5; i++) + pthread_mutex_init( &chop[i], NULL); + + for (i = 0; i < 5; i++) + pthread_create(&phil[i], NULL, dine, (void*)i ); + + sleep(1); + + for (i = 0; i < 5; i++) + pthread_join(phil[i], NULL); + + return 0; +} Added: branches/THRCHECK/thrcheck/tests/tc14_laog_dinphils.stderr.exp =================================================================== Added: branches/THRCHECK/thrcheck/tests/tc14_laog_dinphils.stdout.exp =================================================================== Added: branches/THRCHECK/thrcheck/tests/tc14_laog_dinphils.vgtest =================================================================== --- branches/THRCHECK/thrcheck/tests/tc14_laog_dinphils.vgtest (rev 0) +++ branches/THRCHECK/thrcheck/tests/tc14_laog_dinphils.vgtest 2007-10-03 20:34:03 UTC (rev 6933) @@ -0,0 +1 @@ +prog: tc14_laog_dinphils Added: branches/THRCHECK/thrcheck/tests/tc15_laog_lockdel.c =================================================================== --- branches/THRCHECK/thrcheck/tests/tc15_laog_lockdel.c (rev 0) +++ branches/THRCHECK/thrcheck/tests/tc15_laog_lockdel.c 2007-10-03 20:34:03 UTC (rev 6933) @@ -0,0 +1,67 @@ + +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> + +/* The simplest possible test that triggers a lock order acquisition + error. */ + +int main ( void ) +{ + int r; + pthread_mutex_t *mx1, *mx2; + + mx1 = malloc(sizeof(pthread_mutex_t)); + mx2 = malloc(sizeof(pthread_mutex_t)); + + assert(mx1); + assert(mx2); + + r = pthread_mutex_init( mx1, NULL ); assert(r==0); + r = pthread_mutex_init( mx2, NULL ); assert(r==0); + + /* Establish order 1 -> 2 */ + fprintf(stderr, "Establish order 1 -> 2\n"); + r = pthread_mutex_lock( mx1 ); assert(r==0); + r = pthread_mutex_lock( mx2 ); assert(r==0); + + r = pthread_mutex_unlock( mx1 ); assert(r==0); + r = pthread_mutex_unlock( mx2 ); assert(r==0); + + /* Try order 2 -> 1. This gives an error. */ + fprintf(stderr, "Try order 2 -> 1. This gives an error.\n"); + r = pthread_mutex_lock( mx2 ); assert(r==0); /* error */ + r = pthread_mutex_lock( mx1 ); assert(r==0); + + r = pthread_mutex_unlock( mx1 ); assert(r==0); + r = pthread_mutex_unlock( mx2 ); assert(r==0); + + /* Free 2 and re-allocate it. This gives it a new identity, + so a second locking sequence 2 -> 1 should now be OK. */ + fprintf(stderr, + "Free 2 and re-allocate it. This gives it a new identity,\n"); + fprintf(stderr, "so a second locking sequence 2 -> 1 should now be OK.\n"); + pthread_mutex_destroy( mx2 ); + free(mx2); + mx2 = malloc(sizeof(pthread_mutex_t)); + assert(mx2); + r = pthread_mutex_init( mx2, NULL ); assert(r==0); + + r = pthread_mutex_lock( mx2 ); assert(r==0); /* error */ + r = pthread_mutex_lock( mx1 ); assert(r==0); + + r = pthread_mutex_unlock( mx1 ); assert(r==0); + r = pthread_mutex_unlock( mx2 ); assert(r==0); + + /* done */ + + fprintf(stderr, "done\n"); + r = pthread_mutex_destroy( mx1 ); + r = pthread_mutex_destroy( mx2 ); + + free( mx1 ); + free( mx2 ); + + return 0; +} Added: branches/THRCHECK/thrcheck/tests/tc15_laog_lockdel.stderr.exp =================================================================== Added: branches/THRCHECK/thrcheck/tests/tc15_laog_lockdel.stdout.exp =================================================================== Added: branches/THRCHECK/thrcheck/tests/tc15_laog_lockdel.vgtest =================================================================== --- branches/THRCHECK/thrcheck/tests/tc15_laog_lockdel.vgtest (rev 0) +++ branches/THRCHECK/thrcheck/tests/tc15_laog_lockdel.vgtest 2007-10-03 20:34:03 UTC (rev 6933) @@ -0,0 +1 @@ +prog: tc15_laog_lockdel ------------------------------------------------------------------------- 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