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::Process child_process(SpawnChild("process_util_test_never_die")); | 891 base::ProcessHandle child_process = SpawnChild("process_util_test_never_die"); |
892 ASSERT_TRUE(child_process.IsValid()); | 892 ASSERT_TRUE(child_process); |
893 base::EnsureProcessTerminated(child_process.Duplicate()); | 893 base::EnsureProcessTerminated(child_process); |
894 base::WaitForSingleProcess(child_process.Handle(), | 894 base::WaitForSingleProcess(child_process, base::TimeDelta::FromSeconds(5)); |
895 base::TimeDelta::FromSeconds(5)); | |
896 | 895 |
897 // Check that process was really killed. | 896 // Check that process was really killed. |
898 EXPECT_TRUE(IsProcessDead(child_process.Handle())); | 897 EXPECT_TRUE(IsProcessDead(child_process)); |
| 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::Process child_process(SpawnChild("process_util_test_die_immediately")); | 909 base::ProcessHandle child_process = |
910 ASSERT_TRUE(child_process.IsValid()); | 910 SpawnChild("process_util_test_die_immediately"); |
| 911 ASSERT_TRUE(child_process); |
911 // Give it time to die. | 912 // Give it time to die. |
912 sleep(2); | 913 sleep(2); |
913 base::EnsureProcessTerminated(child_process.Duplicate()); | 914 base::EnsureProcessTerminated(child_process); |
914 | 915 |
915 // Check that process was really killed. | 916 // Check that process was really killed. |
916 EXPECT_TRUE(IsProcessDead(child_process.Handle())); | 917 EXPECT_TRUE(IsProcessDead(child_process)); |
| 918 base::CloseProcessHandle(child_process); |
917 } | 919 } |
918 | 920 |
919 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { | 921 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { |
920 return 0; | 922 return 0; |
921 } | 923 } |
922 | 924 |
923 #endif // defined(OS_POSIX) | 925 #endif // defined(OS_POSIX) |
OLD | NEW |