Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 DPCHECK(ret == 0); | 556 DPCHECK(ret == 0); |
| 557 ret = IGNORE_EINTR(close(sockets[1])); | 557 ret = IGNORE_EINTR(close(sockets[1])); |
| 558 DPCHECK(ret == 0); | 558 DPCHECK(ret == 0); |
| 559 ret = IGNORE_EINTR(close(dev_null)); | 559 ret = IGNORE_EINTR(close(dev_null)); |
| 560 DPCHECK(ret == 0); | 560 DPCHECK(ret == 0); |
| 561 } | 561 } |
| 562 | 562 |
| 563 namespace { | 563 namespace { |
| 564 | 564 |
| 565 std::string TestLaunchProcess(const base::EnvironmentMap& env_changes, | 565 std::string TestLaunchProcess(const base::EnvironmentMap& env_changes, |
| 566 const bool clear_environ, | |
| 566 const int clone_flags) { | 567 const int clone_flags) { |
| 567 std::vector<std::string> args; | 568 std::vector<std::string> args; |
| 568 base::FileHandleMappingVector fds_to_remap; | 569 base::FileHandleMappingVector fds_to_remap; |
| 569 | 570 |
| 570 args.push_back(kPosixShell); | 571 args.push_back(kPosixShell); |
| 571 args.push_back("-c"); | 572 args.push_back("-c"); |
| 572 args.push_back("echo $BASE_TEST"); | 573 args.push_back("echo $BASE_TEST"); |
|
Mark Seaborn
2014/06/02 23:10:29
Could you add a separate test that runs /usr/bin/e
elijahtaylor1
2014/06/03 20:47:54
Done.
| |
| 573 | 574 |
| 574 int fds[2]; | 575 int fds[2]; |
| 575 PCHECK(pipe(fds) == 0); | 576 PCHECK(pipe(fds) == 0); |
| 576 | 577 |
| 577 fds_to_remap.push_back(std::make_pair(fds[1], 1)); | 578 fds_to_remap.push_back(std::make_pair(fds[1], 1)); |
| 578 base::LaunchOptions options; | 579 base::LaunchOptions options; |
| 579 options.wait = true; | 580 options.wait = true; |
| 580 options.environ = env_changes; | 581 options.environ = env_changes; |
| 582 options.clear_environ = clear_environ; | |
| 581 options.fds_to_remap = &fds_to_remap; | 583 options.fds_to_remap = &fds_to_remap; |
| 582 #if defined(OS_LINUX) | 584 #if defined(OS_LINUX) |
| 583 options.clone_flags = clone_flags; | 585 options.clone_flags = clone_flags; |
| 584 #else | 586 #else |
| 585 CHECK_EQ(0, clone_flags); | 587 CHECK_EQ(0, clone_flags); |
| 586 #endif // OS_LINUX | 588 #endif // OS_LINUX |
| 587 EXPECT_TRUE(base::LaunchProcess(args, options, NULL)); | 589 EXPECT_TRUE(base::LaunchProcess(args, options, NULL)); |
| 588 PCHECK(IGNORE_EINTR(close(fds[1])) == 0); | 590 PCHECK(IGNORE_EINTR(close(fds[1])) == 0); |
| 589 | 591 |
| 590 char buf[512]; | 592 char buf[512]; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 603 "0123456789012345678901234567890123456789012345678901234567890123456789" | 605 "0123456789012345678901234567890123456789012345678901234567890123456789" |
| 604 "0123456789012345678901234567890123456789012345678901234567890123456789" | 606 "0123456789012345678901234567890123456789012345678901234567890123456789" |
| 605 "0123456789012345678901234567890123456789012345678901234567890123456789" | 607 "0123456789012345678901234567890123456789012345678901234567890123456789" |
| 606 "0123456789012345678901234567890123456789012345678901234567890123456789"; | 608 "0123456789012345678901234567890123456789012345678901234567890123456789"; |
| 607 | 609 |
| 608 } // namespace | 610 } // namespace |
| 609 | 611 |
| 610 TEST_F(ProcessUtilTest, LaunchProcess) { | 612 TEST_F(ProcessUtilTest, LaunchProcess) { |
| 611 base::EnvironmentMap env_changes; | 613 base::EnvironmentMap env_changes; |
| 612 const int no_clone_flags = 0; | 614 const int no_clone_flags = 0; |
| 615 const bool no_clear_environ = false; | |
| 613 | 616 |
| 614 const char kBaseTest[] = "BASE_TEST"; | 617 const char kBaseTest[] = "BASE_TEST"; |
| 615 | 618 |
| 616 env_changes[kBaseTest] = "bar"; | 619 env_changes[kBaseTest] = "bar"; |
| 617 EXPECT_EQ("bar\n", TestLaunchProcess(env_changes, no_clone_flags)); | 620 EXPECT_EQ("bar\n", |
| 621 TestLaunchProcess(env_changes, no_clear_environ, no_clone_flags)); | |
| 622 EXPECT_EQ("bar\n", TestLaunchProcess(env_changes, true, no_clone_flags)); | |
| 618 env_changes.clear(); | 623 env_changes.clear(); |
| 619 | 624 |
| 620 EXPECT_EQ(0, setenv(kBaseTest, "testing", 1 /* override */)); | 625 EXPECT_EQ(0, setenv(kBaseTest, "testing", 1 /* override */)); |
| 621 EXPECT_EQ("testing\n", TestLaunchProcess(env_changes, no_clone_flags)); | 626 EXPECT_EQ("testing\n", |
| 627 TestLaunchProcess(env_changes, no_clear_environ, no_clone_flags)); | |
| 628 EXPECT_EQ("\n", TestLaunchProcess(env_changes, true, no_clone_flags)); | |
| 622 | 629 |
| 623 env_changes[kBaseTest] = std::string(); | 630 env_changes[kBaseTest] = std::string(); |
| 624 EXPECT_EQ("\n", TestLaunchProcess(env_changes, no_clone_flags)); | 631 EXPECT_EQ("\n", |
| 632 TestLaunchProcess(env_changes, no_clear_environ, no_clone_flags)); | |
| 625 | 633 |
| 626 env_changes[kBaseTest] = "foo"; | 634 env_changes[kBaseTest] = "foo"; |
| 627 EXPECT_EQ("foo\n", TestLaunchProcess(env_changes, no_clone_flags)); | 635 EXPECT_EQ("foo\n", |
| 636 TestLaunchProcess(env_changes, no_clear_environ, no_clone_flags)); | |
| 628 | 637 |
| 629 env_changes.clear(); | 638 env_changes.clear(); |
| 630 EXPECT_EQ(0, setenv(kBaseTest, kLargeString, 1 /* override */)); | 639 EXPECT_EQ(0, setenv(kBaseTest, kLargeString, 1 /* override */)); |
| 631 EXPECT_EQ(std::string(kLargeString) + "\n", | 640 EXPECT_EQ(std::string(kLargeString) + "\n", |
| 632 TestLaunchProcess(env_changes, no_clone_flags)); | 641 TestLaunchProcess(env_changes, no_clear_environ, no_clone_flags)); |
| 633 | 642 |
| 634 env_changes[kBaseTest] = "wibble"; | 643 env_changes[kBaseTest] = "wibble"; |
| 635 EXPECT_EQ("wibble\n", TestLaunchProcess(env_changes, no_clone_flags)); | 644 EXPECT_EQ("wibble\n", |
| 645 TestLaunchProcess(env_changes, no_clear_environ, no_clone_flags)); | |
| 636 | 646 |
| 637 #if defined(OS_LINUX) | 647 #if defined(OS_LINUX) |
| 638 // Test a non-trival value for clone_flags. | 648 // Test a non-trival value for clone_flags. |
| 639 // Don't test on Valgrind as it has limited support for clone(). | 649 // Don't test on Valgrind as it has limited support for clone(). |
| 640 if (!RunningOnValgrind()) { | 650 if (!RunningOnValgrind()) { |
| 641 EXPECT_EQ("wibble\n", TestLaunchProcess(env_changes, CLONE_FS | SIGCHLD)); | 651 EXPECT_EQ( |
| 652 "wibble\n", | |
| 653 TestLaunchProcess(env_changes, no_clear_environ, CLONE_FS | SIGCHLD)); | |
| 642 } | 654 } |
|
jln (very slow on Chromium)
2014/06/02 21:31:47
Could you add a test with clear_environ set to tru
elijahtaylor1
2014/06/03 20:47:54
Done.
| |
| 643 #endif | 655 #endif |
| 644 } | 656 } |
| 645 | 657 |
| 646 TEST_F(ProcessUtilTest, GetAppOutput) { | 658 TEST_F(ProcessUtilTest, GetAppOutput) { |
| 647 std::string output; | 659 std::string output; |
| 648 | 660 |
| 649 #if defined(OS_ANDROID) | 661 #if defined(OS_ANDROID) |
| 650 std::vector<std::string> argv; | 662 std::vector<std::string> argv; |
| 651 argv.push_back("sh"); // Instead of /bin/sh, force path search to find it. | 663 argv.push_back("sh"); // Instead of /bin/sh, force path search to find it. |
| 652 argv.push_back("-c"); | 664 argv.push_back("-c"); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 846 // Check that process was really killed. | 858 // Check that process was really killed. |
| 847 EXPECT_TRUE(IsProcessDead(child_process)); | 859 EXPECT_TRUE(IsProcessDead(child_process)); |
| 848 base::CloseProcessHandle(child_process); | 860 base::CloseProcessHandle(child_process); |
| 849 } | 861 } |
| 850 | 862 |
| 851 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { | 863 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { |
| 852 return 0; | 864 return 0; |
| 853 } | 865 } |
| 854 | 866 |
| 855 #endif // defined(OS_POSIX) | 867 #endif // defined(OS_POSIX) |
| OLD | NEW |