1 //===- MinidumpYAMLTest.cpp - Tests for Minidump<->YAML code --------------===//
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/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"
16 using namespace llvm::minidump
;
18 static Expected
<std::unique_ptr
<object::MinidumpFile
>>
19 toBinary(SmallVectorImpl
<char> &Storage
, StringRef Yaml
) {
21 raw_svector_ostream
OS(Storage
);
22 yaml::Input
YIn(Yaml
);
23 if (Error E
= yaml::convertYAML(YIn
, OS
))
26 return object::MinidumpFile::create(MemoryBufferRef(OS
.str(), "Binary"));
29 TEST(MinidumpYAML
, Basic
) {
30 SmallString
<0> Storage
;
31 auto ExpectedFile
= toBinary(Storage
, R
"(
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
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
"(
78 Content: DEADBEEFBAADF00D)");
79 ASSERT_THAT_EXPECTED(ExpectedFile
, Succeeded());
80 object::MinidumpFile
&File
= **ExpectedFile
;
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
"(
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
"(
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
);
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
));