diff options
| author | Nico Weber <nicolasweber@gmx.de> | 2019-08-01 14:26:37 +0000 |
|---|---|---|
| committer | Nico Weber <nicolasweber@gmx.de> | 2019-08-01 14:26:37 +0000 |
| commit | 5de29a4b0e5af8cae312e01c95d24cfe0e1c51c3 (patch) | |
| tree | d0184c3f70dade381f5b30af023175b58daf2d22 /compiler-rt/lib/tsan/tests/unit/tsan_dense_alloc_test.cpp | |
| parent | 1fc2a47f0b6c415312593e43489cf9ea2507d902 (diff) | |
| download | bcm5719-llvm-5de29a4b0e5af8cae312e01c95d24cfe0e1c51c3.tar.gz bcm5719-llvm-5de29a4b0e5af8cae312e01c95d24cfe0e1c51c3.zip | |
compiler-rt: Rename .cc file in lib/tsan/tests/{rtl,unit} to .cpp
Like r367463, but for tsan/tests/{rtl,unit}.
llvm-svn: 367566
Diffstat (limited to 'compiler-rt/lib/tsan/tests/unit/tsan_dense_alloc_test.cpp')
| -rw-r--r-- | compiler-rt/lib/tsan/tests/unit/tsan_dense_alloc_test.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/compiler-rt/lib/tsan/tests/unit/tsan_dense_alloc_test.cpp b/compiler-rt/lib/tsan/tests/unit/tsan_dense_alloc_test.cpp new file mode 100644 index 00000000000..05045622881 --- /dev/null +++ b/compiler-rt/lib/tsan/tests/unit/tsan_dense_alloc_test.cpp @@ -0,0 +1,54 @@ +//===-- tsan_dense_alloc_test.cpp -----------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file is a part of ThreadSanitizer (TSan), a race detector. +// +//===----------------------------------------------------------------------===// +#include "tsan_dense_alloc.h" +#include "tsan_rtl.h" +#include "tsan_mman.h" +#include "gtest/gtest.h" + +#include <stdlib.h> +#include <stdint.h> +#include <map> + +namespace __tsan { + +TEST(DenseSlabAlloc, Basic) { + typedef DenseSlabAlloc<int, 128, 128> Alloc; + typedef Alloc::Cache Cache; + typedef Alloc::IndexT IndexT; + const int N = 1000; + + Alloc alloc; + Cache cache; + alloc.InitCache(&cache); + + IndexT blocks[N]; + for (int ntry = 0; ntry < 3; ntry++) { + for (int i = 0; i < N; i++) { + IndexT idx = alloc.Alloc(&cache); + blocks[i] = idx; + EXPECT_NE(idx, 0U); + int *v = alloc.Map(idx); + *v = i; + } + + for (int i = 0; i < N; i++) { + IndexT idx = blocks[i]; + int *v = alloc.Map(idx); + EXPECT_EQ(*v, i); + alloc.Free(&cache, idx); + } + + alloc.FlushCache(&cache); + } +} + +} // namespace __tsan |

