| 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, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "util/mach/mach_message_server.h" | 23 #include "util/mach/mach_message_server.h" |
| 24 #include "util/test/mac/mach_errors.h" | 24 #include "util/test/mac/mach_errors.h" |
| 25 | 25 |
| 26 namespace crashpad { | 26 namespace crashpad { |
| 27 namespace test { | 27 namespace test { |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 using testing::AllOf; | 30 using testing::AllOf; |
| 31 using testing::Eq; | 31 using testing::Eq; |
| 32 using testing::Invoke; | 32 using testing::Invoke; |
| 33 using testing::Ne; | |
| 34 using testing::Pointee; | 33 using testing::Pointee; |
| 35 using testing::ResultOf; | 34 using testing::ResultOf; |
| 36 using testing::Return; | 35 using testing::Return; |
| 37 using testing::SetArgPointee; | 36 using testing::SetArgPointee; |
| 38 using testing::StrictMock; | 37 using testing::StrictMock; |
| 39 using testing::WithArg; | 38 using testing::WithArg; |
| 40 | 39 |
| 41 //! \brief Adds a send right to an existing receive right. | 40 //! \brief Adds a send right to an existing receive right. |
| 42 //! | 41 //! |
| 43 //! \param[in] receive_right The receive right to add a send right to. | 42 //! \param[in] receive_right The receive right to add a send right to. |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 //! exactly once, and that no undesired methods are called. | 231 //! exactly once, and that no undesired methods are called. |
| 233 //! | 232 //! |
| 234 //! MachMessageServer::Run() is expected to return `MACH_RCV_TIMED_OUT`, | 233 //! MachMessageServer::Run() is expected to return `MACH_RCV_TIMED_OUT`, |
| 235 //! because it runs in persistent nonblocking mode. If it returns anything | 234 //! because it runs in persistent nonblocking mode. If it returns anything |
| 236 //! else, a gtest assertion is added. | 235 //! else, a gtest assertion is added. |
| 237 void RunServer() { | 236 void RunServer() { |
| 238 NotifyServer notify_server(this); | 237 NotifyServer notify_server(this); |
| 239 mach_msg_return_t mr = | 238 mach_msg_return_t mr = |
| 240 MachMessageServer::Run(¬ify_server, | 239 MachMessageServer::Run(¬ify_server, |
| 241 ServerPort(), | 240 ServerPort(), |
| 242 MACH_MSG_OPTION_NONE, | 241 kMachMessageReceiveAuditTrailer, |
| 243 MachMessageServer::kPersistent, | 242 MachMessageServer::kPersistent, |
| 244 MachMessageServer::kReceiveLargeError, | 243 MachMessageServer::kReceiveLargeError, |
| 245 kMachMessageTimeoutNonblocking); | 244 kMachMessageTimeoutNonblocking); |
| 246 ASSERT_EQ(MACH_RCV_TIMED_OUT, mr) | 245 ASSERT_EQ(MACH_RCV_TIMED_OUT, mr) |
| 247 << MachErrorMessage(mr, "MachMessageServer::Run"); | 246 << MachErrorMessage(mr, "MachMessageServer::Run"); |
| 248 } | 247 } |
| 249 | 248 |
| 250 //! \brief Returns the receive right to be used for the server. | 249 //! \brief Returns the receive right to be used for the server. |
| 251 //! | 250 //! |
| 252 //! This receive right is created lazily on a per-test basis. It is destroyed | 251 //! This receive right is created lazily on a per-test basis. It is destroyed |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 // a port-deleted notification should be generated. | 307 // a port-deleted notification should be generated. |
| 309 TEST_F(NotifyServerTest, MachNotifyPortDeleted) { | 308 TEST_F(NotifyServerTest, MachNotifyPortDeleted) { |
| 310 base::mac::ScopedMachReceiveRight receive_right( | 309 base::mac::ScopedMachReceiveRight receive_right( |
| 311 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); | 310 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); |
| 312 ASSERT_NE(kMachPortNull, receive_right); | 311 ASSERT_NE(kMachPortNull, receive_right); |
| 313 | 312 |
| 314 base::mac::ScopedMachSendRight send_once_right( | 313 base::mac::ScopedMachSendRight send_once_right( |
| 315 SendOnceRightFromReceiveRight(receive_right)); | 314 SendOnceRightFromReceiveRight(receive_right)); |
| 316 ASSERT_NE(kMachPortNull, send_once_right); | 315 ASSERT_NE(kMachPortNull, send_once_right); |
| 317 | 316 |
| 318 ASSERT_TRUE(RequestMachPortNotification( | 317 ASSERT_TRUE( |
| 319 send_once_right, MACH_NOTIFY_DEAD_NAME, 0)); | 318 RequestMachPortNotification(send_once_right, MACH_NOTIFY_DEAD_NAME, 0)); |
| 320 | 319 |
| 321 EXPECT_CALL(*this, DoMachNotifyPortDeleted(ServerPort(), | 320 EXPECT_CALL( |
| 322 send_once_right.get(), | 321 *this, |
| 323 Ne(nullptr))) | 322 DoMachNotifyPortDeleted(ServerPort(), |
| 323 send_once_right.get(), |
| 324 ResultOf(AuditPIDFromMachMessageTrailer, 0))) |
| 324 .WillOnce(Return(MIG_NO_REPLY)) | 325 .WillOnce(Return(MIG_NO_REPLY)) |
| 325 .RetiresOnSaturation(); | 326 .RetiresOnSaturation(); |
| 326 | 327 |
| 327 send_once_right.reset(); | 328 send_once_right.reset(); |
| 328 | 329 |
| 329 RunServer(); | 330 RunServer(); |
| 330 } | 331 } |
| 331 | 332 |
| 332 // When a receive right with a port-destroyed notification request is destroyed, | 333 // When a receive right with a port-destroyed notification request is destroyed, |
| 333 // a port-destroyed notification should be generated. | 334 // a port-destroyed notification should be generated. |
| 334 TEST_F(NotifyServerTest, MachNotifyPortDestroyed) { | 335 TEST_F(NotifyServerTest, MachNotifyPortDestroyed) { |
| 335 base::mac::ScopedMachReceiveRight receive_right( | 336 base::mac::ScopedMachReceiveRight receive_right( |
| 336 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); | 337 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); |
| 337 ASSERT_NE(kMachPortNull, receive_right); | 338 ASSERT_NE(kMachPortNull, receive_right); |
| 338 | 339 |
| 339 ASSERT_TRUE(RequestMachPortNotification( | 340 ASSERT_TRUE(RequestMachPortNotification( |
| 340 receive_right, MACH_NOTIFY_PORT_DESTROYED, 0)); | 341 receive_right, MACH_NOTIFY_PORT_DESTROYED, 0)); |
| 341 | 342 |
| 342 EXPECT_CALL(*this, DoMachNotifyPortDestroyed(ServerPort(), | 343 EXPECT_CALL( |
| 343 ResultOf(IsReceiveRight, true), | 344 *this, |
| 344 Ne(nullptr), | 345 DoMachNotifyPortDestroyed(ServerPort(), |
| 345 Pointee(Eq(false)))) | 346 ResultOf(IsReceiveRight, true), |
| 347 ResultOf(AuditPIDFromMachMessageTrailer, 0), |
| 348 Pointee(Eq(false)))) |
| 346 .WillOnce(DoAll(SetArgPointee<3>(true), Return(MIG_NO_REPLY))) | 349 .WillOnce(DoAll(SetArgPointee<3>(true), Return(MIG_NO_REPLY))) |
| 347 .RetiresOnSaturation(); | 350 .RetiresOnSaturation(); |
| 348 | 351 |
| 349 receive_right.reset(); | 352 receive_right.reset(); |
| 350 | 353 |
| 351 RunServer(); | 354 RunServer(); |
| 352 } | 355 } |
| 353 | 356 |
| 354 // When a receive right with a port-destroyed notification request is not | 357 // When a receive right with a port-destroyed notification request is not |
| 355 // destroyed, no port-destroyed notification should be generated. | 358 // destroyed, no port-destroyed notification should be generated. |
| 356 TEST_F(NotifyServerTest, MachNotifyPortDestroyed_NoNotification) { | 359 TEST_F(NotifyServerTest, MachNotifyPortDestroyed_NoNotification) { |
| 357 base::mac::ScopedMachReceiveRight receive_right( | 360 base::mac::ScopedMachReceiveRight receive_right( |
| 358 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); | 361 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); |
| 359 ASSERT_NE(kMachPortNull, receive_right); | 362 ASSERT_NE(kMachPortNull, receive_right); |
| 360 | 363 |
| 361 ASSERT_TRUE(RequestMachPortNotification( | 364 ASSERT_TRUE(RequestMachPortNotification( |
| 362 receive_right, MACH_NOTIFY_PORT_DESTROYED, 0)); | 365 receive_right, MACH_NOTIFY_PORT_DESTROYED, 0)); |
| 363 | 366 |
| 364 RunServer(); | 367 RunServer(); |
| 365 } | 368 } |
| 366 | 369 |
| 367 // When a no-senders notification request is registered for a receive right with | 370 // When a no-senders notification request is registered for a receive right with |
| 368 // no senders, a no-senders notification should be generated. | 371 // no senders, a no-senders notification should be generated. |
| 369 TEST_F(NotifyServerTest, MachNotifyNoSenders_NoSendRight) { | 372 TEST_F(NotifyServerTest, MachNotifyNoSenders_NoSendRight) { |
| 370 base::mac::ScopedMachReceiveRight receive_right( | 373 base::mac::ScopedMachReceiveRight receive_right( |
| 371 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); | 374 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); |
| 372 ASSERT_NE(kMachPortNull, receive_right); | 375 ASSERT_NE(kMachPortNull, receive_right); |
| 373 | 376 |
| 374 ASSERT_TRUE(RequestMachPortNotification( | 377 ASSERT_TRUE( |
| 375 receive_right, MACH_NOTIFY_NO_SENDERS, 0)); | 378 RequestMachPortNotification(receive_right, MACH_NOTIFY_NO_SENDERS, 0)); |
| 376 | 379 |
| 377 EXPECT_CALL(*this, DoMachNotifyNoSenders(ServerPort(), 0, Ne(nullptr))) | 380 EXPECT_CALL(*this, |
| 381 DoMachNotifyNoSenders( |
| 382 ServerPort(), 0, ResultOf(AuditPIDFromMachMessageTrailer, 0))) |
| 378 .WillOnce(Return(MIG_NO_REPLY)) | 383 .WillOnce(Return(MIG_NO_REPLY)) |
| 379 .RetiresOnSaturation(); | 384 .RetiresOnSaturation(); |
| 380 | 385 |
| 381 RunServer(); | 386 RunServer(); |
| 382 } | 387 } |
| 383 | 388 |
| 384 // When the last send right corresponding to a receive right with a no-senders | 389 // When the last send right corresponding to a receive right with a no-senders |
| 385 // notification request is deallocated, a no-senders notification should be | 390 // notification request is deallocated, a no-senders notification should be |
| 386 // generated. | 391 // generated. |
| 387 TEST_F(NotifyServerTest, MachNotifyNoSenders_SendRightDeallocated) { | 392 TEST_F(NotifyServerTest, MachNotifyNoSenders_SendRightDeallocated) { |
| 388 base::mac::ScopedMachReceiveRight receive_right( | 393 base::mac::ScopedMachReceiveRight receive_right( |
| 389 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); | 394 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); |
| 390 ASSERT_NE(kMachPortNull, receive_right); | 395 ASSERT_NE(kMachPortNull, receive_right); |
| 391 | 396 |
| 392 base::mac::ScopedMachSendRight send_right( | 397 base::mac::ScopedMachSendRight send_right( |
| 393 SendRightFromReceiveRight(receive_right)); | 398 SendRightFromReceiveRight(receive_right)); |
| 394 ASSERT_NE(kMachPortNull, send_right); | 399 ASSERT_NE(kMachPortNull, send_right); |
| 395 | 400 |
| 396 ASSERT_TRUE(RequestMachPortNotification( | 401 ASSERT_TRUE( |
| 397 receive_right, MACH_NOTIFY_NO_SENDERS, 1)); | 402 RequestMachPortNotification(receive_right, MACH_NOTIFY_NO_SENDERS, 1)); |
| 398 | 403 |
| 399 EXPECT_CALL(*this, DoMachNotifyNoSenders(ServerPort(), 1, Ne(nullptr))) | 404 EXPECT_CALL(*this, |
| 405 DoMachNotifyNoSenders( |
| 406 ServerPort(), 1, ResultOf(AuditPIDFromMachMessageTrailer, 0))) |
| 400 .WillOnce(Return(MIG_NO_REPLY)) | 407 .WillOnce(Return(MIG_NO_REPLY)) |
| 401 .RetiresOnSaturation(); | 408 .RetiresOnSaturation(); |
| 402 | 409 |
| 403 send_right.reset(); | 410 send_right.reset(); |
| 404 | 411 |
| 405 RunServer(); | 412 RunServer(); |
| 406 } | 413 } |
| 407 | 414 |
| 408 // When the a receive right with a no-senders notification request never loses | 415 // When the a receive right with a no-senders notification request never loses |
| 409 // all senders, no no-senders notification should be generated. | 416 // all senders, no no-senders notification should be generated. |
| 410 TEST_F(NotifyServerTest, MachNotifyNoSenders_NoNotification) { | 417 TEST_F(NotifyServerTest, MachNotifyNoSenders_NoNotification) { |
| 411 base::mac::ScopedMachReceiveRight receive_right( | 418 base::mac::ScopedMachReceiveRight receive_right( |
| 412 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); | 419 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); |
| 413 ASSERT_NE(kMachPortNull, receive_right); | 420 ASSERT_NE(kMachPortNull, receive_right); |
| 414 | 421 |
| 415 base::mac::ScopedMachSendRight send_right_0( | 422 base::mac::ScopedMachSendRight send_right_0( |
| 416 SendRightFromReceiveRight(receive_right)); | 423 SendRightFromReceiveRight(receive_right)); |
| 417 ASSERT_NE(kMachPortNull, send_right_0); | 424 ASSERT_NE(kMachPortNull, send_right_0); |
| 418 | 425 |
| 419 base::mac::ScopedMachSendRight send_right_1( | 426 base::mac::ScopedMachSendRight send_right_1( |
| 420 SendRightFromReceiveRight(receive_right)); | 427 SendRightFromReceiveRight(receive_right)); |
| 421 ASSERT_NE(kMachPortNull, send_right_1); | 428 ASSERT_NE(kMachPortNull, send_right_1); |
| 422 | 429 |
| 423 ASSERT_TRUE(RequestMachPortNotification( | 430 ASSERT_TRUE( |
| 424 receive_right, MACH_NOTIFY_NO_SENDERS, 1)); | 431 RequestMachPortNotification(receive_right, MACH_NOTIFY_NO_SENDERS, 1)); |
| 425 | 432 |
| 426 send_right_1.reset(); | 433 send_right_1.reset(); |
| 427 | 434 |
| 428 RunServer(); | 435 RunServer(); |
| 429 | 436 |
| 430 EXPECT_EQ(1u, RightRefCount(receive_right, MACH_PORT_RIGHT_RECEIVE)); | 437 EXPECT_EQ(1u, RightRefCount(receive_right, MACH_PORT_RIGHT_RECEIVE)); |
| 431 EXPECT_EQ(1u, RightRefCount(receive_right, MACH_PORT_RIGHT_SEND)); | 438 EXPECT_EQ(1u, RightRefCount(receive_right, MACH_PORT_RIGHT_SEND)); |
| 432 } | 439 } |
| 433 | 440 |
| 434 // When a send-once right is deallocated without being used, a send-once | 441 // When a send-once right is deallocated without being used, a send-once |
| 435 // notification notification should be sent via the send-once right. | 442 // notification notification should be sent via the send-once right. |
| 436 TEST_F(NotifyServerTest, MachNotifySendOnce_ExplicitDeallocation) { | 443 TEST_F(NotifyServerTest, MachNotifySendOnce_ExplicitDeallocation) { |
| 437 base::mac::ScopedMachSendRight send_once_right( | 444 base::mac::ScopedMachSendRight send_once_right( |
| 438 SendOnceRightFromReceiveRight(ServerPort())); | 445 SendOnceRightFromReceiveRight(ServerPort())); |
| 439 ASSERT_NE(kMachPortNull, send_once_right); | 446 ASSERT_NE(kMachPortNull, send_once_right); |
| 440 | 447 |
| 441 EXPECT_CALL(*this, DoMachNotifySendOnce(ServerPort(), Ne(nullptr))) | 448 EXPECT_CALL(*this, |
| 449 DoMachNotifySendOnce(ServerPort(), |
| 450 ResultOf(AuditPIDFromMachMessageTrailer, 0))) |
| 442 .WillOnce(Return(MIG_NO_REPLY)) | 451 .WillOnce(Return(MIG_NO_REPLY)) |
| 443 .RetiresOnSaturation(); | 452 .RetiresOnSaturation(); |
| 444 | 453 |
| 445 send_once_right.reset(); | 454 send_once_right.reset(); |
| 446 | 455 |
| 447 RunServer(); | 456 RunServer(); |
| 448 } | 457 } |
| 449 | 458 |
| 450 // When a send-once right is sent to a receiver that never dequeues the message, | 459 // When a send-once right is sent to a receiver that never dequeues the message, |
| 451 // the send-once right is destroyed, and a send-once notification should appear | 460 // the send-once right is destroyed, and a send-once notification should appear |
| (...skipping 11 matching lines...) Expand all Loading... |
| 463 message.header.msgh_local_port = ServerPort(); | 472 message.header.msgh_local_port = ServerPort(); |
| 464 mach_msg_return_t mr = mach_msg(&message.header, | 473 mach_msg_return_t mr = mach_msg(&message.header, |
| 465 MACH_SEND_MSG | MACH_SEND_TIMEOUT, | 474 MACH_SEND_MSG | MACH_SEND_TIMEOUT, |
| 466 message.header.msgh_size, | 475 message.header.msgh_size, |
| 467 0, | 476 0, |
| 468 MACH_PORT_NULL, | 477 MACH_PORT_NULL, |
| 469 0, | 478 0, |
| 470 MACH_PORT_NULL); | 479 MACH_PORT_NULL); |
| 471 ASSERT_EQ(MACH_MSG_SUCCESS, mr) << MachErrorMessage(mr, "mach_msg"); | 480 ASSERT_EQ(MACH_MSG_SUCCESS, mr) << MachErrorMessage(mr, "mach_msg"); |
| 472 | 481 |
| 473 EXPECT_CALL(*this, DoMachNotifySendOnce(ServerPort(), Ne(nullptr))) | 482 EXPECT_CALL(*this, |
| 483 DoMachNotifySendOnce(ServerPort(), |
| 484 ResultOf(AuditPIDFromMachMessageTrailer, 0))) |
| 474 .WillOnce(Return(MIG_NO_REPLY)) | 485 .WillOnce(Return(MIG_NO_REPLY)) |
| 475 .RetiresOnSaturation(); | 486 .RetiresOnSaturation(); |
| 476 | 487 |
| 477 receive_right.reset(); | 488 receive_right.reset(); |
| 478 | 489 |
| 479 RunServer(); | 490 RunServer(); |
| 480 } | 491 } |
| 481 | 492 |
| 482 // When the receive right corresponding to a send-once right with a dead-name | 493 // When the receive right corresponding to a send-once right with a dead-name |
| 483 // notification request is destroyed, a dead-name notification should be | 494 // notification request is destroyed, a dead-name notification should be |
| 484 // generated. | 495 // generated. |
| 485 TEST_F(NotifyServerTest, MachNotifyDeadName) { | 496 TEST_F(NotifyServerTest, MachNotifyDeadName) { |
| 486 base::mac::ScopedMachReceiveRight receive_right( | 497 base::mac::ScopedMachReceiveRight receive_right( |
| 487 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); | 498 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); |
| 488 ASSERT_NE(kMachPortNull, receive_right); | 499 ASSERT_NE(kMachPortNull, receive_right); |
| 489 | 500 |
| 490 base::mac::ScopedMachSendRight send_once_right( | 501 base::mac::ScopedMachSendRight send_once_right( |
| 491 SendOnceRightFromReceiveRight(receive_right)); | 502 SendOnceRightFromReceiveRight(receive_right)); |
| 492 ASSERT_NE(kMachPortNull, send_once_right); | 503 ASSERT_NE(kMachPortNull, send_once_right); |
| 493 | 504 |
| 494 ASSERT_TRUE(RequestMachPortNotification( | 505 ASSERT_TRUE( |
| 495 send_once_right, MACH_NOTIFY_DEAD_NAME, 0)); | 506 RequestMachPortNotification(send_once_right, MACH_NOTIFY_DEAD_NAME, 0)); |
| 496 | 507 |
| 497 // send_once_right becomes a dead name with the send-once right’s original | 508 // send_once_right becomes a dead name with the send-once right’s original |
| 498 // user reference count of 1, but the dead-name notification increments the | 509 // user reference count of 1, but the dead-name notification increments the |
| 499 // dead-name reference count, so it becomes 2. Take care to deallocate that | 510 // dead-name reference count, so it becomes 2. Take care to deallocate that |
| 500 // reference. The original reference is managed by send_once_right_owner. | 511 // reference. The original reference is managed by send_once_right_owner. |
| 501 EXPECT_CALL(*this, | 512 EXPECT_CALL(*this, |
| 502 DoMachNotifyDeadName(ServerPort(), | 513 DoMachNotifyDeadName(ServerPort(), |
| 503 AllOf(send_once_right.get(), | 514 AllOf(send_once_right.get(), |
| 504 ResultOf(DeadNameRightRefCount, 2)), | 515 ResultOf(DeadNameRightRefCount, 2)), |
| 505 Ne(nullptr))) | 516 ResultOf(AuditPIDFromMachMessageTrailer, 0))) |
| 506 .WillOnce(DoAll(WithArg<1>(Invoke(MachPortDeallocate)), | 517 .WillOnce( |
| 507 Return(MIG_NO_REPLY))) | 518 DoAll(WithArg<1>(Invoke(MachPortDeallocate)), Return(MIG_NO_REPLY))) |
| 508 .RetiresOnSaturation(); | 519 .RetiresOnSaturation(); |
| 509 | 520 |
| 510 receive_right.reset(); | 521 receive_right.reset(); |
| 511 | 522 |
| 512 RunServer(); | 523 RunServer(); |
| 513 | 524 |
| 514 EXPECT_TRUE(IsRight(send_once_right, MACH_PORT_TYPE_DEAD_NAME)); | 525 EXPECT_TRUE(IsRight(send_once_right, MACH_PORT_TYPE_DEAD_NAME)); |
| 515 | 526 |
| 516 EXPECT_EQ(0u, RightRefCount(send_once_right, MACH_PORT_RIGHT_SEND_ONCE)); | 527 EXPECT_EQ(0u, RightRefCount(send_once_right, MACH_PORT_RIGHT_SEND_ONCE)); |
| 517 EXPECT_EQ(1u, DeadNameRightRefCount(send_once_right)); | 528 EXPECT_EQ(1u, DeadNameRightRefCount(send_once_right)); |
| 518 } | 529 } |
| 519 | 530 |
| 520 // When the receive right corresponding to a send-once right with a dead-name | 531 // When the receive right corresponding to a send-once right with a dead-name |
| 521 // notification request is not destroyed, no dead-name notification should be | 532 // notification request is not destroyed, no dead-name notification should be |
| 522 // generated. | 533 // generated. |
| 523 TEST_F(NotifyServerTest, MachNotifyDeadName_NoNotification) { | 534 TEST_F(NotifyServerTest, MachNotifyDeadName_NoNotification) { |
| 524 base::mac::ScopedMachReceiveRight receive_right( | 535 base::mac::ScopedMachReceiveRight receive_right( |
| 525 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); | 536 NewMachPort(MACH_PORT_RIGHT_RECEIVE)); |
| 526 ASSERT_NE(kMachPortNull, receive_right); | 537 ASSERT_NE(kMachPortNull, receive_right); |
| 527 | 538 |
| 528 base::mac::ScopedMachSendRight send_once_right( | 539 base::mac::ScopedMachSendRight send_once_right( |
| 529 SendOnceRightFromReceiveRight(receive_right)); | 540 SendOnceRightFromReceiveRight(receive_right)); |
| 530 ASSERT_NE(kMachPortNull, send_once_right); | 541 ASSERT_NE(kMachPortNull, send_once_right); |
| 531 | 542 |
| 532 ASSERT_TRUE(RequestMachPortNotification( | 543 ASSERT_TRUE( |
| 533 send_once_right, MACH_NOTIFY_DEAD_NAME, 0)); | 544 RequestMachPortNotification(send_once_right, MACH_NOTIFY_DEAD_NAME, 0)); |
| 534 | 545 |
| 535 RunServer(); | 546 RunServer(); |
| 536 | 547 |
| 537 EXPECT_FALSE(IsRight(send_once_right, MACH_PORT_TYPE_DEAD_NAME)); | 548 EXPECT_FALSE(IsRight(send_once_right, MACH_PORT_TYPE_DEAD_NAME)); |
| 538 | 549 |
| 539 EXPECT_EQ(1u, RightRefCount(send_once_right, MACH_PORT_RIGHT_SEND_ONCE)); | 550 EXPECT_EQ(1u, RightRefCount(send_once_right, MACH_PORT_RIGHT_SEND_ONCE)); |
| 540 EXPECT_EQ(0u, DeadNameRightRefCount(send_once_right)); | 551 EXPECT_EQ(0u, DeadNameRightRefCount(send_once_right)); |
| 541 } | 552 } |
| 542 | 553 |
| 543 } // namespace | 554 } // namespace |
| 544 } // namespace test | 555 } // namespace test |
| 545 } // namespace crashpad | 556 } // namespace crashpad |
| OLD | NEW |