Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: base/trace_event/memory_dump_manager_unittest.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | base/trace_event/memory_dump_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/trace_event/memory_dump_manager.h"
6
7 #include "base/trace_event/memory_dump_provider.h"
8 #include "base/trace_event/process_memory_dump.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 using testing::_;
13
14 namespace base {
15 namespace trace_event {
16
17 class MemoryDumpManagerTest : public testing::Test {
18 public:
19 void SetUp() override {
20 MemoryDumpManager::GetInstance()->Initialize();
21 mdm_ = MemoryDumpManager::GetInstance();
22 }
23
24 void TearDown() override {
25 MemoryDumpManager::DeleteForTesting();
26 TraceLog::DeleteForTesting();
27 mdm_ = NULL;
28 }
29
30 protected:
31 const char* const kTraceCategory = MemoryDumpManager::kTraceCategory;
32
33 void EnableTracing(const char* category) {
34 TraceLog::GetInstance()->SetEnabled(
35 CategoryFilter(category), TraceLog::RECORDING_MODE, TraceOptions());
36 }
37
38 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); }
39
40 MemoryDumpManager* mdm_;
41
42 private:
43 // We want our singleton torn down after each test.
44 ShadowingAtExitManager at_exit_manager_;
45 };
46
47 class MockDumpProvider : public MemoryDumpProvider {
48 public:
49 MOCK_METHOD1(DumpInto, void(ProcessMemoryDump* pmd));
50 };
51
52 TEST_F(MemoryDumpManagerTest, SingleDumper) {
53 MockDumpProvider mdp;
54 mdm_->RegisterDumpProvider(&mdp);
55
56 // Check that the dumper is not called if the memory category is not enabled.
57 EnableTracing("foo-and-bar-but-not-memory");
58 EXPECT_CALL(mdp, DumpInto(_)).Times(0);
59 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED);
60 DisableTracing();
61
62 // Now repeat enabling the memory category and check that the dumper is
63 // invoked this time.
64 EnableTracing(kTraceCategory);
65 EXPECT_CALL(mdp, DumpInto(_)).Times(3);
66 for (int i = 0; i < 3; ++i)
67 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED);
68 DisableTracing();
69
70 mdm_->UnregisterDumpProvider(&mdp);
71
72 // Finally check the unregister logic (no calls to the mdp after unregister).
73 EnableTracing(kTraceCategory);
74 EXPECT_CALL(mdp, DumpInto(_)).Times(0);
75 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED);
76 TraceLog::GetInstance()->SetDisabled();
77 }
78
79 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileTracing) {
80 MockDumpProvider mdp;
81 mdm_->RegisterDumpProvider(&mdp);
82
83 EnableTracing(kTraceCategory);
84 EXPECT_CALL(mdp, DumpInto(_)).Times(1);
85 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED);
86
87 mdm_->UnregisterDumpProvider(&mdp);
88 EXPECT_CALL(mdp, DumpInto(_)).Times(0);
89 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED);
90
91 DisableTracing();
92 }
93
94 TEST_F(MemoryDumpManagerTest, MultipleDumpers) {
95 MockDumpProvider mdp1;
96 MockDumpProvider mdp2;
97
98 // Enable only mdp1.
99 mdm_->RegisterDumpProvider(&mdp1);
100 EnableTracing(kTraceCategory);
101 EXPECT_CALL(mdp1, DumpInto(_)).Times(1);
102 EXPECT_CALL(mdp2, DumpInto(_)).Times(0);
103 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED);
104 DisableTracing();
105
106 // Invert: enable mdp1 and disable mdp2.
107 mdm_->UnregisterDumpProvider(&mdp1);
108 mdm_->RegisterDumpProvider(&mdp2);
109 EnableTracing(kTraceCategory);
110 EXPECT_CALL(mdp1, DumpInto(_)).Times(0);
111 EXPECT_CALL(mdp2, DumpInto(_)).Times(1);
112 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED);
113 DisableTracing();
114
115 // Enable both mdp1 and mdp2.
116 mdm_->RegisterDumpProvider(&mdp1);
117 EnableTracing(kTraceCategory);
118 EXPECT_CALL(mdp1, DumpInto(_)).Times(1);
119 EXPECT_CALL(mdp2, DumpInto(_)).Times(1);
120 mdm_->RequestDumpPoint(DumpPointType::EXPLICITLY_TRIGGERED);
121 DisableTracing();
122 }
123
124 } // namespace trace_Event
125 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | base/trace_event/memory_dump_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698