[libc][NFC] Remove extra ; in exhaustive_test.h. (#124216)
[llvm-project.git] / compiler-rt / lib / tsan / tests / unit / tsan_dense_alloc_test.cpp
blob02dddda8b3842dd7714bf8ec5981467e91355a61
1 //===-- tsan_dense_alloc_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_dense_alloc.h"
13 #include "tsan_rtl.h"
14 #include "tsan_mman.h"
15 #include "gtest/gtest.h"
17 #include <stdlib.h>
18 #include <stdint.h>
19 #include <map>
21 namespace __tsan {
23 TEST(DenseSlabAlloc, Basic) {
24 typedef u64 T;
25 typedef DenseSlabAlloc<T, 128, 128> Alloc;
26 typedef Alloc::Cache Cache;
27 typedef Alloc::IndexT IndexT;
28 const T N = 1000;
30 Alloc alloc("test");
31 Cache cache;
32 alloc.InitCache(&cache);
34 IndexT blocks[N];
35 for (int ntry = 0; ntry < 3; ntry++) {
36 for (T i = 0; i < N; i++) {
37 IndexT idx = alloc.Alloc(&cache);
38 blocks[i] = idx;
39 EXPECT_NE(idx, 0U);
40 T *v = alloc.Map(idx);
41 *v = i;
44 for (T i = 0; i < N; i++) {
45 IndexT idx = blocks[i];
46 T *v = alloc.Map(idx);
47 EXPECT_EQ(*v, i);
48 alloc.Free(&cache, idx);
51 alloc.FlushCache(&cache);
55 } // namespace __tsan