blob: c5f222f0f8de024c1208329935fb772a1f038e93 [file] [log] [blame]
Francis Visoiu Mistrih78c92d22019-07-23 18:09:12 +00001//===- 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//===----------------------------------------------------------------------===//
8
9#include "llvm/Remarks/Remark.h"
Francis Visoiu Mistrihcbbdc412019-07-23 19:28:03 +000010#include "llvm/Remarks/YAMLRemarkSerializer.h"
Francis Visoiu Mistrih78c92d22019-07-23 18:09:12 +000011#include "gtest/gtest.h"
12
13using namespace llvm;
14
15static void check(const remarks::Remark &R, StringRef Expected,
16 Optional<StringRef> ExpectedStrTab = None) {
17 std::string Buf;
18 raw_string_ostream OS(Buf);
19 remarks::UseStringTable UseStrTab = ExpectedStrTab.hasValue()
20 ? remarks::UseStringTable::Yes
21 : remarks::UseStringTable::No;
22 remarks::YAMLSerializer S(OS, UseStrTab);
23 S.emit(R);
24 EXPECT_EQ(OS.str(), Expected);
25 if (ExpectedStrTab) {
26 Buf.clear();
27 EXPECT_TRUE(S.StrTab);
28 S.StrTab->serialize(OS);
29 EXPECT_EQ(OS.str(), *ExpectedStrTab);
30 }
31}
32
33TEST(YAMLRemarks, SerializerRemark) {
34 remarks::Remark R;
35 R.RemarkType = remarks::Type::Missed;
36 R.PassName = "pass";
37 R.RemarkName = "name";
38 R.FunctionName = "func";
39 R.Loc = remarks::RemarkLocation{"path", 3, 4};
40 R.Hotness = 5;
41 R.Args.emplace_back();
42 R.Args.back().Key = "key";
43 R.Args.back().Val = "value";
44 R.Args.emplace_back();
45 R.Args.back().Key = "keydebug";
46 R.Args.back().Val = "valuedebug";
47 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
48 check(R, "--- !Missed\n"
49 "Pass: pass\n"
50 "Name: name\n"
51 "DebugLoc: { File: path, Line: 3, Column: 4 }\n"
52 "Function: func\n"
53 "Hotness: 5\n"
54 "Args:\n"
55 " - key: value\n"
56 " - keydebug: valuedebug\n"
57 " DebugLoc: { File: argpath, Line: 6, Column: 7 }\n"
58 "...\n");
59}
60
61TEST(YAMLRemarks, SerializerRemarkStrTab) {
62 remarks::Remark R;
63 R.RemarkType = remarks::Type::Missed;
64 R.PassName = "pass";
65 R.RemarkName = "name";
66 R.FunctionName = "func";
67 R.Loc = remarks::RemarkLocation{"path", 3, 4};
68 R.Hotness = 5;
69 R.Args.emplace_back();
70 R.Args.back().Key = "key";
71 R.Args.back().Val = "value";
72 R.Args.emplace_back();
73 R.Args.back().Key = "keydebug";
74 R.Args.back().Val = "valuedebug";
75 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
76 check(R,
77 "--- !Missed\n"
78 "Pass: 0\n"
79 "Name: 1\n"
80 "DebugLoc: { File: 3, Line: 3, Column: 4 }\n"
81 "Function: 2\n"
82 "Hotness: 5\n"
83 "Args:\n"
84 " - key: 4\n"
85 " - keydebug: 5\n"
86 " DebugLoc: { File: 6, Line: 6, Column: 7 }\n"
87 "...\n",
88 StringRef("pass\0name\0func\0path\0value\0valuedebug\0argpath\0", 45));
89}