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 (!yaml::convertYAML(YIn
, OS
, [](const Twine
&Msg
) {}))
24 return createStringError(std::errc::invalid_argument
,
25 "unable to convert YAML");
27 return object::MinidumpFile::create(MemoryBufferRef(OS
.str(), "Binary"));
30 TEST(MinidumpYAML
, Basic
) {
31 SmallString
<0> Storage
;
32 auto ExpectedFile
= toBinary(Storage
, R
"(
42 400d9000-400db000 r-xp 00000000 b3:04 227 /system/bin/app_process
43 400db000-400dc000 r--p 00001000 b3:04 227 /system/bin/app_process
46 Content: DEADBEEFBAADF00D)");
47 ASSERT_THAT_EXPECTED(ExpectedFile
, Succeeded());
48 object::MinidumpFile
&File
= **ExpectedFile
;
50 ASSERT_EQ(3u, File
.streams().size());
52 EXPECT_EQ(StreamType::SystemInfo
, File
.streams()[0].Type
);
53 auto ExpectedSysInfo
= File
.getSystemInfo();
54 ASSERT_THAT_EXPECTED(ExpectedSysInfo
, Succeeded());
55 const SystemInfo
&SysInfo
= *ExpectedSysInfo
;
56 EXPECT_EQ(ProcessorArchitecture::ARM64
, SysInfo
.ProcessorArch
);
57 EXPECT_EQ(OSPlatform::Linux
, SysInfo
.PlatformId
);
58 EXPECT_EQ(0x05060708u
, SysInfo
.CPU
.Arm
.CPUID
);
60 EXPECT_EQ(StreamType::LinuxMaps
, File
.streams()[1].Type
);
61 EXPECT_EQ("400d9000-400db000 r-xp 00000000 b3:04 227 "
62 "/system/bin/app_process\n"
63 "400db000-400dc000 r--p 00001000 b3:04 227 "
64 "/system/bin/app_process\n",
65 toStringRef(*File
.getRawStream(StreamType::LinuxMaps
)));
67 EXPECT_EQ(StreamType::LinuxAuxv
, File
.streams()[2].Type
);
68 EXPECT_EQ((ArrayRef
<uint8_t>{0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD, 0xF0, 0x0D}),
69 File
.getRawStream(StreamType::LinuxAuxv
));
72 TEST(MinidumpYAML
, RawContent
) {
73 SmallString
<0> Storage
;
74 auto ExpectedFile
= toBinary(Storage
, R
"(
79 Content: DEADBEEFBAADF00D)");
80 ASSERT_THAT_EXPECTED(ExpectedFile
, Succeeded());
81 object::MinidumpFile
&File
= **ExpectedFile
;
84 (ArrayRef
<uint8_t>{0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD, 0xF0, 0x0D, 0x00}),
85 File
.getRawStream(StreamType::LinuxAuxv
));
88 TEST(MinidumpYAML
, X86SystemInfo
) {
89 SmallString
<0> Storage
;
90 auto ExpectedFile
= toBinary(Storage
, R
"(
97 Vendor ID: LLVMLLVMLLVM
98 Version Info: 0x01020304
99 Feature Info: 0x05060708
100 AMD Extended Features: 0x09000102)");
101 ASSERT_THAT_EXPECTED(ExpectedFile
, Succeeded());
102 object::MinidumpFile
&File
= **ExpectedFile
;
104 ASSERT_EQ(1u, File
.streams().size());
106 auto ExpectedSysInfo
= File
.getSystemInfo();
107 ASSERT_THAT_EXPECTED(ExpectedSysInfo
, Succeeded());
108 const SystemInfo
&SysInfo
= *ExpectedSysInfo
;
109 EXPECT_EQ(ProcessorArchitecture::X86
, SysInfo
.ProcessorArch
);
110 EXPECT_EQ(OSPlatform::Linux
, SysInfo
.PlatformId
);
111 EXPECT_EQ("LLVMLLVMLLVM", StringRef(SysInfo
.CPU
.X86
.VendorID
,
112 sizeof(SysInfo
.CPU
.X86
.VendorID
)));
113 EXPECT_EQ(0x01020304u
, SysInfo
.CPU
.X86
.VersionInfo
);
114 EXPECT_EQ(0x05060708u
, SysInfo
.CPU
.X86
.FeatureInfo
);
115 EXPECT_EQ(0x09000102u
, SysInfo
.CPU
.X86
.AMDExtendedFeatures
);
118 TEST(MinidumpYAML
, OtherSystemInfo
) {
119 SmallString
<0> Storage
;
120 auto ExpectedFile
= toBinary(Storage
, R
"(
127 Features: 000102030405060708090a0b0c0d0e0f)");
128 ASSERT_THAT_EXPECTED(ExpectedFile
, Succeeded());
129 object::MinidumpFile
&File
= **ExpectedFile
;
131 ASSERT_EQ(1u, File
.streams().size());
133 auto ExpectedSysInfo
= File
.getSystemInfo();
134 ASSERT_THAT_EXPECTED(ExpectedSysInfo
, Succeeded());
135 const SystemInfo
&SysInfo
= *ExpectedSysInfo
;
136 EXPECT_EQ(ProcessorArchitecture::PPC
, SysInfo
.ProcessorArch
);
137 EXPECT_EQ(OSPlatform::Linux
, SysInfo
.PlatformId
);
139 (ArrayRef
<uint8_t>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}),
140 makeArrayRef(SysInfo
.CPU
.Other
.ProcessorFeatures
));