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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 std::string message; | 318 std::string message; |
319 for (int i = 0; i < 1025; i++) { // 1025 so it does not end on a kilo-byte | 319 for (int i = 0; i < 1025; i++) { // 1025 so it does not end on a kilo-byte |
320 // boundary. | 320 // boundary. |
321 message += "Hello!"; | 321 message += "Hello!"; |
322 } | 322 } |
323 // cmd.exe's echo always adds a \r\n to its output. | 323 // cmd.exe's echo always adds a \r\n to its output. |
324 std::string expected(message); | 324 std::string expected(message); |
325 expected += "\r\n"; | 325 expected += "\r\n"; |
326 | 326 |
327 FilePath cmd(L"cmd.exe"); | 327 FilePath cmd(L"cmd.exe"); |
328 CommandLine cmd_line(cmd); | 328 base::CommandLine cmd_line(cmd); |
329 cmd_line.AppendArg("/c"); | 329 cmd_line.AppendArg("/c"); |
330 cmd_line.AppendArg("echo " + message + ""); | 330 cmd_line.AppendArg("echo " + message + ""); |
331 std::string output; | 331 std::string output; |
332 ASSERT_TRUE(base::GetAppOutput(cmd_line, &output)); | 332 ASSERT_TRUE(base::GetAppOutput(cmd_line, &output)); |
333 EXPECT_EQ(expected, output); | 333 EXPECT_EQ(expected, output); |
334 | 334 |
335 // Let's make sure stderr is ignored. | 335 // Let's make sure stderr is ignored. |
336 CommandLine other_cmd_line(cmd); | 336 base::CommandLine other_cmd_line(cmd); |
337 other_cmd_line.AppendArg("/c"); | 337 other_cmd_line.AppendArg("/c"); |
338 // http://msdn.microsoft.com/library/cc772622.aspx | 338 // http://msdn.microsoft.com/library/cc772622.aspx |
339 cmd_line.AppendArg("echo " + message + " >&2"); | 339 cmd_line.AppendArg("echo " + message + " >&2"); |
340 output.clear(); | 340 output.clear(); |
341 ASSERT_TRUE(base::GetAppOutput(other_cmd_line, &output)); | 341 ASSERT_TRUE(base::GetAppOutput(other_cmd_line, &output)); |
342 EXPECT_EQ("", output); | 342 EXPECT_EQ("", output); |
343 } | 343 } |
344 | 344 |
345 // TODO(estade): if possible, port this test. | 345 // TODO(estade): if possible, port this test. |
346 TEST_F(ProcessUtilTest, LaunchAsUser) { | 346 TEST_F(ProcessUtilTest, LaunchAsUser) { |
347 base::UserTokenHandle token; | 347 base::UserTokenHandle token; |
348 ASSERT_TRUE(OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &token)); | 348 ASSERT_TRUE(OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &token)); |
349 base::LaunchOptions options; | 349 base::LaunchOptions options; |
350 options.as_user = token; | 350 options.as_user = token; |
351 EXPECT_TRUE(base::LaunchProcess(MakeCmdLine("SimpleChildProcess"), options, | 351 EXPECT_TRUE(base::LaunchProcess(MakeCmdLine("SimpleChildProcess"), |
352 NULL)); | 352 options).IsValid()); |
353 } | 353 } |
354 | 354 |
355 static const char kEventToTriggerHandleSwitch[] = "event-to-trigger-handle"; | 355 static const char kEventToTriggerHandleSwitch[] = "event-to-trigger-handle"; |
356 | 356 |
357 MULTIPROCESS_TEST_MAIN(TriggerEventChildProcess) { | 357 MULTIPROCESS_TEST_MAIN(TriggerEventChildProcess) { |
358 std::string handle_value_string = | 358 std::string handle_value_string = |
359 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 359 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
360 kEventToTriggerHandleSwitch); | 360 kEventToTriggerHandleSwitch); |
361 CHECK(!handle_value_string.empty()); | 361 CHECK(!handle_value_string.empty()); |
362 | 362 |
363 uint64 handle_value_uint64; | 363 uint64 handle_value_uint64; |
364 CHECK(base::StringToUint64(handle_value_string, &handle_value_uint64)); | 364 CHECK(base::StringToUint64(handle_value_string, &handle_value_uint64)); |
365 // Give ownership of the handle to |event|. | 365 // Give ownership of the handle to |event|. |
366 base::WaitableEvent event(reinterpret_cast<HANDLE>(handle_value_uint64)); | 366 base::WaitableEvent event(base::win::ScopedHandle( |
| 367 reinterpret_cast<HANDLE>(handle_value_uint64))); |
367 | 368 |
368 event.Signal(); | 369 event.Signal(); |
369 | 370 |
370 return 0; | 371 return 0; |
371 } | 372 } |
372 | 373 |
373 TEST_F(ProcessUtilTest, InheritSpecifiedHandles) { | 374 TEST_F(ProcessUtilTest, InheritSpecifiedHandles) { |
374 // Manually create the event, so that it can be inheritable. | 375 // Manually create the event, so that it can be inheritable. |
375 SECURITY_ATTRIBUTES security_attributes = {}; | 376 SECURITY_ATTRIBUTES security_attributes = {}; |
376 security_attributes.nLength = static_cast<DWORD>(sizeof(security_attributes)); | 377 security_attributes.nLength = static_cast<DWORD>(sizeof(security_attributes)); |
377 security_attributes.lpSecurityDescriptor = NULL; | 378 security_attributes.lpSecurityDescriptor = NULL; |
378 security_attributes.bInheritHandle = true; | 379 security_attributes.bInheritHandle = true; |
379 | 380 |
380 // Takes ownership of the event handle. | 381 // Takes ownership of the event handle. |
381 base::WaitableEvent event( | 382 base::WaitableEvent event(base::win::ScopedHandle( |
382 CreateEvent(&security_attributes, true, false, NULL)); | 383 CreateEvent(&security_attributes, true, false, NULL))); |
383 base::HandlesToInheritVector handles_to_inherit; | 384 base::HandlesToInheritVector handles_to_inherit; |
384 handles_to_inherit.push_back(event.handle()); | 385 handles_to_inherit.push_back(event.handle()); |
385 base::LaunchOptions options; | 386 base::LaunchOptions options; |
386 options.handles_to_inherit = &handles_to_inherit; | 387 options.handles_to_inherit = &handles_to_inherit; |
387 | 388 |
388 CommandLine cmd_line = MakeCmdLine("TriggerEventChildProcess"); | 389 base::CommandLine cmd_line = MakeCmdLine("TriggerEventChildProcess"); |
389 cmd_line.AppendSwitchASCII(kEventToTriggerHandleSwitch, | 390 cmd_line.AppendSwitchASCII(kEventToTriggerHandleSwitch, |
390 base::Uint64ToString(reinterpret_cast<uint64>(event.handle()))); | 391 base::Uint64ToString(reinterpret_cast<uint64>(event.handle()))); |
391 | 392 |
392 // This functionality actually requires Vista or later. Make sure that it | 393 // This functionality actually requires Vista or later. Make sure that it |
393 // fails properly on XP. | 394 // fails properly on XP. |
394 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 395 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
395 EXPECT_FALSE(base::LaunchProcess(cmd_line, options, NULL)); | 396 EXPECT_FALSE(base::LaunchProcess(cmd_line, options).IsValid()); |
396 return; | 397 return; |
397 } | 398 } |
398 | 399 |
399 // Launch the process and wait for it to trigger the event. | 400 // Launch the process and wait for it to trigger the event. |
400 ASSERT_TRUE(base::LaunchProcess(cmd_line, options, NULL)); | 401 ASSERT_TRUE(base::LaunchProcess(cmd_line, options).IsValid()); |
401 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 402 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
402 } | 403 } |
403 #endif // defined(OS_WIN) | 404 #endif // defined(OS_WIN) |
404 | 405 |
405 #if defined(OS_POSIX) | 406 #if defined(OS_POSIX) |
406 | 407 |
407 namespace { | 408 namespace { |
408 | 409 |
409 // Returns the maximum number of files that a process can have open. | 410 // Returns the maximum number of files that a process can have open. |
410 // Returns 0 on error. | 411 // Returns 0 on error. |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 | 704 |
704 TEST_F(ProcessUtilTest, GetAppOutput) { | 705 TEST_F(ProcessUtilTest, GetAppOutput) { |
705 std::string output; | 706 std::string output; |
706 | 707 |
707 #if defined(OS_ANDROID) | 708 #if defined(OS_ANDROID) |
708 std::vector<std::string> argv; | 709 std::vector<std::string> argv; |
709 argv.push_back("sh"); // Instead of /bin/sh, force path search to find it. | 710 argv.push_back("sh"); // Instead of /bin/sh, force path search to find it. |
710 argv.push_back("-c"); | 711 argv.push_back("-c"); |
711 | 712 |
712 argv.push_back("exit 0"); | 713 argv.push_back("exit 0"); |
713 EXPECT_TRUE(base::GetAppOutput(CommandLine(argv), &output)); | 714 EXPECT_TRUE(base::GetAppOutput(base::CommandLine(argv), &output)); |
714 EXPECT_STREQ("", output.c_str()); | 715 EXPECT_STREQ("", output.c_str()); |
715 | 716 |
716 argv[2] = "exit 1"; | 717 argv[2] = "exit 1"; |
717 EXPECT_FALSE(base::GetAppOutput(CommandLine(argv), &output)); | 718 EXPECT_FALSE(base::GetAppOutput(base::CommandLine(argv), &output)); |
718 EXPECT_STREQ("", output.c_str()); | 719 EXPECT_STREQ("", output.c_str()); |
719 | 720 |
720 argv[2] = "echo foobar42"; | 721 argv[2] = "echo foobar42"; |
721 EXPECT_TRUE(base::GetAppOutput(CommandLine(argv), &output)); | 722 EXPECT_TRUE(base::GetAppOutput(base::CommandLine(argv), &output)); |
722 EXPECT_STREQ("foobar42\n", output.c_str()); | 723 EXPECT_STREQ("foobar42\n", output.c_str()); |
723 #else | 724 #else |
724 EXPECT_TRUE(base::GetAppOutput(CommandLine(FilePath("true")), &output)); | 725 EXPECT_TRUE(base::GetAppOutput(base::CommandLine(FilePath("true")), |
| 726 &output)); |
725 EXPECT_STREQ("", output.c_str()); | 727 EXPECT_STREQ("", output.c_str()); |
726 | 728 |
727 EXPECT_FALSE(base::GetAppOutput(CommandLine(FilePath("false")), &output)); | 729 EXPECT_FALSE(base::GetAppOutput(base::CommandLine(FilePath("false")), |
| 730 &output)); |
728 | 731 |
729 std::vector<std::string> argv; | 732 std::vector<std::string> argv; |
730 argv.push_back("/bin/echo"); | 733 argv.push_back("/bin/echo"); |
731 argv.push_back("-n"); | 734 argv.push_back("-n"); |
732 argv.push_back("foobar42"); | 735 argv.push_back("foobar42"); |
733 EXPECT_TRUE(base::GetAppOutput(CommandLine(argv), &output)); | 736 EXPECT_TRUE(base::GetAppOutput(base::CommandLine(argv), &output)); |
734 EXPECT_STREQ("foobar42", output.c_str()); | 737 EXPECT_STREQ("foobar42", output.c_str()); |
735 #endif // defined(OS_ANDROID) | 738 #endif // defined(OS_ANDROID) |
736 } | 739 } |
737 | 740 |
738 // Flakes on Android, crbug.com/375840 | 741 // Flakes on Android, crbug.com/375840 |
739 #if defined(OS_ANDROID) | 742 #if defined(OS_ANDROID) |
740 #define MAYBE_GetAppOutputRestricted DISABLED_GetAppOutputRestricted | 743 #define MAYBE_GetAppOutputRestricted DISABLED_GetAppOutputRestricted |
741 #else | 744 #else |
742 #define MAYBE_GetAppOutputRestricted GetAppOutputRestricted | 745 #define MAYBE_GetAppOutputRestricted GetAppOutputRestricted |
743 #endif | 746 #endif |
744 TEST_F(ProcessUtilTest, MAYBE_GetAppOutputRestricted) { | 747 TEST_F(ProcessUtilTest, MAYBE_GetAppOutputRestricted) { |
745 // Unfortunately, since we can't rely on the path, we need to know where | 748 // Unfortunately, since we can't rely on the path, we need to know where |
746 // everything is. So let's use /bin/sh, which is on every POSIX system, and | 749 // everything is. So let's use /bin/sh, which is on every POSIX system, and |
747 // its built-ins. | 750 // its built-ins. |
748 std::vector<std::string> argv; | 751 std::vector<std::string> argv; |
749 argv.push_back(std::string(kShellPath)); // argv[0] | 752 argv.push_back(std::string(kShellPath)); // argv[0] |
750 argv.push_back("-c"); // argv[1] | 753 argv.push_back("-c"); // argv[1] |
751 | 754 |
752 // On success, should set |output|. We use |/bin/sh -c 'exit 0'| instead of | 755 // On success, should set |output|. We use |/bin/sh -c 'exit 0'| instead of |
753 // |true| since the location of the latter may be |/bin| or |/usr/bin| (and we | 756 // |true| since the location of the latter may be |/bin| or |/usr/bin| (and we |
754 // need absolute paths). | 757 // need absolute paths). |
755 argv.push_back("exit 0"); // argv[2]; equivalent to "true" | 758 argv.push_back("exit 0"); // argv[2]; equivalent to "true" |
756 std::string output = "abc"; | 759 std::string output = "abc"; |
757 EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 100)); | 760 EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, |
| 761 100)); |
758 EXPECT_STREQ("", output.c_str()); | 762 EXPECT_STREQ("", output.c_str()); |
759 | 763 |
760 argv[2] = "exit 1"; // equivalent to "false" | 764 argv[2] = "exit 1"; // equivalent to "false" |
761 output = "before"; | 765 output = "before"; |
762 EXPECT_FALSE(base::GetAppOutputRestricted(CommandLine(argv), | 766 EXPECT_FALSE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, |
763 &output, 100)); | 767 100)); |
764 EXPECT_STREQ("", output.c_str()); | 768 EXPECT_STREQ("", output.c_str()); |
765 | 769 |
766 // Amount of output exactly equal to space allowed. | 770 // Amount of output exactly equal to space allowed. |
767 argv[2] = "echo 123456789"; // (the sh built-in doesn't take "-n") | 771 argv[2] = "echo 123456789"; // (the sh built-in doesn't take "-n") |
768 output.clear(); | 772 output.clear(); |
769 EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 10)); | 773 EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, |
| 774 10)); |
770 EXPECT_STREQ("123456789\n", output.c_str()); | 775 EXPECT_STREQ("123456789\n", output.c_str()); |
771 | 776 |
772 // Amount of output greater than space allowed. | 777 // Amount of output greater than space allowed. |
773 output.clear(); | 778 output.clear(); |
774 EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 5)); | 779 EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, |
| 780 5)); |
775 EXPECT_STREQ("12345", output.c_str()); | 781 EXPECT_STREQ("12345", output.c_str()); |
776 | 782 |
777 // Amount of output less than space allowed. | 783 // Amount of output less than space allowed. |
778 output.clear(); | 784 output.clear(); |
779 EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 15)); | 785 EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, |
| 786 15)); |
780 EXPECT_STREQ("123456789\n", output.c_str()); | 787 EXPECT_STREQ("123456789\n", output.c_str()); |
781 | 788 |
782 // Zero space allowed. | 789 // Zero space allowed. |
783 output = "abc"; | 790 output = "abc"; |
784 EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 0)); | 791 EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, |
| 792 0)); |
785 EXPECT_STREQ("", output.c_str()); | 793 EXPECT_STREQ("", output.c_str()); |
786 } | 794 } |
787 | 795 |
788 #if !defined(OS_MACOSX) && !defined(OS_OPENBSD) | 796 #if !defined(OS_MACOSX) && !defined(OS_OPENBSD) |
789 // TODO(benwells): GetAppOutputRestricted should terminate applications | 797 // TODO(benwells): GetAppOutputRestricted should terminate applications |
790 // with SIGPIPE when we have enough output. http://crbug.com/88502 | 798 // with SIGPIPE when we have enough output. http://crbug.com/88502 |
791 TEST_F(ProcessUtilTest, GetAppOutputRestrictedSIGPIPE) { | 799 TEST_F(ProcessUtilTest, GetAppOutputRestrictedSIGPIPE) { |
792 std::vector<std::string> argv; | 800 std::vector<std::string> argv; |
793 std::string output; | 801 std::string output; |
794 | 802 |
795 argv.push_back(std::string(kShellPath)); // argv[0] | 803 argv.push_back(std::string(kShellPath)); // argv[0] |
796 argv.push_back("-c"); | 804 argv.push_back("-c"); |
797 #if defined(OS_ANDROID) | 805 #if defined(OS_ANDROID) |
798 argv.push_back("while echo 12345678901234567890; do :; done"); | 806 argv.push_back("while echo 12345678901234567890; do :; done"); |
799 EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 10)); | 807 EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, |
| 808 10)); |
800 EXPECT_STREQ("1234567890", output.c_str()); | 809 EXPECT_STREQ("1234567890", output.c_str()); |
801 #else | 810 #else |
802 argv.push_back("yes"); | 811 argv.push_back("yes"); |
803 EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 10)); | 812 EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, |
| 813 10)); |
804 EXPECT_STREQ("y\ny\ny\ny\ny\n", output.c_str()); | 814 EXPECT_STREQ("y\ny\ny\ny\ny\n", output.c_str()); |
805 #endif | 815 #endif |
806 } | 816 } |
807 #endif | 817 #endif |
808 | 818 |
809 #if defined(ADDRESS_SANITIZER) && defined(OS_MACOSX) && \ | 819 #if defined(ADDRESS_SANITIZER) && defined(OS_MACOSX) && \ |
810 defined(ARCH_CPU_64_BITS) | 820 defined(ARCH_CPU_64_BITS) |
811 // Times out under AddressSanitizer on 64-bit OS X, see | 821 // Times out under AddressSanitizer on 64-bit OS X, see |
812 // http://crbug.com/298197. | 822 // http://crbug.com/298197. |
813 #define MAYBE_GetAppOutputRestrictedNoZombies \ | 823 #define MAYBE_GetAppOutputRestrictedNoZombies \ |
814 DISABLED_GetAppOutputRestrictedNoZombies | 824 DISABLED_GetAppOutputRestrictedNoZombies |
815 #else | 825 #else |
816 #define MAYBE_GetAppOutputRestrictedNoZombies GetAppOutputRestrictedNoZombies | 826 #define MAYBE_GetAppOutputRestrictedNoZombies GetAppOutputRestrictedNoZombies |
817 #endif | 827 #endif |
818 TEST_F(ProcessUtilTest, MAYBE_GetAppOutputRestrictedNoZombies) { | 828 TEST_F(ProcessUtilTest, MAYBE_GetAppOutputRestrictedNoZombies) { |
819 std::vector<std::string> argv; | 829 std::vector<std::string> argv; |
820 | 830 |
821 argv.push_back(std::string(kShellPath)); // argv[0] | 831 argv.push_back(std::string(kShellPath)); // argv[0] |
822 argv.push_back("-c"); // argv[1] | 832 argv.push_back("-c"); // argv[1] |
823 argv.push_back("echo 123456789012345678901234567890"); // argv[2] | 833 argv.push_back("echo 123456789012345678901234567890"); // argv[2] |
824 | 834 |
825 // Run |GetAppOutputRestricted()| 300 (> default per-user processes on Mac OS | 835 // Run |GetAppOutputRestricted()| 300 (> default per-user processes on Mac OS |
826 // 10.5) times with an output buffer big enough to capture all output. | 836 // 10.5) times with an output buffer big enough to capture all output. |
827 for (int i = 0; i < 300; i++) { | 837 for (int i = 0; i < 300; i++) { |
828 std::string output; | 838 std::string output; |
829 EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 100)); | 839 EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, |
| 840 100)); |
830 EXPECT_STREQ("123456789012345678901234567890\n", output.c_str()); | 841 EXPECT_STREQ("123456789012345678901234567890\n", output.c_str()); |
831 } | 842 } |
832 | 843 |
833 // Ditto, but with an output buffer too small to capture all output. | 844 // Ditto, but with an output buffer too small to capture all output. |
834 for (int i = 0; i < 300; i++) { | 845 for (int i = 0; i < 300; i++) { |
835 std::string output; | 846 std::string output; |
836 EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 10)); | 847 EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, |
| 848 10)); |
837 EXPECT_STREQ("1234567890", output.c_str()); | 849 EXPECT_STREQ("1234567890", output.c_str()); |
838 } | 850 } |
839 } | 851 } |
840 | 852 |
841 TEST_F(ProcessUtilTest, GetAppOutputWithExitCode) { | 853 TEST_F(ProcessUtilTest, GetAppOutputWithExitCode) { |
842 // Test getting output from a successful application. | 854 // Test getting output from a successful application. |
843 std::vector<std::string> argv; | 855 std::vector<std::string> argv; |
844 std::string output; | 856 std::string output; |
845 int exit_code; | 857 int exit_code; |
846 argv.push_back(std::string(kShellPath)); // argv[0] | 858 argv.push_back(std::string(kShellPath)); // argv[0] |
847 argv.push_back("-c"); // argv[1] | 859 argv.push_back("-c"); // argv[1] |
848 argv.push_back("echo foo"); // argv[2]; | 860 argv.push_back("echo foo"); // argv[2]; |
849 EXPECT_TRUE(base::GetAppOutputWithExitCode(CommandLine(argv), &output, | 861 EXPECT_TRUE(base::GetAppOutputWithExitCode(base::CommandLine(argv), &output, |
850 &exit_code)); | 862 &exit_code)); |
851 EXPECT_STREQ("foo\n", output.c_str()); | 863 EXPECT_STREQ("foo\n", output.c_str()); |
852 EXPECT_EQ(exit_code, 0); | 864 EXPECT_EQ(exit_code, 0); |
853 | 865 |
854 // Test getting output from an application which fails with a specific exit | 866 // Test getting output from an application which fails with a specific exit |
855 // code. | 867 // code. |
856 output.clear(); | 868 output.clear(); |
857 argv[2] = "echo foo; exit 2"; | 869 argv[2] = "echo foo; exit 2"; |
858 EXPECT_TRUE(base::GetAppOutputWithExitCode(CommandLine(argv), &output, | 870 EXPECT_TRUE(base::GetAppOutputWithExitCode(base::CommandLine(argv), &output, |
859 &exit_code)); | 871 &exit_code)); |
860 EXPECT_STREQ("foo\n", output.c_str()); | 872 EXPECT_STREQ("foo\n", output.c_str()); |
861 EXPECT_EQ(exit_code, 2); | 873 EXPECT_EQ(exit_code, 2); |
862 } | 874 } |
863 | 875 |
864 TEST_F(ProcessUtilTest, GetParentProcessId) { | 876 TEST_F(ProcessUtilTest, GetParentProcessId) { |
865 base::ProcessId ppid = base::GetParentProcessId(base::GetCurrentProcId()); | 877 base::ProcessId ppid = base::GetParentProcessId(base::GetCurrentProcId()); |
866 EXPECT_EQ(ppid, getppid()); | 878 EXPECT_EQ(ppid, getppid()); |
867 } | 879 } |
868 | 880 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 // Check that process was really killed. | 916 // Check that process was really killed. |
905 EXPECT_TRUE(IsProcessDead(child_process)); | 917 EXPECT_TRUE(IsProcessDead(child_process)); |
906 base::CloseProcessHandle(child_process); | 918 base::CloseProcessHandle(child_process); |
907 } | 919 } |
908 | 920 |
909 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { | 921 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { |
910 return 0; | 922 return 0; |
911 } | 923 } |
912 | 924 |
913 #endif // defined(OS_POSIX) | 925 #endif // defined(OS_POSIX) |
OLD | NEW |