1 //===-- tsan_dense_alloc_test.cpp -----------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //===----------------------------------------------------------------------===//
12 #include "tsan_dense_alloc.h"
14 #include "tsan_mman.h"
15 #include "gtest/gtest.h"
23 TEST(DenseSlabAlloc
, Basic
) {
25 typedef DenseSlabAlloc
<T
, 128, 128> Alloc
;
26 typedef Alloc::Cache Cache
;
27 typedef Alloc::IndexT IndexT
;
32 alloc
.InitCache(&cache
);
35 for (int ntry
= 0; ntry
< 3; ntry
++) {
36 for (T i
= 0; i
< N
; i
++) {
37 IndexT idx
= alloc
.Alloc(&cache
);
40 T
*v
= alloc
.Map(idx
);
44 for (T i
= 0; i
< N
; i
++) {
45 IndexT idx
= blocks
[i
];
46 T
*v
= alloc
.Map(idx
);
48 alloc
.Free(&cache
, idx
);
51 alloc
.FlushCache(&cache
);