Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: base/process_util_unittest.cc

Issue 8674003: Move the ProcessWatcher methods out of content/common/process_watcher into base/process_util, alo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/eintr_wrapper.h" 10 #include "base/eintr_wrapper.h"
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 const char kSelfStat[] = "5364 (cat) R 5354 5364 5354 34819 5364 " 826 const char kSelfStat[] = "5364 (cat) R 5354 5364 5354 34819 5364 "
827 "0 142 0 0 0 " 827 "0 142 0 0 0 "
828 "0 0 0 0 " // <- No CPU, apparently. 828 "0 0 0 0 " // <- No CPU, apparently.
829 "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 " 829 "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 "
830 "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0"; 830 "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0";
831 831
832 EXPECT_EQ(0, base::ParseProcStatCPU(kSelfStat)); 832 EXPECT_EQ(0, base::ParseProcStatCPU(kSelfStat));
833 } 833 }
834 #endif // defined(OS_LINUX) || defined(OS_ANDROID) 834 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
835 835
836 // TODO(port): port those unit tests.
837 bool IsProcessDead(base::ProcessHandle child) {
838 // waitpid() will actually reap the process which is exactly NOT what we
839 // want to test for. The good thing is that if it can't find the process
840 // we'll get a nice value for errno which we can test for.
841 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG));
842 return result == -1 && errno == ECHILD;
843 }
844
845 TEST_F(ProcessUtilTest, DelayedTermination) {
846 base::ProcessHandle child_process =
847 SpawnChild("process_util_test_never_die", false);
848 ASSERT_TRUE(child_process);
849 base::EnsureProcessTerminated(child_process);
850 base::WaitForSingleProcess(child_process, 5000);
cpu_(ooo_6.6-7.5) 2011/11/24 00:22:07 the problem here is that EnsureProcessTerminated c
851
852 // Check that process was really killed.
853 EXPECT_TRUE(IsProcessDead(child_process));
854 base::CloseProcessHandle(child_process);
855 }
856
857 MULTIPROCESS_TEST_MAIN(process_util_test_never_die) {
858 while (1) {
859 sleep(500);
860 }
861 return 0;
862 }
863
864 TEST_F(ProcessUtilTest, ImmediateTermination) {
865 base::ProcessHandle child_process =
866 SpawnChild("process_util_test_die_immediately", false);
867 ASSERT_TRUE(child_process);
868 // Give it time to die.
869 sleep(2);
870 base::EnsureProcessTerminated(child_process);
871
872 // Check that process was really killed.
873 EXPECT_TRUE(IsProcessDead(child_process));
874 base::CloseProcessHandle(child_process);
875 }
876
877 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) {
878 return 0;
879 }
880
836 #endif // defined(OS_POSIX) 881 #endif // defined(OS_POSIX)
837 882
838 // TODO(vandebo) make this work on Windows too. 883 // TODO(vandebo) make this work on Windows too.
839 #if !defined(OS_WIN) 884 #if !defined(OS_WIN)
840 885
841 #if defined(USE_TCMALLOC) 886 #if defined(USE_TCMALLOC)
842 extern "C" { 887 extern "C" {
843 int tc_set_new_mode(int mode); 888 int tc_set_new_mode(int mode);
844 } 889 }
845 #endif // defined(USE_TCMALLOC) 890 #endif // defined(USE_TCMALLOC)
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} 1121 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {}
1077 }, ""); 1122 }, "");
1078 } 1123 }
1079 1124
1080 #endif // !ARCH_CPU_64_BITS 1125 #endif // !ARCH_CPU_64_BITS
1081 #endif // OS_MACOSX 1126 #endif // OS_MACOSX
1082 1127
1083 #endif // !defined(OS_ANDROID) 1128 #endif // !defined(OS_ANDROID)
1084 1129
1085 #endif // !defined(OS_WIN) 1130 #endif // !defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698