|
From: <sv...@va...> - 2008-03-02 19:03:19
|
Author: bart
Date: 2008-03-02 19:03:19 +0000 (Sun, 02 Mar 2008)
New Revision: 7536
Log:
Added regression test for pthread_*timedlock() and pthread_*trylock() calls.
Added:
trunk/exp-drd/tests/trylock.c
trunk/exp-drd/tests/trylock.stderr.exp
trunk/exp-drd/tests/trylock.vgtest
Modified:
trunk/exp-drd/tests/Makefile.am
Modified: trunk/exp-drd/tests/Makefile.am
===================================================================
--- trunk/exp-drd/tests/Makefile.am 2008-03-02 18:12:59 UTC (rev 7535)
+++ trunk/exp-drd/tests/Makefile.am 2008-03-02 19:03:19 UTC (rev 7536)
@@ -50,6 +50,8 @@
recursive_mutex.vgtest recursive_mutex.stderr.exp \
sem_as_mutex.vgtest sem_as_mutex.stderr.exp \
sem_as_mutex2.vgtest sem_as_mutex2.stderr.exp \
+ sigalrm.vgtest \
+ sigalrm.stdout.exp sigalrm.stderr.exp \
tc01_simple_race.vgtest \
tc01_simple_race.stderr.exp \
tc02_simple_tls.vgtest \
@@ -93,8 +95,7 @@
tc23_bogus_condwait.stderr.exp \
tc24_nonzero_sem.vgtest \
tc24_nonzero_sem.stderr.exp \
- sigalrm.vgtest \
- sigalrm.stdout.exp sigalrm.stderr.exp
+ trylock.c trylock.stderr.exp
# tc07_hbl1.vgtest
# tc07_hbl1.stderr.exp tc07_hbl1.stdout.exp
@@ -143,7 +144,8 @@
tc21_pthonce \
tc22_exit_w_lock \
tc23_bogus_condwait \
- tc24_nonzero_sem
+ tc24_nonzero_sem \
+ trylock
# tc07_hbl1 -- requires bus locking support.
# tc08_hbl2 -- requires bus locking support.
@@ -266,3 +268,6 @@
tc24_nonzero_sem_SOURCES = ../../helgrind/tests/tc24_nonzero_sem.c
tc24_nonzero_sem_LDADD = -lpthread
+
+trylock_SOURCES = trylock.c
+trylock_LDADD = -lpthread -lrt
Added: trunk/exp-drd/tests/trylock.c
===================================================================
--- trunk/exp-drd/tests/trylock.c (rev 0)
+++ trunk/exp-drd/tests/trylock.c 2008-03-02 19:03:19 UTC (rev 7536)
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <assert.h>
+#include <pthread.h>
+
+int main(int argc, char** argv)
+{
+ int r;
+ pthread_mutex_t mutex;
+ pthread_rwlock_t rwlock;
+ struct timespec abs_timeout;
+
+ r = clock_gettime(CLOCK_REALTIME, &abs_timeout); assert(r == 0);
+ abs_timeout.tv_sec += 10;
+
+ r = pthread_rwlock_init(&rwlock, NULL); assert(r == 0);
+ fprintf(stderr, "Locking rwlock via pthread_rwlock_wrlock().\n");
+ r = pthread_rwlock_wrlock(&rwlock); assert(r == 0);
+ r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
+ fprintf(stderr, "Locking rwlock via pthread_rwlock_trywrlock().\n");
+ r = pthread_rwlock_trywrlock(&rwlock); assert(r == 0);
+ r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
+ fprintf(stderr, "Locking rwlock via pthread_rwlock_timedwrlock().\n");
+ r = pthread_rwlock_timedwrlock(&rwlock, &abs_timeout); assert(r == 0);
+ r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
+ fprintf(stderr, "Locking rwlock via pthread_rwlock_rdlock().\n");
+ r = pthread_rwlock_rdlock(&rwlock); assert(r == 0);
+ r = pthread_rwlock_rdlock(&rwlock); assert(r == 0);
+ r = pthread_rwlock_rdlock(&rwlock); assert(r == 0);
+ r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
+ r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
+ r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
+ fprintf(stderr, "Locking rwlock via pthread_rwlock_tryrdlock().\n");
+ r = pthread_rwlock_tryrdlock(&rwlock); assert(r == 0);
+ r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
+ fprintf(stderr, "Locking rwlock via pthread_rwlock_timedrdlock().\n");
+ r = pthread_rwlock_timedrdlock(&rwlock, &abs_timeout); assert(r == 0);
+ r = pthread_rwlock_unlock(&rwlock); assert(r == 0);
+ r = pthread_rwlock_destroy(&rwlock); assert(r == 0);
+
+ r = pthread_mutex_init(&mutex, NULL); assert(r == 0);
+ fprintf(stderr, "Locking mutex via pthread_mutex_trylock().\n");
+ r = pthread_mutex_trylock(&mutex); assert(r == 0);
+ r = pthread_mutex_unlock(&mutex); assert(r == 0);
+ fprintf(stderr, "Locking mutex via pthread_mutex_lock().\n");
+ r = pthread_mutex_lock(&mutex); assert(r == 0);
+ r = pthread_mutex_unlock(&mutex); assert(r == 0);
+ fprintf(stderr, "Locking mutex via pthread_mutex_timedlock().\n");
+ r = pthread_mutex_timedlock(&mutex, &abs_timeout); assert(r == 0);
+ r = pthread_mutex_unlock(&mutex); assert(r == 0);
+ r = pthread_mutex_destroy(&mutex); assert(r == 0);
+
+ return 0;
+}
Added: trunk/exp-drd/tests/trylock.stderr.exp
===================================================================
--- trunk/exp-drd/tests/trylock.stderr.exp (rev 0)
+++ trunk/exp-drd/tests/trylock.stderr.exp 2008-03-02 19:03:19 UTC (rev 7536)
@@ -0,0 +1,12 @@
+
+Locking rwlock via pthread_rwlock_wrlock().
+Locking rwlock via pthread_rwlock_trywrlock().
+Locking rwlock via pthread_rwlock_timedwrlock().
+Locking rwlock via pthread_rwlock_rdlock().
+Locking rwlock via pthread_rwlock_tryrdlock().
+Locking rwlock via pthread_rwlock_timedrdlock().
+Locking mutex via pthread_mutex_trylock().
+Locking mutex via pthread_mutex_lock().
+Locking mutex via pthread_mutex_timedlock().
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Added: trunk/exp-drd/tests/trylock.vgtest
===================================================================
--- trunk/exp-drd/tests/trylock.vgtest (rev 0)
+++ trunk/exp-drd/tests/trylock.vgtest 2008-03-02 19:03:19 UTC (rev 7536)
@@ -0,0 +1 @@
+prog: trylock
|