1 //===- unittests/Support/SymbolRemappingReaderTest.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/ProfileData/SymbolRemappingReader.h"
10 #include "llvm/Support/MemoryBuffer.h"
11 #include "gtest/gtest.h"
16 class SymbolRemappingReaderTest
: public testing::Test
{
18 std::unique_ptr
<MemoryBuffer
> Buffer
;
19 SymbolRemappingReader Reader
;
21 std::string
readWithErrors(StringRef Text
, StringRef BufferName
) {
22 Buffer
= MemoryBuffer::getMemBuffer(Text
, BufferName
);
23 Error E
= Reader
.read(*Buffer
);
25 return toString(std::move(E
));
28 void read(StringRef Text
, StringRef BufferName
) {
29 Buffer
= MemoryBuffer::getMemBuffer(Text
, BufferName
);
30 Error E
= Reader
.read(*Buffer
);
31 EXPECT_FALSE((bool)E
);
34 } // unnamed namespace
36 TEST_F(SymbolRemappingReaderTest
, ParseErrors
) {
37 EXPECT_EQ(readWithErrors("error", "foo.map"),
38 "foo.map:1: Expected 'kind mangled_name mangled_name', "
41 EXPECT_EQ(readWithErrors("error m1 m2", "foo.map"),
42 "foo.map:1: Invalid kind, expected 'name', 'type', or 'encoding', "
46 TEST_F(SymbolRemappingReaderTest
, DemanglingErrors
) {
47 EXPECT_EQ(readWithErrors("type i banana", "foo.map"),
48 "foo.map:1: Could not demangle 'banana' as a <type>; "
50 EXPECT_EQ(readWithErrors("name i 1X", "foo.map"),
51 "foo.map:1: Could not demangle 'i' as a <name>; "
53 EXPECT_EQ(readWithErrors("name 1X 1fv", "foo.map"),
54 "foo.map:1: Could not demangle '1fv' as a <name>; "
56 EXPECT_EQ(readWithErrors("encoding 1fv 1f1gE", "foo.map"),
57 "foo.map:1: Could not demangle '1f1gE' as a <encoding>; "
61 TEST_F(SymbolRemappingReaderTest
, BadMappingOrder
) {
64 name N1N3fooE N1M3barE
69 EXPECT_EQ(readWithErrors(Map
, "foo.map"),
70 "foo.map:6: Manglings '1N' and '1M' have both been used in prior "
71 "remappings. Move this remapping earlier in the file.");
74 TEST_F(SymbolRemappingReaderTest
, RemappingsAdded
) {
77 name N1A3fooE N1B3barE
82 # void f<int>() = void g<int>()
83 encoding 1fIiEvv 1gIiEvv
87 auto Key
= Reader
.insert("_ZN1B3bar3bazIiEEvv");
88 EXPECT_NE(Key
, SymbolRemappingReader::Key());
89 EXPECT_EQ(Key
, Reader
.lookup("_ZN1A3foo3bazIlEEvv"));
90 EXPECT_NE(Key
, Reader
.lookup("_ZN1C3foo3bazIlEEvv"));
92 Key
= Reader
.insert("_Z1fIiEvv");
93 EXPECT_NE(Key
, SymbolRemappingReader::Key());
94 EXPECT_EQ(Key
, Reader
.lookup("_Z1gIlEvv"));