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

Side by Side Diff: ipc/attachment_broker_mac_unittest.cc

Issue 2087163003: Remove calls to deprecated MessageLoop methods in ipc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: manual changes Created 4 years, 6 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 | « no previous file | ipc/ipc_channel_posix_unittest.cc » ('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 2015 The Chromium Authors. All rights reserved. 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 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <mach/mach_vm.h> 8 #include <mach/mach_vm.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/mman.h> 10 #include <sys/mman.h>
11 11
12 #include <memory> 12 #include <memory>
13 #include <tuple> 13 #include <tuple>
14 14
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/files/scoped_file.h" 17 #include "base/files/scoped_file.h"
18 #include "base/files/scoped_temp_dir.h" 18 #include "base/files/scoped_temp_dir.h"
19 #include "base/mac/mac_util.h" 19 #include "base/mac/mac_util.h"
20 #include "base/mac/mach_logging.h" 20 #include "base/mac/mach_logging.h"
21 #include "base/memory/free_deleter.h" 21 #include "base/memory/free_deleter.h"
22 #include "base/memory/shared_memory.h" 22 #include "base/memory/shared_memory.h"
23 #include "base/run_loop.h"
23 #include "base/strings/string_number_conversions.h" 24 #include "base/strings/string_number_conversions.h"
24 #include "base/synchronization/spin_wait.h" 25 #include "base/synchronization/spin_wait.h"
25 #include "base/time/time.h" 26 #include "base/time/time.h"
26 #include "ipc/attachment_broker_messages.h" 27 #include "ipc/attachment_broker_messages.h"
27 #include "ipc/attachment_broker_privileged_mac.h" 28 #include "ipc/attachment_broker_privileged_mac.h"
28 #include "ipc/attachment_broker_unprivileged_mac.h" 29 #include "ipc/attachment_broker_unprivileged_mac.h"
29 #include "ipc/ipc_listener.h" 30 #include "ipc/ipc_listener.h"
30 #include "ipc/ipc_message.h" 31 #include "ipc/ipc_message.h"
31 #include "ipc/ipc_test_base.h" 32 #include "ipc/ipc_test_base.h"
32 #include "ipc/ipc_test_messages.h" 33 #include "ipc/ipc_test_messages.h"
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 std::unique_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( 578 std::unique_ptr<IPC::Channel> channel(IPC::Channel::CreateClient(
578 IPCTestBase::GetChannelName(channel_name), &listener)); 579 IPCTestBase::GetChannelName(channel_name), &listener));
579 globals->broker->RegisterCommunicationChannel(channel.get(), nullptr); 580 globals->broker->RegisterCommunicationChannel(channel.get(), nullptr);
580 CHECK(channel->Connect()); 581 CHECK(channel->Connect());
581 582
582 globals->initial_resident_size = GetResidentSize(); 583 globals->initial_resident_size = GetResidentSize();
583 584
584 while (true) { 585 while (true) {
585 if (globals->message_logging) 586 if (globals->message_logging)
586 LOG(INFO) << "Privileged process spinning run loop."; 587 LOG(INFO) << "Privileged process spinning run loop.";
587 base::MessageLoop::current()->Run(); 588 base::RunLoop().Run();
588 ProxyListener::Reason reason = listener.get_reason(); 589 ProxyListener::Reason reason = listener.get_reason();
589 if (reason == ProxyListener::CHANNEL_ERROR) 590 if (reason == ProxyListener::CHANNEL_ERROR)
590 break; 591 break;
591 592
592 while (listener.has_message()) { 593 while (listener.has_message()) {
593 if (globals->message_logging) 594 if (globals->message_logging)
594 LOG(INFO) << "Privileged process running callback."; 595 LOG(INFO) << "Privileged process running callback.";
595 callback(channel.get(), listener.get_first_message(), globals.get()); 596 callback(channel.get(), listener.get_first_message(), globals.get());
596 if (globals->message_logging) 597 if (globals->message_logging)
597 LOG(INFO) << "Privileged process finishing callback."; 598 LOG(INFO) << "Privileged process finishing callback.";
598 listener.pop_first_message(); 599 listener.pop_first_message();
599 } 600 }
600 } 601 }
601 602
602 if (active_names_at_start != IPC::GetActiveNameCount()) { 603 if (active_names_at_start != IPC::GetActiveNameCount()) {
603 LOG(INFO) << "Memory leak!."; 604 LOG(INFO) << "Memory leak!.";
604 } 605 }
605 LOG(INFO) << "Privileged process end."; 606 LOG(INFO) << "Privileged process end.";
606 return 0; 607 return 0;
607 } 608 }
608 609
609 // An unprivileged process makes a shared memory region, and writes a string to 610 // An unprivileged process makes a shared memory region, and writes a string to
610 // it. The SharedMemoryHandle is sent to the privileged process using Chrome 611 // it. The SharedMemoryHandle is sent to the privileged process using Chrome
611 // IPC. The privileged process checks that it received the same memory region. 612 // IPC. The privileged process checks that it received the same memory region.
612 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandle) { 613 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandle) {
613 CommonSetUp("SendSharedMemoryHandle"); 614 CommonSetUp("SendSharedMemoryHandle");
614 615
615 SendMessage1(kDataBuffer1); 616 SendMessage1(kDataBuffer1);
616 base::MessageLoop::current()->Run(); 617 base::RunLoop().Run();
617 CommonTearDown(); 618 CommonTearDown();
618 } 619 }
619 620
620 void SendSharedMemoryHandleCallback(IPC::Sender* sender, 621 void SendSharedMemoryHandleCallback(IPC::Sender* sender,
621 const IPC::Message& message, 622 const IPC::Message& message,
622 ChildProcessGlobals* globals) { 623 ChildProcessGlobals* globals) {
623 bool success = CheckContentsOfMessage1(message, kDataBuffer1); 624 bool success = CheckContentsOfMessage1(message, kDataBuffer1);
624 SendControlMessage(sender, success); 625 SendControlMessage(sender, success);
625 } 626 }
626 627
627 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandle) { 628 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandle) {
628 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleCallback, 629 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleCallback,
629 "SendSharedMemoryHandle"); 630 "SendSharedMemoryHandle");
630 } 631 }
631 632
632 // Similar to SendSharedMemoryHandle, but sends a very long shared memory 633 // Similar to SendSharedMemoryHandle, but sends a very long shared memory
633 // region. 634 // region.
634 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandleLong) { 635 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandleLong) {
635 CommonSetUp("SendSharedMemoryHandleLong"); 636 CommonSetUp("SendSharedMemoryHandleLong");
636 637
637 std::string buffer(1 << 23, 'a'); 638 std::string buffer(1 << 23, 'a');
638 SendMessage1(buffer); 639 SendMessage1(buffer);
639 base::MessageLoop::current()->Run(); 640 base::RunLoop().Run();
640 CommonTearDown(); 641 CommonTearDown();
641 } 642 }
642 643
643 void SendSharedMemoryHandleLongCallback(IPC::Sender* sender, 644 void SendSharedMemoryHandleLongCallback(IPC::Sender* sender,
644 const IPC::Message& message, 645 const IPC::Message& message,
645 ChildProcessGlobals* globals) { 646 ChildProcessGlobals* globals) {
646 std::string buffer(1 << 23, 'a'); 647 std::string buffer(1 << 23, 'a');
647 bool success = CheckContentsOfMessage1(message, buffer); 648 bool success = CheckContentsOfMessage1(message, buffer);
648 SendControlMessage(sender, success); 649 SendControlMessage(sender, success);
649 } 650 }
650 651
651 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandleLong) { 652 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandleLong) {
652 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleLongCallback, 653 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleLongCallback,
653 "SendSharedMemoryHandleLong"); 654 "SendSharedMemoryHandleLong");
654 } 655 }
655 656
656 // Similar to SendSharedMemoryHandle, but sends two different shared memory 657 // Similar to SendSharedMemoryHandle, but sends two different shared memory
657 // regions in two messages. 658 // regions in two messages.
658 TEST_F(IPCAttachmentBrokerMacTest, SendTwoMessagesDifferentSharedMemoryHandle) { 659 TEST_F(IPCAttachmentBrokerMacTest, SendTwoMessagesDifferentSharedMemoryHandle) {
659 CommonSetUp("SendTwoMessagesDifferentSharedMemoryHandle"); 660 CommonSetUp("SendTwoMessagesDifferentSharedMemoryHandle");
660 661
661 SendMessage1(kDataBuffer1); 662 SendMessage1(kDataBuffer1);
662 SendMessage1(kDataBuffer2); 663 SendMessage1(kDataBuffer2);
663 base::MessageLoop::current()->Run(); 664 base::RunLoop().Run();
664 CommonTearDown(); 665 CommonTearDown();
665 } 666 }
666 667
667 void SendTwoMessagesDifferentSharedMemoryHandleCallback( 668 void SendTwoMessagesDifferentSharedMemoryHandleCallback(
668 IPC::Sender* sender, 669 IPC::Sender* sender,
669 const IPC::Message& message, 670 const IPC::Message& message,
670 ChildProcessGlobals* globals) { 671 ChildProcessGlobals* globals) {
671 static int count = 0; 672 static int count = 0;
672 static bool success = true; 673 static bool success = true;
673 ++count; 674 ++count;
(...skipping 20 matching lines...) Expand all
694 std::unique_ptr<base::SharedMemory> shared_memory( 695 std::unique_ptr<base::SharedMemory> shared_memory(
695 MakeSharedMemory(kDataBuffer1)); 696 MakeSharedMemory(kDataBuffer1));
696 697
697 for (int i = 0; i < 2; ++i) { 698 for (int i = 0; i < 2; ++i) {
698 IPC::Message* message = 699 IPC::Message* message =
699 new TestSharedMemoryHandleMsg1(100, shared_memory->handle(), 200); 700 new TestSharedMemoryHandleMsg1(100, shared_memory->handle(), 200);
700 sender()->Send(message); 701 sender()->Send(message);
701 } 702 }
702 } 703 }
703 704
704 base::MessageLoop::current()->Run(); 705 base::RunLoop().Run();
705 CommonTearDown(); 706 CommonTearDown();
706 } 707 }
707 708
708 void SendTwoMessagesSameSharedMemoryHandleCallback( 709 void SendTwoMessagesSameSharedMemoryHandleCallback(
709 IPC::Sender* sender, 710 IPC::Sender* sender,
710 const IPC::Message& message, 711 const IPC::Message& message,
711 ChildProcessGlobals* globals) { 712 ChildProcessGlobals* globals) {
712 static int count = 0; 713 static int count = 0;
713 static base::SharedMemoryHandle handle1; 714 static base::SharedMemoryHandle handle1;
714 ++count; 715 ++count;
(...skipping 23 matching lines...) Expand all
738 739
739 { 740 {
740 std::unique_ptr<base::SharedMemory> shared_memory1( 741 std::unique_ptr<base::SharedMemory> shared_memory1(
741 MakeSharedMemory(kDataBuffer1)); 742 MakeSharedMemory(kDataBuffer1));
742 std::unique_ptr<base::SharedMemory> shared_memory2( 743 std::unique_ptr<base::SharedMemory> shared_memory2(
743 MakeSharedMemory(kDataBuffer2)); 744 MakeSharedMemory(kDataBuffer2));
744 IPC::Message* message = new TestSharedMemoryHandleMsg2( 745 IPC::Message* message = new TestSharedMemoryHandleMsg2(
745 shared_memory1->handle(), shared_memory2->handle()); 746 shared_memory1->handle(), shared_memory2->handle());
746 sender()->Send(message); 747 sender()->Send(message);
747 } 748 }
748 base::MessageLoop::current()->Run(); 749 base::RunLoop().Run();
749 CommonTearDown(); 750 CommonTearDown();
750 } 751 }
751 752
752 void SendOneMessageWithTwoDifferentSharedMemoryHandlesCallback( 753 void SendOneMessageWithTwoDifferentSharedMemoryHandlesCallback(
753 IPC::Sender* sender, 754 IPC::Sender* sender,
754 const IPC::Message& message, 755 const IPC::Message& message,
755 ChildProcessGlobals* globals) { 756 ChildProcessGlobals* globals) {
756 base::SharedMemoryHandle handle1; 757 base::SharedMemoryHandle handle1;
757 base::SharedMemoryHandle handle2; 758 base::SharedMemoryHandle handle2;
758 if (!GetSharedMemoryHandlesFromMsg2(message, &handle1, &handle2)) { 759 if (!GetSharedMemoryHandlesFromMsg2(message, &handle1, &handle2)) {
(...skipping 20 matching lines...) Expand all
779 SendOneMessageWithTwoSameSharedMemoryHandles) { 780 SendOneMessageWithTwoSameSharedMemoryHandles) {
780 CommonSetUp("SendOneMessageWithTwoSameSharedMemoryHandles"); 781 CommonSetUp("SendOneMessageWithTwoSameSharedMemoryHandles");
781 782
782 { 783 {
783 std::unique_ptr<base::SharedMemory> shared_memory( 784 std::unique_ptr<base::SharedMemory> shared_memory(
784 MakeSharedMemory(kDataBuffer1)); 785 MakeSharedMemory(kDataBuffer1));
785 IPC::Message* message = new TestSharedMemoryHandleMsg2( 786 IPC::Message* message = new TestSharedMemoryHandleMsg2(
786 shared_memory->handle(), shared_memory->handle()); 787 shared_memory->handle(), shared_memory->handle());
787 sender()->Send(message); 788 sender()->Send(message);
788 } 789 }
789 base::MessageLoop::current()->Run(); 790 base::RunLoop().Run();
790 CommonTearDown(); 791 CommonTearDown();
791 } 792 }
792 793
793 void SendOneMessageWithTwoSameSharedMemoryHandlesCallback( 794 void SendOneMessageWithTwoSameSharedMemoryHandlesCallback(
794 IPC::Sender* sender, 795 IPC::Sender* sender,
795 const IPC::Message& message, 796 const IPC::Message& message,
796 ChildProcessGlobals* globals) { 797 ChildProcessGlobals* globals) {
797 base::SharedMemoryHandle handle1; 798 base::SharedMemoryHandle handle1;
798 base::SharedMemoryHandle handle2; 799 base::SharedMemoryHandle handle2;
799 if (!GetSharedMemoryHandlesFromMsg2(message, &handle1, &handle2)) { 800 if (!GetSharedMemoryHandlesFromMsg2(message, &handle1, &handle2)) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 MakeFileDescriptor(fp1, kDataBuffer3)); 835 MakeFileDescriptor(fp1, kDataBuffer3));
835 base::FileDescriptor file_descriptor2( 836 base::FileDescriptor file_descriptor2(
836 MakeFileDescriptor(fp2, kDataBuffer4)); 837 MakeFileDescriptor(fp2, kDataBuffer4));
837 838
838 IPC::Message* message = new TestSharedMemoryHandleMsg3( 839 IPC::Message* message = new TestSharedMemoryHandleMsg3(
839 file_descriptor1, shared_memory1->handle(), file_descriptor2, 840 file_descriptor1, shared_memory1->handle(), file_descriptor2,
840 shared_memory2->handle()); 841 shared_memory2->handle());
841 sender()->Send(message); 842 sender()->Send(message);
842 } 843 }
843 844
844 base::MessageLoop::current()->Run(); 845 base::RunLoop().Run();
845 CommonTearDown(); 846 CommonTearDown();
846 } 847 }
847 848
848 void SendPosixFDAndMachPortCallback(IPC::Sender* sender, 849 void SendPosixFDAndMachPortCallback(IPC::Sender* sender,
849 const IPC::Message& message, 850 const IPC::Message& message,
850 ChildProcessGlobals* globals) { 851 ChildProcessGlobals* globals) {
851 TestSharedMemoryHandleMsg3::Schema::Param p; 852 TestSharedMemoryHandleMsg3::Schema::Param p;
852 if (!TestSharedMemoryHandleMsg3::Read(&message, &p)) { 853 if (!TestSharedMemoryHandleMsg3::Read(&message, &p)) {
853 LOG(ERROR) << "Failed to deserialize message."; 854 LOG(ERROR) << "Failed to deserialize message.";
854 SendControlMessage(sender, false); 855 SendControlMessage(sender, false);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 std::unique_ptr<base::SharedMemory> shared_memory( 893 std::unique_ptr<base::SharedMemory> shared_memory(
893 MakeSharedMemory(kDataBuffer1)); 894 MakeSharedMemory(kDataBuffer1));
894 mach_port_urefs_t ref_count = IPC::GetMachRefCount( 895 mach_port_urefs_t ref_count = IPC::GetMachRefCount(
895 shared_memory->handle().GetMemoryObject(), MACH_PORT_RIGHT_SEND); 896 shared_memory->handle().GetMemoryObject(), MACH_PORT_RIGHT_SEND);
896 897
897 IPC::Message* message = 898 IPC::Message* message =
898 new TestSharedMemoryHandleMsg1(100, shared_memory->handle(), 200); 899 new TestSharedMemoryHandleMsg1(100, shared_memory->handle(), 200);
899 sender()->Send(message); 900 sender()->Send(message);
900 901
901 // Wait until the child process has sent this process a message. 902 // Wait until the child process has sent this process a message.
902 base::MessageLoop::current()->Run(); 903 base::RunLoop().Run();
903 904
904 // Wait for any asynchronous activity to complete. 905 // Wait for any asynchronous activity to complete.
905 base::MessageLoop::current()->RunUntilIdle(); 906 base::RunLoop().RunUntilIdle();
906 907
907 // Get the received attachment. 908 // Get the received attachment.
908 IPC::BrokerableAttachment::AttachmentId* id = get_observer()->get_id(); 909 IPC::BrokerableAttachment::AttachmentId* id = get_observer()->get_id();
909 ASSERT_TRUE(id); 910 ASSERT_TRUE(id);
910 scoped_refptr<IPC::BrokerableAttachment> received_attachment; 911 scoped_refptr<IPC::BrokerableAttachment> received_attachment;
911 get_broker()->GetAttachmentWithId(*id, &received_attachment); 912 get_broker()->GetAttachmentWithId(*id, &received_attachment);
912 ASSERT_NE(received_attachment.get(), nullptr); 913 ASSERT_NE(received_attachment.get(), nullptr);
913 914
914 // Check that it's has the same name, but that the ref count has increased. 915 // Check that it's has the same name, but that the ref count has increased.
915 base::mac::ScopedMachSendRight memory_object( 916 base::mac::ScopedMachSendRight memory_object(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 CreateChannelFactory(GetTestChannelHandle(), thread->task_runner().get()), 958 CreateChannelFactory(GetTestChannelHandle(), thread->task_runner().get()),
958 true); 959 true);
959 960
960 ASSERT_TRUE(StartClient()); 961 ASSERT_TRUE(StartClient());
961 962
962 MachPostForkSetUp(); 963 MachPostForkSetUp();
963 active_names_at_start_ = IPC::GetActiveNameCount(); 964 active_names_at_start_ = IPC::GetActiveNameCount();
964 get_proxy_listener()->set_listener(get_result_listener()); 965 get_proxy_listener()->set_listener(get_result_listener());
965 966
966 SendMessage1(kDataBuffer1); 967 SendMessage1(kDataBuffer1);
967 base::MessageLoop::current()->Run(); 968 base::RunLoop().Run();
968 969
969 CheckChildResult(); 970 CheckChildResult();
970 971
971 // There should be no leaked names. 972 // There should be no leaked names.
972 EXPECT_EQ(active_names_at_start_, IPC::GetActiveNameCount()); 973 EXPECT_EQ(active_names_at_start_, IPC::GetActiveNameCount());
973 974
974 // Close the channel so the client's OnChannelError() gets fired. 975 // Close the channel so the client's OnChannelError() gets fired.
975 channel_proxy()->Close(); 976 channel_proxy()->Close();
976 977
977 EXPECT_TRUE(WaitForClientShutdown()); 978 EXPECT_TRUE(WaitForClientShutdown());
(...skipping 21 matching lines...) Expand all
999 { 1000 {
1000 std::unique_ptr<base::SharedMemory> shared_memory( 1001 std::unique_ptr<base::SharedMemory> shared_memory(
1001 MakeSharedMemory(kDataBuffer1)); 1002 MakeSharedMemory(kDataBuffer1));
1002 base::SharedMemoryHandle new_handle; 1003 base::SharedMemoryHandle new_handle;
1003 ASSERT_TRUE(shared_memory->ShareToProcess(0, &new_handle)); 1004 ASSERT_TRUE(shared_memory->ShareToProcess(0, &new_handle));
1004 IPC::Message* message = 1005 IPC::Message* message =
1005 new TestSharedMemoryHandleMsg1(100, new_handle, 200); 1006 new TestSharedMemoryHandleMsg1(100, new_handle, 200);
1006 sender()->Send(message); 1007 sender()->Send(message);
1007 } 1008 }
1008 1009
1009 base::MessageLoop::current()->Run(); 1010 base::RunLoop().Run();
1010 CommonTearDown(); 1011 CommonTearDown();
1011 } 1012 }
1012 1013
1013 void ShareToProcessCallback(IPC::Sender* sender, 1014 void ShareToProcessCallback(IPC::Sender* sender,
1014 const IPC::Message& message, 1015 const IPC::Message& message,
1015 ChildProcessGlobals* globals) { 1016 ChildProcessGlobals* globals) {
1016 bool success = CheckContentsOfMessage1(message, kDataBuffer1); 1017 bool success = CheckContentsOfMessage1(message, kDataBuffer1);
1017 SendControlMessage(sender, success); 1018 SendControlMessage(sender, success);
1018 } 1019 }
1019 1020
1020 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(ShareToProcess) { 1021 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(ShareToProcess) {
1021 return CommonPrivilegedProcessMain(&ShareToProcessCallback, "ShareToProcess"); 1022 return CommonPrivilegedProcessMain(&ShareToProcessCallback, "ShareToProcess");
1022 } 1023 }
1023 1024
1024 // Similar to ShareToProcess, but instead shares the memory object only with 1025 // Similar to ShareToProcess, but instead shares the memory object only with
1025 // read permissions. 1026 // read permissions.
1026 TEST_F(IPCAttachmentBrokerMacTest, ShareReadOnlyToProcess) { 1027 TEST_F(IPCAttachmentBrokerMacTest, ShareReadOnlyToProcess) {
1027 CommonSetUp("ShareReadOnlyToProcess"); 1028 CommonSetUp("ShareReadOnlyToProcess");
1028 1029
1029 { 1030 {
1030 std::unique_ptr<base::SharedMemory> shared_memory( 1031 std::unique_ptr<base::SharedMemory> shared_memory(
1031 MakeSharedMemory(kDataBuffer1)); 1032 MakeSharedMemory(kDataBuffer1));
1032 base::SharedMemoryHandle new_handle; 1033 base::SharedMemoryHandle new_handle;
1033 ASSERT_TRUE(shared_memory->ShareReadOnlyToProcess(0, &new_handle)); 1034 ASSERT_TRUE(shared_memory->ShareReadOnlyToProcess(0, &new_handle));
1034 IPC::Message* message = 1035 IPC::Message* message =
1035 new TestSharedMemoryHandleMsg1(100, new_handle, 200); 1036 new TestSharedMemoryHandleMsg1(100, new_handle, 200);
1036 sender()->Send(message); 1037 sender()->Send(message);
1037 } 1038 }
1038 1039
1039 base::MessageLoop::current()->Run(); 1040 base::RunLoop().Run();
1040 CommonTearDown(); 1041 CommonTearDown();
1041 } 1042 }
1042 1043
1043 void ShareReadOnlyToProcessCallback(IPC::Sender* sender, 1044 void ShareReadOnlyToProcessCallback(IPC::Sender* sender,
1044 const IPC::Message& message, 1045 const IPC::Message& message,
1045 ChildProcessGlobals* globals) { 1046 ChildProcessGlobals* globals) {
1046 base::SharedMemoryHandle shm(GetSharedMemoryHandleFromMsg1(message)); 1047 base::SharedMemoryHandle shm(GetSharedMemoryHandleFromMsg1(message));
1047 1048
1048 // Try to map the memory as writable. 1049 // Try to map the memory as writable.
1049 std::unique_ptr<base::SharedMemory> shared_memory( 1050 std::unique_ptr<base::SharedMemory> shared_memory(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 sender()->Send(new AttachmentBrokerMsg_DuplicateMachPort(wire_format)); 1099 sender()->Send(new AttachmentBrokerMsg_DuplicateMachPort(wire_format));
1099 1100
1100 // Send a dummy message, which will trigger the callback handler in the 1101 // Send a dummy message, which will trigger the callback handler in the
1101 // child process. 1102 // child process.
1102 sender()->Send(new TestSharedMemoryHandleMsg4(1)); 1103 sender()->Send(new TestSharedMemoryHandleMsg4(1));
1103 } 1104 }
1104 1105
1105 int received_message_count = 0; 1106 int received_message_count = 0;
1106 while (received_message_count < kMessagesToTest) { 1107 while (received_message_count < kMessagesToTest) {
1107 // Wait until the child process has sent this process a message. 1108 // Wait until the child process has sent this process a message.
1108 base::MessageLoop::current()->Run(); 1109 base::RunLoop().Run();
1109 1110
1110 // Wait for any asynchronous activity to complete. 1111 // Wait for any asynchronous activity to complete.
1111 base::MessageLoop::current()->RunUntilIdle(); 1112 base::RunLoop().RunUntilIdle();
1112 1113
1113 while (get_proxy_listener()->has_message()) { 1114 while (get_proxy_listener()->has_message()) {
1114 get_proxy_listener()->pop_first_message(); 1115 get_proxy_listener()->pop_first_message();
1115 received_message_count++; 1116 received_message_count++;
1116 } 1117 }
1117 } 1118 }
1118 1119
1119 for (int i = 0; i < kMessagesToTest; ++i) { 1120 for (int i = 0; i < kMessagesToTest; ++i) {
1120 IPC::BrokerableAttachment::AttachmentId* id = &ids[i]; 1121 IPC::BrokerableAttachment::AttachmentId* id = &ids[i];
1121 ASSERT_TRUE(id); 1122 ASSERT_TRUE(id);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 1167
1167 // Tests the memory usage characteristics of attachment brokering a single large 1168 // Tests the memory usage characteristics of attachment brokering a single large
1168 // message. This test has the *potential* to be flaky, since it compares 1169 // message. This test has the *potential* to be flaky, since it compares
1169 // resident memory at different points in time, and that measurement is 1170 // resident memory at different points in time, and that measurement is
1170 // non-deterministic. 1171 // non-deterministic.
1171 TEST_F(IPCAttachmentBrokerMacTest, MemoryUsageLargeMessage) { 1172 TEST_F(IPCAttachmentBrokerMacTest, MemoryUsageLargeMessage) {
1172 CommonSetUp("MemoryUsageLargeMessage"); 1173 CommonSetUp("MemoryUsageLargeMessage");
1173 1174
1174 std::string test_string(g_large_message_size, 'a'); 1175 std::string test_string(g_large_message_size, 'a');
1175 SendMessage1(test_string); 1176 SendMessage1(test_string);
1176 base::MessageLoop::current()->Run(); 1177 base::RunLoop().Run();
1177 CommonTearDown(); 1178 CommonTearDown();
1178 } 1179 }
1179 1180
1180 void MemoryUsageLargeMessageCallback(IPC::Sender* sender, 1181 void MemoryUsageLargeMessageCallback(IPC::Sender* sender,
1181 const IPC::Message& message, 1182 const IPC::Message& message,
1182 ChildProcessGlobals* globals) { 1183 ChildProcessGlobals* globals) {
1183 EXPECT_LE(GetResidentSize(), 1184 EXPECT_LE(GetResidentSize(),
1184 globals->initial_resident_size + g_expected_memory_increase); 1185 globals->initial_resident_size + g_expected_memory_increase);
1185 1186
1186 base::SharedMemoryHandle shm(GetSharedMemoryHandleFromMsg1(message)); 1187 base::SharedMemoryHandle shm(GetSharedMemoryHandleFromMsg1(message));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 CommonSetUp("MemoryUsageManyMessages"); 1223 CommonSetUp("MemoryUsageManyMessages");
1223 1224
1224 for (int i = 0; i < g_large_message_count; ++i) { 1225 for (int i = 0; i < g_large_message_count; ++i) {
1225 std::string message = base::IntToString(i); 1226 std::string message = base::IntToString(i);
1226 message += '\0'; 1227 message += '\0';
1227 size_t end = message.size(); 1228 size_t end = message.size();
1228 message.resize(g_medium_message_size); 1229 message.resize(g_medium_message_size);
1229 std::fill(message.begin() + end, message.end(), 'a'); 1230 std::fill(message.begin() + end, message.end(), 'a');
1230 SendMessage1(message); 1231 SendMessage1(message);
1231 1232
1232 base::MessageLoop::current()->RunUntilIdle(); 1233 base::RunLoop().RunUntilIdle();
1233 } 1234 }
1234 1235
1235 if (get_result_listener()->get_result() == RESULT_UNKNOWN) 1236 if (get_result_listener()->get_result() == RESULT_UNKNOWN)
1236 base::MessageLoop::current()->Run(); 1237 base::RunLoop().Run();
1237 1238
1238 CommonTearDown(); 1239 CommonTearDown();
1239 } 1240 }
1240 1241
1241 void MemoryUsageManyMessagesCallback(IPC::Sender* sender, 1242 void MemoryUsageManyMessagesCallback(IPC::Sender* sender,
1242 const IPC::Message& message, 1243 const IPC::Message& message,
1243 ChildProcessGlobals* globals) { 1244 ChildProcessGlobals* globals) {
1244 static int message_index = 0; 1245 static int message_index = 0;
1245 1246
1246 { 1247 {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 SendControlMessage(sender, success); 1290 SendControlMessage(sender, success);
1290 } 1291 }
1291 } 1292 }
1292 1293
1293 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(MemoryUsageManyMessages) { 1294 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(MemoryUsageManyMessages) {
1294 return CommonPrivilegedProcessMain(&MemoryUsageManyMessagesCallback, 1295 return CommonPrivilegedProcessMain(&MemoryUsageManyMessagesCallback,
1295 "MemoryUsageManyMessages"); 1296 "MemoryUsageManyMessages");
1296 } 1297 }
1297 1298
1298 } // namespace 1299 } // namespace
OLDNEW
« no previous file with comments | « no previous file | ipc/ipc_channel_posix_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698