| OLD | NEW |
| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 const char kSignalFileCrash[] = "CrashingChildProcess.die"; | 52 const char kSignalFileCrash[] = "CrashingChildProcess.die"; |
| 53 const char kSignalFileKill[] = "KilledChildProcess.die"; | 53 const char kSignalFileKill[] = "KilledChildProcess.die"; |
| 54 | 54 |
| 55 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
| 56 const int kExpectedStillRunningExitCode = 0x102; | 56 const int kExpectedStillRunningExitCode = 0x102; |
| 57 const int kExpectedKilledExitCode = 1; | 57 const int kExpectedKilledExitCode = 1; |
| 58 #else | 58 #else |
| 59 const int kExpectedStillRunningExitCode = 0; | 59 const int kExpectedStillRunningExitCode = 0; |
| 60 #endif | 60 #endif |
| 61 | 61 |
| 62 // The longest we'll wait for a process, in milliseconds. | |
| 63 const int kMaxWaitTimeMs = TestTimeouts::action_max_timeout_ms(); | |
| 64 | |
| 65 // Sleeps until file filename is created. | 62 // Sleeps until file filename is created. |
| 66 void WaitToDie(const char* filename) { | 63 void WaitToDie(const char* filename) { |
| 67 FILE *fp; | 64 FILE *fp; |
| 68 do { | 65 do { |
| 69 base::PlatformThread::Sleep(10); | 66 base::PlatformThread::Sleep(10); |
| 70 fp = fopen(filename, "r"); | 67 fp = fopen(filename, "r"); |
| 71 } while (!fp); | 68 } while (!fp); |
| 72 fclose(fp); | 69 fclose(fp); |
| 73 } | 70 } |
| 74 | 71 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 87 int* exit_code) { | 84 int* exit_code) { |
| 88 // Now we wait until the result is something other than STILL_RUNNING. | 85 // Now we wait until the result is something other than STILL_RUNNING. |
| 89 base::TerminationStatus status = base::TERMINATION_STATUS_STILL_RUNNING; | 86 base::TerminationStatus status = base::TERMINATION_STATUS_STILL_RUNNING; |
| 90 const int kIntervalMs = 20; | 87 const int kIntervalMs = 20; |
| 91 int waited = 0; | 88 int waited = 0; |
| 92 do { | 89 do { |
| 93 status = base::GetTerminationStatus(handle, exit_code); | 90 status = base::GetTerminationStatus(handle, exit_code); |
| 94 base::PlatformThread::Sleep(kIntervalMs); | 91 base::PlatformThread::Sleep(kIntervalMs); |
| 95 waited += kIntervalMs; | 92 waited += kIntervalMs; |
| 96 } while (status == base::TERMINATION_STATUS_STILL_RUNNING && | 93 } while (status == base::TERMINATION_STATUS_STILL_RUNNING && |
| 97 waited < kMaxWaitTimeMs); | 94 waited < TestTimeouts::action_max_timeout_ms()); |
| 98 | 95 |
| 99 return status; | 96 return status; |
| 100 } | 97 } |
| 101 | 98 |
| 102 } // namespace | 99 } // namespace |
| 103 | 100 |
| 104 class ProcessUtilTest : public base::MultiProcessTest { | 101 class ProcessUtilTest : public base::MultiProcessTest { |
| 105 #if defined(OS_POSIX) | 102 #if defined(OS_POSIX) |
| 106 public: | 103 public: |
| 107 // Spawn a child process that counts how many file descriptors are open. | 104 // Spawn a child process that counts how many file descriptors are open. |
| 108 int CountOpenFDsInChild(); | 105 int CountOpenFDsInChild(); |
| 109 #endif | 106 #endif |
| 110 }; | 107 }; |
| 111 | 108 |
| 112 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { | 109 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { |
| 113 return 0; | 110 return 0; |
| 114 } | 111 } |
| 115 | 112 |
| 116 TEST_F(ProcessUtilTest, SpawnChild) { | 113 TEST_F(ProcessUtilTest, SpawnChild) { |
| 117 base::ProcessHandle handle = this->SpawnChild("SimpleChildProcess", false); | 114 base::ProcessHandle handle = this->SpawnChild("SimpleChildProcess", false); |
| 118 ASSERT_NE(base::kNullProcessHandle, handle); | 115 ASSERT_NE(base::kNullProcessHandle, handle); |
| 119 EXPECT_TRUE(base::WaitForSingleProcess(handle, kMaxWaitTimeMs)); | 116 EXPECT_TRUE(base::WaitForSingleProcess( |
| 117 handle, TestTimeouts::action_max_timeout_ms())); |
| 120 base::CloseProcessHandle(handle); | 118 base::CloseProcessHandle(handle); |
| 121 } | 119 } |
| 122 | 120 |
| 123 MULTIPROCESS_TEST_MAIN(SlowChildProcess) { | 121 MULTIPROCESS_TEST_MAIN(SlowChildProcess) { |
| 124 WaitToDie(kSignalFileSlow); | 122 WaitToDie(kSignalFileSlow); |
| 125 return 0; | 123 return 0; |
| 126 } | 124 } |
| 127 | 125 |
| 128 TEST_F(ProcessUtilTest, KillSlowChild) { | 126 TEST_F(ProcessUtilTest, KillSlowChild) { |
| 129 remove(kSignalFileSlow); | 127 remove(kSignalFileSlow); |
| 130 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false); | 128 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false); |
| 131 ASSERT_NE(base::kNullProcessHandle, handle); | 129 ASSERT_NE(base::kNullProcessHandle, handle); |
| 132 SignalChildren(kSignalFileSlow); | 130 SignalChildren(kSignalFileSlow); |
| 133 EXPECT_TRUE(base::WaitForSingleProcess(handle, kMaxWaitTimeMs)); | 131 EXPECT_TRUE(base::WaitForSingleProcess( |
| 132 handle, TestTimeouts::action_max_timeout_ms())); |
| 134 base::CloseProcessHandle(handle); | 133 base::CloseProcessHandle(handle); |
| 135 remove(kSignalFileSlow); | 134 remove(kSignalFileSlow); |
| 136 } | 135 } |
| 137 | 136 |
| 138 TEST_F(ProcessUtilTest, GetTerminationStatusExit) { | 137 TEST_F(ProcessUtilTest, GetTerminationStatusExit) { |
| 139 remove(kSignalFileSlow); | 138 remove(kSignalFileSlow); |
| 140 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false); | 139 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false); |
| 141 ASSERT_NE(base::kNullProcessHandle, handle); | 140 ASSERT_NE(base::kNullProcessHandle, handle); |
| 142 | 141 |
| 143 int exit_code = 42; | 142 int exit_code = 42; |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 ASSERT_DEATH({ | 945 ASSERT_DEATH({ |
| 947 SetUpInDeathAssert(); | 946 SetUpInDeathAssert(); |
| 948 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} | 947 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} |
| 949 }, ""); | 948 }, ""); |
| 950 } | 949 } |
| 951 | 950 |
| 952 #endif // !ARCH_CPU_64_BITS | 951 #endif // !ARCH_CPU_64_BITS |
| 953 #endif // OS_MACOSX | 952 #endif // OS_MACOSX |
| 954 | 953 |
| 955 #endif // !defined(OS_WIN) | 954 #endif // !defined(OS_WIN) |
| OLD | NEW |