[flang][cuda] Do not register global constants (#118582)
[llvm-project.git] / llvm / unittests / DWARFLinkerParallel / StringPoolTest.cpp
blob2612e763648b341fd7d858299273e7530f3fdde0
1 //===- llvm/unittest/DWARFLinkerParallel/StringPoolTest.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 //===----------------------------------------------------------------------===//
9 #include "llvm/DWARFLinker/StringPool.h"
10 #include "llvm/Support/Parallel.h"
11 #include "gtest/gtest.h"
12 #include <cstdlib>
14 using namespace llvm;
15 using namespace dwarf_linker;
17 namespace {
19 TEST(StringPoolTest, TestStringPool) {
20 StringPool Strings;
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;
27 tg.spawn([&]() {
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);
43 });
46 TEST(StringPoolTest, TestStringPoolParallel) {
47 StringPool Strings;
49 // Add data.
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));
54 });
56 // Check data.
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));
61 });
64 } // anonymous namespace