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

Side by Side Diff: mojo/system/core_unittest.cc

Issue 231353002: Make mojo_system static and mojo_system_impl a component, never use both (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix the mac loader path dependencies Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « mojo/system/core_test_base.cc ('k') | mojo/system/data_pipe.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/system/core_impl.h" 5 #include "mojo/system/core.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "mojo/system/core_test_base.h" 12 #include "mojo/system/core_test_base.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 namespace system { 15 namespace system {
16 namespace { 16 namespace {
17 17
18 typedef test::CoreTestBase CoreImplTest; 18 typedef test::CoreTestBase CoreTest;
19 19
20 TEST_F(CoreImplTest, GetTimeTicksNow) { 20 TEST_F(CoreTest, GetTimeTicksNow) {
21 const MojoTimeTicks start = core()->GetTimeTicksNow(); 21 const MojoTimeTicks start = core()->GetTimeTicksNow();
22 EXPECT_NE(static_cast<MojoTimeTicks>(0), start) 22 EXPECT_NE(static_cast<MojoTimeTicks>(0), start)
23 << "GetTimeTicksNow should return nonzero value"; 23 << "GetTimeTicksNow should return nonzero value";
24 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(15)); 24 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(15));
25 const MojoTimeTicks finish = core()->GetTimeTicksNow(); 25 const MojoTimeTicks finish = core()->GetTimeTicksNow();
26 // Allow for some fuzz in sleep. 26 // Allow for some fuzz in sleep.
27 EXPECT_GE((finish - start), static_cast<MojoTimeTicks>(8000)) 27 EXPECT_GE((finish - start), static_cast<MojoTimeTicks>(8000))
28 << "Sleeping should result in increasing time ticks"; 28 << "Sleeping should result in increasing time ticks";
29 } 29 }
30 30
31 TEST_F(CoreImplTest, Basic) { 31 TEST_F(CoreTest, Basic) {
32 MockHandleInfo info; 32 MockHandleInfo info;
33 33
34 EXPECT_EQ(0u, info.GetCtorCallCount()); 34 EXPECT_EQ(0u, info.GetCtorCallCount());
35 MojoHandle h = CreateMockHandle(&info); 35 MojoHandle h = CreateMockHandle(&info);
36 EXPECT_EQ(1u, info.GetCtorCallCount()); 36 EXPECT_EQ(1u, info.GetCtorCallCount());
37 EXPECT_NE(h, MOJO_HANDLE_INVALID); 37 EXPECT_NE(h, MOJO_HANDLE_INVALID);
38 38
39 EXPECT_EQ(0u, info.GetWriteMessageCallCount()); 39 EXPECT_EQ(0u, info.GetWriteMessageCallCount());
40 EXPECT_EQ(MOJO_RESULT_OK, 40 EXPECT_EQ(MOJO_RESULT_OK,
41 core()->WriteMessage(h, NULL, 0, NULL, 0, 41 core()->WriteMessage(h, NULL, 0, NULL, 0,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 EXPECT_EQ(0u, info.GetCancelAllWaitersCallCount()); 113 EXPECT_EQ(0u, info.GetCancelAllWaitersCallCount());
114 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 114 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
115 EXPECT_EQ(1u, info.GetCancelAllWaitersCallCount()); 115 EXPECT_EQ(1u, info.GetCancelAllWaitersCallCount());
116 EXPECT_EQ(1u, info.GetCloseCallCount()); 116 EXPECT_EQ(1u, info.GetCloseCallCount());
117 EXPECT_EQ(1u, info.GetDtorCallCount()); 117 EXPECT_EQ(1u, info.GetDtorCallCount());
118 118
119 // No waiters should ever have ever been added. 119 // No waiters should ever have ever been added.
120 EXPECT_EQ(0u, info.GetRemoveWaiterCallCount()); 120 EXPECT_EQ(0u, info.GetRemoveWaiterCallCount());
121 } 121 }
122 122
123 TEST_F(CoreImplTest, InvalidArguments) { 123 TEST_F(CoreTest, InvalidArguments) {
124 // |Close()|: 124 // |Close()|:
125 { 125 {
126 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(MOJO_HANDLE_INVALID)); 126 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(MOJO_HANDLE_INVALID));
127 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(10)); 127 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(10));
128 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(1000000000)); 128 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(1000000000));
129 129
130 // Test a double-close. 130 // Test a double-close.
131 MockHandleInfo info; 131 MockHandleInfo info;
132 MojoHandle h = CreateMockHandle(&info); 132 MojoHandle h = CreateMockHandle(&info);
133 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 133 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 MojoHandle h; 188 MojoHandle h;
189 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 189 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
190 core()->CreateMessagePipe(NULL, NULL)); 190 core()->CreateMessagePipe(NULL, NULL));
191 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 191 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
192 core()->CreateMessagePipe(&h, NULL)); 192 core()->CreateMessagePipe(&h, NULL));
193 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 193 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
194 core()->CreateMessagePipe(NULL, &h)); 194 core()->CreateMessagePipe(NULL, &h));
195 } 195 }
196 196
197 // |WriteMessage()|: 197 // |WriteMessage()|:
198 // Only check arguments checked by |CoreImpl|, namely |handle|, |handles|, and 198 // Only check arguments checked by |Core|, namely |handle|, |handles|, and
199 // |num_handles|. 199 // |num_handles|.
200 { 200 {
201 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 201 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
202 core()->WriteMessage(MOJO_HANDLE_INVALID, NULL, 0, NULL, 0, 202 core()->WriteMessage(MOJO_HANDLE_INVALID, NULL, 0, NULL, 0,
203 MOJO_WRITE_MESSAGE_FLAG_NONE)); 203 MOJO_WRITE_MESSAGE_FLAG_NONE));
204 204
205 MockHandleInfo info; 205 MockHandleInfo info;
206 MojoHandle h = CreateMockHandle(&info); 206 MojoHandle h = CreateMockHandle(&info);
207 MojoHandle handles[2] = { MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID }; 207 MojoHandle handles[2] = { MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID };
208 208
209 // Null |handles| with nonzero |num_handles|. 209 // Null |handles| with nonzero |num_handles|.
210 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 210 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
211 core()->WriteMessage(h, NULL, 0, NULL, 1, 211 core()->WriteMessage(h, NULL, 0, NULL, 1,
212 MOJO_WRITE_MESSAGE_FLAG_NONE)); 212 MOJO_WRITE_MESSAGE_FLAG_NONE));
213 // Checked by |CoreImpl|, shouldn't go through to the dispatcher. 213 // Checked by |Core|, shouldn't go through to the dispatcher.
214 EXPECT_EQ(0u, info.GetWriteMessageCallCount()); 214 EXPECT_EQ(0u, info.GetWriteMessageCallCount());
215 215
216 // Huge handle count (implausibly big on some systems -- more than can be 216 // Huge handle count (implausibly big on some systems -- more than can be
217 // stored in a 32-bit address space). 217 // stored in a 32-bit address space).
218 // Note: This may return either |MOJO_RESULT_INVALID_ARGUMENT| or 218 // Note: This may return either |MOJO_RESULT_INVALID_ARGUMENT| or
219 // |MOJO_RESULT_RESOURCE_EXHAUSTED|, depending on whether it's plausible or 219 // |MOJO_RESULT_RESOURCE_EXHAUSTED|, depending on whether it's plausible or
220 // not. 220 // not.
221 EXPECT_NE(MOJO_RESULT_OK, 221 EXPECT_NE(MOJO_RESULT_OK,
222 core()->WriteMessage(h, NULL, 0, handles, 222 core()->WriteMessage(h, NULL, 0, handles,
223 std::numeric_limits<uint32_t>::max(), 223 std::numeric_limits<uint32_t>::max(),
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 EXPECT_EQ(1u, info.GetWriteMessageCallCount()); 282 EXPECT_EQ(1u, info.GetWriteMessageCallCount());
283 283
284 // Note: Since we never successfully sent anything with it, |h2| should 284 // Note: Since we never successfully sent anything with it, |h2| should
285 // still be valid. 285 // still be valid.
286 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h2)); 286 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h2));
287 287
288 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 288 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
289 } 289 }
290 290
291 // |ReadMessage()|: 291 // |ReadMessage()|:
292 // Only check arguments checked by |CoreImpl|, namely |handle|, |handles|, and 292 // Only check arguments checked by |Core|, namely |handle|, |handles|, and
293 // |num_handles|. 293 // |num_handles|.
294 { 294 {
295 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 295 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
296 core()->ReadMessage(MOJO_HANDLE_INVALID, NULL, NULL, NULL, NULL, 296 core()->ReadMessage(MOJO_HANDLE_INVALID, NULL, NULL, NULL, NULL,
297 MOJO_READ_MESSAGE_FLAG_NONE)); 297 MOJO_READ_MESSAGE_FLAG_NONE));
298 298
299 MockHandleInfo info; 299 MockHandleInfo info;
300 MojoHandle h = CreateMockHandle(&info); 300 MojoHandle h = CreateMockHandle(&info);
301 301
302 uint32_t handle_count = 1; 302 uint32_t handle_count = 1;
303 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 303 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
304 core()->ReadMessage(h, NULL, NULL, NULL, &handle_count, 304 core()->ReadMessage(h, NULL, NULL, NULL, &handle_count,
305 MOJO_READ_MESSAGE_FLAG_NONE)); 305 MOJO_READ_MESSAGE_FLAG_NONE));
306 // Checked by |CoreImpl|, shouldn't go through to the dispatcher. 306 // Checked by |Core|, shouldn't go through to the dispatcher.
307 EXPECT_EQ(0u, info.GetReadMessageCallCount()); 307 EXPECT_EQ(0u, info.GetReadMessageCallCount());
308 308
309 // Okay. 309 // Okay.
310 handle_count = 0; 310 handle_count = 0;
311 EXPECT_EQ(MOJO_RESULT_OK, 311 EXPECT_EQ(MOJO_RESULT_OK,
312 core()->ReadMessage(h, NULL, NULL, NULL, &handle_count, 312 core()->ReadMessage(h, NULL, NULL, NULL, &handle_count,
313 MOJO_READ_MESSAGE_FLAG_NONE)); 313 MOJO_READ_MESSAGE_FLAG_NONE));
314 // Checked by |CoreImpl|, shouldn't go through to the dispatcher. 314 // Checked by |Core|, shouldn't go through to the dispatcher.
315 EXPECT_EQ(1u, info.GetReadMessageCallCount()); 315 EXPECT_EQ(1u, info.GetReadMessageCallCount());
316 316
317 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 317 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
318 } 318 }
319 } 319 }
320 320
321 // TODO(vtl): test |Wait()| and |WaitMany()| properly 321 // TODO(vtl): test |Wait()| and |WaitMany()| properly
322 // - including |WaitMany()| with the same handle more than once (with 322 // - including |WaitMany()| with the same handle more than once (with
323 // same/different flags) 323 // same/different flags)
324 324
325 TEST_F(CoreImplTest, MessagePipe) { 325 TEST_F(CoreTest, MessagePipe) {
326 MojoHandle h[2]; 326 MojoHandle h[2];
327 327
328 EXPECT_EQ(MOJO_RESULT_OK, core()->CreateMessagePipe(&h[0], &h[1])); 328 EXPECT_EQ(MOJO_RESULT_OK, core()->CreateMessagePipe(&h[0], &h[1]));
329 // Should get two distinct, valid handles. 329 // Should get two distinct, valid handles.
330 EXPECT_NE(h[0], MOJO_HANDLE_INVALID); 330 EXPECT_NE(h[0], MOJO_HANDLE_INVALID);
331 EXPECT_NE(h[1], MOJO_HANDLE_INVALID); 331 EXPECT_NE(h[1], MOJO_HANDLE_INVALID);
332 EXPECT_NE(h[0], h[1]); 332 EXPECT_NE(h[0], h[1]);
333 333
334 // Neither should be readable. 334 // Neither should be readable.
335 MojoWaitFlags flags[2] = { MOJO_WAIT_FLAG_READABLE, MOJO_WAIT_FLAG_READABLE }; 335 MojoWaitFlags flags[2] = { MOJO_WAIT_FLAG_READABLE, MOJO_WAIT_FLAG_READABLE };
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 // Try writing to |h[1]|. 417 // Try writing to |h[1]|.
418 buffer[0] = 'e'; 418 buffer[0] = 'e';
419 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 419 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
420 core()->WriteMessage(h[1], buffer, 1, NULL, 0, 420 core()->WriteMessage(h[1], buffer, 1, NULL, 0,
421 MOJO_WRITE_MESSAGE_FLAG_NONE)); 421 MOJO_WRITE_MESSAGE_FLAG_NONE));
422 422
423 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h[1])); 423 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h[1]));
424 } 424 }
425 425
426 // Tests passing a message pipe handle. 426 // Tests passing a message pipe handle.
427 TEST_F(CoreImplTest, MessagePipeBasicLocalHandlePassing1) { 427 TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) {
428 const char kHello[] = "hello"; 428 const char kHello[] = "hello";
429 const uint32_t kHelloSize = static_cast<uint32_t>(sizeof(kHello)); 429 const uint32_t kHelloSize = static_cast<uint32_t>(sizeof(kHello));
430 const char kWorld[] = "world!!!"; 430 const char kWorld[] = "world!!!";
431 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld)); 431 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld));
432 char buffer[100]; 432 char buffer[100];
433 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); 433 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer));
434 uint32_t num_bytes; 434 uint32_t num_bytes;
435 MojoHandle handles[10]; 435 MojoHandle handles[10];
436 uint32_t num_handles; 436 uint32_t num_handles;
437 MojoHandle h_received; 437 MojoHandle h_received;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 EXPECT_EQ(kHelloSize, num_bytes); 544 EXPECT_EQ(kHelloSize, num_bytes);
545 EXPECT_STREQ(kHello, buffer); 545 EXPECT_STREQ(kHello, buffer);
546 EXPECT_EQ(0u, num_handles); 546 EXPECT_EQ(0u, num_handles);
547 547
548 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[0])); 548 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[0]));
549 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[1])); 549 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[1]));
550 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passed[0])); 550 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passed[0]));
551 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_received)); 551 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_received));
552 } 552 }
553 553
554 TEST_F(CoreImplTest, DataPipe) { 554 TEST_F(CoreTest, DataPipe) {
555 MojoHandle ph, ch; // p is for producer and c is for consumer. 555 MojoHandle ph, ch; // p is for producer and c is for consumer.
556 556
557 EXPECT_EQ(MOJO_RESULT_OK, core()->CreateDataPipe(NULL, &ph, &ch)); 557 EXPECT_EQ(MOJO_RESULT_OK, core()->CreateDataPipe(NULL, &ph, &ch));
558 // Should get two distinct, valid handles. 558 // Should get two distinct, valid handles.
559 EXPECT_NE(ph, MOJO_HANDLE_INVALID); 559 EXPECT_NE(ph, MOJO_HANDLE_INVALID);
560 EXPECT_NE(ch, MOJO_HANDLE_INVALID); 560 EXPECT_NE(ch, MOJO_HANDLE_INVALID);
561 EXPECT_NE(ph, ch); 561 EXPECT_NE(ph, ch);
562 562
563 // Producer should be never-readable, but already writable. 563 // Producer should be never-readable, but already writable.
564 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 564 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ph)); 666 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ph));
667 667
668 // The consumer should now be never-readable. 668 // The consumer should now be never-readable.
669 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 669 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
670 core()->Wait(ch, MOJO_WAIT_FLAG_READABLE, 0)); 670 core()->Wait(ch, MOJO_WAIT_FLAG_READABLE, 0));
671 671
672 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ch)); 672 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ch));
673 } 673 }
674 674
675 // Tests passing data pipe producer and consumer handles. 675 // Tests passing data pipe producer and consumer handles.
676 TEST_F(CoreImplTest, MessagePipeBasicLocalHandlePassing2) { 676 TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) {
677 const char kHello[] = "hello"; 677 const char kHello[] = "hello";
678 const uint32_t kHelloSize = static_cast<uint32_t>(sizeof(kHello)); 678 const uint32_t kHelloSize = static_cast<uint32_t>(sizeof(kHello));
679 const char kWorld[] = "world!!!"; 679 const char kWorld[] = "world!!!";
680 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld)); 680 const uint32_t kWorldSize = static_cast<uint32_t>(sizeof(kWorld));
681 char buffer[100]; 681 char buffer[100];
682 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); 682 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer));
683 uint32_t num_bytes; 683 uint32_t num_bytes;
684 MojoHandle handles[10]; 684 MojoHandle handles[10];
685 uint32_t num_handles; 685 uint32_t num_handles;
686 686
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[1])); 872 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_passing[1]));
873 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ph)); 873 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ph));
874 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ch)); 874 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ch));
875 } 875 }
876 876
877 // TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|. 877 // TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|.
878 878
879 } // namespace 879 } // namespace
880 } // namespace system 880 } // namespace system
881 } // namespace mojo 881 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/core_test_base.cc ('k') | mojo/system/data_pipe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698