1 //===- llvm/unittest/DWARFLinkerParallel/StringPoolTest.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 #include "llvm/DWARFLinker/StringPool.h"
10 #include "llvm/Support/Parallel.h"
11 #include "gtest/gtest.h"
15 using namespace dwarf_linker
;
19 TEST(StringPoolTest
, TestStringPool
) {
22 // StringPool uses PerThreadBumpPtrAllocator which should be accessed from
23 // threads created by ThreadPoolExecutor. Use TaskGroup to run on
24 // ThreadPoolExecutor threads.
25 parallel::TaskGroup tg
;
28 std::pair
<StringEntry
*, bool> Entry
= Strings
.insert("test");
29 EXPECT_TRUE(Entry
.second
);
30 EXPECT_TRUE(Entry
.first
->getKey() == "test");
32 StringEntry
*EntryPtr
= Entry
.first
;
34 Entry
= Strings
.insert("test");
35 EXPECT_FALSE(Entry
.second
);
36 EXPECT_TRUE(Entry
.first
->getKey() == "test");
37 EXPECT_TRUE(EntryPtr
== Entry
.first
);
39 Entry
= Strings
.insert("test2");
40 EXPECT_TRUE(Entry
.second
);
41 EXPECT_TRUE(Entry
.first
->getKey() == "test2");
42 EXPECT_TRUE(EntryPtr
!= Entry
.first
);
46 TEST(StringPoolTest
, TestStringPoolParallel
) {
50 parallelFor(0, 1000, [&](size_t Idx
) {
51 std::pair
<StringEntry
*, bool> Entry
= Strings
.insert(std::to_string(Idx
));
52 EXPECT_TRUE(Entry
.second
);
53 EXPECT_TRUE(Entry
.first
->getKey() == std::to_string(Idx
));
57 parallelFor(0, 1000, [&](size_t Idx
) {
58 std::pair
<StringEntry
*, bool> Entry
= Strings
.insert(std::to_string(Idx
));
59 EXPECT_FALSE(Entry
.second
);
60 EXPECT_TRUE(Entry
.first
->getKey() == std::to_string(Idx
));
64 } // anonymous namespace