[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / unittests / Remarks / YAMLRemarksSerializerTest.cpp
blob1ce932db2e3aa8ed49120feb4a2902d08f9b8698
1 //===- unittest/Support/YAMLRemarksSerializerTest.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 //===----------------------------------------------------------------------===//
9 #include "llvm/Remarks/Remark.h"
10 #include "llvm/Remarks/YAMLRemarkSerializer.h"
11 #include "llvm/Support/Error.h"
12 #include "gtest/gtest.h"
14 // We need to supprt Windows paths as well. In order to have paths with the same
15 // length, use a different path according to the platform.
16 #ifdef _WIN32
17 #define EXTERNALFILETESTPATH "C:/externalfi"
18 #else
19 #define EXTERNALFILETESTPATH "/externalfile"
20 #endif
22 using namespace llvm;
24 static void check(remarks::SerializerMode Mode, ArrayRef<remarks::Remark> Rs,
25 StringRef ExpectedR, Optional<StringRef> ExpectedMeta,
26 bool UseStrTab = false,
27 Optional<remarks::StringTable> StrTab = None) {
28 std::string Buf;
29 raw_string_ostream OS(Buf);
30 Expected<std::unique_ptr<remarks::RemarkSerializer>> MaybeS = [&] {
31 if (UseStrTab) {
32 if (StrTab)
33 return createRemarkSerializer(remarks::Format::YAMLStrTab, Mode, OS,
34 std::move(*StrTab));
35 else
36 return createRemarkSerializer(remarks::Format::YAMLStrTab, Mode, OS);
37 } else
38 return createRemarkSerializer(remarks::Format::YAML, Mode, OS);
39 }();
40 EXPECT_FALSE(errorToBool(MaybeS.takeError()));
41 std::unique_ptr<remarks::RemarkSerializer> S = std::move(*MaybeS);
43 for (const remarks::Remark &R : Rs)
44 S->emit(R);
45 EXPECT_EQ(OS.str(), ExpectedR);
47 if (ExpectedMeta) {
48 Buf.clear();
49 std::unique_ptr<remarks::MetaSerializer> MS =
50 S->metaSerializer(OS, StringRef(EXTERNALFILETESTPATH));
51 MS->emit();
52 EXPECT_EQ(OS.str(), *ExpectedMeta);
56 static void check(const remarks::Remark &R, StringRef ExpectedR,
57 StringRef ExpectedMeta, bool UseStrTab = false,
58 Optional<remarks::StringTable> StrTab = None) {
59 return check(remarks::SerializerMode::Separate, makeArrayRef(&R, &R + 1), ExpectedR, ExpectedMeta,
60 UseStrTab, std::move(StrTab));
63 static void checkStandalone(const remarks::Remark &R, StringRef ExpectedR,
64 Optional<remarks::StringTable> StrTab = None) {
65 bool UseStrTab = StrTab.hasValue();
66 return check(remarks::SerializerMode::Standalone, makeArrayRef(&R, &R +1), ExpectedR,
67 /*ExpectedMeta=*/None, UseStrTab, std::move(StrTab));
70 TEST(YAMLRemarks, SerializerRemark) {
71 remarks::Remark R;
72 R.RemarkType = remarks::Type::Missed;
73 R.PassName = "pass";
74 R.RemarkName = "name";
75 R.FunctionName = "func";
76 R.Loc = remarks::RemarkLocation{"path", 3, 4};
77 R.Hotness = 5;
78 R.Args.emplace_back();
79 R.Args.back().Key = "key";
80 R.Args.back().Val = "value";
81 R.Args.emplace_back();
82 R.Args.back().Key = "keydebug";
83 R.Args.back().Val = "valuedebug";
84 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
85 check(R,
86 "--- !Missed\n"
87 "Pass: pass\n"
88 "Name: name\n"
89 "DebugLoc: { File: path, Line: 3, Column: 4 }\n"
90 "Function: func\n"
91 "Hotness: 5\n"
92 "Args:\n"
93 " - key: value\n"
94 " - keydebug: valuedebug\n"
95 " DebugLoc: { File: argpath, Line: 6, Column: 7 }\n"
96 "...\n",
97 StringRef("REMARKS\0"
98 "\0\0\0\0\0\0\0\0"
99 "\0\0\0\0\0\0\0\0"
100 EXTERNALFILETESTPATH"\0",
101 38));
104 TEST(YAMLRemarks, SerializerRemarkStandalone) {
105 remarks::Remark R;
106 R.RemarkType = remarks::Type::Missed;
107 R.PassName = "pass";
108 R.RemarkName = "name";
109 R.FunctionName = "func";
110 R.Loc = remarks::RemarkLocation{"path", 3, 4};
111 R.Hotness = 5;
112 R.Args.emplace_back();
113 R.Args.back().Key = "key";
114 R.Args.back().Val = "value";
115 R.Args.emplace_back();
116 R.Args.back().Key = "keydebug";
117 R.Args.back().Val = "valuedebug";
118 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
119 checkStandalone(
121 StringRef("--- !Missed\n"
122 "Pass: pass\n"
123 "Name: name\n"
124 "DebugLoc: { File: path, Line: 3, Column: 4 }\n"
125 "Function: func\n"
126 "Hotness: 5\n"
127 "Args:\n"
128 " - key: value\n"
129 " - keydebug: valuedebug\n"
130 " DebugLoc: { File: argpath, Line: 6, Column: 7 }\n"
131 "...\n"));
134 TEST(YAMLRemarks, SerializerRemarkStrTab) {
135 remarks::Remark R;
136 R.RemarkType = remarks::Type::Missed;
137 R.PassName = "pass";
138 R.RemarkName = "name";
139 R.FunctionName = "func";
140 R.Loc = remarks::RemarkLocation{"path", 3, 4};
141 R.Hotness = 5;
142 R.Args.emplace_back();
143 R.Args.back().Key = "key";
144 R.Args.back().Val = "value";
145 R.Args.emplace_back();
146 R.Args.back().Key = "keydebug";
147 R.Args.back().Val = "valuedebug";
148 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
149 check(R,
150 "--- !Missed\n"
151 "Pass: 0\n"
152 "Name: 1\n"
153 "DebugLoc: { File: 3, Line: 3, Column: 4 }\n"
154 "Function: 2\n"
155 "Hotness: 5\n"
156 "Args:\n"
157 " - key: 4\n"
158 " - keydebug: 5\n"
159 " DebugLoc: { File: 6, Line: 6, Column: 7 }\n"
160 "...\n",
161 StringRef("REMARKS\0"
162 "\0\0\0\0\0\0\0\0"
163 "\x2d\0\0\0\0\0\0\0"
164 "pass\0name\0func\0path\0value\0valuedebug\0argpath\0"
165 EXTERNALFILETESTPATH"\0",
166 83),
167 /*UseStrTab=*/true);
170 TEST(YAMLRemarks, SerializerRemarkParsedStrTab) {
171 StringRef StrTab("pass\0name\0func\0path\0value\0valuedebug\0argpath\0", 45);
172 remarks::Remark R;
173 R.RemarkType = remarks::Type::Missed;
174 R.PassName = "pass";
175 R.RemarkName = "name";
176 R.FunctionName = "func";
177 R.Loc = remarks::RemarkLocation{"path", 3, 4};
178 R.Hotness = 5;
179 R.Args.emplace_back();
180 R.Args.back().Key = "key";
181 R.Args.back().Val = "value";
182 R.Args.emplace_back();
183 R.Args.back().Key = "keydebug";
184 R.Args.back().Val = "valuedebug";
185 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
186 check(R,
187 "--- !Missed\n"
188 "Pass: 0\n"
189 "Name: 1\n"
190 "DebugLoc: { File: 3, Line: 3, Column: 4 }\n"
191 "Function: 2\n"
192 "Hotness: 5\n"
193 "Args:\n"
194 " - key: 4\n"
195 " - keydebug: 5\n"
196 " DebugLoc: { File: 6, Line: 6, Column: 7 }\n"
197 "...\n",
198 StringRef("REMARKS\0"
199 "\0\0\0\0\0\0\0\0"
200 "\x2d\0\0\0\0\0\0\0"
201 "pass\0name\0func\0path\0value\0valuedebug\0argpath\0"
202 EXTERNALFILETESTPATH"\0",
203 83),
204 /*UseStrTab=*/true,
205 remarks::StringTable(remarks::ParsedStringTable(StrTab)));
208 TEST(YAMLRemarks, SerializerRemarkParsedStrTabStandalone) {
209 StringRef StrTab("pass\0name\0func\0path\0value\0valuedebug\0argpath\0", 45);
210 remarks::ParsedStringTable ParsedStrTab(StrTab);
211 remarks::StringTable PreFilledStrTab(ParsedStrTab);
212 remarks::Remark R;
213 R.RemarkType = remarks::Type::Missed;
214 R.PassName = "pass";
215 R.RemarkName = "name";
216 R.FunctionName = "func";
217 R.Loc = remarks::RemarkLocation{"path", 3, 4};
218 R.Hotness = 5;
219 R.Args.emplace_back();
220 R.Args.back().Key = "key";
221 R.Args.back().Val = "value";
222 R.Args.emplace_back();
223 R.Args.back().Key = "keydebug";
224 R.Args.back().Val = "valuedebug";
225 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
226 checkStandalone(
228 StringRef("REMARKS\0"
229 "\0\0\0\0\0\0\0\0"
230 "\x2d\0\0\0\0\0\0\0"
231 "pass\0name\0func\0path\0value\0valuedebug\0argpath\0"
232 "--- !Missed\n"
233 "Pass: 0\n"
234 "Name: 1\n"
235 "DebugLoc: { File: 3, Line: 3, Column: 4 }\n"
236 "Function: 2\n"
237 "Hotness: 5\n"
238 "Args:\n"
239 " - key: 4\n"
240 " - keydebug: 5\n"
241 " DebugLoc: { File: 6, Line: 6, Column: 7 }\n"
242 "...\n",
243 315),
244 std::move(PreFilledStrTab));
247 TEST(YAMLRemarks, SerializerRemarkParsedStrTabStandaloneMultipleRemarks) {
248 StringRef StrTab("pass\0name\0func\0path\0value\0valuedebug\0argpath\0", 45);
249 remarks::ParsedStringTable ParsedStrTab(StrTab);
250 remarks::StringTable PreFilledStrTab(ParsedStrTab);
251 SmallVector<remarks::Remark, 2> Rs;
252 remarks::Remark R;
253 R.RemarkType = remarks::Type::Missed;
254 R.PassName = "pass";
255 R.RemarkName = "name";
256 R.FunctionName = "func";
257 R.Loc = remarks::RemarkLocation{"path", 3, 4};
258 R.Hotness = 5;
259 R.Args.emplace_back();
260 R.Args.back().Key = "key";
261 R.Args.back().Val = "value";
262 R.Args.emplace_back();
263 R.Args.back().Key = "keydebug";
264 R.Args.back().Val = "valuedebug";
265 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
266 Rs.emplace_back(R.clone());
267 Rs.emplace_back(std::move(R));
268 check(remarks::SerializerMode::Standalone, Rs,
269 StringRef("REMARKS\0"
270 "\0\0\0\0\0\0\0\0"
271 "\x2d\0\0\0\0\0\0\0"
272 "pass\0name\0func\0path\0value\0valuedebug\0argpath\0"
273 "--- !Missed\n"
274 "Pass: 0\n"
275 "Name: 1\n"
276 "DebugLoc: { File: 3, Line: 3, Column: 4 }\n"
277 "Function: 2\n"
278 "Hotness: 5\n"
279 "Args:\n"
280 " - key: 4\n"
281 " - keydebug: 5\n"
282 " DebugLoc: { File: 6, Line: 6, Column: 7 }\n"
283 "...\n"
284 "--- !Missed\n"
285 "Pass: 0\n"
286 "Name: 1\n"
287 "DebugLoc: { File: 3, Line: 3, Column: 4 }\n"
288 "Function: 2\n"
289 "Hotness: 5\n"
290 "Args:\n"
291 " - key: 4\n"
292 " - keydebug: 5\n"
293 " DebugLoc: { File: 6, Line: 6, Column: 7 }\n"
294 "...\n",
295 561),
296 /*ExpectedMeta=*/None,
297 /*UseStrTab=*/true, std::move(PreFilledStrTab));