|
| 1 | +#include "propeller/proto_branch_frequencies_aggregator.h" |
| 2 | + |
| 3 | +#include "propeller/status_testing_macros.h" |
| 4 | +#include "gmock/gmock.h" |
| 5 | +#include "gtest/gtest.h" |
| 6 | +#include "absl/status/status_matchers.h" |
| 7 | +#include "propeller/binary_content.h" |
| 8 | +#include "propeller/branch_frequencies.h" |
| 9 | +#include "propeller/branch_frequencies.pb.h" |
| 10 | +#include "propeller/parse_text_proto.h" |
| 11 | +#include "propeller/propeller_options.pb.h" |
| 12 | +#include "propeller/propeller_statistics.h" |
| 13 | + |
| 14 | +namespace propeller { |
| 15 | +namespace { |
| 16 | +using ::propeller_testing::ParseTextProtoOrDie; |
| 17 | +using ::testing::AllOf; |
| 18 | +using ::testing::ElementsAre; |
| 19 | +using ::testing::Field; |
| 20 | +using ::testing::FieldsAre; |
| 21 | +using ::testing::Pair; |
| 22 | +using ::absl_testing::IsOkAndHolds; |
| 23 | + |
| 24 | +TEST(ProtoBranchFrequenciesAggregator, AggregateBranchFrequencies) { |
| 25 | + BranchFrequenciesProto proto = ParseTextProtoOrDie(R"pb( |
| 26 | + taken_counts: { source: 1 dest: 2 count: 3 } |
| 27 | + not_taken_counts: { address: 1 count: 2 } |
| 28 | + )pb"); |
| 29 | + |
| 30 | + PropellerStats ignored; |
| 31 | + |
| 32 | + EXPECT_THAT( |
| 33 | + ProtoBranchFrequenciesAggregator::Create(ParseTextProtoOrDie(R"pb( |
| 34 | + taken_counts: { source: 1 dest: 2 count: 3 } |
| 35 | + not_taken_counts: { address: 1 count: 2 } |
| 36 | + )pb")) |
| 37 | + .AggregateBranchFrequencies(PropellerOptions{}, BinaryContent{}, |
| 38 | + ignored), |
| 39 | + IsOkAndHolds( |
| 40 | + AllOf(Field("taken_branch_counters", |
| 41 | + &BranchFrequencies::taken_branch_counters, |
| 42 | + ElementsAre(Pair(FieldsAre(/*.from=*/1, /*.to=*/2), 3))), |
| 43 | + Field("not_taken_branch_counters", |
| 44 | + &BranchFrequencies::not_taken_branch_counters, |
| 45 | + ElementsAre(Pair(FieldsAre(/*.address=*/1), 2)))))); |
| 46 | +} |
| 47 | + |
| 48 | +} // namespace |
| 49 | +} // namespace propeller |
0 commit comments