OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_util.h" | 10 #include "base/debug_util.h" |
11 #include "base/eintr_wrapper.h" | 11 #include "base/eintr_wrapper.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/platform_thread.h" | |
16 #include "base/process_util.h" | 15 #include "base/process_util.h" |
17 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
18 #include "base/test/multiprocess_test.h" | 17 #include "base/test/multiprocess_test.h" |
19 #include "base/test/test_timeouts.h" | 18 #include "base/test/test_timeouts.h" |
| 19 #include "base/threading/platform_thread.h" |
20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "testing/multiprocess_func_list.h" | 22 #include "testing/multiprocess_func_list.h" |
23 | 23 |
24 #if defined(OS_LINUX) | 24 #if defined(OS_LINUX) |
25 #include <errno.h> | 25 #include <errno.h> |
26 #include <malloc.h> | 26 #include <malloc.h> |
27 #include <glib.h> | 27 #include <glib.h> |
28 #endif | 28 #endif |
29 #if defined(OS_POSIX) | 29 #if defined(OS_POSIX) |
(...skipping 30 matching lines...) Expand all Loading... |
60 const int kExpectedStillRunningExitCode = 0; | 60 const int kExpectedStillRunningExitCode = 0; |
61 #endif | 61 #endif |
62 | 62 |
63 // The longest we'll wait for a process, in milliseconds. | 63 // The longest we'll wait for a process, in milliseconds. |
64 const int kMaxWaitTimeMs = TestTimeouts::action_max_timeout_ms(); | 64 const int kMaxWaitTimeMs = TestTimeouts::action_max_timeout_ms(); |
65 | 65 |
66 // Sleeps until file filename is created. | 66 // Sleeps until file filename is created. |
67 void WaitToDie(const char* filename) { | 67 void WaitToDie(const char* filename) { |
68 FILE *fp; | 68 FILE *fp; |
69 do { | 69 do { |
70 PlatformThread::Sleep(10); | 70 base::PlatformThread::Sleep(10); |
71 fp = fopen(filename, "r"); | 71 fp = fopen(filename, "r"); |
72 } while (!fp); | 72 } while (!fp); |
73 fclose(fp); | 73 fclose(fp); |
74 } | 74 } |
75 | 75 |
76 // Signals children they should die now. | 76 // Signals children they should die now. |
77 void SignalChildren(const char* filename) { | 77 void SignalChildren(const char* filename) { |
78 FILE *fp = fopen(filename, "w"); | 78 FILE *fp = fopen(filename, "w"); |
79 fclose(fp); | 79 fclose(fp); |
80 } | 80 } |
81 | 81 |
82 // Using a pipe to the child to wait for an event was considered, but | 82 // Using a pipe to the child to wait for an event was considered, but |
83 // there were cases in the past where pipes caused problems (other | 83 // there were cases in the past where pipes caused problems (other |
84 // libraries closing the fds, child deadlocking). This is a simple | 84 // libraries closing the fds, child deadlocking). This is a simple |
85 // case, so it's not worth the risk. Using wait loops is discouraged | 85 // case, so it's not worth the risk. Using wait loops is discouraged |
86 // in most instances. | 86 // in most instances. |
87 base::TerminationStatus WaitForChildTermination(base::ProcessHandle handle, | 87 base::TerminationStatus WaitForChildTermination(base::ProcessHandle handle, |
88 int* exit_code) { | 88 int* exit_code) { |
89 // Now we wait until the result is something other than STILL_RUNNING. | 89 // Now we wait until the result is something other than STILL_RUNNING. |
90 base::TerminationStatus status = base::TERMINATION_STATUS_STILL_RUNNING; | 90 base::TerminationStatus status = base::TERMINATION_STATUS_STILL_RUNNING; |
91 const int kIntervalMs = 20; | 91 const int kIntervalMs = 20; |
92 int waited = 0; | 92 int waited = 0; |
93 do { | 93 do { |
94 status = base::GetTerminationStatus(handle, exit_code); | 94 status = base::GetTerminationStatus(handle, exit_code); |
95 PlatformThread::Sleep(kIntervalMs); | 95 base::PlatformThread::Sleep(kIntervalMs); |
96 waited += kIntervalMs; | 96 waited += kIntervalMs; |
97 } while (status == base::TERMINATION_STATUS_STILL_RUNNING && | 97 } while (status == base::TERMINATION_STATUS_STILL_RUNNING && |
98 waited < kMaxWaitTimeMs); | 98 waited < kMaxWaitTimeMs); |
99 | 99 |
100 return status; | 100 return status; |
101 } | 101 } |
102 | 102 |
103 } // namespace | 103 } // namespace |
104 | 104 |
105 class ProcessUtilTest : public base::MultiProcessTest { | 105 class ProcessUtilTest : public base::MultiProcessTest { |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 ASSERT_DEATH({ | 919 ASSERT_DEATH({ |
920 SetUpInDeathAssert(); | 920 SetUpInDeathAssert(); |
921 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} | 921 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} |
922 }, ""); | 922 }, ""); |
923 } | 923 } |
924 | 924 |
925 #endif // !ARCH_CPU_64_BITS | 925 #endif // !ARCH_CPU_64_BITS |
926 #endif // OS_MACOSX | 926 #endif // OS_MACOSX |
927 | 927 |
928 #endif // !defined(OS_WIN) | 928 #endif // !defined(OS_WIN) |
OLD | NEW |