1//===-- tsan_test.cc ------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file is a part of ThreadSanitizer (TSan), a race detector. 11// 12//===----------------------------------------------------------------------===// 13#include "tsan_interface.h" 14#include "tsan_test_util.h" 15#include "gtest/gtest.h" 16 17static void foo() {} 18static void bar() {} 19 20TEST(ThreadSanitizer, FuncCall) { 21 ScopedThread t1, t2; 22 MemLoc l; 23 t1.Write1(l); 24 t2.Call(foo); 25 t2.Call(bar); 26 t2.Write1(l, true); 27 t2.Return(); 28 t2.Return(); 29} 30 31// We use this function instead of main, as ISO C++ forbids taking the address 32// of main, which we need to pass inside __tsan_func_entry. 33int run_tests(int argc, char **argv) { 34 TestMutexBeforeInit(); // Mutexes must be usable before __tsan_init(); 35 __tsan_init(); 36 __tsan_func_entry(__builtin_return_address(0)); 37 __tsan_func_entry((void*)((intptr_t)&run_tests + 1)); 38 39 testing::GTEST_FLAG(death_test_style) = "threadsafe"; 40 testing::InitGoogleTest(&argc, argv); 41 int res = RUN_ALL_TESTS(); 42 43 __tsan_func_exit(); 44 __tsan_func_exit(); 45 return res; 46} 47 48int main(int argc, char **argv) { 49 return run_tests(argc, argv); 50} 51