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

Side by Side Diff: base/process/process_util_unittest.cc

Issue 100253002: Don't HANDLE_EINTR(close). Either IGNORE_EINTR(close) or just close. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 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 | Annotate | Revision Log
« no previous file with comments | « base/process/launch_posix.cc ('k') | base/test/multiprocess_test_android.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #define _CRT_SECURE_NO_WARNINGS 5 #define _CRT_SECURE_NO_WARNINGS
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 if ((fd = HANDLE_EINTR(dup(i))) != -1) { 435 if ((fd = HANDLE_EINTR(dup(i))) != -1) {
436 close(fd); 436 close(fd);
437 num_open_files += 1; 437 num_open_files += 1;
438 } 438 }
439 } 439 }
440 } 440 }
441 441
442 int written = HANDLE_EINTR(write(write_pipe, &num_open_files, 442 int written = HANDLE_EINTR(write(write_pipe, &num_open_files,
443 sizeof(num_open_files))); 443 sizeof(num_open_files)));
444 DCHECK_EQ(static_cast<size_t>(written), sizeof(num_open_files)); 444 DCHECK_EQ(static_cast<size_t>(written), sizeof(num_open_files));
445 int ret = HANDLE_EINTR(close(write_pipe)); 445 int ret = IGNORE_EINTR(close(write_pipe));
446 DPCHECK(ret == 0); 446 DPCHECK(ret == 0);
447 447
448 return 0; 448 return 0;
449 } 449 }
450 450
451 int ProcessUtilTest::CountOpenFDsInChild() { 451 int ProcessUtilTest::CountOpenFDsInChild() {
452 int fds[2]; 452 int fds[2];
453 if (pipe(fds) < 0) 453 if (pipe(fds) < 0)
454 NOTREACHED(); 454 NOTREACHED();
455 455
456 base::FileHandleMappingVector fd_mapping_vec; 456 base::FileHandleMappingVector fd_mapping_vec;
457 fd_mapping_vec.push_back(std::pair<int, int>(fds[1], kChildPipe)); 457 fd_mapping_vec.push_back(std::pair<int, int>(fds[1], kChildPipe));
458 base::ProcessHandle handle = this->SpawnChild( 458 base::ProcessHandle handle = this->SpawnChild(
459 "ProcessUtilsLeakFDChildProcess", fd_mapping_vec, false); 459 "ProcessUtilsLeakFDChildProcess", fd_mapping_vec, false);
460 CHECK(handle); 460 CHECK(handle);
461 int ret = HANDLE_EINTR(close(fds[1])); 461 int ret = IGNORE_EINTR(close(fds[1]));
462 DPCHECK(ret == 0); 462 DPCHECK(ret == 0);
463 463
464 // Read number of open files in client process from pipe; 464 // Read number of open files in client process from pipe;
465 int num_open_files = -1; 465 int num_open_files = -1;
466 ssize_t bytes_read = 466 ssize_t bytes_read =
467 HANDLE_EINTR(read(fds[0], &num_open_files, sizeof(num_open_files))); 467 HANDLE_EINTR(read(fds[0], &num_open_files, sizeof(num_open_files)));
468 CHECK_EQ(bytes_read, static_cast<ssize_t>(sizeof(num_open_files))); 468 CHECK_EQ(bytes_read, static_cast<ssize_t>(sizeof(num_open_files)));
469 469
470 #if defined(THREAD_SANITIZER) || defined(USE_HEAPCHECKER) 470 #if defined(THREAD_SANITIZER) || defined(USE_HEAPCHECKER)
471 // Compiler-based ThreadSanitizer makes this test slow. 471 // Compiler-based ThreadSanitizer makes this test slow.
472 CHECK(base::WaitForSingleProcess(handle, base::TimeDelta::FromSeconds(3))); 472 CHECK(base::WaitForSingleProcess(handle, base::TimeDelta::FromSeconds(3)));
473 #else 473 #else
474 CHECK(base::WaitForSingleProcess(handle, base::TimeDelta::FromSeconds(1))); 474 CHECK(base::WaitForSingleProcess(handle, base::TimeDelta::FromSeconds(1)));
475 #endif 475 #endif
476 base::CloseProcessHandle(handle); 476 base::CloseProcessHandle(handle);
477 ret = HANDLE_EINTR(close(fds[0])); 477 ret = IGNORE_EINTR(close(fds[0]));
478 DPCHECK(ret == 0); 478 DPCHECK(ret == 0);
479 479
480 return num_open_files; 480 return num_open_files;
481 } 481 }
482 482
483 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) 483 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER)
484 // ProcessUtilTest.FDRemapping is flaky when ran under xvfb-run on Precise. 484 // ProcessUtilTest.FDRemapping is flaky when ran under xvfb-run on Precise.
485 // The problem is 100% reproducible with both ASan and TSan. 485 // The problem is 100% reproducible with both ASan and TSan.
486 // See http://crbug.com/136720. 486 // See http://crbug.com/136720.
487 #define MAYBE_FDRemapping DISABLED_FDRemapping 487 #define MAYBE_FDRemapping DISABLED_FDRemapping
488 #else 488 #else
489 #define MAYBE_FDRemapping FDRemapping 489 #define MAYBE_FDRemapping FDRemapping
490 #endif 490 #endif
491 TEST_F(ProcessUtilTest, MAYBE_FDRemapping) { 491 TEST_F(ProcessUtilTest, MAYBE_FDRemapping) {
492 int fds_before = CountOpenFDsInChild(); 492 int fds_before = CountOpenFDsInChild();
493 493
494 // open some dummy fds to make sure they don't propagate over to the 494 // open some dummy fds to make sure they don't propagate over to the
495 // child process. 495 // child process.
496 int dev_null = open("/dev/null", O_RDONLY); 496 int dev_null = open("/dev/null", O_RDONLY);
497 int sockets[2]; 497 int sockets[2];
498 socketpair(AF_UNIX, SOCK_STREAM, 0, sockets); 498 socketpair(AF_UNIX, SOCK_STREAM, 0, sockets);
499 499
500 int fds_after = CountOpenFDsInChild(); 500 int fds_after = CountOpenFDsInChild();
501 501
502 ASSERT_EQ(fds_after, fds_before); 502 ASSERT_EQ(fds_after, fds_before);
503 503
504 int ret; 504 int ret;
505 ret = HANDLE_EINTR(close(sockets[0])); 505 ret = IGNORE_EINTR(close(sockets[0]));
506 DPCHECK(ret == 0); 506 DPCHECK(ret == 0);
507 ret = HANDLE_EINTR(close(sockets[1])); 507 ret = IGNORE_EINTR(close(sockets[1]));
508 DPCHECK(ret == 0); 508 DPCHECK(ret == 0);
509 ret = HANDLE_EINTR(close(dev_null)); 509 ret = IGNORE_EINTR(close(dev_null));
510 DPCHECK(ret == 0); 510 DPCHECK(ret == 0);
511 } 511 }
512 512
513 namespace { 513 namespace {
514 514
515 std::string TestLaunchProcess(const base::EnvironmentMap& env_changes, 515 std::string TestLaunchProcess(const base::EnvironmentMap& env_changes,
516 const int clone_flags) { 516 const int clone_flags) {
517 std::vector<std::string> args; 517 std::vector<std::string> args;
518 base::FileHandleMappingVector fds_to_remap; 518 base::FileHandleMappingVector fds_to_remap;
519 519
520 args.push_back(kPosixShell); 520 args.push_back(kPosixShell);
521 args.push_back("-c"); 521 args.push_back("-c");
522 args.push_back("echo $BASE_TEST"); 522 args.push_back("echo $BASE_TEST");
523 523
524 int fds[2]; 524 int fds[2];
525 PCHECK(pipe(fds) == 0); 525 PCHECK(pipe(fds) == 0);
526 526
527 fds_to_remap.push_back(std::make_pair(fds[1], 1)); 527 fds_to_remap.push_back(std::make_pair(fds[1], 1));
528 base::LaunchOptions options; 528 base::LaunchOptions options;
529 options.wait = true; 529 options.wait = true;
530 options.environ = env_changes; 530 options.environ = env_changes;
531 options.fds_to_remap = &fds_to_remap; 531 options.fds_to_remap = &fds_to_remap;
532 #if defined(OS_LINUX) 532 #if defined(OS_LINUX)
533 options.clone_flags = clone_flags; 533 options.clone_flags = clone_flags;
534 #else 534 #else
535 CHECK_EQ(0, clone_flags); 535 CHECK_EQ(0, clone_flags);
536 #endif // OS_LINUX 536 #endif // OS_LINUX
537 EXPECT_TRUE(base::LaunchProcess(args, options, NULL)); 537 EXPECT_TRUE(base::LaunchProcess(args, options, NULL));
538 PCHECK(HANDLE_EINTR(close(fds[1])) == 0); 538 PCHECK(IGNORE_EINTR(close(fds[1])) == 0);
539 539
540 char buf[512]; 540 char buf[512];
541 const ssize_t n = HANDLE_EINTR(read(fds[0], buf, sizeof(buf))); 541 const ssize_t n = HANDLE_EINTR(read(fds[0], buf, sizeof(buf)));
542 PCHECK(n > 0); 542 PCHECK(n > 0);
543 543
544 PCHECK(HANDLE_EINTR(close(fds[0])) == 0); 544 PCHECK(IGNORE_EINTR(close(fds[0])) == 0);
545 545
546 return std::string(buf, n); 546 return std::string(buf, n);
547 } 547 }
548 548
549 const char kLargeString[] = 549 const char kLargeString[] =
550 "0123456789012345678901234567890123456789012345678901234567890123456789" 550 "0123456789012345678901234567890123456789012345678901234567890123456789"
551 "0123456789012345678901234567890123456789012345678901234567890123456789" 551 "0123456789012345678901234567890123456789012345678901234567890123456789"
552 "0123456789012345678901234567890123456789012345678901234567890123456789" 552 "0123456789012345678901234567890123456789012345678901234567890123456789"
553 "0123456789012345678901234567890123456789012345678901234567890123456789" 553 "0123456789012345678901234567890123456789012345678901234567890123456789"
554 "0123456789012345678901234567890123456789012345678901234567890123456789" 554 "0123456789012345678901234567890123456789012345678901234567890123456789"
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 // Check that process was really killed. 791 // Check that process was really killed.
792 EXPECT_TRUE(IsProcessDead(child_process)); 792 EXPECT_TRUE(IsProcessDead(child_process));
793 base::CloseProcessHandle(child_process); 793 base::CloseProcessHandle(child_process);
794 } 794 }
795 795
796 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { 796 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) {
797 return 0; 797 return 0;
798 } 798 }
799 799
800 #endif // defined(OS_POSIX) 800 #endif // defined(OS_POSIX)
OLDNEW
« no previous file with comments | « base/process/launch_posix.cc ('k') | base/test/multiprocess_test_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698