[ARM] MVE big endian loads/stores
[llvm-complete.git] / unittests / ObjectYAML / MinidumpYAMLTest.cpp
blob66d44e0675964a71034ce9c08851536a50b54630
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/ObjectYAML/MinidumpYAML.h"
10 #include "llvm/Object/Minidump.h"
11 #include "llvm/ObjectYAML/ObjectYAML.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 if (Error E = MinidumpYAML::writeAsBinary(Yaml, OS))
23 return std::move(E);
25 return object::MinidumpFile::create(MemoryBufferRef(OS.str(), "Binary"));
28 TEST(MinidumpYAML, Basic) {
29 SmallString<0> Storage;
30 auto ExpectedFile = toBinary(Storage, R"(
31 --- !minidump
32 Streams:
33 - Type: SystemInfo
34 Processor Arch: ARM64
35 Platform ID: Linux
36 CPU:
37 CPUID: 0x05060708
38 - Type: LinuxMaps
39 Text: |
40 400d9000-400db000 r-xp 00000000 b3:04 227 /system/bin/app_process
41 400db000-400dc000 r--p 00001000 b3:04 227 /system/bin/app_process
43 - Type: LinuxAuxv
44 Content: DEADBEEFBAADF00D)");
45 ASSERT_THAT_EXPECTED(ExpectedFile, Succeeded());
46 object::MinidumpFile &File = **ExpectedFile;
48 ASSERT_EQ(3u, File.streams().size());
50 EXPECT_EQ(StreamType::SystemInfo, File.streams()[0].Type);
51 auto ExpectedSysInfo = File.getSystemInfo();
52 ASSERT_THAT_EXPECTED(ExpectedSysInfo, Succeeded());
53 const SystemInfo &SysInfo = *ExpectedSysInfo;
54 EXPECT_EQ(ProcessorArchitecture::ARM64, SysInfo.ProcessorArch);
55 EXPECT_EQ(OSPlatform::Linux, SysInfo.PlatformId);
56 EXPECT_EQ(0x05060708u, SysInfo.CPU.Arm.CPUID);
58 EXPECT_EQ(StreamType::LinuxMaps, File.streams()[1].Type);
59 EXPECT_EQ("400d9000-400db000 r-xp 00000000 b3:04 227 "
60 "/system/bin/app_process\n"
61 "400db000-400dc000 r--p 00001000 b3:04 227 "
62 "/system/bin/app_process\n",
63 toStringRef(*File.getRawStream(StreamType::LinuxMaps)));
65 EXPECT_EQ(StreamType::LinuxAuxv, File.streams()[2].Type);
66 EXPECT_EQ((ArrayRef<uint8_t>{0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD, 0xF0, 0x0D}),
67 File.getRawStream(StreamType::LinuxAuxv));
70 TEST(MinidumpYAML, RawContent) {
71 SmallString<0> Storage;
72 auto ExpectedFile = toBinary(Storage, R"(
73 --- !minidump
74 Streams:
75 - Type: LinuxAuxv
76 Size: 9
77 Content: DEADBEEFBAADF00D)");
78 ASSERT_THAT_EXPECTED(ExpectedFile, Succeeded());
79 object::MinidumpFile &File = **ExpectedFile;
81 EXPECT_EQ(
82 (ArrayRef<uint8_t>{0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD, 0xF0, 0x0D, 0x00}),
83 File.getRawStream(StreamType::LinuxAuxv));
86 TEST(MinidumpYAML, X86SystemInfo) {
87 SmallString<0> Storage;
88 auto ExpectedFile = toBinary(Storage, R"(
89 --- !minidump
90 Streams:
91 - Type: SystemInfo
92 Processor Arch: X86
93 Platform ID: Linux
94 CPU:
95 Vendor ID: LLVMLLVMLLVM
96 Version Info: 0x01020304
97 Feature Info: 0x05060708
98 AMD Extended Features: 0x09000102)");
99 ASSERT_THAT_EXPECTED(ExpectedFile, Succeeded());
100 object::MinidumpFile &File = **ExpectedFile;
102 ASSERT_EQ(1u, File.streams().size());
104 auto ExpectedSysInfo = File.getSystemInfo();
105 ASSERT_THAT_EXPECTED(ExpectedSysInfo, Succeeded());
106 const SystemInfo &SysInfo = *ExpectedSysInfo;
107 EXPECT_EQ(ProcessorArchitecture::X86, SysInfo.ProcessorArch);
108 EXPECT_EQ(OSPlatform::Linux, SysInfo.PlatformId);
109 EXPECT_EQ("LLVMLLVMLLVM", StringRef(SysInfo.CPU.X86.VendorID,
110 sizeof(SysInfo.CPU.X86.VendorID)));
111 EXPECT_EQ(0x01020304u, SysInfo.CPU.X86.VersionInfo);
112 EXPECT_EQ(0x05060708u, SysInfo.CPU.X86.FeatureInfo);
113 EXPECT_EQ(0x09000102u, SysInfo.CPU.X86.AMDExtendedFeatures);
116 TEST(MinidumpYAML, OtherSystemInfo) {
117 SmallString<0> Storage;
118 auto ExpectedFile = toBinary(Storage, R"(
119 --- !minidump
120 Streams:
121 - Type: SystemInfo
122 Processor Arch: PPC
123 Platform ID: Linux
124 CPU:
125 Features: 000102030405060708090a0b0c0d0e0f)");
126 ASSERT_THAT_EXPECTED(ExpectedFile, Succeeded());
127 object::MinidumpFile &File = **ExpectedFile;
129 ASSERT_EQ(1u, File.streams().size());
131 auto ExpectedSysInfo = File.getSystemInfo();
132 ASSERT_THAT_EXPECTED(ExpectedSysInfo, Succeeded());
133 const SystemInfo &SysInfo = *ExpectedSysInfo;
134 EXPECT_EQ(ProcessorArchitecture::PPC, SysInfo.ProcessorArch);
135 EXPECT_EQ(OSPlatform::Linux, SysInfo.PlatformId);
136 EXPECT_EQ(
137 (ArrayRef<uint8_t>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}),
138 makeArrayRef(SysInfo.CPU.Other.ProcessorFeatures));