|
From: <sv...@va...> - 2010-03-21 17:24:59
|
Author: bart
Date: 2010-03-21 17:24:47 +0000 (Sun, 21 Mar 2010)
New Revision: 11095
Log:
Added two additional regression tests.
Added:
trunk/drd/tests/annotate_barrier.c
trunk/drd/tests/annotate_barrier.stderr.exp
trunk/drd/tests/annotate_barrier.vgtest
trunk/drd/tests/annotate_static.cpp
trunk/drd/tests/annotate_static.stderr.exp
trunk/drd/tests/annotate_static.vgtest
Modified:
trunk/drd/tests/
trunk/drd/tests/Makefile.am
Property changes on: trunk/drd/tests
___________________________________________________________________
Name: svn:ignore
- *.dSYM
*.stderr.diff*
*.stderr.out
*.stdout.diff*
*.stdout.out
.deps
Makefile
Makefile.in
annotate_hb_err
annotate_hb_race
annotate_ignore_rw
annotate_ignore_write
annotate_publish_hg
annotate_rwlock
annotate_smart_pointer
atomic_var
bar_bad
bar_trivial
boost_thread
circular_buffer
custom_alloc
drd_bitmap_test
fp_race
hg01_all_ok
hg02_deadlock
hg03_inherit
hg04_race
hg05_race2
hg06_readshared
hold_lock
linuxthreads_det
matinv
memory_allocation
monitor_example
new_delete
omp_matinv
omp_prime
omp_printf
pth_barrier
pth_barrier_race
pth_barrier_reinit
pth_broadcast
pth_cancel_locked
pth_cleanup_handler
pth_cond_race
pth_create_chain
pth_create_glibc_2_0
pth_detached
pth_detached_sem
pth_inconsistent_cond_wait
pth_mutex_reinit
pth_process_shared_mutex
pth_spinlock
qt4_atomic
qt4_mutex
qt4_rwlock
qt4_semaphore
recursive_mutex
rwlock_race
rwlock_test
rwlock_type_checking
sem_as_mutex
sem_open
sigalrm
tc01_simple_race
tc02_simple_tls
tc03_re_excl
tc04_free_lock
tc05_simple_race
tc06_two_races
tc07_hbl1
tc08_hbl2
tc09_bad_unlock
tc10_rec_lock
tc11_XCHG
tc12_rwl_trivial
tc13_laog1
tc15_laog_lockdel
tc16_byterace
tc17_sembar
tc18_semabuse
tc19_shadowmem
tc20_verifywrap
tc21_pthonce
tc22_exit_w_lock
tc23_bogus_condwait
tc24_nonzero_sem
thread_name
trylock
tsan_unittest
unit_bitmap
unit_vc
vg_regtest.tmp*
+ *.dSYM
*.stderr.diff*
*.stderr.out
*.stdout.diff*
*.stdout.out
.deps
annotate_barrier
annotate_hb_err
annotate_hb_race
annotate_ignore_rw
annotate_ignore_write
annotate_publish_hg
annotate_rwlock
annotate_smart_pointer
annotate_static
atomic_var
bar_bad
bar_trivial
boost_thread
circular_buffer
custom_alloc
drd_bitmap_test
fp_race
hg01_all_ok
hg02_deadlock
hg03_inherit
hg04_race
hg05_race2
hg06_readshared
hold_lock
linuxthreads_det
Makefile
Makefile.in
matinv
memory_allocation
monitor_example
new_delete
omp_matinv
omp_prime
omp_printf
pth_barrier
pth_barrier_race
pth_barrier_reinit
pth_broadcast
pth_cancel_locked
pth_cleanup_handler
pth_cond_race
pth_create_chain
pth_create_glibc_2_0
pth_detached
pth_detached_sem
pth_inconsistent_cond_wait
pth_mutex_reinit
pth_process_shared_mutex
pth_spinlock
qt4_atomic
qt4_mutex
qt4_rwlock
qt4_semaphore
recursive_mutex
rwlock_race
rwlock_test
rwlock_type_checking
sem_as_mutex
sem_open
sigalrm
tc01_simple_race
tc02_simple_tls
tc03_re_excl
tc04_free_lock
tc05_simple_race
tc06_two_races
tc07_hbl1
tc08_hbl2
tc09_bad_unlock
tc10_rec_lock
tc11_XCHG
tc12_rwl_trivial
tc13_laog1
tc15_laog_lockdel
tc16_byterace
tc17_sembar
tc18_semabuse
tc19_shadowmem
tc20_verifywrap
tc21_pthonce
tc22_exit_w_lock
tc23_bogus_condwait
tc24_nonzero_sem
thread_name
trylock
tsan_unittest
unit_bitmap
unit_vc
vg_regtest.tmp*
Modified: trunk/drd/tests/Makefile.am
===================================================================
--- trunk/drd/tests/Makefile.am 2010-03-15 09:03:25 UTC (rev 11094)
+++ trunk/drd/tests/Makefile.am 2010-03-21 17:24:47 UTC (rev 11095)
@@ -14,6 +14,8 @@
tsan_thread_wrappers_pthread.h
EXTRA_DIST = \
+ annotate_barrier.stderr.exp \
+ annotate_barrier.vgtest \
annotate_hb_err.stderr.exp \
annotate_hb_err.vgtest \
annotate_hb_race.stderr.exp \
@@ -48,6 +50,8 @@
annotate_ignore_write2.vgtest \
annotate_trace_memory.stderr.exp \
annotate_trace_memory.vgtest \
+ annotate_static.stderr.exp \
+ annotate_static.vgtest \
atomic_var.stderr.exp \
atomic_var.vgtest \
bar_bad.stderr.exp \
@@ -255,6 +259,7 @@
annotate_ignore_rw \
annotate_ignore_write \
annotate_publish_hg \
+ annotate_static \
custom_alloc \
fp_race \
hold_lock \
@@ -290,6 +295,7 @@
if HAVE_BUILTIN_ATOMIC
check_PROGRAMS += \
+ annotate_barrier \
annotate_rwlock \
annotate_smart_pointer \
atomic_var \
@@ -355,6 +361,8 @@
annotate_smart_pointer_SOURCES = annotate_smart_pointer.cpp
endif
+annotate_static_SOURCES = annotate_static.cpp
+
if HAVE_OPENMP
omp_matinv_CFLAGS = $(AM_CFLAGS) -fopenmp
omp_matinv_LDFLAGS = -fopenmp
Added: trunk/drd/tests/annotate_barrier.c
===================================================================
--- trunk/drd/tests/annotate_barrier.c (rev 0)
+++ trunk/drd/tests/annotate_barrier.c 2010-03-21 17:24:47 UTC (rev 11095)
@@ -0,0 +1,158 @@
+/*
+ * Test whether all data races are detected in a multithreaded program with
+ * user-annotated barriers. See also pth_barrier.c.
+ */
+
+
+#define _GNU_SOURCE
+
+
+#include <pthread.h> /* pthread_create() */
+#include <stdio.h> /* fprintf() */
+#include <stdlib.h> /* atoi() */
+#include <string.h> /* memset() */
+#include "../../drd/drd.h"
+
+
+/* Local datatypes. */
+
+typedef struct
+{
+ /*
+ * number of threads that must call barrier_wait() before any of them
+ * successfully return from the call.
+ */
+ unsigned thread_count;
+ /* number of barrier_wait() calls since last barrier. */
+ volatile unsigned wait_count;
+ /*
+ * barrier count. Only the least significant bit matters -- a single bit
+ * counter would be sufficient.
+ */
+ volatile unsigned barrier_count;
+} barrier_t;
+
+struct threadinfo
+{
+ barrier_t* b;
+ pthread_t tid;
+ int* array;
+ int iterations;
+};
+
+
+/* Local variables. */
+
+static int s_silent;
+
+
+/* Local functions. */
+
+static void barrier_init(barrier_t* b, unsigned count)
+{
+ b->thread_count = count;
+ b->wait_count = 0;
+ b->barrier_count = 0;
+ ANNOTATE_BARRIER_INIT(b, count, 0);
+}
+
+static void barrier_destroy(barrier_t* b)
+{
+ ANNOTATE_BARRIER_DESTROY(b);
+ memset(b, 0, sizeof(*b));
+}
+
+static int barrier_wait(barrier_t* b)
+{
+ int res;
+ unsigned barrier_count;
+
+ res = 0;
+ ANNOTATE_BARRIER_WAIT_BEFORE(b);
+ barrier_count = b->barrier_count;
+ if (__sync_add_and_fetch(&b->wait_count, 1) == b->thread_count)
+ {
+ __sync_sub_and_fetch(&b->wait_count, b->thread_count);
+ __sync_add_and_fetch(&b->barrier_count, 1);
+ res = PTHREAD_BARRIER_SERIAL_THREAD;
+ }
+ else
+ {
+ while (b->barrier_count == barrier_count)
+ pthread_yield();
+ }
+ ANNOTATE_BARRIER_WAIT_AFTER(b);
+ return res;
+}
+
+/*
+ * 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;
+ barrier_t* const b = p->b;
+ if (! s_silent)
+ printf("thread %lx iteration 0\n", pthread_self());
+ 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;
+ 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;
+ 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);
+
+ barrier_init(&b, 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);
+
+ 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);
+
+ fprintf(stderr, "Done.\n");
+
+ return 0;
+}
Added: trunk/drd/tests/annotate_barrier.stderr.exp
===================================================================
--- trunk/drd/tests/annotate_barrier.stderr.exp (rev 0)
+++ trunk/drd/tests/annotate_barrier.stderr.exp 2010-03-21 17:24:47 UTC (rev 11095)
@@ -0,0 +1,47 @@
+
+The annotation macro ANNOTATE_BARRIER_INIT has not yet been implemented in <valgrind/drd.h>
+ at 0x........: vgDrdCl_annotate_barrier_init (drd.h:?)
+ by 0x........: barrier_init (annotate_barrier.c:?)
+ by 0x........: barriers_and_races (annotate_barrier.c:?)
+
+Thread 2:
+The annotation macro ANNOTATE_BARRIER_WAIT_BEFORE has not yet been implemented in <valgrind/drd.h>
+ at 0x........: vgDrdCl_annotate_barrier_wait_before (drd.h:?)
+ by 0x........: barrier_wait (annotate_barrier.c:?)
+ by 0x........: threadfunc (annotate_barrier.c:?)
+
+Thread 3:
+The annotation macro ANNOTATE_BARRIER_WAIT_AFTER has not yet been implemented in <valgrind/drd.h>
+ at 0x........: vgDrdCl_annotate_barrier_wait_after (drd.h:?)
+ by 0x........: barrier_wait (annotate_barrier.c:?)
+ by 0x........: threadfunc (annotate_barrier.c:?)
+
+The annotation macro ANNOTATE_BARRIER_WAIT_BEFORE has not yet been implemented in <valgrind/drd.h>
+ at 0x........: vgDrdCl_annotate_barrier_wait_before (drd.h:?)
+ by 0x........: barrier_wait (annotate_barrier.c:?)
+ by 0x........: threadfunc (annotate_barrier.c:?)
+
+Thread 2:
+Conflicting store by thread 2 at 0x........ size 4
+ at 0x........: threadfunc (annotate_barrier.c:?)
+ by 0x........: vgDrd_thread_wrapper (drd_pthread_intercepts.c:?)
+ by 0x........: (within libpthread-?.?.so)
+Address 0x........ is at offset 0 from 0x......... Allocation context:
+ at 0x........: malloc (vg_replace_malloc.c:...)
+ by 0x........: barriers_and_races (annotate_barrier.c:?)
+ by 0x........: main (annotate_barrier.c:?)
+
+The annotation macro ANNOTATE_BARRIER_WAIT_AFTER has not yet been implemented in <valgrind/drd.h>
+ at 0x........: vgDrdCl_annotate_barrier_wait_after (drd.h:?)
+ by 0x........: barrier_wait (annotate_barrier.c:?)
+ by 0x........: threadfunc (annotate_barrier.c:?)
+
+Thread 1:
+The annotation macro ANNOTATE_BARRIER_DESTROY has not yet been implemented in <valgrind/drd.h>
+ at 0x........: vgDrdCl_annotate_barrier_destroy (drd.h:?)
+ by 0x........: barrier_destroy (annotate_barrier.c:?)
+ by 0x........: barriers_and_races (annotate_barrier.c:?)
+
+Done.
+
+ERROR SUMMARY: 11 errors from 7 contexts (suppressed: 0 from 0)
Added: trunk/drd/tests/annotate_barrier.vgtest
===================================================================
--- trunk/drd/tests/annotate_barrier.vgtest (rev 0)
+++ trunk/drd/tests/annotate_barrier.vgtest 2010-03-21 17:24:47 UTC (rev 11095)
@@ -0,0 +1,4 @@
+prereq: test -e annotate_barrier && ./supported_libpthread
+vgopts: --read-var-info=yes --check-stack-var=yes --show-confl-seg=no --num-callers=3
+prog: annotate_barrier 2 1 1
+stderr_filter: filter_stderr
Added: trunk/drd/tests/annotate_static.cpp
===================================================================
--- trunk/drd/tests/annotate_static.cpp (rev 0)
+++ trunk/drd/tests/annotate_static.cpp 2010-03-21 17:24:47 UTC (rev 11095)
@@ -0,0 +1,37 @@
+// Test for ANNOTATE_BENIGN_RACE_STATIC() and ANNOTATE_UNPROTECTED_READ().
+
+
+#include <pthread.h> /* pthread_create() */
+#include <stdio.h> /* fprintf() */
+#include "../../drd/drd.h"
+
+
+/* Local variables. */
+
+static int s_i;
+static volatile int s_j;
+
+ANNOTATE_BENIGN_RACE_STATIC(s_i, "Benign because duplicate assignment.");
+
+
+/* Local functions. */
+
+static void* thread_func(void*)
+{
+ s_i = ANNOTATE_UNPROTECTED_READ(s_j);
+ return 0;
+}
+
+int main(int argc, char** argv)
+{
+ pthread_t tid;
+
+ pthread_create(&tid, 0, thread_func, NULL);
+ s_j++;
+ s_i = s_j;
+ pthread_join(tid, NULL);
+
+ fprintf(stderr, "Done.\n");
+
+ return 0;
+}
Added: trunk/drd/tests/annotate_static.stderr.exp
===================================================================
--- trunk/drd/tests/annotate_static.stderr.exp (rev 0)
+++ trunk/drd/tests/annotate_static.stderr.exp 2010-03-21 17:24:47 UTC (rev 11095)
@@ -0,0 +1,4 @@
+
+Done.
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Added: trunk/drd/tests/annotate_static.vgtest
===================================================================
--- trunk/drd/tests/annotate_static.vgtest (rev 0)
+++ trunk/drd/tests/annotate_static.vgtest 2010-03-21 17:24:47 UTC (rev 11095)
@@ -0,0 +1,4 @@
+prereq: test -e annotate_static && ./supported_libpthread
+vgopts: --read-var-info=yes --check-stack-var=yes --show-confl-seg=no
+prog: annotate_static
+stderr_filter: filter_stderr
|