diff options
author | bart <bart@a5019735-40e9-0310-863c-91ae7b9d1cf9> | 2009-02-20 19:00:18 +0000 |
---|---|---|
committer | bart <bart@a5019735-40e9-0310-863c-91ae7b9d1cf9> | 2009-02-20 19:00:18 +0000 |
commit | b5d3abdfddffc9c8e0dfee8065a5a74a0a049823 (patch) | |
tree | a6642b1f6114f5acecdfd870b6ede5c1edfa66c1 /helgrind | |
parent | 221666fbecd5198908befdb3d21d6c5ea9835a57 (diff) | |
download | valgrind-b5d3abdfddffc9c8e0dfee8065a5a74a0a049823.tar.gz |
Moved drd/tests/pth_barrier.c, drd/tests/rwlock_race.c and
drd/tests/rwlock_test.c back to their original location.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9206 a5019735-40e9-0310-863c-91ae7b9d1cf9
Diffstat (limited to 'helgrind')
-rw-r--r-- | helgrind/tests/Makefile.am | 4 | ||||
-rw-r--r-- | helgrind/tests/pth_barrier.c | 110 | ||||
-rw-r--r-- | helgrind/tests/pth_barrier1.vgtest | 2 | ||||
-rw-r--r-- | helgrind/tests/pth_barrier2.vgtest | 2 | ||||
-rw-r--r-- | helgrind/tests/pth_barrier3.vgtest | 2 | ||||
-rw-r--r-- | helgrind/tests/rwlock_race.c | 56 | ||||
-rw-r--r-- | helgrind/tests/rwlock_race.vgtest | 2 | ||||
-rw-r--r-- | helgrind/tests/rwlock_test.c | 52 | ||||
-rw-r--r-- | helgrind/tests/rwlock_test.vgtest | 2 |
9 files changed, 6 insertions, 226 deletions
diff --git a/helgrind/tests/Makefile.am b/helgrind/tests/Makefile.am index 23d84428e..6ffecd8b1 100644 --- a/helgrind/tests/Makefile.am +++ b/helgrind/tests/Makefile.am @@ -126,8 +126,6 @@ check_PROGRAMS = \ hg04_race \ hg05_race2 \ hg06_readshared \ - rwlock_race \ - rwlock_test \ tc01_simple_race \ tc02_simple_tls \ tc03_re_excl \ @@ -154,7 +152,7 @@ check_PROGRAMS = \ tc24_nonzero_sem if HAVE_PTHREAD_BARRIER -check_PROGRAMS += bar_bad bar_trivial pth_barrier +check_PROGRAMS += bar_bad bar_trivial endif diff --git a/helgrind/tests/pth_barrier.c b/helgrind/tests/pth_barrier.c deleted file mode 100644 index e0b40a7a1..000000000 --- a/helgrind/tests/pth_barrier.c +++ /dev/null @@ -1,110 +0,0 @@ -/* Test whether all data races are detected in a multithreaded program with - * barriers. - */ - - -#define _GNU_SOURCE - -/***********************/ -/* Include directives. */ -/***********************/ - -#include <assert.h> -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> - - -/*********************/ -/* Type definitions. */ -/*********************/ - -struct threadinfo -{ - pthread_barrier_t* b; - pthread_t tid; - int* array; - int iterations; -}; - - -/********************/ -/* Local variables. */ -/********************/ - -static int s_silent; - - -/*************************/ -/* Function definitions. */ -/*************************/ - -/** Single thread, which touches p->iterations elements of array p->array. - * Each modification of an element of p->array is a data race. */ -static void* threadfunc(struct threadinfo* p) -{ - int i; - int* const array = p->array; - pthread_barrier_t* const b = p->b; - if (! s_silent) - printf("thread %lx iteration 0\n", pthread_self()); - pthread_barrier_wait(b); - for (i = 0; i < p->iterations; i++) - { - if (! s_silent) - printf("thread %lx iteration %d; writing to %p\n", - pthread_self(), i + 1, &array[i]); - array[i] = i; - pthread_barrier_wait(b); - } - return 0; -} - -/** Actual test, consisting of nthread threads. */ -static void barriers_and_races(const int nthread, const int iterations) -{ - int i; - struct threadinfo* t; - pthread_barrier_t b; - int* array; - - t = malloc(nthread * sizeof(struct threadinfo)); - array = malloc(iterations * sizeof(array[0])); - - if (! s_silent) - printf("&array[0] = %p\n", array); - - pthread_barrier_init(&b, 0, nthread); - - for (i = 0; i < nthread; i++) - { - t[i].b = &b; - t[i].array = array; - t[i].iterations = iterations; - pthread_create(&t[i].tid, 0, (void*(*)(void*))threadfunc, &t[i]); - } - - for (i = 0; i < nthread; i++) - { - pthread_join(t[i].tid, 0); - } - - pthread_barrier_destroy(&b); - - free(array); - free(t); -} - -int main(int argc, char** argv) -{ - int nthread; - int iterations; - - nthread = (argc > 1) ? atoi(argv[1]) : 2; - iterations = (argc > 2) ? atoi(argv[2]) : 3; - s_silent = (argc > 3) ? atoi(argv[3]) : 0; - - barriers_and_races(nthread, iterations); - - return 0; -} diff --git a/helgrind/tests/pth_barrier1.vgtest b/helgrind/tests/pth_barrier1.vgtest index f28eb6674..7b0d62f1c 100644 --- a/helgrind/tests/pth_barrier1.vgtest +++ b/helgrind/tests/pth_barrier1.vgtest @@ -1,4 +1,4 @@ prereq: test -e bar_trivial -prog: pth_barrier +prog: ../../drd/tests/pth_barrier args: 2 1 1 vgopts: -q diff --git a/helgrind/tests/pth_barrier2.vgtest b/helgrind/tests/pth_barrier2.vgtest index d9bb01aa7..13036b39c 100644 --- a/helgrind/tests/pth_barrier2.vgtest +++ b/helgrind/tests/pth_barrier2.vgtest @@ -1,4 +1,4 @@ prereq: test -e bar_trivial -prog: pth_barrier +prog: ../../drd/tests/pth_barrier args: 2 32 1 vgopts: -q --cmp-race-err-addrs=yes diff --git a/helgrind/tests/pth_barrier3.vgtest b/helgrind/tests/pth_barrier3.vgtest index d17e7824f..06ab6c353 100644 --- a/helgrind/tests/pth_barrier3.vgtest +++ b/helgrind/tests/pth_barrier3.vgtest @@ -1,4 +1,4 @@ prereq: test -e bar_trivial -prog: pth_barrier +prog: ../../drd/tests/pth_barrier args: 32 1 1 vgopts: -q diff --git a/helgrind/tests/rwlock_race.c b/helgrind/tests/rwlock_race.c deleted file mode 100644 index e07524f09..000000000 --- a/helgrind/tests/rwlock_race.c +++ /dev/null @@ -1,56 +0,0 @@ -/** Cause a race inside code protected by a reader lock. - */ - - -/* Needed for older glibc's (2.3 and older, at least) who don't - otherwise "know" about pthread_rwlock_anything or about - PTHREAD_MUTEX_RECURSIVE (amongst things). */ - -#define _GNU_SOURCE 1 - -#include <pthread.h> -#include <stdio.h> -#include <unistd.h> - - - -static pthread_rwlock_t s_rwlock; -static int s_racy; - -static void sleep_ms(const int ms) -{ - struct timespec delay = { ms / 1000, (ms % 1000) * 1000 * 1000 }; - nanosleep(&delay, 0); -} - -static void* thread_func(void* arg) -{ - pthread_rwlock_rdlock(&s_rwlock); - s_racy++; - pthread_rwlock_unlock(&s_rwlock); - sleep_ms(100); - return 0; -} - -int main(int argc, char** argv) -{ - pthread_t thread1; - pthread_t thread2; - -#if 0 - int res; - VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__DRD_TRACE_ADDR, - &s_racy, 0, 0, 0, 0); -#endif - - pthread_rwlock_init(&s_rwlock, 0); - pthread_create(&thread1, 0, thread_func, 0); - pthread_create(&thread2, 0, thread_func, 0); - pthread_join(thread1, 0); - pthread_join(thread2, 0); - pthread_rwlock_destroy(&s_rwlock); - - fprintf(stderr, "Result: %d\n", s_racy); - - return 0; -} diff --git a/helgrind/tests/rwlock_race.vgtest b/helgrind/tests/rwlock_race.vgtest index a7be20509..00b462f2c 100644 --- a/helgrind/tests/rwlock_race.vgtest +++ b/helgrind/tests/rwlock_race.vgtest @@ -1,2 +1,2 @@ -prog: rwlock_race +prog: ../../drd/tests/rwlock_race vgopts: --read-var-info=yes diff --git a/helgrind/tests/rwlock_test.c b/helgrind/tests/rwlock_test.c deleted file mode 100644 index 87731f5b2..000000000 --- a/helgrind/tests/rwlock_test.c +++ /dev/null @@ -1,52 +0,0 @@ -/** Multithreaded test program that triggers various access patterns without - * triggering any race conditions. - */ - - -#define _GNU_SOURCE 1 - -#include <pthread.h> -#include <stdio.h> - - -static pthread_rwlock_t s_rwlock; -static int s_counter; - -static void* thread_func(void* arg) -{ - int i; - int sum = 0; - - for (i = 0; i < 1000; i++) - { - pthread_rwlock_rdlock(&s_rwlock); - sum += s_counter; - pthread_rwlock_unlock(&s_rwlock); - pthread_rwlock_wrlock(&s_rwlock); - s_counter++; - pthread_rwlock_unlock(&s_rwlock); - } - - return 0; -} - -int main(int argc, char** argv) -{ - const int thread_count = 10; - pthread_t tid[thread_count]; - int i; - - for (i = 0; i < thread_count; i++) - { - pthread_create(&tid[i], 0, thread_func, 0); - } - - for (i = 0; i < thread_count; i++) - { - pthread_join(tid[i], 0); - } - - fprintf(stderr, "Finished.\n"); - - return 0; -} diff --git a/helgrind/tests/rwlock_test.vgtest b/helgrind/tests/rwlock_test.vgtest index 6ce026326..4257fc9cf 100644 --- a/helgrind/tests/rwlock_test.vgtest +++ b/helgrind/tests/rwlock_test.vgtest @@ -1 +1 @@ -prog: rwlock_test +prog: ../../drd/tests/rwlock_test |