1//===- BPFunctionNodeTest.cpp - BPFunctionNode 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//===----------------------------------------------------------------------===//
8
9#include "llvm/ProfileData/InstrProf.h"
10#include "llvm/Support/BalancedPartitioning.h"
11#include "llvm/Testing/Support/SupportHelpers.h"
12#include "gmock/gmock.h"
13#include "gtest/gtest.h"
14
15using testing::Field;
16using testing::UnorderedElementsAre;
17using testing::UnorderedElementsAreArray;
18
19namespace llvm {
20
21void PrintTo(const BPFunctionNode &Node, std::ostream *OS) {
22 raw_os_ostream ROS(*OS);
23 Node.dump(OS&: ROS);
24}
25
26TEST(BPFunctionNodeTest, Basic) {
27 auto NodeIs = [](BPFunctionNode::IDT Id,
28 ArrayRef<BPFunctionNode::UtilityNodeT> UNs) {
29 return AllOf(matchers: Field(field_name: "Id", field: &BPFunctionNode::Id, matcher: Id),
30 matchers: Field(field_name: "UtilityNodes", field: &BPFunctionNode::UtilityNodes,
31 matcher: UnorderedElementsAreArray(container: UNs)));
32 };
33
34 auto Nodes = TemporalProfTraceTy::createBPFunctionNodes(Traces: {
35 TemporalProfTraceTy({0, 1, 2, 3}),
36 });
37 EXPECT_THAT(Nodes,
38 UnorderedElementsAre(NodeIs(0, {0, 1, 2}), NodeIs(1, {1, 2}),
39 NodeIs(2, {1, 2}), NodeIs(3, {2})));
40
41 Nodes = TemporalProfTraceTy::createBPFunctionNodes(Traces: {
42 TemporalProfTraceTy({0, 1, 2, 3, 4}),
43 TemporalProfTraceTy({4, 2}),
44 });
45
46 EXPECT_THAT(Nodes,
47 UnorderedElementsAre(NodeIs(0, {0, 1, 2}), NodeIs(1, {1, 2}),
48 NodeIs(2, {1, 2, 4, 5}), NodeIs(3, {2}),
49 NodeIs(4, {2, 3, 4, 5})));
50}
51
52} // end namespace llvm
53

source code of llvm/unittests/ProfileData/BPFunctionNodeTest.cpp