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

Side by Side Diff: util/mach/mach_message_server_test.cc

Issue 756803002: Add a ReceiveLarge parameter to MachMessageServer::Run() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years 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 | « util/mach/mach_message_server.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // MACH_SEND_INVALID_DEST, and the client will not expect a reply. 51 // MACH_SEND_INVALID_DEST, and the client will not expect a reply.
52 kReplyPortDead, 52 kReplyPortDead,
53 }; 53 };
54 54
55 Options() 55 Options()
56 : expect_server_interface_method_called(true), 56 : expect_server_interface_method_called(true),
57 parent_wait_for_child_pipe(false), 57 parent_wait_for_child_pipe(false),
58 server_options(MACH_MSG_OPTION_NONE), 58 server_options(MACH_MSG_OPTION_NONE),
59 server_persistent(MachMessageServer::kOneShot), 59 server_persistent(MachMessageServer::kOneShot),
60 server_nonblocking(MachMessageServer::kBlocking), 60 server_nonblocking(MachMessageServer::kBlocking),
61 server_receive_large(MachMessageServer::kReceiveLargeError),
61 server_timeout_ms(MACH_MSG_TIMEOUT_NONE), 62 server_timeout_ms(MACH_MSG_TIMEOUT_NONE),
62 server_mig_retcode(KERN_SUCCESS), 63 server_mig_retcode(KERN_SUCCESS),
63 server_destroy_complex(true), 64 server_destroy_complex(true),
64 expect_server_destroyed_complex(true), 65 expect_server_destroyed_complex(true),
65 expect_server_result(KERN_SUCCESS), 66 expect_server_result(KERN_SUCCESS),
66 expect_server_transaction_count(1), 67 expect_server_transaction_count(1),
67 child_wait_for_parent_pipe_early(false), 68 child_wait_for_parent_pipe_early(false),
68 client_send_request_count(1), 69 client_send_request_count(1),
69 client_send_complex(false), 70 client_send_complex(false),
70 client_send_large(false), 71 client_send_large(false),
(...skipping 15 matching lines...) Expand all
86 87
87 // Options to pass to MachMessageServer::Run() as the |options| parameter. 88 // Options to pass to MachMessageServer::Run() as the |options| parameter.
88 mach_msg_options_t server_options; 89 mach_msg_options_t server_options;
89 90
90 // Whether the server should run in one-shot or persistent mode. 91 // Whether the server should run in one-shot or persistent mode.
91 MachMessageServer::Persistent server_persistent; 92 MachMessageServer::Persistent server_persistent;
92 93
93 // Whether the server should run in blocking or nonblocking mode. 94 // Whether the server should run in blocking or nonblocking mode.
94 MachMessageServer::Nonblocking server_nonblocking; 95 MachMessageServer::Nonblocking server_nonblocking;
95 96
97 // The strategy for handling large messages.
98 MachMessageServer::ReceiveLarge server_receive_large;
99
96 // The server’s timeout. 100 // The server’s timeout.
97 mach_msg_timeout_t server_timeout_ms; 101 mach_msg_timeout_t server_timeout_ms;
98 102
99 // The return code that the server returns to the client via the 103 // The return code that the server returns to the client via the
100 // mig_reply_error_t::RetCode field. A client would normally see this as 104 // mig_reply_error_t::RetCode field. A client would normally see this as
101 // a Mach RPC return value. 105 // a Mach RPC return value.
102 kern_return_t server_mig_retcode; 106 kern_return_t server_mig_retcode;
103 107
104 // The value that the server function should set its destroy_complex_request 108 // The value that the server function should set its destroy_complex_request
105 // parameter to. This is true if resources sent in complex request messages 109 // parameter to. This is true if resources sent in complex request messages
(...skipping 21 matching lines...) Expand all
127 bool child_wait_for_parent_pipe_early; 131 bool child_wait_for_parent_pipe_early;
128 132
129 // The number of requests that the client should send to the server. 133 // The number of requests that the client should send to the server.
130 size_t client_send_request_count; 134 size_t client_send_request_count;
131 135
132 // true if the client should send a complex message, one that carries a port 136 // true if the client should send a complex message, one that carries a port
133 // descriptor in its body. Normally false. 137 // descriptor in its body. Normally false.
134 bool client_send_complex; 138 bool client_send_complex;
135 139
136 // true if the client should send a larger message than the server has 140 // true if the client should send a larger message than the server has
137 // allocated space to receive. If server_options contains MACH_RCV_LARGE, 141 // allocated space to receive. The server’s response is directed by
138 // the server will resize its buffer to receive the message. Otherwise, the 142 // server_receive_large.
139 // message will be destroyed and the server will return MACH_RCV_TOO_LARGE.
140 bool client_send_large; 143 bool client_send_large;
141 144
142 // The type of reply port that the client should provide in its request’s 145 // The type of reply port that the client should provide in its request’s
143 // mach_msg_header_t::msgh_local_port, which will appear to the server as 146 // mach_msg_header_t::msgh_local_port, which will appear to the server as
144 // mach_msg_header_t::msgh_remote_port. 147 // mach_msg_header_t::msgh_remote_port.
145 ReplyPortType client_reply_port_type; 148 ReplyPortType client_reply_port_type;
146 149
147 // true if the client should wait for a reply from the server. For 150 // true if the client should wait for a reply from the server. For
148 // non-normal reply ports or requests which the server responds to with no 151 // non-normal reply ports or requests which the server responds to with no
149 // reply (MIG_NO_REPLY), the server will either not send a reply or not 152 // reply (MIG_NO_REPLY), the server will either not send a reply or not
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 CheckedReadFD(ReadPipeFD(), &c, 1); 338 CheckedReadFD(ReadPipeFD(), &c, 1);
336 EXPECT_EQ('\0', c); 339 EXPECT_EQ('\0', c);
337 } 340 }
338 341
339 ASSERT_EQ(options_.expect_server_result, 342 ASSERT_EQ(options_.expect_server_result,
340 (kr = MachMessageServer::Run(this, 343 (kr = MachMessageServer::Run(this,
341 local_port, 344 local_port,
342 options_.server_options, 345 options_.server_options,
343 options_.server_persistent, 346 options_.server_persistent,
344 options_.server_nonblocking, 347 options_.server_nonblocking,
348 options_.server_receive_large,
345 options_.server_timeout_ms))) 349 options_.server_timeout_ms)))
346 << MachErrorMessage(kr, "MachMessageServer"); 350 << MachErrorMessage(kr, "MachMessageServer");
347 351
348 if (options_.client_send_complex) { 352 if (options_.client_send_complex) {
349 EXPECT_NE(kMachPortNull, parent_complex_message_port_); 353 EXPECT_NE(kMachPortNull, parent_complex_message_port_);
350 mach_port_type_t type; 354 mach_port_type_t type;
351 355
352 if (!options_.expect_server_destroyed_complex) { 356 if (!options_.expect_server_destroyed_complex) {
353 // MachMessageServer should not have destroyed the resources sent in the 357 // MachMessageServer should not have destroyed the resources sent in the
354 // complex request message. 358 // complex request message.
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 options.server_mig_retcode = MIG_NO_REPLY; 799 options.server_mig_retcode = MIG_NO_REPLY;
796 options.server_destroy_complex = false; 800 options.server_destroy_complex = false;
797 options.expect_server_destroyed_complex = false; 801 options.expect_server_destroyed_complex = false;
798 options.client_send_complex = true; 802 options.client_send_complex = true;
799 options.client_expect_reply = false; 803 options.client_expect_reply = false;
800 options.child_wait_for_parent_pipe_late = true; 804 options.child_wait_for_parent_pipe_late = true;
801 TestMachMessageServer test_mach_message_server(options); 805 TestMachMessageServer test_mach_message_server(options);
802 test_mach_message_server.Test(); 806 test_mach_message_server.Test();
803 } 807 }
804 808
805 TEST(MachMessageServer, LargeUnexpected) { 809 TEST(MachMessageServer, ReceiveLargeError) {
806 // The client sends a request to the server that is larger than the server is 810 // The client sends a request to the server that is larger than the server is
807 // expecting. The server did not specify MACH_RCV_LARGE in its options, so the 811 // expecting. server_receive_large is kReceiveLargeError, so the request is
808 // request is destroyed and the server returns a MACH_RCV_TOO_LARGE error. The 812 // destroyed and the server returns a MACH_RCV_TOO_LARGE error. The client
809 // client does not receive a reply. 813 // does not receive a reply.
810 TestMachMessageServer::Options options; 814 TestMachMessageServer::Options options;
811 options.expect_server_result = MACH_RCV_TOO_LARGE; 815 options.expect_server_result = MACH_RCV_TOO_LARGE;
812 options.expect_server_transaction_count = 0; 816 options.expect_server_transaction_count = 0;
813 options.client_send_large = true; 817 options.client_send_large = true;
814 options.client_expect_reply = false; 818 options.client_expect_reply = false;
815 TestMachMessageServer test_mach_message_server(options); 819 TestMachMessageServer test_mach_message_server(options);
816 test_mach_message_server.Test(); 820 test_mach_message_server.Test();
817 } 821 }
818 822
819 TEST(MachMessageServer, LargeExpected) { 823 TEST(MachMessageServer, ReceiveLargeRetry) {
820 // The client sends a request to the server that is larger than the server is 824 // The client sends a request to the server that is larger than the server is
821 // initially expecting. The server did specify MACH_RCV_LARGE in its options, 825 // initially expecting. server_receive_large is kReceiveLargeResize, so a new
822 // so a new buffer is allocated to receive the message. The server receives 826 // buffer is allocated to receive the message. The server receives the large
823 // the large request message, processes it, and returns a reply to the client. 827 // request message, processes it, and returns a reply to the client.
824 TestMachMessageServer::Options options; 828 TestMachMessageServer::Options options;
825 options.server_options = MACH_RCV_LARGE; 829 options.server_receive_large = MachMessageServer::kReceiveLargeResize;
826 options.client_send_large = true; 830 options.client_send_large = true;
827 TestMachMessageServer test_mach_message_server(options); 831 TestMachMessageServer test_mach_message_server(options);
828 test_mach_message_server.Test(); 832 test_mach_message_server.Test();
829 } 833 }
834
835 TEST(MachMessageServer, ReceiveLargeIgnore) {
836 // The client sends a request to the server that is larger than the server is
837 // expecting. server_receive_large is kReceiveLargeIgnore, so the request is
838 // destroyed but the server does not consider this an error. The server is
839 // running in blocking mode with a timeout, and continues to wait for a
840 // message until it times out. The client does not receive a reply.
841 TestMachMessageServer::Options options;
842 options.server_receive_large = MachMessageServer::kReceiveLargeIgnore;
843 options.server_timeout_ms = 10;
844 options.expect_server_result = MACH_RCV_TIMED_OUT;
845 options.expect_server_transaction_count = 0;
846 options.client_send_large = true;
847 options.client_expect_reply = false;
848 TestMachMessageServer test_mach_message_server(options);
849 test_mach_message_server.Test();
850 }
830 851
831 } // namespace 852 } // namespace
832 } // namespace test 853 } // namespace test
833 } // namespace crashpad 854 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/mach/mach_message_server.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698