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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 const int kExpectedStillRunningExitCode = 0x102; | 67 const int kExpectedStillRunningExitCode = 0x102; |
68 const int kExpectedKilledExitCode = 1; | 68 const int kExpectedKilledExitCode = 1; |
69 #else | 69 #else |
70 const int kExpectedStillRunningExitCode = 0; | 70 const int kExpectedStillRunningExitCode = 0; |
71 #endif | 71 #endif |
72 | 72 |
73 // Sleeps until file filename is created. | 73 // Sleeps until file filename is created. |
74 void WaitToDie(const char* filename) { | 74 void WaitToDie(const char* filename) { |
75 FILE *fp; | 75 FILE *fp; |
76 do { | 76 do { |
77 base::PlatformThread::Sleep(10); | 77 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); |
78 fp = fopen(filename, "r"); | 78 fp = fopen(filename, "r"); |
79 } while (!fp); | 79 } while (!fp); |
80 fclose(fp); | 80 fclose(fp); |
81 } | 81 } |
82 | 82 |
83 // Signals children they should die now. | 83 // Signals children they should die now. |
84 void SignalChildren(const char* filename) { | 84 void SignalChildren(const char* filename) { |
85 FILE *fp = fopen(filename, "w"); | 85 FILE *fp = fopen(filename, "w"); |
86 fclose(fp); | 86 fclose(fp); |
87 } | 87 } |
88 | 88 |
89 // Using a pipe to the child to wait for an event was considered, but | 89 // Using a pipe to the child to wait for an event was considered, but |
90 // there were cases in the past where pipes caused problems (other | 90 // there were cases in the past where pipes caused problems (other |
91 // libraries closing the fds, child deadlocking). This is a simple | 91 // libraries closing the fds, child deadlocking). This is a simple |
92 // case, so it's not worth the risk. Using wait loops is discouraged | 92 // case, so it's not worth the risk. Using wait loops is discouraged |
93 // in most instances. | 93 // in most instances. |
94 base::TerminationStatus WaitForChildTermination(base::ProcessHandle handle, | 94 base::TerminationStatus WaitForChildTermination(base::ProcessHandle handle, |
95 int* exit_code) { | 95 int* exit_code) { |
96 // Now we wait until the result is something other than STILL_RUNNING. | 96 // Now we wait until the result is something other than STILL_RUNNING. |
97 base::TerminationStatus status = base::TERMINATION_STATUS_STILL_RUNNING; | 97 base::TerminationStatus status = base::TERMINATION_STATUS_STILL_RUNNING; |
98 const int kIntervalMs = 20; | 98 const base::TimeDelta kInterval = base::TimeDelta::FromMilliseconds(20); |
99 int waited = 0; | 99 base::TimeDelta waited; |
100 do { | 100 do { |
101 status = base::GetTerminationStatus(handle, exit_code); | 101 status = base::GetTerminationStatus(handle, exit_code); |
102 base::PlatformThread::Sleep(kIntervalMs); | 102 base::PlatformThread::Sleep(kInterval); |
103 waited += kIntervalMs; | 103 waited += kInterval; |
104 } while (status == base::TERMINATION_STATUS_STILL_RUNNING && | 104 } while (status == base::TERMINATION_STATUS_STILL_RUNNING && |
105 waited < TestTimeouts::action_max_timeout_ms()); | 105 waited.InMilliseconds() < TestTimeouts::action_max_timeout_ms()); |
106 | 106 |
107 return status; | 107 return status; |
108 } | 108 } |
109 | 109 |
110 } // namespace | 110 } // namespace |
111 | 111 |
112 class ProcessUtilTest : public base::MultiProcessTest { | 112 class ProcessUtilTest : public base::MultiProcessTest { |
113 #if defined(OS_POSIX) | 113 #if defined(OS_POSIX) |
114 public: | 114 public: |
115 // Spawn a child process that counts how many file descriptors are open. | 115 // Spawn a child process that counts how many file descriptors are open. |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 SetUpInDeathAssert(); | 1123 SetUpInDeathAssert(); |
1124 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} | 1124 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} |
1125 }, ""); | 1125 }, ""); |
1126 } | 1126 } |
1127 | 1127 |
1128 #endif // !ARCH_CPU_64_BITS | 1128 #endif // !ARCH_CPU_64_BITS |
1129 #endif // OS_MACOSX | 1129 #endif // OS_MACOSX |
1130 | 1130 |
1131 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && | 1131 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && |
1132 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) | 1132 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) |
OLD | NEW |