[llvm-nm] - Fix a bug and unbreak ASan BB.
[llvm-complete.git] / unittests / ObjectYAML / MinidumpYAMLTest.cpp
blob6df9536e9d3bf4f17abb1f0ee9c6328074a5c026
1 //===- MinidumpYAMLTest.cpp - Tests for Minidump<->YAML code --------------===//
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/Object/Minidump.h"
10 #include "llvm/ObjectYAML/yaml2obj.h"
11 #include "llvm/Support/YAMLTraits.h"
12 #include "llvm/Testing/Support/Error.h"
13 #include "gtest/gtest.h"
15 using namespace llvm;
16 using namespace llvm::minidump;
18 static Expected<std::unique_ptr<object::MinidumpFile>>
19 toBinary(SmallVectorImpl<char> &Storage, StringRef Yaml) {
20 Storage.clear();
21 raw_svector_ostream OS(Storage);
22 yaml::Input YIn(Yaml);
23 if (Error E = yaml::convertYAML(YIn, OS))
24 return std::move(E);
26 return object::MinidumpFile::create(MemoryBufferRef(OS.str(), "Binary"));
29 TEST(MinidumpYAML, Basic) {
30 SmallString<0> Storage;
31 auto ExpectedFile = toBinary(Storage, R"(
32 --- !minidump
33 Streams:
34 - Type: SystemInfo
35 Processor Arch: ARM64
36 Platform ID: Linux
37 CPU:
38 CPUID: 0x05060708
39 - Type: LinuxMaps
40 Text: |
41 400d9000-400db000 r-xp 00000000 b3:04 227 /system/bin/app_process
42 400db000-400dc000 r--p 00001000 b3:04 227 /system/bin/app_process
44 - Type: LinuxAuxv
45 Content: DEADBEEFBAADF00D)");
46 ASSERT_THAT_EXPECTED(ExpectedFile, Succeeded());
47 object::MinidumpFile &File = **ExpectedFile;
49 ASSERT_EQ(3u, File.streams().size());
51 EXPECT_EQ(StreamType::SystemInfo, File.streams()[0].Type);
52 auto ExpectedSysInfo = File.getSystemInfo();
53 ASSERT_THAT_EXPECTED(ExpectedSysInfo, Succeeded());
54 const SystemInfo &SysInfo = *ExpectedSysInfo;
55 EXPECT_EQ(ProcessorArchitecture::ARM64, SysInfo.ProcessorArch);
56 EXPECT_EQ(OSPlatform::Linux, SysInfo.PlatformId);
57 EXPECT_EQ(0x05060708u, SysInfo.CPU.Arm.CPUID);
59 EXPECT_EQ(StreamType::LinuxMaps, File.streams()[1].Type);
60 EXPECT_EQ("400d9000-400db000 r-xp 00000000 b3:04 227 "
61 "/system/bin/app_process\n"
62 "400db000-400dc000 r--p 00001000 b3:04 227 "
63 "/system/bin/app_process\n",
64 toStringRef(*File.getRawStream(StreamType::LinuxMaps)));
66 EXPECT_EQ(StreamType::LinuxAuxv, File.streams()[2].Type);
67 EXPECT_EQ((ArrayRef<uint8_t>{0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD, 0xF0, 0x0D}),
68 File.getRawStream(StreamType::LinuxAuxv));
71 TEST(MinidumpYAML, RawContent) {
72 SmallString<0> Storage;
73 auto ExpectedFile = toBinary(Storage, R"(
74 --- !minidump
75 Streams:
76 - Type: LinuxAuxv
77 Size: 9
78 Content: DEADBEEFBAADF00D)");
79 ASSERT_THAT_EXPECTED(ExpectedFile, Succeeded());
80 object::MinidumpFile &File = **ExpectedFile;
82 EXPECT_EQ(
83 (ArrayRef<uint8_t>{0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD, 0xF0, 0x0D, 0x00}),
84 File.getRawStream(StreamType::LinuxAuxv));
87 TEST(MinidumpYAML, X86SystemInfo) {
88 SmallString<0> Storage;
89 auto ExpectedFile = toBinary(Storage, R"(
90 --- !minidump
91 Streams:
92 - Type: SystemInfo
93 Processor Arch: X86
94 Platform ID: Linux
95 CPU:
96 Vendor ID: LLVMLLVMLLVM
97 Version Info: 0x01020304
98 Feature Info: 0x05060708
99 AMD Extended Features: 0x09000102)");
100 ASSERT_THAT_EXPECTED(ExpectedFile, Succeeded());
101 object::MinidumpFile &File = **ExpectedFile;
103 ASSERT_EQ(1u, File.streams().size());
105 auto ExpectedSysInfo = File.getSystemInfo();
106 ASSERT_THAT_EXPECTED(ExpectedSysInfo, Succeeded());
107 const SystemInfo &SysInfo = *ExpectedSysInfo;
108 EXPECT_EQ(ProcessorArchitecture::X86, SysInfo.ProcessorArch);
109 EXPECT_EQ(OSPlatform::Linux, SysInfo.PlatformId);
110 EXPECT_EQ("LLVMLLVMLLVM", StringRef(SysInfo.CPU.X86.VendorID,
111 sizeof(SysInfo.CPU.X86.VendorID)));
112 EXPECT_EQ(0x01020304u, SysInfo.CPU.X86.VersionInfo);
113 EXPECT_EQ(0x05060708u, SysInfo.CPU.X86.FeatureInfo);
114 EXPECT_EQ(0x09000102u, SysInfo.CPU.X86.AMDExtendedFeatures);
117 TEST(MinidumpYAML, OtherSystemInfo) {
118 SmallString<0> Storage;
119 auto ExpectedFile = toBinary(Storage, R"(
120 --- !minidump
121 Streams:
122 - Type: SystemInfo
123 Processor Arch: PPC
124 Platform ID: Linux
125 CPU:
126 Features: 000102030405060708090a0b0c0d0e0f)");
127 ASSERT_THAT_EXPECTED(ExpectedFile, Succeeded());
128 object::MinidumpFile &File = **ExpectedFile;
130 ASSERT_EQ(1u, File.streams().size());
132 auto ExpectedSysInfo = File.getSystemInfo();
133 ASSERT_THAT_EXPECTED(ExpectedSysInfo, Succeeded());
134 const SystemInfo &SysInfo = *ExpectedSysInfo;
135 EXPECT_EQ(ProcessorArchitecture::PPC, SysInfo.ProcessorArch);
136 EXPECT_EQ(OSPlatform::Linux, SysInfo.PlatformId);
137 EXPECT_EQ(
138 (ArrayRef<uint8_t>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}),
139 makeArrayRef(SysInfo.CPU.Other.ProcessorFeatures));