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

Side by Side Diff: test/unittests/heap/embedder-tracing-unittest.cc

Issue 2576453002: [heap] Create a thin wrapper around wrapper tracing in V8 to avoid misuse (Closed)
Patch Set: Include Created 3 years, 12 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 | « test/unittests/BUILD.gn ('k') | test/unittests/unittests.gyp » ('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 2016 the V8 project 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 "src/heap/embedder-tracing.h"
6 #include "testing/gmock/include/gmock/gmock.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace v8 {
10 namespace internal {
11 namespace heap {
12
13 using testing::StrictMock;
14 using testing::_;
15 using testing::Return;
16 using v8::EmbedderHeapTracer;
17 using v8::internal::LocalEmbedderHeapTracer;
18
19 namespace {
20
21 LocalEmbedderHeapTracer::WrapperInfo CreateWrapperInfo() {
22 return LocalEmbedderHeapTracer::WrapperInfo(nullptr, nullptr);
23 }
24
25 } // namespace
26
27 class MockEmbedderHeapTracer : public EmbedderHeapTracer {
28 public:
29 MOCK_METHOD0(TracePrologue, void());
30 MOCK_METHOD0(TraceEpilogue, void());
31 MOCK_METHOD0(AbortTracing, void());
32 MOCK_METHOD0(EnterFinalPause, void());
33 MOCK_METHOD0(NumberOfWrappersToTrace, size_t());
34 MOCK_METHOD1(RegisterV8References,
35 void(const std::vector<std::pair<void*, void*> >&));
36 MOCK_METHOD2(AdvanceTracing,
37 bool(double deadline_in_ms, AdvanceTracingActions actions));
38 };
39
40 TEST(LocalEmbedderHeapTracer, InUse) {
41 LocalEmbedderHeapTracer local_tracer;
42 MockEmbedderHeapTracer mock_remote_tracer;
43 local_tracer.SetRemoteTracer(&mock_remote_tracer);
44 EXPECT_TRUE(local_tracer.InUse());
45 }
46
47 TEST(LocalEmbedderHeapTracer, NoRemoteTracer) {
48 LocalEmbedderHeapTracer local_tracer;
49 // We should be able to call all functions without a remote tracer being
50 // attached.
51 EXPECT_FALSE(local_tracer.InUse());
52 local_tracer.TracePrologue();
53 local_tracer.EnterFinalPause();
54 bool more_work = local_tracer.Trace(
55 0, EmbedderHeapTracer::AdvanceTracingActions(
56 EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION));
57 EXPECT_FALSE(more_work);
58 local_tracer.TraceEpilogue();
59 }
60
61 TEST(LocalEmbedderHeapTracer, TracePrologueForwards) {
62 LocalEmbedderHeapTracer local_tracer;
63 StrictMock<MockEmbedderHeapTracer> remote_tracer;
64 local_tracer.SetRemoteTracer(&remote_tracer);
65 EXPECT_CALL(remote_tracer, TracePrologue());
66 local_tracer.TracePrologue();
67 }
68
69 TEST(LocalEmbedderHeapTracer, TraceEpilogueForwards) {
70 LocalEmbedderHeapTracer local_tracer;
71 StrictMock<MockEmbedderHeapTracer> remote_tracer;
72 local_tracer.SetRemoteTracer(&remote_tracer);
73 EXPECT_CALL(remote_tracer, TraceEpilogue());
74 local_tracer.TraceEpilogue();
75 }
76
77 TEST(LocalEmbedderHeapTracer, AbortTracingForwards) {
78 LocalEmbedderHeapTracer local_tracer;
79 StrictMock<MockEmbedderHeapTracer> remote_tracer;
80 local_tracer.SetRemoteTracer(&remote_tracer);
81 EXPECT_CALL(remote_tracer, AbortTracing());
82 local_tracer.AbortTracing();
83 }
84
85 TEST(LocalEmbedderHeapTracer, AbortTracingClearsCachedWrappers) {
86 LocalEmbedderHeapTracer local_tracer;
87 StrictMock<MockEmbedderHeapTracer> remote_tracer;
88 local_tracer.SetRemoteTracer(&remote_tracer);
89 local_tracer.AddWrapperToTrace(CreateWrapperInfo());
90 EXPECT_CALL(remote_tracer, AbortTracing());
91 local_tracer.AbortTracing();
92 EXPECT_EQ(0u, local_tracer.NumberOfCachedWrappersToTrace());
93 }
94
95 TEST(LocalEmbedderHeapTracer, EnterFinalPauseForwards) {
96 LocalEmbedderHeapTracer local_tracer;
97 StrictMock<MockEmbedderHeapTracer> remote_tracer;
98 local_tracer.SetRemoteTracer(&remote_tracer);
99 EXPECT_CALL(remote_tracer, EnterFinalPause());
100 local_tracer.EnterFinalPause();
101 }
102
103 TEST(LocalEmbedderHeapTracer, NumberOfWrappersToTraceIncludesRemote) {
104 LocalEmbedderHeapTracer local_tracer;
105 StrictMock<MockEmbedderHeapTracer> remote_tracer;
106 local_tracer.SetRemoteTracer(&remote_tracer);
107 EXPECT_CALL(remote_tracer, NumberOfWrappersToTrace());
108 local_tracer.NumberOfWrappersToTrace();
109 }
110
111 TEST(LocalEmbedderHeapTracer, NumberOfCachedWrappersToTraceExcludesRemote) {
112 LocalEmbedderHeapTracer local_tracer;
113 StrictMock<MockEmbedderHeapTracer> remote_tracer;
114 local_tracer.SetRemoteTracer(&remote_tracer);
115 local_tracer.NumberOfCachedWrappersToTrace();
116 }
117
118 TEST(LocalEmbedderHeapTracer, RegisterWrappersWithRemoteTracer) {
119 LocalEmbedderHeapTracer local_tracer;
120 StrictMock<MockEmbedderHeapTracer> remote_tracer;
121 local_tracer.SetRemoteTracer(&remote_tracer);
122 local_tracer.AddWrapperToTrace(CreateWrapperInfo());
123 EXPECT_EQ(1u, local_tracer.NumberOfCachedWrappersToTrace());
124 EXPECT_CALL(remote_tracer, RegisterV8References(_));
125 local_tracer.RegisterWrappersWithRemoteTracer();
126 EXPECT_EQ(0u, local_tracer.NumberOfCachedWrappersToTrace());
127 EXPECT_CALL(remote_tracer, NumberOfWrappersToTrace()).WillOnce(Return(1));
128 EXPECT_EQ(1u, local_tracer.NumberOfWrappersToTrace());
129 }
130
131 TEST(LocalEmbedderHeapTracer, TraceFinishes) {
132 LocalEmbedderHeapTracer local_tracer;
133 StrictMock<MockEmbedderHeapTracer> remote_tracer;
134 local_tracer.SetRemoteTracer(&remote_tracer);
135 local_tracer.AddWrapperToTrace(CreateWrapperInfo());
136 EXPECT_EQ(1u, local_tracer.NumberOfCachedWrappersToTrace());
137 EXPECT_CALL(remote_tracer, RegisterV8References(_));
138 EXPECT_CALL(remote_tracer, AdvanceTracing(0, _)).WillOnce(Return(false));
139 EXPECT_EQ(
140 false,
141 local_tracer.Trace(
142 0, EmbedderHeapTracer::AdvanceTracingActions(
143 EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)));
144 EXPECT_EQ(0u, local_tracer.NumberOfCachedWrappersToTrace());
145 }
146
147 TEST(LocalEmbedderHeapTracer, TraceDoesNotFinish) {
148 LocalEmbedderHeapTracer local_tracer;
149 StrictMock<MockEmbedderHeapTracer> remote_tracer;
150 local_tracer.SetRemoteTracer(&remote_tracer);
151 local_tracer.AddWrapperToTrace(CreateWrapperInfo());
152 EXPECT_EQ(1u, local_tracer.NumberOfCachedWrappersToTrace());
153 EXPECT_CALL(remote_tracer, RegisterV8References(_));
154 EXPECT_CALL(remote_tracer, AdvanceTracing(0, _)).WillOnce(Return(true));
155 EXPECT_EQ(
156 true,
157 local_tracer.Trace(
158 0, EmbedderHeapTracer::AdvanceTracingActions(
159 EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)));
160 EXPECT_EQ(0u, local_tracer.NumberOfCachedWrappersToTrace());
161 }
162
163 } // namespace heap
164 } // namespace internal
165 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/BUILD.gn ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698