blob: 629811a8ba1d7c90763800f211f7d7630fe87b5b [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);
Francis Visoiu Mistrihc5b5cc42019-07-23 20:42:46 +000019 bool UseStrTab = ExpectedStrTab.hasValue();
20 std::unique_ptr<remarks::Serializer> S =
21 UseStrTab ? llvm::make_unique<remarks::YAMLStrTabSerializer>(OS)
22 : llvm::make_unique<remarks::YAMLSerializer>(OS);
23
24 S->emit(R);
Francis Visoiu Mistrih78c92d22019-07-23 18:09:12 +000025 EXPECT_EQ(OS.str(), Expected);
26 if (ExpectedStrTab) {
27 Buf.clear();
Francis Visoiu Mistrihc5b5cc42019-07-23 20:42:46 +000028 EXPECT_TRUE(S->StrTab);
29 S->StrTab->serialize(OS);
Francis Visoiu Mistrih78c92d22019-07-23 18:09:12 +000030 EXPECT_EQ(OS.str(), *ExpectedStrTab);
31 }
32}
33
34TEST(YAMLRemarks, SerializerRemark) {
35 remarks::Remark R;
36 R.RemarkType = remarks::Type::Missed;
37 R.PassName = "pass";
38 R.RemarkName = "name";
39 R.FunctionName = "func";
40 R.Loc = remarks::RemarkLocation{"path", 3, 4};
41 R.Hotness = 5;
42 R.Args.emplace_back();
43 R.Args.back().Key = "key";
44 R.Args.back().Val = "value";
45 R.Args.emplace_back();
46 R.Args.back().Key = "keydebug";
47 R.Args.back().Val = "valuedebug";
48 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
49 check(R, "--- !Missed\n"
50 "Pass: pass\n"
51 "Name: name\n"
52 "DebugLoc: { File: path, Line: 3, Column: 4 }\n"
53 "Function: func\n"
54 "Hotness: 5\n"
55 "Args:\n"
56 " - key: value\n"
57 " - keydebug: valuedebug\n"
58 " DebugLoc: { File: argpath, Line: 6, Column: 7 }\n"
59 "...\n");
60}
61
62TEST(YAMLRemarks, SerializerRemarkStrTab) {
63 remarks::Remark R;
64 R.RemarkType = remarks::Type::Missed;
65 R.PassName = "pass";
66 R.RemarkName = "name";
67 R.FunctionName = "func";
68 R.Loc = remarks::RemarkLocation{"path", 3, 4};
69 R.Hotness = 5;
70 R.Args.emplace_back();
71 R.Args.back().Key = "key";
72 R.Args.back().Val = "value";
73 R.Args.emplace_back();
74 R.Args.back().Key = "keydebug";
75 R.Args.back().Val = "valuedebug";
76 R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
77 check(R,
78 "--- !Missed\n"
79 "Pass: 0\n"
80 "Name: 1\n"
81 "DebugLoc: { File: 3, Line: 3, Column: 4 }\n"
82 "Function: 2\n"
83 "Hotness: 5\n"
84 "Args:\n"
85 " - key: 4\n"
86 " - keydebug: 5\n"
87 " DebugLoc: { File: 6, Line: 6, Column: 7 }\n"
88 "...\n",
89 StringRef("pass\0name\0func\0path\0value\0valuedebug\0argpath\0", 45));
90}