Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

liblockdep: Add pthread_mutex_t test suite

This is a rather simple and basic test suite to test common
locking issues.

Beyond tests, it also shows how to use the library.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: torvalds@linux-foundation.org
Link: http://lkml.kernel.org/r/1371163284-6346-5-git-send-email-sasha.levin@oracle.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Sasha Levin and committed by
Ingo Molnar
878f968e 45e62074

+158
+27
tools/lib/lockdep/run_tests.sh
··· 1 + #! /bin/bash 2 + 3 + make &> /dev/null 4 + 5 + for i in `ls tests/*.c`; do 6 + testname=$(basename -s .c "$i") 7 + gcc -o tests/$testname -pthread -lpthread $i liblockdep.a -Iinclude -D__USE_LIBLOCKDEP &> /dev/null 8 + echo -ne "$testname... " 9 + if [ $(timeout 1 ./tests/$testname | wc -l) -gt 0 ]; then 10 + echo "PASSED!" 11 + else 12 + echo "FAILED!" 13 + fi 14 + rm tests/$testname 15 + done 16 + 17 + for i in `ls tests/*.c`; do 18 + testname=$(basename -s .c "$i") 19 + gcc -o tests/$testname -pthread -lpthread -Iinclude $i &> /dev/null 20 + echo -ne "(PRELOAD) $testname... " 21 + if [ $(timeout 1 ./lockdep ./tests/$testname | wc -l) -gt 0 ]; then 22 + echo "PASSED!" 23 + else 24 + echo "FAILED!" 25 + fi 26 + rm tests/$testname 27 + done
+13
tools/lib/lockdep/tests/AA.c
··· 1 + #include <liblockdep/mutex.h> 2 + 3 + void main(void) 4 + { 5 + pthread_mutex_t a, b; 6 + 7 + pthread_mutex_init(&a, NULL); 8 + pthread_mutex_init(&b, NULL); 9 + 10 + pthread_mutex_lock(&a); 11 + pthread_mutex_lock(&b); 12 + pthread_mutex_lock(&a); 13 + }
+13
tools/lib/lockdep/tests/ABBA.c
··· 1 + #include <liblockdep/mutex.h> 2 + #include "common.h" 3 + 4 + void main(void) 5 + { 6 + pthread_mutex_t a, b; 7 + 8 + pthread_mutex_init(&a, NULL); 9 + pthread_mutex_init(&b, NULL); 10 + 11 + LOCK_UNLOCK_2(a, b); 12 + LOCK_UNLOCK_2(b, a); 13 + }
+15
tools/lib/lockdep/tests/ABBCCA.c
··· 1 + #include <liblockdep/mutex.h> 2 + #include "common.h" 3 + 4 + void main(void) 5 + { 6 + pthread_mutex_t a, b, c; 7 + 8 + pthread_mutex_init(&a, NULL); 9 + pthread_mutex_init(&b, NULL); 10 + pthread_mutex_init(&c, NULL); 11 + 12 + LOCK_UNLOCK_2(a, b); 13 + LOCK_UNLOCK_2(b, c); 14 + LOCK_UNLOCK_2(c, a); 15 + }
+17
tools/lib/lockdep/tests/ABBCCDDA.c
··· 1 + #include <liblockdep/mutex.h> 2 + #include "common.h" 3 + 4 + void main(void) 5 + { 6 + pthread_mutex_t a, b, c, d; 7 + 8 + pthread_mutex_init(&a, NULL); 9 + pthread_mutex_init(&b, NULL); 10 + pthread_mutex_init(&c, NULL); 11 + pthread_mutex_init(&d, NULL); 12 + 13 + LOCK_UNLOCK_2(a, b); 14 + LOCK_UNLOCK_2(b, c); 15 + LOCK_UNLOCK_2(c, d); 16 + LOCK_UNLOCK_2(d, a); 17 + }
+15
tools/lib/lockdep/tests/ABCABC.c
··· 1 + #include <liblockdep/mutex.h> 2 + #include "common.h" 3 + 4 + void main(void) 5 + { 6 + pthread_mutex_t a, b, c; 7 + 8 + pthread_mutex_init(&a, NULL); 9 + pthread_mutex_init(&b, NULL); 10 + pthread_mutex_init(&c, NULL); 11 + 12 + LOCK_UNLOCK_2(a, b); 13 + LOCK_UNLOCK_2(c, a); 14 + LOCK_UNLOCK_2(b, c); 15 + }
+17
tools/lib/lockdep/tests/ABCDBCDA.c
··· 1 + #include <liblockdep/mutex.h> 2 + #include "common.h" 3 + 4 + void main(void) 5 + { 6 + pthread_mutex_t a, b, c, d; 7 + 8 + pthread_mutex_init(&a, NULL); 9 + pthread_mutex_init(&b, NULL); 10 + pthread_mutex_init(&c, NULL); 11 + pthread_mutex_init(&d, NULL); 12 + 13 + LOCK_UNLOCK_2(a, b); 14 + LOCK_UNLOCK_2(c, d); 15 + LOCK_UNLOCK_2(b, c); 16 + LOCK_UNLOCK_2(d, a); 17 + }
+17
tools/lib/lockdep/tests/ABCDBDDA.c
··· 1 + #include <liblockdep/mutex.h> 2 + #include "common.h" 3 + 4 + void main(void) 5 + { 6 + pthread_mutex_t a, b, c, d; 7 + 8 + pthread_mutex_init(&a, NULL); 9 + pthread_mutex_init(&b, NULL); 10 + pthread_mutex_init(&c, NULL); 11 + pthread_mutex_init(&d, NULL); 12 + 13 + LOCK_UNLOCK_2(a, b); 14 + LOCK_UNLOCK_2(c, d); 15 + LOCK_UNLOCK_2(b, d); 16 + LOCK_UNLOCK_2(d, a); 17 + }
+12
tools/lib/lockdep/tests/common.h
··· 1 + #ifndef _LIBLOCKDEP_TEST_COMMON_H 2 + #define _LIBLOCKDEP_TEST_COMMON_H 3 + 4 + #define LOCK_UNLOCK_2(a, b) \ 5 + do { \ 6 + pthread_mutex_lock(&(a)); \ 7 + pthread_mutex_lock(&(b)); \ 8 + pthread_mutex_unlock(&(b)); \ 9 + pthread_mutex_unlock(&(a)); \ 10 + } while(0) 11 + 12 + #endif
+12
tools/lib/lockdep/tests/unlock_balance.c
··· 1 + #include <liblockdep/mutex.h> 2 + 3 + void main(void) 4 + { 5 + pthread_mutex_t a; 6 + 7 + pthread_mutex_init(&a, NULL); 8 + 9 + pthread_mutex_lock(&a); 10 + pthread_mutex_unlock(&a); 11 + pthread_mutex_unlock(&a); 12 + }