From: Mark Wielaard Date: Fri, 4 Sep 2015 09:41:42 +0000 (+0000) Subject: Add safe sem_post handler and glibc-2.21 expected output for helgrind tests. X-Git-Tag: svn/VALGRIND_3_11_0~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=235c116f2da2290d83d40a5f3475197baaf8d5b8;p=thirdparty%2Fvalgrind.git Add safe sem_post handler and glibc-2.21 expected output for helgrind tests. This fixes the tc18 and tc20 testcases. On some bad semaphores glibc now might just abort, we catch the SIGABRT and turn it into a EINVAL. The program will see this, but the helgrind wrapper won't. Which works for tc18 since there is an alternate exp file with that result (silent bad sem_post). We add a similar alternative exp file for tc21. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15620 --- diff --git a/helgrind/tests/Makefile.am b/helgrind/tests/Makefile.am index fc73633716..8a0d6e650d 100644 --- a/helgrind/tests/Makefile.am +++ b/helgrind/tests/Makefile.am @@ -98,6 +98,7 @@ EXTRA_DIST = \ tc20_verifywrap.vgtest tc20_verifywrap.stdout.exp \ tc20_verifywrap.stderr.exp \ tc20_verifywrap.stderr.exp-glibc-2.18 \ + tc20_verifywrap.stderr.exp-glibc-2.21 \ tc20_verifywrap.stderr.exp-mips32 \ tc20_verifywrap.stderr.exp-mips32-b \ tc20_verifywrap.stderr.exp-s390x \ @@ -115,8 +116,8 @@ EXTRA_DIST = \ tls_threads.vgtest tls_threads.stdout.exp \ tls_threads.stderr.exp -# Wrapper header used by some check programs. -noinst_HEADERS = safe-pthread.h +# Wrapper headers used by some check programs. +noinst_HEADERS = safe-pthread.h safe-semaphore.h # XXX: tc18_semabuse uses operations that are unsupported on Darwin. It # should be conditionally compiled like tc20_verifywrap is. diff --git a/helgrind/tests/safe-semaphore.h b/helgrind/tests/safe-semaphore.h new file mode 100644 index 0000000000..3aa0dc4e4c --- /dev/null +++ b/helgrind/tests/safe-semaphore.h @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include + +static sigjmp_buf env; + +/* + * Newer glibc crashes on really bogus semaphors. + * Catch a SIGABRT and turn it into a EINVAL. + */ +static void abrt_handler( int signum, siginfo_t *siginfo, void *sigcontext ) { + siglongjmp( env, EINVAL ); +} + +static int safe_sem_post( sem_t *sem ) { + struct sigaction sa; + struct sigaction oldsa; + int r, e; + + sa.sa_handler = NULL; + sa.sa_sigaction = abrt_handler; + sigemptyset( &sa.sa_mask ); + sa.sa_flags = SA_SIGINFO; + + sigaction( SIGABRT, &sa, &oldsa ); + + if ( ( e = sigsetjmp( env, 1 ) ) == 0 ) { + r = sem_post( sem ); + } else { + r = -1; + } + errno = e; + + sigaction( SIGABRT, &oldsa, NULL ); + + return r; +} + +#define sem_post safe_sem_post diff --git a/helgrind/tests/tc18_semabuse.c b/helgrind/tests/tc18_semabuse.c index eab308c1c3..62242f11f2 100644 --- a/helgrind/tests/tc18_semabuse.c +++ b/helgrind/tests/tc18_semabuse.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include "safe-semaphore.h" #include void start_watchdog ( void ); int main ( void ) diff --git a/helgrind/tests/tc20_verifywrap.c b/helgrind/tests/tc20_verifywrap.c index 3c976a2c3c..f71c7f8d4d 100644 --- a/helgrind/tests/tc20_verifywrap.c +++ b/helgrind/tests/tc20_verifywrap.c @@ -16,7 +16,7 @@ #include #include #include "safe-pthread.h" -#include +#include "safe-semaphore.h" #if !defined(__APPLE__) diff --git a/helgrind/tests/tc20_verifywrap.stderr.exp-glibc-2.21 b/helgrind/tests/tc20_verifywrap.stderr.exp-glibc-2.21 new file mode 100644 index 0000000000..7f4eb21db6 --- /dev/null +++ b/helgrind/tests/tc20_verifywrap.stderr.exp-glibc-2.21 @@ -0,0 +1,247 @@ + + + +------ This is output for >= glibc 2.4 ------ + +---------------- pthread_create/join ---------------- + +---Thread-Announcement------------------------------------------ + +Thread #x is the program's root thread + +---Thread-Announcement------------------------------------------ + +Thread #x was created + ... + by 0x........: pthread_create@* (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:81) + +---------------------------------------------------------------- + +Possible data race during write of size 2 at 0x........ by thread #x +Locks held: none + at 0x........: main (tc20_verifywrap.c:83) + +This conflicts with a previous write of size 2 by thread #x +Locks held: none + at 0x........: racy_child (tc20_verifywrap.c:39) + by 0x........: mythread_wrapper (hg_intercepts.c:...) + ... + Location 0x........ is 0 bytes inside global var "unprotected" + declared at tc20_verifywrap.c:32 + +---------------------------------------------------------------- + +Thread #x's call to pthread_join failed + with error code 35 (EDEADLK: Resource deadlock would occur) + at 0x........: pthread_join_WRK (hg_intercepts.c:...) + by 0x........: pthread_join (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:88) + + +---------------- pthread_mutex_lock et al ---------------- + +---------------------------------------------------------------- + +Thread #x's call to pthread_mutex_init failed + with error code 95 (EOPNOTSUPP: Operation not supported on transport endpoint) + at 0x........: pthread_mutex_init (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:102) + +---------------------------------------------------------------- + +Thread #x: pthread_mutex_destroy of a locked mutex + at 0x........: mutex_destroy_WRK (hg_intercepts.c:...) + by 0x........: pthread_mutex_destroy (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:112) + +---------------------------------------------------------------- + +Thread #x's call to pthread_mutex_destroy failed + with error code 16 (EBUSY: Device or resource busy) + at 0x........: mutex_destroy_WRK (hg_intercepts.c:...) + by 0x........: pthread_mutex_destroy (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:112) + +---------------------------------------------------------------- + +Thread #x's call to pthread_mutex_lock failed + with error code 22 (EINVAL: Invalid argument) + at 0x........: mutex_lock_WRK (hg_intercepts.c:...) + by 0x........: pthread_mutex_lock (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:118) + +---------------------------------------------------------------- + +Thread #x's call to pthread_mutex_trylock failed + with error code 22 (EINVAL: Invalid argument) + at 0x........: mutex_trylock_WRK (hg_intercepts.c:...) + by 0x........: pthread_mutex_trylock (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:126) + +---------------------------------------------------------------- + +Thread #x's call to pthread_mutex_timedlock failed + with error code 22 (EINVAL: Invalid argument) + at 0x........: mutex_timedlock_WRK (hg_intercepts.c:...) + by 0x........: pthread_mutex_timedlock (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:131) + +---------------------------------------------------------------- + +Thread #x unlocked an invalid lock at 0x........ + at 0x........: mutex_unlock_WRK (hg_intercepts.c:...) + by 0x........: pthread_mutex_unlock (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:135) + +---------------------------------------------------------------- + +Thread #x's call to pthread_mutex_unlock failed + with error code 22 (EINVAL: Invalid argument) + at 0x........: mutex_unlock_WRK (hg_intercepts.c:...) + by 0x........: pthread_mutex_unlock (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:135) + + +---------------- pthread_cond_wait et al ---------------- + +---------------------------------------------------------------- + +Thread #x: pthread_cond_{timed}wait called with un-held mutex + at 0x........: pthread_cond_wait_WRK (hg_intercepts.c:...) + by 0x........: pthread_cond_wait@* (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:157) + +---------------------------------------------------------------- + +Thread #x's call to pthread_cond_wait failed + with error code 1 (EPERM: Operation not permitted) + at 0x........: pthread_cond_wait_WRK (hg_intercepts.c:...) + by 0x........: pthread_cond_wait@* (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:157) + +---------------------------------------------------------------- + +Thread #x: pthread_cond_{signal,broadcast}: dubious: associated lock is not held by any thread + at 0x........: pthread_cond_signal_WRK (hg_intercepts.c:...) + by 0x........: pthread_cond_signal@* (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:162) + + +FIXME: can't figure out how to verify wrap of pthread_cond_signal + +---------------------------------------------------------------- + +Thread #x: pthread_cond_{signal,broadcast}: dubious: associated lock is not held by any thread + at 0x........: pthread_cond_broadcast_WRK (hg_intercepts.c:...) + by 0x........: pthread_cond_broadcast@* (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:168) + + +FIXME: can't figure out how to verify wrap of pthread_broadcast_signal + +---------------------------------------------------------------- + +Thread #x: pthread_cond_{timed}wait called with un-held mutex + at 0x........: pthread_cond_timedwait_WRK (hg_intercepts.c:...) + by 0x........: pthread_cond_timedwait@* (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:175) + +---------------------------------------------------------------- + +Thread #x's call to pthread_cond_timedwait failed + with error code 22 (EINVAL: Invalid argument) + at 0x........: pthread_cond_timedwait_WRK (hg_intercepts.c:...) + by 0x........: pthread_cond_timedwait@* (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:175) + + +---------------- pthread_rwlock_* ---------------- + +---------------------------------------------------------------- + +Thread #x unlocked a not-locked lock at 0x........ + at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...) + by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...) + ... + by 0x........: main (tc20_verifywrap.c:189) + Lock at 0x........ was first observed + at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...) + by 0x........: pthread_rwlock_init (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:188) + Location 0x........ is 0 bytes inside local var "rwl" + declared at tc20_verifywrap.c:52, in frame #x of thread x + + +(1) no error on next line +(2) no error on next line +(3) ERROR on next line +---------------------------------------------------------------- + +Thread #x unlocked a not-locked lock at 0x........ + at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...) + by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...) + ... + by 0x........: main (tc20_verifywrap.c:206) + Lock at 0x........ was first observed + at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...) + by 0x........: pthread_rwlock_init (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:196) + Location 0x........ is 0 bytes inside local var "rwl2" + declared at tc20_verifywrap.c:53, in frame #x of thread x + + +(4) no error on next line +(5) no error on next line +(6) no error on next line +(7) no error on next line +(8) ERROR on next line +---------------------------------------------------------------- + +Thread #x unlocked a not-locked lock at 0x........ + at 0x........: pthread_rwlock_unlock_WRK (hg_intercepts.c:...) + by 0x........: pthread_rwlock_unlock (hg_intercepts.c:...) + ... + by 0x........: main (tc20_verifywrap.c:227) + Lock at 0x........ was first observed + at 0x........: pthread_rwlock_init_WRK (hg_intercepts.c:...) + by 0x........: pthread_rwlock_init (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:196) + Location 0x........ is 0 bytes inside local var "rwl2" + declared at tc20_verifywrap.c:53, in frame #x of thread x + + + +---------------- sem_* ---------------- + +---------------------------------------------------------------- + +Thread #x's call to sem_init failed + with error code 22 (EINVAL: Invalid argument) + at 0x........: sem_init_WRK (hg_intercepts.c:...) + by 0x........: sem_init@* (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:248) + + +FIXME: can't figure out how to verify wrap of sem_destroy + +---------------------------------------------------------------- + +Thread #x: Bug in libpthread: sem_wait succeeded on semaphore without prior sem_post + at 0x........: sem_wait_WRK (hg_intercepts.c:...) + by 0x........: sem_wait (hg_intercepts.c:...) + by 0x........: main (tc20_verifywrap.c:262) + + +FIXME: can't figure out how to verify wrap of sem_post + + +------------ dealloc of mem holding locks ------------ + +---------------------------------------------------------------- + +Thread #x: Exiting thread still holds 1 lock + ... + + +ERROR SUMMARY: 22 errors from 22 contexts (suppressed: 0 from 0)