| OLD | NEW |
| 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, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "util/mach/mach_message_server.h" | 15 #include "util/mach/mach_message_server.h" |
| 16 | 16 |
| 17 #include <mach/mach.h> | 17 #include <mach/mach.h> |
| 18 #include <string.h> | 18 #include <string.h> |
| 19 | 19 |
| 20 #include <set> | 20 #include <set> |
| 21 | 21 |
| 22 #include "base/basictypes.h" | 22 #include "base/basictypes.h" |
| 23 #include "base/mac/scoped_mach_port.h" | 23 #include "base/mac/scoped_mach_port.h" |
| 24 #include "gtest/gtest.h" | 24 #include "gtest/gtest.h" |
| 25 #include "util/file/fd_io.h" | 25 #include "util/file/file_io.h" |
| 26 #include "util/mach/mach_extensions.h" | 26 #include "util/mach/mach_extensions.h" |
| 27 #include "util/mach/mach_message.h" | 27 #include "util/mach/mach_message.h" |
| 28 #include "util/test/mac/mach_errors.h" | 28 #include "util/test/mac/mach_errors.h" |
| 29 #include "util/test/mac/mach_multiprocess.h" | 29 #include "util/test/mac/mach_multiprocess.h" |
| 30 | 30 |
| 31 namespace crashpad { | 31 namespace crashpad { |
| 32 namespace test { | 32 namespace test { |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 class TestMachMessageServer : public MachMessageServer::Interface, | 35 class TestMachMessageServer : public MachMessageServer::Interface, |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 MACH_PORT_LIMITS_INFO, | 328 MACH_PORT_LIMITS_INFO, |
| 329 reinterpret_cast<mach_port_info_t>(&limits), | 329 reinterpret_cast<mach_port_info_t>(&limits), |
| 330 MACH_PORT_LIMITS_INFO_COUNT); | 330 MACH_PORT_LIMITS_INFO_COUNT); |
| 331 ASSERT_EQ(KERN_SUCCESS, kr) | 331 ASSERT_EQ(KERN_SUCCESS, kr) |
| 332 << MachErrorMessage(kr, "mach_port_set_attributes"); | 332 << MachErrorMessage(kr, "mach_port_set_attributes"); |
| 333 } | 333 } |
| 334 | 334 |
| 335 if (options_.child_wait_for_parent_pipe_early) { | 335 if (options_.child_wait_for_parent_pipe_early) { |
| 336 // Tell the child to begin sending messages. | 336 // Tell the child to begin sending messages. |
| 337 char c = '\0'; | 337 char c = '\0'; |
| 338 CheckedWriteFD(WritePipeFD(), &c, 1); | 338 CheckedWriteFile(WritePipeFD(), &c, 1); |
| 339 } | 339 } |
| 340 | 340 |
| 341 if (options_.parent_wait_for_child_pipe) { | 341 if (options_.parent_wait_for_child_pipe) { |
| 342 // Wait until the child is done sending what it’s going to send. | 342 // Wait until the child is done sending what it’s going to send. |
| 343 char c; | 343 char c; |
| 344 CheckedReadFD(ReadPipeFD(), &c, 1); | 344 CheckedReadFile(ReadPipeFD(), &c, 1); |
| 345 EXPECT_EQ('\0', c); | 345 EXPECT_EQ('\0', c); |
| 346 } | 346 } |
| 347 | 347 |
| 348 ASSERT_EQ(options_.expect_server_result, | 348 ASSERT_EQ(options_.expect_server_result, |
| 349 (kr = MachMessageServer::Run(this, | 349 (kr = MachMessageServer::Run(this, |
| 350 local_port, | 350 local_port, |
| 351 options_.server_options, | 351 options_.server_options, |
| 352 options_.server_persistent, | 352 options_.server_persistent, |
| 353 options_.server_receive_large, | 353 options_.server_receive_large, |
| 354 options_.server_timeout_ms))) | 354 options_.server_timeout_ms))) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 379 // this test environment. | 379 // this test environment. |
| 380 kr = mach_port_type( | 380 kr = mach_port_type( |
| 381 mach_task_self(), parent_complex_message_port_, &type); | 381 mach_task_self(), parent_complex_message_port_, &type); |
| 382 EXPECT_EQ(KERN_INVALID_NAME, kr) | 382 EXPECT_EQ(KERN_INVALID_NAME, kr) |
| 383 << MachErrorMessage(kr, "mach_port_type"); | 383 << MachErrorMessage(kr, "mach_port_type"); |
| 384 } | 384 } |
| 385 | 385 |
| 386 if (options_.child_wait_for_parent_pipe_late) { | 386 if (options_.child_wait_for_parent_pipe_late) { |
| 387 // Let the child know it’s safe to exit. | 387 // Let the child know it’s safe to exit. |
| 388 char c = '\0'; | 388 char c = '\0'; |
| 389 CheckedWriteFD(WritePipeFD(), &c, 1); | 389 CheckedWriteFile(WritePipeFD(), &c, 1); |
| 390 } | 390 } |
| 391 } | 391 } |
| 392 | 392 |
| 393 void MachMultiprocessChild() override { | 393 void MachMultiprocessChild() override { |
| 394 if (options_.child_wait_for_parent_pipe_early) { | 394 if (options_.child_wait_for_parent_pipe_early) { |
| 395 // Wait until the parent is done setting things up on its end. | 395 // Wait until the parent is done setting things up on its end. |
| 396 char c; | 396 char c; |
| 397 CheckedReadFD(ReadPipeFD(), &c, 1); | 397 CheckedReadFile(ReadPipeFD(), &c, 1); |
| 398 EXPECT_EQ('\0', c); | 398 EXPECT_EQ('\0', c); |
| 399 } | 399 } |
| 400 | 400 |
| 401 for (size_t index = 0; | 401 for (size_t index = 0; |
| 402 index < options_.client_send_request_count; | 402 index < options_.client_send_request_count; |
| 403 ++index) { | 403 ++index) { |
| 404 if (options_.child_send_all_requests_before_receiving_any_replies) { | 404 if (options_.child_send_all_requests_before_receiving_any_replies) { |
| 405 // For this test, all of the messages need to go into the queue before | 405 // For this test, all of the messages need to go into the queue before |
| 406 // the parent is allowed to start processing them. Don’t attempt to | 406 // the parent is allowed to start processing them. Don’t attempt to |
| 407 // process replies before all of the requests are sent, because the | 407 // process replies before all of the requests are sent, because the |
| (...skipping 13 matching lines...) Expand all Loading... |
| 421 | 421 |
| 422 for (size_t index = 0; | 422 for (size_t index = 0; |
| 423 index < options_.client_send_request_count; | 423 index < options_.client_send_request_count; |
| 424 ++index) { | 424 ++index) { |
| 425 ASSERT_NO_FATAL_FAILURE(ChildWaitForReply()); | 425 ASSERT_NO_FATAL_FAILURE(ChildWaitForReply()); |
| 426 } | 426 } |
| 427 } | 427 } |
| 428 | 428 |
| 429 if (options_.child_wait_for_parent_pipe_late) { | 429 if (options_.child_wait_for_parent_pipe_late) { |
| 430 char c; | 430 char c; |
| 431 CheckedReadFD(ReadPipeFD(), &c, 1); | 431 CheckedReadFile(ReadPipeFD(), &c, 1); |
| 432 ASSERT_EQ('\0', c); | 432 ASSERT_EQ('\0', c); |
| 433 } | 433 } |
| 434 } | 434 } |
| 435 | 435 |
| 436 // In the child process, sends a request message to the server. | 436 // In the child process, sends a request message to the server. |
| 437 void ChildSendRequest() { | 437 void ChildSendRequest() { |
| 438 // local_receive_port_owner will the receive right that is created in this | 438 // local_receive_port_owner will the receive right that is created in this |
| 439 // scope and intended to be destroyed when leaving this scope, after it has | 439 // scope and intended to be destroyed when leaving this scope, after it has |
| 440 // been carried in a Mach message. | 440 // been carried in a Mach message. |
| 441 base::mac::ScopedMachReceiveRight local_receive_port_owner; | 441 base::mac::ScopedMachReceiveRight local_receive_port_owner; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 | 549 |
| 550 ++replies_; | 550 ++replies_; |
| 551 } | 551 } |
| 552 | 552 |
| 553 // For test types where the child needs to notify the server in the parent | 553 // For test types where the child needs to notify the server in the parent |
| 554 // that the child is ready, this method will send a byte via the POSIX pipe. | 554 // that the child is ready, this method will send a byte via the POSIX pipe. |
| 555 // The parent will be waiting in a read() on this pipe, and will proceed to | 555 // The parent will be waiting in a read() on this pipe, and will proceed to |
| 556 // running MachMessageServer() once it’s received. | 556 // running MachMessageServer() once it’s received. |
| 557 void ChildNotifyParentViaPipe() { | 557 void ChildNotifyParentViaPipe() { |
| 558 char c = '\0'; | 558 char c = '\0'; |
| 559 CheckedWriteFD(WritePipeFD(), &c, 1); | 559 CheckedWriteFile(WritePipeFD(), &c, 1); |
| 560 } | 560 } |
| 561 | 561 |
| 562 // In the child process, sends a request message to the server and then | 562 // In the child process, sends a request message to the server and then |
| 563 // receives a reply message. | 563 // receives a reply message. |
| 564 void ChildSendRequestAndWaitForReply() { | 564 void ChildSendRequestAndWaitForReply() { |
| 565 ASSERT_NO_FATAL_FAILURE(ChildSendRequest()); | 565 ASSERT_NO_FATAL_FAILURE(ChildSendRequest()); |
| 566 | 566 |
| 567 if (options_.parent_wait_for_child_pipe && | 567 if (options_.parent_wait_for_child_pipe && |
| 568 !options_.child_send_all_requests_before_receiving_any_replies) { | 568 !options_.child_send_all_requests_before_receiving_any_replies) { |
| 569 // The parent is waiting to read a byte to indicate that the message has | 569 // The parent is waiting to read a byte to indicate that the message has |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 options.expect_server_transaction_count = 0; | 850 options.expect_server_transaction_count = 0; |
| 851 options.client_send_large = true; | 851 options.client_send_large = true; |
| 852 options.client_expect_reply = false; | 852 options.client_expect_reply = false; |
| 853 TestMachMessageServer test_mach_message_server(options); | 853 TestMachMessageServer test_mach_message_server(options); |
| 854 test_mach_message_server.Test(); | 854 test_mach_message_server.Test(); |
| 855 } | 855 } |
| 856 | 856 |
| 857 } // namespace | 857 } // namespace |
| 858 } // namespace test | 858 } // namespace test |
| 859 } // namespace crashpad | 859 } // namespace crashpad |
| OLD | NEW |