[yaml2obj/obj2yaml] - Add support for .stack_sizes sections.
[llvm-complete.git] / unittests / Remarks / RemarksAPITest.cpp
blob19fa90f5a6aa599986a7e9a2fb723cc8bb309234
1 //===- unittest/Support/RemarksAPITest.cpp - C++ API tests ----------------===//
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/RemarkStringTable.h"
11 #include "gtest/gtest.h"
13 using namespace llvm;
15 TEST(RemarksAPI, Comparison) {
16 remarks::Remark R;
17 R.RemarkType = remarks::Type::Missed;
18 R.PassName = "pass";
19 R.RemarkName = "name";
20 R.FunctionName = "func";
21 R.Loc = remarks::RemarkLocation{"path", 3, 4};
22 R.Hotness = 5;
23 R.Args.emplace_back();
24 R.Args.back().Key = "key";
25 R.Args.back().Val = "value";
26 R.Args.emplace_back();
27 R.Args.back().Key = "keydebug";
28 R.Args.back().Val = "valuedebug";
29 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
31 // Check that == works.
32 EXPECT_EQ(R, R);
34 // Check that != works.
35 remarks::Remark R2 = R.clone();
36 R2.FunctionName = "func0";
37 EXPECT_NE(R, R2);
39 // Check that we iterate through all the arguments.
40 remarks::Remark R3 = R.clone();
41 R3.Args.back().Val = "not";
42 EXPECT_NE(R, R3);
45 TEST(RemarksAPI, Clone) {
46 remarks::Remark R;
47 R.RemarkType = remarks::Type::Missed;
48 R.PassName = "pass";
49 R.RemarkName = "name";
50 R.FunctionName = "func";
51 R.Loc = remarks::RemarkLocation{"path", 3, 4};
52 R.Hotness = 5;
53 R.Args.emplace_back();
54 R.Args.back().Key = "key";
55 R.Args.back().Val = "value";
56 R.Args.emplace_back();
57 R.Args.back().Key = "keydebug";
58 R.Args.back().Val = "valuedebug";
59 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
61 // Check that clone works.
62 remarks::Remark R2 = R.clone();
63 EXPECT_EQ(R, R2);
66 TEST(RemarksAPI, ArgsAsMsg) {
67 remarks::Remark R;
68 R.RemarkType = remarks::Type::Missed;
69 R.Args.emplace_back();
70 R.Args.back().Key = "key";
71 R.Args.back().Val = "can not do this ";
72 R.Args.emplace_back();
73 R.Args.back().Key = "keydebug";
74 R.Args.back().Val = "because of that.";
75 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
77 EXPECT_EQ(R.getArgsAsMsg(), "can not do this because of that.");
80 TEST(RemarksAPI, StringTableInternalize) {
81 remarks::StringTable StrTab;
83 // Empty table.
84 EXPECT_EQ(StrTab.SerializedSize, 0UL);
86 remarks::Remark R;
87 R.RemarkType = remarks::Type::Missed;
88 R.PassName = "pass";
89 R.RemarkName = "name";
90 R.FunctionName = "func";
91 R.Loc = remarks::RemarkLocation{"path", 3, 4};
92 R.Args.emplace_back();
93 R.Args.back().Key = "keydebug";
94 R.Args.back().Val = "valuedebug";
95 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
97 // Check that internalize starts using the strings from the string table.
98 remarks::Remark R2 = R.clone();
99 StrTab.internalize(R2);
101 // Check that the pointers in the remarks are different.
102 EXPECT_NE(R.PassName.data(), R2.PassName.data());
103 EXPECT_NE(R.RemarkName.data(), R2.RemarkName.data());
104 EXPECT_NE(R.FunctionName.data(), R2.FunctionName.data());
105 EXPECT_NE(R.Loc->SourceFilePath.data(), R2.Loc->SourceFilePath.data());
106 EXPECT_NE(R.Args.back().Key.data(), R2.Args.back().Key.data());
107 EXPECT_NE(R.Args.back().Val.data(), R2.Args.back().Val.data());
108 EXPECT_NE(R.Args.back().Loc->SourceFilePath.data(),
109 R2.Args.back().Loc->SourceFilePath.data());
111 // Check that the internalized remark is using the pointers from the string table.
112 EXPECT_EQ(StrTab.add(R.PassName).second.data(), R2.PassName.data());
113 EXPECT_EQ(StrTab.add(R.RemarkName).second.data(), R2.RemarkName.data());
114 EXPECT_EQ(StrTab.add(R.FunctionName).second.data(), R2.FunctionName.data());
115 EXPECT_EQ(StrTab.add(R.Loc->SourceFilePath).second.data(),
116 R2.Loc->SourceFilePath.data());
117 EXPECT_EQ(StrTab.add(R.Args.back().Key).second.data(),
118 R2.Args.back().Key.data());
119 EXPECT_EQ(StrTab.add(R.Args.back().Val).second.data(),
120 R2.Args.back().Val.data());
121 EXPECT_EQ(StrTab.add(R.Args.back().Loc->SourceFilePath).second.data(),
122 R2.Args.back().Loc->SourceFilePath.data());