[clang] Handle __declspec() attributes in using
[llvm-project.git] / compiler-rt / lib / tsan / tests / rtl / tsan_bench.cpp
blobf65aebc02bba492bef5cc01cf439a107605e2787
1 //===-- tsan_bench.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_test_util.h"
13 #include "tsan_interface.h"
14 #include "tsan_defs.h"
15 #include "gtest/gtest.h"
16 #include <stdint.h>
18 const int kSize = 128;
19 const int kRepeat = 2*1024*1024;
21 void noinstr(void *p) {}
23 template<typename T, void(*__tsan_mop)(void *p)>
24 static void Benchmark() {
25 volatile T data[kSize];
26 for (int i = 0; i < kRepeat; i++) {
27 for (int j = 0; j < kSize; j++) {
28 __tsan_mop((void*)&data[j]);
29 data[j]++;
34 TEST(DISABLED_BENCH, Mop1) {
35 Benchmark<uint8_t, noinstr>();
38 TEST(DISABLED_BENCH, Mop1Read) {
39 Benchmark<uint8_t, __tsan_read1>();
42 TEST(DISABLED_BENCH, Mop1Write) {
43 Benchmark<uint8_t, __tsan_write1>();
46 TEST(DISABLED_BENCH, Mop2) {
47 Benchmark<uint16_t, noinstr>();
50 TEST(DISABLED_BENCH, Mop2Read) {
51 Benchmark<uint16_t, __tsan_read2>();
54 TEST(DISABLED_BENCH, Mop2Write) {
55 Benchmark<uint16_t, __tsan_write2>();
58 TEST(DISABLED_BENCH, Mop4) {
59 Benchmark<uint32_t, noinstr>();
62 TEST(DISABLED_BENCH, Mop4Read) {
63 Benchmark<uint32_t, __tsan_read4>();
66 TEST(DISABLED_BENCH, Mop4Write) {
67 Benchmark<uint32_t, __tsan_write4>();
70 TEST(DISABLED_BENCH, Mop8) {
71 Benchmark<uint8_t, noinstr>();
74 TEST(DISABLED_BENCH, Mop8Read) {
75 Benchmark<uint64_t, __tsan_read8>();
78 TEST(DISABLED_BENCH, Mop8Write) {
79 Benchmark<uint64_t, __tsan_write8>();
82 TEST(DISABLED_BENCH, FuncCall) {
83 for (int i = 0; i < kRepeat; i++) {
84 for (int j = 0; j < kSize; j++)
85 __tsan_func_entry((void*)(uintptr_t)j);
86 for (int j = 0; j < kSize; j++)
87 __tsan_func_exit();
91 TEST(DISABLED_BENCH, MutexLocal) {
92 UserMutex m;
93 ScopedThread().Create(m);
94 for (int i = 0; i < 50; i++) {
95 ScopedThread t;
96 t.Lock(m);
97 t.Unlock(m);
99 for (int i = 0; i < 16*1024*1024; i++) {
100 m.Lock();
101 m.Unlock();
103 ScopedThread().Destroy(m);