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

Side by Side Diff: base/process_util_unittest.cc

Issue 10387218: Make GlobalDescriptors::MaybeGet return -1 when the key is not found. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Modifying the MULTIPROCESS_TEST_MAIN macro so it can be passed a setup method. Created 8 years, 6 months 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) 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } // namespace 112 } // namespace
113 113
114 class ProcessUtilTest : public base::MultiProcessTest { 114 class ProcessUtilTest : public base::MultiProcessTest {
115 #if defined(OS_POSIX) 115 #if defined(OS_POSIX)
116 public: 116 public:
117 // Spawn a child process that counts how many file descriptors are open. 117 // Spawn a child process that counts how many file descriptors are open.
118 int CountOpenFDsInChild(); 118 int CountOpenFDsInChild();
119 #endif 119 #endif
120 }; 120 };
121 121
122 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { 122 MULTIPROCESS_TEST_MAIN(SimpleChildProcess, NULL) {
123 return 0; 123 return 0;
124 } 124 }
125 125
126 TEST_F(ProcessUtilTest, SpawnChild) { 126 TEST_F(ProcessUtilTest, SpawnChild) {
127 base::ProcessHandle handle = this->SpawnChild("SimpleChildProcess", false); 127 base::ProcessHandle handle = this->SpawnChild("SimpleChildProcess", false);
128 ASSERT_NE(base::kNullProcessHandle, handle); 128 ASSERT_NE(base::kNullProcessHandle, handle);
129 EXPECT_TRUE(base::WaitForSingleProcess( 129 EXPECT_TRUE(base::WaitForSingleProcess(
130 handle, TestTimeouts::action_max_timeout_ms())); 130 handle, TestTimeouts::action_max_timeout_ms()));
131 base::CloseProcessHandle(handle); 131 base::CloseProcessHandle(handle);
132 } 132 }
133 133
134 MULTIPROCESS_TEST_MAIN(SlowChildProcess) { 134 MULTIPROCESS_TEST_MAIN(SlowChildProcess, NULL) {
135 WaitToDie(kSignalFileSlow); 135 WaitToDie(kSignalFileSlow);
136 return 0; 136 return 0;
137 } 137 }
138 138
139 TEST_F(ProcessUtilTest, KillSlowChild) { 139 TEST_F(ProcessUtilTest, KillSlowChild) {
140 remove(kSignalFileSlow); 140 remove(kSignalFileSlow);
141 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false); 141 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false);
142 ASSERT_NE(base::kNullProcessHandle, handle); 142 ASSERT_NE(base::kNullProcessHandle, handle);
143 SignalChildren(kSignalFileSlow); 143 SignalChildren(kSignalFileSlow);
144 EXPECT_TRUE(base::WaitForSingleProcess( 144 EXPECT_TRUE(base::WaitForSingleProcess(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 #if !defined(OS_MACOSX) 204 #if !defined(OS_MACOSX)
205 // This test is disabled on Mac, since it's flaky due to ReportCrash 205 // This test is disabled on Mac, since it's flaky due to ReportCrash
206 // taking a variable amount of time to parse and load the debug and 206 // taking a variable amount of time to parse and load the debug and
207 // symbol data for this unit test's executable before firing the 207 // symbol data for this unit test's executable before firing the
208 // signal handler. 208 // signal handler.
209 // 209 //
210 // TODO(gspencer): turn this test process into a very small program 210 // TODO(gspencer): turn this test process into a very small program
211 // with no symbols (instead of using the multiprocess testing 211 // with no symbols (instead of using the multiprocess testing
212 // framework) to reduce the ReportCrash overhead. 212 // framework) to reduce the ReportCrash overhead.
213 213
214 MULTIPROCESS_TEST_MAIN(CrashingChildProcess) { 214 MULTIPROCESS_TEST_MAIN(CrashingChildProcess, NULL) {
215 WaitToDie(kSignalFileCrash); 215 WaitToDie(kSignalFileCrash);
216 #if defined(OS_POSIX) 216 #if defined(OS_POSIX)
217 // Have to disable to signal handler for segv so we can get a crash 217 // Have to disable to signal handler for segv so we can get a crash
218 // instead of an abnormal termination through the crash dump handler. 218 // instead of an abnormal termination through the crash dump handler.
219 ::signal(SIGSEGV, SIG_DFL); 219 ::signal(SIGSEGV, SIG_DFL);
220 #endif 220 #endif
221 // Make this process have a segmentation fault. 221 // Make this process have a segmentation fault.
222 volatile int* oops = NULL; 222 volatile int* oops = NULL;
223 *oops = 0xDEAD; 223 *oops = 0xDEAD;
224 return 1; 224 return 1;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 EXPECT_EQ(SIGSEGV, signal); 257 EXPECT_EQ(SIGSEGV, signal);
258 #endif 258 #endif
259 base::CloseProcessHandle(handle); 259 base::CloseProcessHandle(handle);
260 260
261 // Reset signal handlers back to "normal". 261 // Reset signal handlers back to "normal".
262 base::EnableInProcessStackDumping(); 262 base::EnableInProcessStackDumping();
263 remove(kSignalFileCrash); 263 remove(kSignalFileCrash);
264 } 264 }
265 #endif // !defined(OS_MACOSX) 265 #endif // !defined(OS_MACOSX)
266 266
267 MULTIPROCESS_TEST_MAIN(KilledChildProcess) { 267 MULTIPROCESS_TEST_MAIN(KilledChildProcess, NULL) {
268 WaitToDie(kSignalFileKill); 268 WaitToDie(kSignalFileKill);
269 #if defined(OS_WIN) 269 #if defined(OS_WIN)
270 // Kill ourselves. 270 // Kill ourselves.
271 HANDLE handle = ::OpenProcess(PROCESS_ALL_ACCESS, 0, ::GetCurrentProcessId()); 271 HANDLE handle = ::OpenProcess(PROCESS_ALL_ACCESS, 0, ::GetCurrentProcessId());
272 ::TerminateProcess(handle, kExpectedKilledExitCode); 272 ::TerminateProcess(handle, kExpectedKilledExitCode);
273 #elif defined(OS_POSIX) 273 #elif defined(OS_POSIX)
274 // Send a SIGKILL to this process, just like the OOM killer would. 274 // Send a SIGKILL to this process, just like the OOM killer would.
275 ::kill(getpid(), SIGKILL); 275 ::kill(getpid(), SIGKILL);
276 #endif 276 #endif
277 return 1; 277 return 1;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 return max_int; 515 return max_int;
516 } 516 }
517 517
518 return rlim.rlim_cur; 518 return rlim.rlim_cur;
519 } 519 }
520 520
521 const int kChildPipe = 20; // FD # for write end of pipe in child process. 521 const int kChildPipe = 20; // FD # for write end of pipe in child process.
522 522
523 } // namespace 523 } // namespace
524 524
525 MULTIPROCESS_TEST_MAIN(ProcessUtilsLeakFDChildProcess) { 525 MULTIPROCESS_TEST_MAIN(ProcessUtilsLeakFDChildProcess, NULL) {
526 // This child process counts the number of open FDs, it then writes that 526 // This child process counts the number of open FDs, it then writes that
527 // number out to a pipe connected to the parent. 527 // number out to a pipe connected to the parent.
528 int num_open_files = 0; 528 int num_open_files = 0;
529 int write_pipe = kChildPipe; 529 int write_pipe = kChildPipe;
530 int max_files = GetMaxFilesOpenInProcess(); 530 int max_files = GetMaxFilesOpenInProcess();
531 for (int i = STDERR_FILENO + 1; i < max_files; i++) { 531 for (int i = STDERR_FILENO + 1; i < max_files; i++) {
532 if (i != kChildPipe) { 532 if (i != kChildPipe) {
533 int fd; 533 int fd;
534 if ((fd = HANDLE_EINTR(dup(i))) != -1) { 534 if ((fd = HANDLE_EINTR(dup(i))) != -1) {
535 close(fd); 535 close(fd);
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 SpawnChild("process_util_test_never_die", false); 908 SpawnChild("process_util_test_never_die", false);
909 ASSERT_TRUE(child_process); 909 ASSERT_TRUE(child_process);
910 base::EnsureProcessTerminated(child_process); 910 base::EnsureProcessTerminated(child_process);
911 base::WaitForSingleProcess(child_process, 5000); 911 base::WaitForSingleProcess(child_process, 5000);
912 912
913 // Check that process was really killed. 913 // Check that process was really killed.
914 EXPECT_TRUE(IsProcessDead(child_process)); 914 EXPECT_TRUE(IsProcessDead(child_process));
915 base::CloseProcessHandle(child_process); 915 base::CloseProcessHandle(child_process);
916 } 916 }
917 917
918 MULTIPROCESS_TEST_MAIN(process_util_test_never_die) { 918 MULTIPROCESS_TEST_MAIN(process_util_test_never_die, NULL) {
919 while (1) { 919 while (1) {
920 sleep(500); 920 sleep(500);
921 } 921 }
922 return 0; 922 return 0;
923 } 923 }
924 924
925 TEST_F(ProcessUtilTest, ImmediateTermination) { 925 TEST_F(ProcessUtilTest, ImmediateTermination) {
926 base::ProcessHandle child_process = 926 base::ProcessHandle child_process =
927 SpawnChild("process_util_test_die_immediately", false); 927 SpawnChild("process_util_test_die_immediately", false);
928 ASSERT_TRUE(child_process); 928 ASSERT_TRUE(child_process);
929 // Give it time to die. 929 // Give it time to die.
930 sleep(2); 930 sleep(2);
931 base::EnsureProcessTerminated(child_process); 931 base::EnsureProcessTerminated(child_process);
932 932
933 // Check that process was really killed. 933 // Check that process was really killed.
934 EXPECT_TRUE(IsProcessDead(child_process)); 934 EXPECT_TRUE(IsProcessDead(child_process));
935 base::CloseProcessHandle(child_process); 935 base::CloseProcessHandle(child_process);
936 } 936 }
937 937
938 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { 938 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately, NULL) {
939 return 0; 939 return 0;
940 } 940 }
941 941
942 #endif // defined(OS_POSIX) 942 #endif // defined(OS_POSIX)
943 943
944 // Android doesn't implement set_new_handler, so we can't use the 944 // Android doesn't implement set_new_handler, so we can't use the
945 // OutOfMemoryTest cases. 945 // OutOfMemoryTest cases.
946 // OpenBSD does not support these tests either. 946 // OpenBSD does not support these tests either.
947 // AddressSanitizer defines the malloc()/free()/etc. functions so that they 947 // AddressSanitizer defines the malloc()/free()/etc. functions so that they
948 // don't crash if the program is out of memory, so the OOM tests aren't supposed 948 // don't crash if the program is out of memory, so the OOM tests aren't supposed
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 SetUpInDeathAssert(); 1184 SetUpInDeathAssert();
1185 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} 1185 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {}
1186 }, ""); 1186 }, "");
1187 } 1187 }
1188 1188
1189 #endif // !ARCH_CPU_64_BITS 1189 #endif // !ARCH_CPU_64_BITS
1190 #endif // OS_MACOSX 1190 #endif // OS_MACOSX
1191 1191
1192 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && 1192 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) &&
1193 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) 1193 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698