SymbolRemappingReaderTest.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //===- unittests/Support/SymbolRemappingReaderTest.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. #include "llvm/Support/SymbolRemappingReader.h"
  9. #include "llvm/Support/MemoryBuffer.h"
  10. #include "gtest/gtest.h"
  11. using namespace llvm;
  12. namespace {
  13. class SymbolRemappingReaderTest : public testing::Test {
  14. public:
  15. std::unique_ptr<MemoryBuffer> Buffer;
  16. SymbolRemappingReader Reader;
  17. std::string readWithErrors(StringRef Text, StringRef BufferName) {
  18. Buffer = MemoryBuffer::getMemBuffer(Text, BufferName);
  19. Error E = Reader.read(*Buffer);
  20. EXPECT_TRUE((bool)E);
  21. return toString(std::move(E));
  22. }
  23. void read(StringRef Text, StringRef BufferName) {
  24. Buffer = MemoryBuffer::getMemBuffer(Text, BufferName);
  25. Error E = Reader.read(*Buffer);
  26. EXPECT_FALSE((bool)E);
  27. }
  28. };
  29. } // unnamed namespace
  30. TEST_F(SymbolRemappingReaderTest, ParseErrors) {
  31. EXPECT_EQ(readWithErrors("error", "foo.map"),
  32. "foo.map:1: Expected 'kind mangled_name mangled_name', "
  33. "found 'error'");
  34. EXPECT_EQ(readWithErrors("error m1 m2", "foo.map"),
  35. "foo.map:1: Invalid kind, expected 'name', 'type', or 'encoding', "
  36. "found 'error'");
  37. }
  38. TEST_F(SymbolRemappingReaderTest, DemanglingErrors) {
  39. EXPECT_EQ(readWithErrors("type i banana", "foo.map"),
  40. "foo.map:1: Could not demangle 'banana' as a <type>; "
  41. "invalid mangling?");
  42. EXPECT_EQ(readWithErrors("name i 1X", "foo.map"),
  43. "foo.map:1: Could not demangle 'i' as a <name>; "
  44. "invalid mangling?");
  45. EXPECT_EQ(readWithErrors("name 1X 1fv", "foo.map"),
  46. "foo.map:1: Could not demangle '1fv' as a <name>; "
  47. "invalid mangling?");
  48. EXPECT_EQ(readWithErrors("encoding 1fv 1f1gE", "foo.map"),
  49. "foo.map:1: Could not demangle '1f1gE' as a <encoding>; "
  50. "invalid mangling?");
  51. }
  52. TEST_F(SymbolRemappingReaderTest, BadMappingOrder) {
  53. StringRef Map = R"(
  54. # N::foo == M::bar
  55. name N1N3fooE N1M3barE
  56. # N:: == M::
  57. name 1N 1M
  58. )";
  59. EXPECT_EQ(readWithErrors(Map, "foo.map"),
  60. "foo.map:6: Manglings '1N' and '1M' have both been used in prior "
  61. "remappings. Move this remapping earlier in the file.");
  62. }
  63. TEST_F(SymbolRemappingReaderTest, RemappingsAdded) {
  64. StringRef Map = R"(
  65. # A::foo == B::bar
  66. name N1A3fooE N1B3barE
  67. # int == long
  68. type i l
  69. # void f<int>() = void g<int>()
  70. encoding 1fIiEvv 1gIiEvv
  71. )";
  72. read(Map, "foo.map");
  73. auto Key = Reader.insert("_ZN1B3bar3bazIiEEvv");
  74. EXPECT_NE(Key, SymbolRemappingReader::Key());
  75. EXPECT_EQ(Key, Reader.lookup("_ZN1A3foo3bazIlEEvv"));
  76. EXPECT_NE(Key, Reader.lookup("_ZN1C3foo3bazIlEEvv"));
  77. Key = Reader.insert("_Z1fIiEvv");
  78. EXPECT_NE(Key, SymbolRemappingReader::Key());
  79. EXPECT_EQ(Key, Reader.lookup("_Z1gIlEvv"));
  80. }