From: Bart Van Assche Date: Sat, 28 Jun 2008 15:03:26 +0000 (+0000) Subject: Semaphore and barrier reinitialization are now reported. X-Git-Tag: svn/VALGRIND_3_4_0~417 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cceb5509e5e0e36956aaab8a745f682013985932;p=thirdparty%2Fvalgrind.git Semaphore and barrier reinitialization are now reported. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8297 --- diff --git a/exp-drd/drd_barrier.c b/exp-drd/drd_barrier.c index a7cd281dcc..d9c3ebbf9c 100644 --- a/exp-drd/drd_barrier.c +++ b/exp-drd/drd_barrier.c @@ -184,6 +184,19 @@ void barrier_init(const Addr barrier, tl_assert(barrier_type == pthread_barrier || barrier_type == gomp_barrier); + if (! reinitialization && barrier_type == pthread_barrier) + { + p = barrier_get(barrier); + if (p) + { + BarrierErrInfo bei = { barrier }; + VG_(maybe_record_error)(VG_(get_running_tid)(), + BarrierErr, + VG_(get_IP)(VG_(get_running_tid)()), + "Barrier reinitializatoin", + &bei); + } + } p = barrier_get_or_allocate(barrier, barrier_type, count); if (s_trace_barrier) diff --git a/exp-drd/drd_semaphore.c b/exp-drd/drd_semaphore.c index 0e97ea06ad..4bedf8f0c8 100644 --- a/exp-drd/drd_semaphore.c +++ b/exp-drd/drd_semaphore.c @@ -123,11 +123,22 @@ struct semaphore_info* semaphore_init(const Addr semaphore, thread_get_running_tid(), semaphore); } - if (semaphore_get(semaphore)) + p = semaphore_get(semaphore); + if (p) { - // To do: print an error message that a semaphore is being reinitialized. + const ThreadId vg_tid = VG_(get_running_tid)(); + SemaphoreErrInfo SEI = { semaphore }; + VG_(maybe_record_error)(vg_tid, + SemaphoreErr, + VG_(get_IP)(vg_tid), + "Semaphore reinitialization", + &SEI); } - p = semaphore_get_or_allocate(semaphore); + else + { + p = semaphore_get_or_allocate(semaphore); + } + tl_assert(p); p->value = value; return p; } diff --git a/exp-drd/tests/Makefile.am b/exp-drd/tests/Makefile.am index 2b78cbab8c..5c7af6df92 100644 --- a/exp-drd/tests/Makefile.am +++ b/exp-drd/tests/Makefile.am @@ -63,6 +63,8 @@ EXTRA_DIST = \ pth_barrier2.vgtest \ pth_barrier3.stderr.exp \ pth_barrier3.vgtest \ + pth_barrier_reinit.stderr.exp \ + pth_barrier_reinit.vgtest \ pth_broadcast.stderr.exp \ pth_broadcast.vgtest \ pth_cond_race.stderr.exp \ @@ -176,6 +178,7 @@ check_PROGRAMS_COMMON = \ memory_allocation \ new_delete \ pth_barrier \ + pth_barrier_reinit \ pth_broadcast \ pth_cond_race \ pth_create_chain \ @@ -264,6 +267,9 @@ new_delete_SOURCES = new_delete.cpp pth_barrier_SOURCES = pth_barrier.c pth_barrier_LDADD = -lpthread +pth_barrier_reinit_SOURCES = pth_barrier_reinit.c +pth_barrier_reinit_LDADD = -lpthread + pth_broadcast_SOURCES = pth_broadcast.c pth_broadcast_LDADD = -lpthread diff --git a/exp-drd/tests/pth_barrier_reinit.c b/exp-drd/tests/pth_barrier_reinit.c new file mode 100644 index 0000000000..416233235c --- /dev/null +++ b/exp-drd/tests/pth_barrier_reinit.c @@ -0,0 +1,9 @@ +#include + +int main(int argc, char** argv) +{ + pthread_barrier_t b; + pthread_barrier_init(&b, 0, 1); + pthread_barrier_init(&b, 0, 1); + return 0; +} diff --git a/exp-drd/tests/tc18_semabuse.stderr.exp b/exp-drd/tests/tc18_semabuse.stderr.exp index 7b21919cab..17d11f1418 100644 --- a/exp-drd/tests/tc18_semabuse.stderr.exp +++ b/exp-drd/tests/tc18_semabuse.stderr.exp @@ -1,6 +1,10 @@ +Semaphore reinitialization: semaphore 0x........ + at 0x........: sem_init* (drd_pthread_intercepts.c:?) + by 0x........: main (tc18_semabuse.c:26) + Invalid semaphore: semaphore 0x........ at 0x........: sem_wait* (drd_pthread_intercepts.c:?) by 0x........: main (tc18_semabuse.c:34) -ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) +ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0) diff --git a/exp-drd/tests/tc20_verifywrap.stderr.exp b/exp-drd/tests/tc20_verifywrap.stderr.exp index 7228c41103..57532209a8 100644 --- a/exp-drd/tests/tc20_verifywrap.stderr.exp +++ b/exp-drd/tests/tc20_verifywrap.stderr.exp @@ -84,6 +84,10 @@ Reader-writer lock not locked by calling thread: rwlock 0x......... ---------------- sem_* ---------------- +Semaphore reinitialization: semaphore 0x........ + at 0x........: sem_init* (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:231) + FIXME: can't figure out how to verify wrap of sem_destroy @@ -103,4 +107,4 @@ Destroying locked rwlock: rwlock 0x......... Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. at 0x........: main (tc20_verifywrap.c:262) -ERROR SUMMARY: 15 errors from 15 contexts (suppressed: 0 from 0) +ERROR SUMMARY: 16 errors from 16 contexts (suppressed: 0 from 0) diff --git a/exp-drd/tests/tc20_verifywrap2.stderr.exp b/exp-drd/tests/tc20_verifywrap2.stderr.exp index a43c281f7e..1c8e909852 100644 --- a/exp-drd/tests/tc20_verifywrap2.stderr.exp +++ b/exp-drd/tests/tc20_verifywrap2.stderr.exp @@ -110,6 +110,10 @@ Reader-writer lock not locked by calling thread: rwlock 0x......... [1/1] semaphore_init 0x........ [1/1] semaphore_init 0x........ +Semaphore reinitialization: semaphore 0x........ + at 0x........: sem_init* (drd_pthread_intercepts.c:?) + by 0x........: main (tc20_verifywrap.c:231) + FIXME: can't figure out how to verify wrap of sem_destroy [1/1] semaphore_pre_wait 0x........ @@ -183,4 +187,4 @@ Destroying locked mutex: mutex 0x........, recursion count 1, owner 1. [1/1] post_mutex_lock recursive mutex 0x........ rc 0 owner 1 [1/1] mutex_unlock recursive mutex 0x........ rc 1 -ERROR SUMMARY: 15 errors from 15 contexts (suppressed: 0 from 0) +ERROR SUMMARY: 16 errors from 16 contexts (suppressed: 0 from 0)