mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-06 19:54:18 +00:00
Added hold_lock regression test.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8077
This commit is contained in:
parent
2e233846bf
commit
0527fbdd0a
@ -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
|
||||
|
||||
|
||||
79
exp-drd/tests/hold_lock.c
Normal file
79
exp-drd/tests/hold_lock.c
Normal file
@ -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;
|
||||
}
|
||||
20
exp-drd/tests/hold_lock_1.stderr.exp
Normal file
20
exp-drd/tests/hold_lock_1.stderr.exp
Normal file
@ -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)
|
||||
4
exp-drd/tests/hold_lock_1.vgtest
Normal file
4
exp-drd/tests/hold_lock_1.vgtest
Normal file
@ -0,0 +1,4 @@
|
||||
prereq: ./supported_libpthread
|
||||
prog: hold_lock
|
||||
vgopts: --exclusive-threshold=500 --shared-threshold=2000
|
||||
args: -i 1000
|
||||
13
exp-drd/tests/hold_lock_2.stderr.exp
Normal file
13
exp-drd/tests/hold_lock_2.stderr.exp
Normal file
@ -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)
|
||||
4
exp-drd/tests/hold_lock_2.vgtest
Normal file
4
exp-drd/tests/hold_lock_2.vgtest
Normal file
@ -0,0 +1,4 @@
|
||||
prereq: ./supported_libpthread
|
||||
prog: hold_lock
|
||||
vgopts: --exclusive-threshold=2000 --shared-threshold=500
|
||||
args: -i 1000
|
||||
Loading…
x
Reference in New Issue
Block a user