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