From: Bart Van Assche Date: Wed, 14 May 2008 12:22:15 +0000 (+0000) Subject: Added hold_lock regression test. X-Git-Tag: svn/VALGRIND_3_4_0~568 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0527fbdd0a6950c113bacc7d88dfd0eccccac192;p=thirdparty%2Fvalgrind.git Added hold_lock regression test. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8077 --- diff --git a/exp-drd/tests/Makefile.am b/exp-drd/tests/Makefile.am index 0f6d20a7f5..f668b0aa33 100644 --- a/exp-drd/tests/Makefile.am +++ b/exp-drd/tests/Makefile.am @@ -34,6 +34,10 @@ EXTRA_DIST = \ hg05_race2.vgtest \ hg06_readshared.stderr.exp \ hg06_readshared.vgtest \ + hold_lock_1.stderr.exp \ + hold_lock_1.vgtest \ + hold_lock_2.stderr.exp \ + hold_lock_2.vgtest \ linuxthreads_det.stderr.exp \ linuxthreads_det.stderr.exp-linuxthreads \ linuxthreads_det.stdout.exp \ @@ -164,6 +168,7 @@ check_PROGRAMS_COMMON = \ hg04_race \ hg05_race2 \ hg06_readshared \ + hold_lock \ linuxthreads_det \ matinv \ memory_allocation \ @@ -240,6 +245,9 @@ hg05_race2_LDADD = -lpthread hg06_readshared_SOURCES = ../../helgrind/tests/hg06_readshared.c hg06_readshared_LDADD = -lpthread +hold_lock_SOURCES = hold_lock.c +hold_lock_LDADD = -lpthread + linuxthreads_det_SOURCES = linuxthreads_det.c linuxthreads_det_LDADD = -lpthread diff --git a/exp-drd/tests/hold_lock.c b/exp-drd/tests/hold_lock.c new file mode 100644 index 0000000000..cf5ad9cd56 --- /dev/null +++ b/exp-drd/tests/hold_lock.c @@ -0,0 +1,79 @@ +/** Hold several types of synchronization objects locked as long as specified. + */ + +#define _GNU_SOURCE 1 + +#include +#include +#include +#include +#include +#include + + +static void delay_ms(const int ms) +{ + struct timespec ts; + + assert(ms >= 0); + ts.tv_sec = ms / 1000; + ts.tv_nsec = (ms % 1000) * 1000 * 1000; + nanosleep(&ts, 0); +} + +int main(int argc, char** argv) +{ + int interval = 0; + int optchar; + pthread_mutex_t mutex; + pthread_mutexattr_t mutexattr; + pthread_rwlock_t rwlock; + + while ((optchar = getopt(argc, argv, "i:")) != EOF) + { + switch (optchar) + { + case 'i': + interval = atoi(optarg); + break; + default: + fprintf(stderr, "Usage: %s [-i ].\n", argv[0]); + break; + } + } + + fprintf(stderr, "Locking mutex ...\n"); + + pthread_mutexattr_init(&mutexattr); + pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&mutex, &mutexattr); + pthread_mutexattr_destroy(&mutexattr); + pthread_mutex_lock(&mutex); + delay_ms(interval); + pthread_mutex_lock(&mutex); + pthread_mutex_unlock(&mutex); + pthread_mutex_unlock(&mutex); + pthread_mutex_destroy(&mutex); + + fprintf(stderr, "Locking rwlock exclusively ...\n"); + + pthread_rwlock_init(&rwlock, 0); + pthread_rwlock_wrlock(&rwlock); + delay_ms(interval); + pthread_rwlock_unlock(&rwlock); + pthread_rwlock_destroy(&rwlock); + + fprintf(stderr, "Locking rwlock shared ...\n"); + + pthread_rwlock_init(&rwlock, 0); + pthread_rwlock_rdlock(&rwlock); + delay_ms(interval); + pthread_rwlock_rdlock(&rwlock); + pthread_rwlock_unlock(&rwlock); + pthread_rwlock_unlock(&rwlock); + pthread_rwlock_destroy(&rwlock); + + fprintf(stderr, "Done.\n"); + + return 0; +} diff --git a/exp-drd/tests/hold_lock_1.stderr.exp b/exp-drd/tests/hold_lock_1.stderr.exp new file mode 100644 index 0000000000..2571d62745 --- /dev/null +++ b/exp-drd/tests/hold_lock_1.stderr.exp @@ -0,0 +1,20 @@ + +Locking mutex ... +Acquired at: + at 0x........: pthread_mutex_lock (drd_pthread_intercepts.c:?) + by 0x........: main (hold_lock.c:?) +Lock on mutex 0x........ was held during ... ms (threshold: 500 ms). + at 0x........: pthread_mutex_unlock (drd_pthread_intercepts.c:?) + by 0x........: main (hold_lock.c:?) +Locking rwlock exclusively ... + +Acquired at: + at 0x........: pthread_rwlock_wrlock* (drd_pthread_intercepts.c:?) + by 0x........: main (hold_lock.c:?) +Lock on rwlock 0x........ was held during ... ms (threshold: 500 ms). + at 0x........: pthread_rwlock_unlock* (drd_pthread_intercepts.c:?) + by 0x........: main (hold_lock.c:?) +Locking rwlock shared ... +Done. + +ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0) diff --git a/exp-drd/tests/hold_lock_1.vgtest b/exp-drd/tests/hold_lock_1.vgtest new file mode 100644 index 0000000000..aeeddb3a5e --- /dev/null +++ b/exp-drd/tests/hold_lock_1.vgtest @@ -0,0 +1,4 @@ +prereq: ./supported_libpthread +prog: hold_lock +vgopts: --exclusive-threshold=500 --shared-threshold=2000 +args: -i 1000 diff --git a/exp-drd/tests/hold_lock_2.stderr.exp b/exp-drd/tests/hold_lock_2.stderr.exp new file mode 100644 index 0000000000..b4a5acffd9 --- /dev/null +++ b/exp-drd/tests/hold_lock_2.stderr.exp @@ -0,0 +1,13 @@ + +Locking mutex ... +Locking rwlock exclusively ... +Locking rwlock shared ... +Acquired at: + at 0x........: pthread_rwlock_rdlock* (drd_pthread_intercepts.c:?) + by 0x........: main (hold_lock.c:?) +Lock on rwlock 0x........ was held during ... ms (threshold: 500 ms). + at 0x........: pthread_rwlock_unlock* (drd_pthread_intercepts.c:?) + by 0x........: main (hold_lock.c:?) +Done. + +ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) diff --git a/exp-drd/tests/hold_lock_2.vgtest b/exp-drd/tests/hold_lock_2.vgtest new file mode 100644 index 0000000000..d1611b12c3 --- /dev/null +++ b/exp-drd/tests/hold_lock_2.vgtest @@ -0,0 +1,4 @@ +prereq: ./supported_libpthread +prog: hold_lock +vgopts: --exclusive-threshold=2000 --shared-threshold=500 +args: -i 1000