llvm.org GIT mirror llvm / 0031b4f
Add test cases for BlockFrequency. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136244 91177308-0d34-0410-b5e6-96231b3b80d8 Jakub Staszak 9 years ago
1 changed file(s) with 56 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 #include "llvm/Support/DataTypes.h"
1 #include "llvm/Support/BlockFrequency.h"
2 #include "llvm/Support/BranchProbability.h"
3
4 #include "gtest/gtest.h"
5 #include
6
7 using namespace llvm;
8
9 namespace {
10
11 TEST(BlockFrequencyTest, OneToZero) {
12 BlockFrequency Freq(1);
13 BranchProbability Prob(UINT32_MAX - 1, UINT32_MAX);
14 Freq *= Prob;
15 EXPECT_EQ(Freq.getFrequency(), 0u);
16 }
17
18 TEST(BlockFrequencyTest, OneToOne) {
19 BlockFrequency Freq(1);
20 BranchProbability Prob(UINT32_MAX, UINT32_MAX);
21 Freq *= Prob;
22 EXPECT_EQ(Freq.getFrequency(), 1u);
23 }
24
25 TEST(BlockFrequencyTest, ThreeToOne) {
26 BlockFrequency Freq(3);
27 BranchProbability Prob(3000000, 9000000);
28 Freq *= Prob;
29 EXPECT_EQ(Freq.getFrequency(), 1u);
30 }
31
32 TEST(BlockFrequencyTest, MaxToHalfMax) {
33 BlockFrequency Freq(UINT64_MAX);
34 BranchProbability Prob(UINT32_MAX / 2, UINT32_MAX);
35 Freq *= Prob;
36 EXPECT_EQ(Freq.getFrequency(), 9223372034707292159LLu);
37 }
38
39 TEST(BlockFrequencyTest, BigToBig) {
40 const uint64_t Big = 387246523487234346LL;
41 const uint32_t P = 123456789;
42 BlockFrequency Freq(Big);
43 BranchProbability Prob(P, P);
44 Freq *= Prob;
45 EXPECT_EQ(Freq.getFrequency(), Big);
46 }
47
48 TEST(BlockFrequencyTest, MaxToMax) {
49 BlockFrequency Freq(UINT64_MAX);
50 BranchProbability Prob(UINT32_MAX, UINT32_MAX);
51 Freq *= Prob;
52 EXPECT_EQ(Freq.getFrequency(), UINT64_MAX);
53 }
54
55 }