add a tsan example

This commit is contained in:
Sylvestre Ledru 2020-02-02 21:43:58 +01:00
parent 8bca9142e1
commit 66786d35c6

View File

@ -510,6 +510,40 @@ int main(int argc, char **argv)
clang-$VERSION -fsanitize=address foo.c -o foo -lc
./foo &> /dev/null || true
echo '
#include <pthread.h>
#include <stdio.h>
int Global;
void *Thread1(void *x) {
Global++;
return NULL;
}
void *Thread2(void *x) {
Global--;
return NULL;
}
int main() {
pthread_t t[2];
pthread_create(&t[0], NULL, Thread1, NULL);
pthread_create(&t[1], NULL, Thread2, NULL);
pthread_join(t[0], NULL);
pthread_join(t[1], NULL);
} ' > foo.c
clang-$VERSION -o foo -fsanitize=thread -g -O1 foo.c
if ! strings ./foo 2>&1 | grep -q "tsan"; then
echo "binary doesn't contain tsan code"
strings foo
exit 42
fi
if ! ./foo 2>&1 | grep -q "data race"; then
echo "sanitize=address is failing"
exit 42
fi
echo '
class a {