[clang] Handle __declspec() attributes in using
[llvm-project.git] / compiler-rt / lib / tsan / tests / rtl / tsan_test.cpp
blob477a41d98c1d23a7788864c2a98d96f666edbe1d
1 //===-- tsan_test.cpp -----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //===----------------------------------------------------------------------===//
12 #include "tsan_interface.h"
13 #include "tsan_test_util.h"
14 #include "gtest/gtest.h"
16 static void foo() {}
17 static void bar() {}
19 TEST_F(ThreadSanitizer, FuncCall) {
20 ScopedThread t1, t2;
21 MemLoc l;
22 t1.Write1(l);
23 t2.Call(foo);
24 t2.Call(bar);
25 t2.Write1(l, true);
26 t2.Return();
27 t2.Return();
30 // We use this function instead of main, as ISO C++ forbids taking the address
31 // of main, which we need to pass inside __tsan_func_entry.
32 int run_tests(int argc, char **argv) {
33 TestMutexBeforeInit(); // Mutexes must be usable before __tsan_init();
34 __tsan_init();
35 __tsan_func_entry(__builtin_return_address(0));
36 __tsan_func_entry((void*)((intptr_t)&run_tests + 1));
38 testing::GTEST_FLAG(death_test_style) = "threadsafe";
39 testing::InitGoogleTest(&argc, argv);
40 int res = RUN_ALL_TESTS();
42 __tsan_func_exit();
43 __tsan_func_exit();
44 return res;
47 const char *argv0;
49 #ifdef __APPLE__
50 // On Darwin, turns off symbolication and crash logs to make tests faster.
51 extern "C" const char* __tsan_default_options() {
52 return "symbolize=false:abort_on_error=0";
54 #endif
56 int main(int argc, char **argv) {
57 argv0 = argv[0];
58 return run_tests(argc, argv);