]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add safe sem_post handler and glibc-2.21 expected output for helgrind tests.
authorMark Wielaard <mark@klomp.org>
Fri, 4 Sep 2015 09:41:42 +0000 (09:41 +0000)
committerMark Wielaard <mark@klomp.org>
Fri, 4 Sep 2015 09:41:42 +0000 (09:41 +0000)
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

helgrind/tests/Makefile.am
helgrind/tests/safe-semaphore.h [new file with mode: 0644]
helgrind/tests/tc18_semabuse.c
helgrind/tests/tc20_verifywrap.c
helgrind/tests/tc20_verifywrap.stderr.exp-glibc-2.21 [new file with mode: 0644]

index fc73633716f26971e932a320e0432bfe7298d8db..8a0d6e650db768f115050d89d3b7196e56e065bd 100644 (file)
@@ -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 (file)
index 0000000..3aa0dc4
--- /dev/null
@@ -0,0 +1,41 @@
+#include <semaphore.h>
+#include <signal.h>
+#include <setjmp.h>
+#include <errno.h>
+#include <assert.h>
+
+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
index eab308c1c35bc5dde5aabf9713ccae08f6f583b0..62242f11f2c7fd141121b921ce95fcf075b5b592 100644 (file)
@@ -11,7 +11,7 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <pthread.h>
-#include <semaphore.h>
+#include "safe-semaphore.h"
 #include <string.h>
 void start_watchdog ( void );
 int main ( void )
index 3c976a2c3c57d643d9a5d4655754ac201122e4c6..f71c7f8d4dfec5e603e9463ec7a770512d0b9469 100644 (file)
@@ -16,7 +16,7 @@
 #include <assert.h>
 #include <unistd.h>
 #include "safe-pthread.h"
-#include <semaphore.h>
+#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 (file)
index 0000000..7f4eb21
--- /dev/null
@@ -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)