From: <sv...@va...> - 2009-02-20 19:00:26
|
Author: bart Date: 2009-02-20 19:00:18 +0000 (Fri, 20 Feb 2009) New Revision: 9206 Log: Moved drd/tests/pth_barrier.c, drd/tests/rwlock_race.c and drd/tests/rwlock_test.c back to their original location. Added: trunk/drd/tests/pth_barrier.c trunk/drd/tests/rwlock_race.c trunk/drd/tests/rwlock_test.c Removed: trunk/helgrind/tests/pth_barrier.c trunk/helgrind/tests/rwlock_race.c trunk/helgrind/tests/rwlock_test.c Modified: trunk/drd/tests/Makefile.am trunk/drd/tests/pth_barrier.vgtest trunk/drd/tests/pth_barrier2.vgtest trunk/drd/tests/pth_barrier3.vgtest trunk/drd/tests/rwlock_race.vgtest trunk/drd/tests/rwlock_test.vgtest trunk/helgrind/tests/Makefile.am trunk/helgrind/tests/pth_barrier1.vgtest trunk/helgrind/tests/pth_barrier2.vgtest trunk/helgrind/tests/pth_barrier3.vgtest trunk/helgrind/tests/rwlock_race.vgtest trunk/helgrind/tests/rwlock_test.vgtest Modified: trunk/drd/tests/Makefile.am =================================================================== --- trunk/drd/tests/Makefile.am 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/drd/tests/Makefile.am 2009-02-20 19:00:18 UTC (rev 9206) @@ -203,6 +203,8 @@ memory_allocation \ monitor_example \ new_delete \ + rwlock_race \ + rwlock_test \ pth_broadcast \ pth_cancel_locked \ pth_cond_race \ @@ -224,7 +226,7 @@ endif if HAVE_PTHREAD_BARRIER -check_PROGRAMS += matinv pth_barrier_reinit +check_PROGRAMS += matinv pth_barrier pth_barrier_reinit endif if HAVE_PTHREAD_SPINLOCK Copied: trunk/drd/tests/pth_barrier.c (from rev 9205, trunk/helgrind/tests/pth_barrier.c) =================================================================== --- trunk/drd/tests/pth_barrier.c (rev 0) +++ trunk/drd/tests/pth_barrier.c 2009-02-20 19:00:18 UTC (rev 9206) @@ -0,0 +1,110 @@ +/* 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; +} Modified: trunk/drd/tests/pth_barrier.vgtest =================================================================== --- trunk/drd/tests/pth_barrier.vgtest 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/drd/tests/pth_barrier.vgtest 2009-02-20 19:00:18 UTC (rev 9206) @@ -1,4 +1,4 @@ -prereq: test -e ../../helgrind/tests/pth_barrier && ./supported_libpthread -prog: ../../helgrind/tests/pth_barrier +prereq: test -e pth_barrier && ./supported_libpthread +prog: pth_barrier args: 2 1 1 stderr_filter: filter_error_summary Modified: trunk/drd/tests/pth_barrier2.vgtest =================================================================== --- trunk/drd/tests/pth_barrier2.vgtest 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/drd/tests/pth_barrier2.vgtest 2009-02-20 19:00:18 UTC (rev 9206) @@ -1,4 +1,4 @@ -prereq: test -e ../../helgrind/tests/pth_barrier && ./supported_libpthread -prog: ../../helgrind/tests/pth_barrier +prereq: test -e pth_barrier && ./supported_libpthread +prog: pth_barrier args: 2 32 1 stderr_filter: filter_error_summary Modified: trunk/drd/tests/pth_barrier3.vgtest =================================================================== --- trunk/drd/tests/pth_barrier3.vgtest 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/drd/tests/pth_barrier3.vgtest 2009-02-20 19:00:18 UTC (rev 9206) @@ -1,4 +1,4 @@ -prereq: test -e ../../helgrind/tests/pth_barrier && ./supported_libpthread -prog: ../../helgrind/tests/pth_barrier +prereq: test -e pth_barrier && ./supported_libpthread +prog: pth_barrier args: 32 1 1 stderr_filter: filter_error_summary Copied: trunk/drd/tests/rwlock_race.c (from rev 9205, trunk/helgrind/tests/rwlock_race.c) =================================================================== --- trunk/drd/tests/rwlock_race.c (rev 0) +++ trunk/drd/tests/rwlock_race.c 2009-02-20 19:00:18 UTC (rev 9206) @@ -0,0 +1,56 @@ +/** 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; +} Modified: trunk/drd/tests/rwlock_race.vgtest =================================================================== --- trunk/drd/tests/rwlock_race.vgtest 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/drd/tests/rwlock_race.vgtest 2009-02-20 19:00:18 UTC (rev 9206) @@ -1,3 +1,3 @@ prereq: ./supported_libpthread vgopts: --var-info=yes -prog: ../../helgrind/tests/rwlock_race +prog: rwlock_race Copied: trunk/drd/tests/rwlock_test.c (from rev 9205, trunk/helgrind/tests/rwlock_test.c) =================================================================== --- trunk/drd/tests/rwlock_test.c (rev 0) +++ trunk/drd/tests/rwlock_test.c 2009-02-20 19:00:18 UTC (rev 9206) @@ -0,0 +1,52 @@ +/** 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; +} Modified: trunk/drd/tests/rwlock_test.vgtest =================================================================== --- trunk/drd/tests/rwlock_test.vgtest 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/drd/tests/rwlock_test.vgtest 2009-02-20 19:00:18 UTC (rev 9206) @@ -1 +1 @@ -prog: ../../helgrind/tests/rwlock_test +prog: rwlock_test Modified: trunk/helgrind/tests/Makefile.am =================================================================== --- trunk/helgrind/tests/Makefile.am 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/helgrind/tests/Makefile.am 2009-02-20 19:00:18 UTC (rev 9206) @@ -126,8 +126,6 @@ hg04_race \ hg05_race2 \ hg06_readshared \ - rwlock_race \ - rwlock_test \ tc01_simple_race \ tc02_simple_tls \ tc03_re_excl \ @@ -154,7 +152,7 @@ tc24_nonzero_sem if HAVE_PTHREAD_BARRIER -check_PROGRAMS += bar_bad bar_trivial pth_barrier +check_PROGRAMS += bar_bad bar_trivial endif Deleted: trunk/helgrind/tests/pth_barrier.c =================================================================== --- trunk/helgrind/tests/pth_barrier.c 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/helgrind/tests/pth_barrier.c 2009-02-20 19:00:18 UTC (rev 9206) @@ -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; -} Modified: trunk/helgrind/tests/pth_barrier1.vgtest =================================================================== --- trunk/helgrind/tests/pth_barrier1.vgtest 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/helgrind/tests/pth_barrier1.vgtest 2009-02-20 19:00:18 UTC (rev 9206) @@ -1,4 +1,4 @@ prereq: test -e bar_trivial -prog: pth_barrier +prog: ../../drd/tests/pth_barrier args: 2 1 1 vgopts: -q Modified: trunk/helgrind/tests/pth_barrier2.vgtest =================================================================== --- trunk/helgrind/tests/pth_barrier2.vgtest 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/helgrind/tests/pth_barrier2.vgtest 2009-02-20 19:00:18 UTC (rev 9206) @@ -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 Modified: trunk/helgrind/tests/pth_barrier3.vgtest =================================================================== --- trunk/helgrind/tests/pth_barrier3.vgtest 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/helgrind/tests/pth_barrier3.vgtest 2009-02-20 19:00:18 UTC (rev 9206) @@ -1,4 +1,4 @@ prereq: test -e bar_trivial -prog: pth_barrier +prog: ../../drd/tests/pth_barrier args: 32 1 1 vgopts: -q Deleted: trunk/helgrind/tests/rwlock_race.c =================================================================== --- trunk/helgrind/tests/rwlock_race.c 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/helgrind/tests/rwlock_race.c 2009-02-20 19:00:18 UTC (rev 9206) @@ -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; -} Modified: trunk/helgrind/tests/rwlock_race.vgtest =================================================================== --- trunk/helgrind/tests/rwlock_race.vgtest 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/helgrind/tests/rwlock_race.vgtest 2009-02-20 19:00:18 UTC (rev 9206) @@ -1,2 +1,2 @@ -prog: rwlock_race +prog: ../../drd/tests/rwlock_race vgopts: --read-var-info=yes Deleted: trunk/helgrind/tests/rwlock_test.c =================================================================== --- trunk/helgrind/tests/rwlock_test.c 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/helgrind/tests/rwlock_test.c 2009-02-20 19:00:18 UTC (rev 9206) @@ -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; -} Modified: trunk/helgrind/tests/rwlock_test.vgtest =================================================================== --- trunk/helgrind/tests/rwlock_test.vgtest 2009-02-20 06:37:52 UTC (rev 9205) +++ trunk/helgrind/tests/rwlock_test.vgtest 2009-02-20 19:00:18 UTC (rev 9206) @@ -1 +1 @@ -prog: rwlock_test +prog: ../../drd/tests/rwlock_test |