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::Matcher; 17 using testing::UnorderedElementsAre; 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 UNIdsAre = [](auto... Ids) { 28 return UnorderedElementsAre(Field("Id", &BPFunctionNode::UtilityNodeT::Id, 29 std::forward<uint32_t>(Ids))...); 30 }; 31 auto NodeIs = [](BPFunctionNode::IDT Id, 32 Matcher<ArrayRef<BPFunctionNode::UtilityNodeT>> UNsMatcher) { 33 return AllOf( 34 Field("Id", &BPFunctionNode::Id, Id), 35 Field("UtilityNodes", &BPFunctionNode::UtilityNodes, UNsMatcher)); 36 }; 37 38 auto Nodes = TemporalProfTraceTy::createBPFunctionNodes({ 39 TemporalProfTraceTy({0, 1, 2, 3}), 40 }); 41 EXPECT_THAT(Nodes, UnorderedElementsAre(NodeIs(0, UNIdsAre(0, 1, 2)), 42 NodeIs(1, UNIdsAre(1, 2)), 43 NodeIs(2, UNIdsAre(1, 2)), 44 NodeIs(3, UNIdsAre(2)))); 45 46 Nodes = TemporalProfTraceTy::createBPFunctionNodes({ 47 TemporalProfTraceTy({0, 1, 2, 3, 4}), 48 TemporalProfTraceTy({4, 2}), 49 }); 50 51 EXPECT_THAT(Nodes, UnorderedElementsAre(NodeIs(0, UNIdsAre(0, 1, 2)), 52 NodeIs(1, UNIdsAre(1, 2)), 53 NodeIs(2, UNIdsAre(1, 2, 4, 5)), 54 NodeIs(3, UNIdsAre(2)), 55 NodeIs(4, UNIdsAre(2, 3, 4, 5)))); 56 } 57 58 } // end namespace llvm 59