]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Added hold_lock regression test.
authorBart Van Assche <bvanassche@acm.org>
Wed, 14 May 2008 12:22:15 +0000 (12:22 +0000)
committerBart Van Assche <bvanassche@acm.org>
Wed, 14 May 2008 12:22:15 +0000 (12:22 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8077

exp-drd/tests/Makefile.am
exp-drd/tests/hold_lock.c [new file with mode: 0644]
exp-drd/tests/hold_lock_1.stderr.exp [new file with mode: 0644]
exp-drd/tests/hold_lock_1.vgtest [new file with mode: 0644]
exp-drd/tests/hold_lock_2.stderr.exp [new file with mode: 0644]
exp-drd/tests/hold_lock_2.vgtest [new file with mode: 0644]

index 0f6d20a7f563f8e0e0833bb05a348570db4b7e60..f668b0aa3373acb0bedb412792ec5a0db5fcdcb5 100644 (file)
@@ -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 (file)
index 0000000..cf5ad9c
--- /dev/null
@@ -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;
+}
diff --git a/exp-drd/tests/hold_lock_1.stderr.exp b/exp-drd/tests/hold_lock_1.stderr.exp
new file mode 100644 (file)
index 0000000..2571d62
--- /dev/null
@@ -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 (file)
index 0000000..aeeddb3
--- /dev/null
@@ -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 (file)
index 0000000..b4a5acf
--- /dev/null
@@ -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 (file)
index 0000000..d1611b1
--- /dev/null
@@ -0,0 +1,4 @@
+prereq: ./supported_libpthread
+prog: hold_lock
+vgopts: --exclusive-threshold=2000 --shared-threshold=500
+args: -i 1000