| 1 |
//===-- ResultAggregatorTest.cpp --------------------------------*- C++ -*-===// |
| 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 "ResultAggregator.h" |
| 10 |
#include "gtest/gtest.h" |
| 11 |
|
| 12 |
namespace llvm { |
| 13 |
namespace exegesis { |
| 14 |
|
| 15 |
namespace { |
| 16 |
|
| 17 |
TEST(ResultAggregatorTest, DefaultAggregator) { |
| 18 |
std::vector<Benchmark> Results(1); |
| 19 |
|
| 20 |
Results[0].Measurements = {BenchmarkMeasure::Create("x", 1, {})}; |
| 21 |
|
| 22 |
Benchmark &Result = Results[0]; |
| 23 |
|
| 24 |
std::unique_ptr<ResultAggregator> AggregatorToTest = |
| 25 |
ResultAggregator::CreateAggregator(Benchmark::RepetitionModeE::Duplicate); |
| 26 |
AggregatorToTest->AggregateResults(Result, ArrayRef(Results).drop_front()); |
| 27 |
|
| 28 |
EXPECT_EQ(Result.Measurements[0].PerInstructionValue, 1); |
| 29 |
EXPECT_EQ(Result.Measurements[0].PerSnippetValue, 1); |
| 30 |
EXPECT_EQ(Result.Measurements[0].RawValue, 1); |
| 31 |
} |
| 32 |
|
| 33 |
TEST(ResultAggregatorTest, MinimumResultAggregator) { |
| 34 |
std::vector<Benchmark> Results(2); |
| 35 |
|
| 36 |
Results[0].Measurements = {BenchmarkMeasure::Create("x", 2, {})}; |
| 37 |
Results[1].Measurements = {BenchmarkMeasure::Create("x", 1, {})}; |
| 38 |
|
| 39 |
Benchmark &Result = Results[0]; |
| 40 |
|
| 41 |
std::unique_ptr<ResultAggregator> AggregatorToTest = |
| 42 |
ResultAggregator::CreateAggregator( |
| 43 |
Benchmark::RepetitionModeE::AggregateMin); |
| 44 |
AggregatorToTest->AggregateResults(Result, ArrayRef(Results).drop_front()); |
| 45 |
|
| 46 |
EXPECT_EQ(Result.Measurements[0].PerInstructionValue, 1); |
| 47 |
EXPECT_EQ(Result.Measurements[0].PerSnippetValue, 1); |
| 48 |
EXPECT_EQ(Result.Measurements[0].RawValue, 1); |
| 49 |
} |
| 50 |
|
| 51 |
TEST(ResultAggregatorTest, MiddleHalfAggregator) { |
| 52 |
std::vector<Benchmark> Results(2); |
| 53 |
|
| 54 |
Results[0].Measurements = {BenchmarkMeasure::Create("x", 2, {})}; |
| 55 |
Results[1].Measurements = {BenchmarkMeasure::Create("x", 6, {})}; |
| 56 |
|
| 57 |
Results[0].Key.Instructions.push_back(MCInst()); |
| 58 |
Results[1].Key.Instructions.push_back(MCInst()); |
| 59 |
|
| 60 |
Results[0].MinInstructions = 1; |
| 61 |
Results[1].MinInstructions = 3; |
| 62 |
|
| 63 |
Benchmark &Result = Results[0]; |
| 64 |
|
| 65 |
std::unique_ptr<ResultAggregator> AggregatorToTest = |
| 66 |
ResultAggregator::CreateAggregator( |
| 67 |
Benchmark::RepetitionModeE::MiddleHalfLoop); |
| 68 |
AggregatorToTest->AggregateResults(Result, ArrayRef(Results).drop_front()); |
| 69 |
|
| 70 |
EXPECT_EQ(Result.Measurements[0].PerInstructionValue, 4); |
| 71 |
EXPECT_EQ(Result.Measurements[0].PerSnippetValue, 4); |
| 72 |
EXPECT_EQ(Result.Measurements[0].RawValue, 4); |
| 73 |
} |
| 74 |
|
| 75 |
} // namespace |
| 76 |
|
| 77 |
} // namespace exegesis |
| 78 |
} // namespace llvm |