diff options
author | Jakub Staszak <jstaszak@apple.com> | 2011-07-27 18:57:40 +0000 |
---|---|---|
committer | Jakub Staszak <jstaszak@apple.com> | 2011-07-27 18:57:40 +0000 |
commit | 0031b4f74e4dd944720f896843e05598b7de2fee (patch) | |
tree | 7d215aa5e9883562028fddb4816eb7da0ee8c9b3 /unittests | |
parent | 18dceba0bb5e38250535401ecc9d9737943d0657 (diff) |
Add test cases for BlockFrequency.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136244 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Support/BlockFrequencyTest.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/unittests/Support/BlockFrequencyTest.cpp b/unittests/Support/BlockFrequencyTest.cpp new file mode 100644 index 0000000000..edeea9b357 --- /dev/null +++ b/unittests/Support/BlockFrequencyTest.cpp @@ -0,0 +1,56 @@ +#include "llvm/Support/DataTypes.h" +#include "llvm/Support/BlockFrequency.h" +#include "llvm/Support/BranchProbability.h" + +#include "gtest/gtest.h" +#include <climits> + +using namespace llvm; + +namespace { + +TEST(BlockFrequencyTest, OneToZero) { + BlockFrequency Freq(1); + BranchProbability Prob(UINT32_MAX - 1, UINT32_MAX); + Freq *= Prob; + EXPECT_EQ(Freq.getFrequency(), 0u); +} + +TEST(BlockFrequencyTest, OneToOne) { + BlockFrequency Freq(1); + BranchProbability Prob(UINT32_MAX, UINT32_MAX); + Freq *= Prob; + EXPECT_EQ(Freq.getFrequency(), 1u); +} + +TEST(BlockFrequencyTest, ThreeToOne) { + BlockFrequency Freq(3); + BranchProbability Prob(3000000, 9000000); + Freq *= Prob; + EXPECT_EQ(Freq.getFrequency(), 1u); +} + +TEST(BlockFrequencyTest, MaxToHalfMax) { + BlockFrequency Freq(UINT64_MAX); + BranchProbability Prob(UINT32_MAX / 2, UINT32_MAX); + Freq *= Prob; + EXPECT_EQ(Freq.getFrequency(), 9223372034707292159LLu); +} + +TEST(BlockFrequencyTest, BigToBig) { + const uint64_t Big = 387246523487234346LL; + const uint32_t P = 123456789; + BlockFrequency Freq(Big); + BranchProbability Prob(P, P); + Freq *= Prob; + EXPECT_EQ(Freq.getFrequency(), Big); +} + +TEST(BlockFrequencyTest, MaxToMax) { + BlockFrequency Freq(UINT64_MAX); + BranchProbability Prob(UINT32_MAX, UINT32_MAX); + Freq *= Prob; + EXPECT_EQ(Freq.getFrequency(), UINT64_MAX); +} + +} |