1 : // Copyright 2015 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #include "syzygy/bard/backdrops/heap_backdrop.h"
16 :
17 : #include "gtest/gtest.h"
18 :
19 : namespace bard {
20 : namespace backdrops {
21 :
22 : namespace {
23 :
24 : class TestHeapBackdrop : public HeapBackdrop {
25 : public:
26 : using HeapBackdrop::total_stats_;
27 : };
28 :
29 : } // namespace
30 :
31 E : TEST(HeapBackdropTest, StatsTest) {
32 : using EventType = EventInterface::EventType;
33 E : const EventType kFuncType1 = static_cast<EventType>(0);
34 E : const EventType kFuncType2 = static_cast<EventType>(1);
35 :
36 E : TestHeapBackdrop backdrop;
37 :
38 E : backdrop.UpdateStats(kFuncType1, 0);
39 E : backdrop.UpdateStats(kFuncType2, 0);
40 :
41 E : auto func1 = backdrop.total_stats_.find(kFuncType1);
42 E : auto func2 = backdrop.total_stats_.find(kFuncType2);
43 :
44 E : backdrop.UpdateStats(kFuncType1, 100);
45 E : EXPECT_EQ(2, func1->second.calls);
46 E : EXPECT_EQ(100, func1->second.time);
47 :
48 E : backdrop.UpdateStats(kFuncType1, 9);
49 E : EXPECT_EQ(3, func1->second.calls);
50 E : EXPECT_EQ(100 + 9, func1->second.time);
51 :
52 E : backdrop.UpdateStats(kFuncType2, 166);
53 E : EXPECT_EQ(2, func2->second.calls);
54 E : EXPECT_EQ(166, func2->second.time);
55 :
56 E : backdrop.UpdateStats(kFuncType1, 34);
57 E : EXPECT_EQ(4, func1->second.calls);
58 E : EXPECT_EQ(100 + 9 + 34, func1->second.time);
59 :
60 E : backdrop.UpdateStats(kFuncType2, 72);
61 E : EXPECT_EQ(3, func2->second.calls);
62 E : EXPECT_EQ(166 + 72, func2->second.time);
63 E : }
64 :
65 : } // namespace backdrops
66 : } // namespace bard
|