| OLD | NEW |
| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
| 16 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/threading/platform_thread.h" // For |Sleep()|. | 20 #include "base/threading/platform_thread.h" // For |Sleep()|. |
| 21 #include "build/build_config.h" // TODO(vtl): Remove this. | 21 #include "build/build_config.h" // TODO(vtl): Remove this. |
| 22 #include "mojo/common/test/multiprocess_test_helper.h" | 22 #include "mojo/common/test/multiprocess_test_helper.h" |
| 23 #include "mojo/common/test/test_utils.h" | 23 #include "mojo/common/test/test_utils.h" |
| 24 #include "mojo/embedder/platform_shared_buffer.h" |
| 24 #include "mojo/embedder/scoped_platform_handle.h" | 25 #include "mojo/embedder/scoped_platform_handle.h" |
| 25 #include "mojo/system/channel.h" | 26 #include "mojo/system/channel.h" |
| 26 #include "mojo/system/dispatcher.h" | 27 #include "mojo/system/dispatcher.h" |
| 27 #include "mojo/system/local_message_pipe_endpoint.h" | 28 #include "mojo/system/local_message_pipe_endpoint.h" |
| 28 #include "mojo/system/message_pipe.h" | 29 #include "mojo/system/message_pipe.h" |
| 29 #include "mojo/system/platform_handle_dispatcher.h" | 30 #include "mojo/system/platform_handle_dispatcher.h" |
| 30 #include "mojo/system/proxy_message_pipe_endpoint.h" | 31 #include "mojo/system/proxy_message_pipe_endpoint.h" |
| 31 #include "mojo/system/raw_channel.h" | 32 #include "mojo/system/raw_channel.h" |
| 32 #include "mojo/system/raw_shared_buffer.h" | |
| 33 #include "mojo/system/shared_buffer_dispatcher.h" | 33 #include "mojo/system/shared_buffer_dispatcher.h" |
| 34 #include "mojo/system/test_utils.h" | 34 #include "mojo/system/test_utils.h" |
| 35 #include "mojo/system/waiter.h" | 35 #include "mojo/system/waiter.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 | 37 |
| 38 namespace mojo { | 38 namespace mojo { |
| 39 namespace system { | 39 namespace system { |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 class ChannelThread { | 42 class ChannelThread { |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 read_buffer.resize(num_bytes); | 351 read_buffer.resize(num_bytes); |
| 352 CHECK_EQ(read_buffer, std::string("go 1")); | 352 CHECK_EQ(read_buffer, std::string("go 1")); |
| 353 CHECK_EQ(num_dispatchers, 1u); | 353 CHECK_EQ(num_dispatchers, 1u); |
| 354 | 354 |
| 355 CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::kTypeSharedBuffer); | 355 CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::kTypeSharedBuffer); |
| 356 | 356 |
| 357 scoped_refptr<SharedBufferDispatcher> dispatcher( | 357 scoped_refptr<SharedBufferDispatcher> dispatcher( |
| 358 static_cast<SharedBufferDispatcher*>(dispatchers[0].get())); | 358 static_cast<SharedBufferDispatcher*>(dispatchers[0].get())); |
| 359 | 359 |
| 360 // Make a mapping. | 360 // Make a mapping. |
| 361 scoped_ptr<RawSharedBufferMapping> mapping; | 361 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping; |
| 362 CHECK_EQ(dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping), | 362 CHECK_EQ(dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping), |
| 363 MOJO_RESULT_OK); | 363 MOJO_RESULT_OK); |
| 364 CHECK(mapping); | 364 CHECK(mapping); |
| 365 CHECK(mapping->base()); | 365 CHECK(mapping->GetBase()); |
| 366 CHECK_EQ(mapping->length(), 100u); | 366 CHECK_EQ(mapping->GetLength(), 100u); |
| 367 | 367 |
| 368 // Write some stuff to the shared buffer. | 368 // Write some stuff to the shared buffer. |
| 369 static const char kHello[] = "hello"; | 369 static const char kHello[] = "hello"; |
| 370 memcpy(mapping->base(), kHello, sizeof(kHello)); | 370 memcpy(mapping->GetBase(), kHello, sizeof(kHello)); |
| 371 | 371 |
| 372 // We should be able to close the dispatcher now. | 372 // We should be able to close the dispatcher now. |
| 373 dispatcher->Close(); | 373 dispatcher->Close(); |
| 374 | 374 |
| 375 // And send a message to signal that we've written stuff. | 375 // And send a message to signal that we've written stuff. |
| 376 const std::string go2("go 2"); | 376 const std::string go2("go 2"); |
| 377 CHECK_EQ(mp->WriteMessage(0, | 377 CHECK_EQ(mp->WriteMessage(0, |
| 378 UserPointer<const void>(&go2[0]), | 378 UserPointer<const void>(&go2[0]), |
| 379 static_cast<uint32_t>(go2.size()), | 379 static_cast<uint32_t>(go2.size()), |
| 380 NULL, | 380 NULL, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 397 MakeUserPointer(&num_bytes), | 397 MakeUserPointer(&num_bytes), |
| 398 NULL, | 398 NULL, |
| 399 NULL, | 399 NULL, |
| 400 MOJO_READ_MESSAGE_FLAG_NONE), | 400 MOJO_READ_MESSAGE_FLAG_NONE), |
| 401 MOJO_RESULT_OK); | 401 MOJO_RESULT_OK); |
| 402 read_buffer.resize(num_bytes); | 402 read_buffer.resize(num_bytes); |
| 403 CHECK_EQ(read_buffer, std::string("go 3")); | 403 CHECK_EQ(read_buffer, std::string("go 3")); |
| 404 | 404 |
| 405 // It should have written something to the shared buffer. | 405 // It should have written something to the shared buffer. |
| 406 static const char kWorld[] = "world!!!"; | 406 static const char kWorld[] = "world!!!"; |
| 407 CHECK_EQ(memcmp(mapping->base(), kWorld, sizeof(kWorld)), 0); | 407 CHECK_EQ(memcmp(mapping->GetBase(), kWorld, sizeof(kWorld)), 0); |
| 408 | 408 |
| 409 // And we're done. | 409 // And we're done. |
| 410 mp->Close(0); | 410 mp->Close(0); |
| 411 | 411 |
| 412 return 0; | 412 return 0; |
| 413 } | 413 } |
| 414 | 414 |
| 415 #if defined(OS_POSIX) | 415 #if defined(OS_POSIX) |
| 416 #define MAYBE_SharedBufferPassing SharedBufferPassing | 416 #define MAYBE_SharedBufferPassing SharedBufferPassing |
| 417 #else | 417 #else |
| (...skipping 10 matching lines...) Expand all Loading... |
| 428 | 428 |
| 429 // Make a shared buffer. | 429 // Make a shared buffer. |
| 430 scoped_refptr<SharedBufferDispatcher> dispatcher; | 430 scoped_refptr<SharedBufferDispatcher> dispatcher; |
| 431 EXPECT_EQ( | 431 EXPECT_EQ( |
| 432 MOJO_RESULT_OK, | 432 MOJO_RESULT_OK, |
| 433 SharedBufferDispatcher::Create( | 433 SharedBufferDispatcher::Create( |
| 434 SharedBufferDispatcher::kDefaultCreateOptions, 100, &dispatcher)); | 434 SharedBufferDispatcher::kDefaultCreateOptions, 100, &dispatcher)); |
| 435 ASSERT_TRUE(dispatcher); | 435 ASSERT_TRUE(dispatcher); |
| 436 | 436 |
| 437 // Make a mapping. | 437 // Make a mapping. |
| 438 scoped_ptr<RawSharedBufferMapping> mapping; | 438 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping; |
| 439 EXPECT_EQ(MOJO_RESULT_OK, | 439 EXPECT_EQ(MOJO_RESULT_OK, |
| 440 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); | 440 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); |
| 441 ASSERT_TRUE(mapping); | 441 ASSERT_TRUE(mapping); |
| 442 ASSERT_TRUE(mapping->base()); | 442 ASSERT_TRUE(mapping->GetBase()); |
| 443 ASSERT_EQ(100u, mapping->length()); | 443 ASSERT_EQ(100u, mapping->GetLength()); |
| 444 | 444 |
| 445 // Send the shared buffer. | 445 // Send the shared buffer. |
| 446 const std::string go1("go 1"); | 446 const std::string go1("go 1"); |
| 447 DispatcherTransport transport( | 447 DispatcherTransport transport( |
| 448 test::DispatcherTryStartTransport(dispatcher.get())); | 448 test::DispatcherTryStartTransport(dispatcher.get())); |
| 449 ASSERT_TRUE(transport.is_valid()); | 449 ASSERT_TRUE(transport.is_valid()); |
| 450 | 450 |
| 451 std::vector<DispatcherTransport> transports; | 451 std::vector<DispatcherTransport> transports; |
| 452 transports.push_back(transport); | 452 transports.push_back(transport); |
| 453 EXPECT_EQ(MOJO_RESULT_OK, | 453 EXPECT_EQ(MOJO_RESULT_OK, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 476 MakeUserPointer(&num_bytes), | 476 MakeUserPointer(&num_bytes), |
| 477 NULL, | 477 NULL, |
| 478 NULL, | 478 NULL, |
| 479 MOJO_READ_MESSAGE_FLAG_NONE)); | 479 MOJO_READ_MESSAGE_FLAG_NONE)); |
| 480 read_buffer.resize(num_bytes); | 480 read_buffer.resize(num_bytes); |
| 481 EXPECT_EQ(std::string("go 2"), read_buffer); | 481 EXPECT_EQ(std::string("go 2"), read_buffer); |
| 482 | 482 |
| 483 // After we get it, the child should have written something to the shared | 483 // After we get it, the child should have written something to the shared |
| 484 // buffer. | 484 // buffer. |
| 485 static const char kHello[] = "hello"; | 485 static const char kHello[] = "hello"; |
| 486 EXPECT_EQ(0, memcmp(mapping->base(), kHello, sizeof(kHello))); | 486 EXPECT_EQ(0, memcmp(mapping->GetBase(), kHello, sizeof(kHello))); |
| 487 | 487 |
| 488 // Now we'll write some stuff to the shared buffer. | 488 // Now we'll write some stuff to the shared buffer. |
| 489 static const char kWorld[] = "world!!!"; | 489 static const char kWorld[] = "world!!!"; |
| 490 memcpy(mapping->base(), kWorld, sizeof(kWorld)); | 490 memcpy(mapping->GetBase(), kWorld, sizeof(kWorld)); |
| 491 | 491 |
| 492 // And send a message to signal that we've written stuff. | 492 // And send a message to signal that we've written stuff. |
| 493 const std::string go3("go 3"); | 493 const std::string go3("go 3"); |
| 494 EXPECT_EQ(MOJO_RESULT_OK, | 494 EXPECT_EQ(MOJO_RESULT_OK, |
| 495 mp->WriteMessage(0, | 495 mp->WriteMessage(0, |
| 496 UserPointer<const void>(&go3[0]), | 496 UserPointer<const void>(&go3[0]), |
| 497 static_cast<uint32_t>(go3.size()), | 497 static_cast<uint32_t>(go3.size()), |
| 498 NULL, | 498 NULL, |
| 499 MOJO_WRITE_MESSAGE_FLAG_NONE)); | 499 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 500 | 500 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 EXPECT_EQ(0u, hss.satisfiable_signals); | 619 EXPECT_EQ(0u, hss.satisfiable_signals); |
| 620 | 620 |
| 621 mp->Close(0); | 621 mp->Close(0); |
| 622 | 622 |
| 623 EXPECT_EQ(0, helper()->WaitForChildShutdown()); | 623 EXPECT_EQ(0, helper()->WaitForChildShutdown()); |
| 624 } | 624 } |
| 625 | 625 |
| 626 } // namespace | 626 } // namespace |
| 627 } // namespace system | 627 } // namespace system |
| 628 } // namespace mojo | 628 } // namespace mojo |
| OLD | NEW |