|
From: <sv...@va...> - 2008-05-14 12:22:09
|
Author: bart
Date: 2008-05-14 13:22:15 +0100 (Wed, 14 May 2008)
New Revision: 8077
Log:
Added hold_lock regression test.
Added:
trunk/exp-drd/tests/hold_lock.c
trunk/exp-drd/tests/hold_lock_1.stderr.exp
trunk/exp-drd/tests/hold_lock_1.vgtest
trunk/exp-drd/tests/hold_lock_2.stderr.exp
trunk/exp-drd/tests/hold_lock_2.vgtest
Modified:
trunk/exp-drd/tests/Makefile.am
Modified: trunk/exp-drd/tests/Makefile.am
===================================================================
--- trunk/exp-drd/tests/Makefile.am 2008-05-14 12:21:29 UTC (rev 8076)
+++ trunk/exp-drd/tests/Makefile.am 2008-05-14 12:22:15 UTC (rev 8077)
@@ -34,6 +34,10 @@
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 @@
hg04_race \
hg05_race2 \
hg06_readshared \
+ hold_lock \
linuxthreads_det \
matinv \
memory_allocation \
@@ -240,6 +245,9 @@
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
Added: trunk/exp-drd/tests/hold_lock.c
===================================================================
--- trunk/exp-drd/tests/hold_lock.c (rev 0)
+++ trunk/exp-drd/tests/hold_lock.c 2008-05-14 12:22:15 UTC (rev 8077)
@@ -0,0 +1,79 @@
+/** Hold several types of synchronization objects locked as long as specified.
+ */
+
+#define _GNU_SOURCE 1
+
+#include <assert.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+
+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 <interval time in ms>].\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;
+}
Added: trunk/exp-drd/tests/hold_lock_1.stderr.exp
===================================================================
--- trunk/exp-drd/tests/hold_lock_1.stderr.exp (rev 0)
+++ trunk/exp-drd/tests/hold_lock_1.stderr.exp 2008-05-14 12:22:15 UTC (rev 8077)
@@ -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)
Added: trunk/exp-drd/tests/hold_lock_1.vgtest
===================================================================
--- trunk/exp-drd/tests/hold_lock_1.vgtest (rev 0)
+++ trunk/exp-drd/tests/hold_lock_1.vgtest 2008-05-14 12:22:15 UTC (rev 8077)
@@ -0,0 +1,4 @@
+prereq: ./supported_libpthread
+prog: hold_lock
+vgopts: --exclusive-threshold=500 --shared-threshold=2000
+args: -i 1000
Added: trunk/exp-drd/tests/hold_lock_2.stderr.exp
===================================================================
--- trunk/exp-drd/tests/hold_lock_2.stderr.exp (rev 0)
+++ trunk/exp-drd/tests/hold_lock_2.stderr.exp 2008-05-14 12:22:15 UTC (rev 8077)
@@ -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)
Added: trunk/exp-drd/tests/hold_lock_2.vgtest
===================================================================
--- trunk/exp-drd/tests/hold_lock_2.vgtest (rev 0)
+++ trunk/exp-drd/tests/hold_lock_2.vgtest 2008-05-14 12:22:15 UTC (rev 8077)
@@ -0,0 +1,4 @@
+prereq: ./supported_libpthread
+prog: hold_lock
+vgopts: --exclusive-threshold=2000 --shared-threshold=500
+args: -i 1000
|