| 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 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 // TODO(port): port those unit tests. | 869 // TODO(port): port those unit tests. |
| 870 bool IsProcessDead(base::ProcessHandle child) { | 870 bool IsProcessDead(base::ProcessHandle child) { |
| 871 // waitpid() will actually reap the process which is exactly NOT what we | 871 // waitpid() will actually reap the process which is exactly NOT what we |
| 872 // want to test for. The good thing is that if it can't find the process | 872 // want to test for. The good thing is that if it can't find the process |
| 873 // we'll get a nice value for errno which we can test for. | 873 // we'll get a nice value for errno which we can test for. |
| 874 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); | 874 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); |
| 875 return result == -1 && errno == ECHILD; | 875 return result == -1 && errno == ECHILD; |
| 876 } | 876 } |
| 877 | 877 |
| 878 TEST_F(ProcessUtilTest, DelayedTermination) { | 878 TEST_F(ProcessUtilTest, DelayedTermination) { |
| 879 base::ProcessHandle child_process = SpawnChild("process_util_test_never_die"); | 879 base::Process child_process(SpawnChild("process_util_test_never_die")); |
| 880 ASSERT_TRUE(child_process); | 880 ASSERT_TRUE(child_process.IsValid()); |
| 881 base::EnsureProcessTerminated(child_process); | 881 base::EnsureProcessTerminated(child_process.Duplicate()); |
| 882 base::WaitForSingleProcess(child_process, base::TimeDelta::FromSeconds(5)); | 882 base::WaitForSingleProcess(child_process.Handle(), |
| 883 base::TimeDelta::FromSeconds(5)); |
| 883 | 884 |
| 884 // Check that process was really killed. | 885 // Check that process was really killed. |
| 885 EXPECT_TRUE(IsProcessDead(child_process)); | 886 EXPECT_TRUE(IsProcessDead(child_process.Handle())); |
| 886 base::CloseProcessHandle(child_process); | |
| 887 } | 887 } |
| 888 | 888 |
| 889 MULTIPROCESS_TEST_MAIN(process_util_test_never_die) { | 889 MULTIPROCESS_TEST_MAIN(process_util_test_never_die) { |
| 890 while (1) { | 890 while (1) { |
| 891 sleep(500); | 891 sleep(500); |
| 892 } | 892 } |
| 893 return 0; | 893 return 0; |
| 894 } | 894 } |
| 895 | 895 |
| 896 TEST_F(ProcessUtilTest, ImmediateTermination) { | 896 TEST_F(ProcessUtilTest, ImmediateTermination) { |
| 897 base::ProcessHandle child_process = | 897 base::Process child_process(SpawnChild("process_util_test_die_immediately")); |
| 898 SpawnChild("process_util_test_die_immediately"); | 898 ASSERT_TRUE(child_process.IsValid()); |
| 899 ASSERT_TRUE(child_process); | |
| 900 // Give it time to die. | 899 // Give it time to die. |
| 901 sleep(2); | 900 sleep(2); |
| 902 base::EnsureProcessTerminated(child_process); | 901 base::EnsureProcessTerminated(child_process.Duplicate()); |
| 903 | 902 |
| 904 // Check that process was really killed. | 903 // Check that process was really killed. |
| 905 EXPECT_TRUE(IsProcessDead(child_process)); | 904 EXPECT_TRUE(IsProcessDead(child_process.Handle())); |
| 906 base::CloseProcessHandle(child_process); | |
| 907 } | 905 } |
| 908 | 906 |
| 909 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { | 907 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { |
| 910 return 0; | 908 return 0; |
| 911 } | 909 } |
| 912 | 910 |
| 913 #endif // defined(OS_POSIX) | 911 #endif // defined(OS_POSIX) |
| OLD | NEW |