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 15 using testing::Field; 16 using testing::UnorderedElementsAre; 17 using testing::UnorderedElementsAreArray; 18 19 namespace llvm { 20 21 void PrintTo(const BPFunctionNode &Node, std::ostream *OS) { 22 raw_os_ostream ROS(*OS); 23 Node.dump(ROS); 24 } 25 26 TEST(BPFunctionNodeTest, Basic) { 27 auto Nodes = TemporalProfTraceTy::createBPFunctionNodes({ 28 TemporalProfTraceTy({0, 1, 2, 3, 4}), 29 TemporalProfTraceTy({4, 2}), 30 }); 31 32 auto NodeIs = [](BPFunctionNode::IDT Id, 33 ArrayRef<BPFunctionNode::UtilityNodeT> UNs) { 34 return AllOf(Field("Id", &BPFunctionNode::Id, Id), 35 Field("UtilityNodes", &BPFunctionNode::UtilityNodes, 36 UnorderedElementsAreArray(UNs))); 37 }; 38 39 EXPECT_THAT(Nodes, 40 UnorderedElementsAre(NodeIs(0, {0, 1, 2}), NodeIs(1, {1, 2}), 41 NodeIs(2, {1, 2, 4, 5}), NodeIs(3, {2}), 42 NodeIs(4, {2, 3, 4, 5}))); 43 } 44 45 } // end namespace llvm 46