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

Side by Side Diff: base/process_util_unittest.cc

Issue 3035062: Revert 55400 - Cleanup in base. This moves the implementation (and a bunch of... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 4 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
« no previous file with comments | « base/multiprocess_test.h ('k') | base/shared_memory_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/eintr_wrapper.h" 10 #include "base/eintr_wrapper.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/multiprocess_test.h"
12 #include "base/path_service.h" 13 #include "base/path_service.h"
13 #include "base/platform_thread.h" 14 #include "base/platform_thread.h"
14 #include "base/process_util.h" 15 #include "base/process_util.h"
15 #include "base/scoped_ptr.h" 16 #include "base/scoped_ptr.h"
16 #include "base/test/multiprocess_test.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/multiprocess_func_list.h"
20 19
21 #if defined(OS_LINUX) 20 #if defined(OS_LINUX)
22 #include <errno.h> 21 #include <errno.h>
23 #include <malloc.h> 22 #include <malloc.h>
24 #include <glib.h> 23 #include <glib.h>
25 #endif 24 #endif
26 #if defined(OS_POSIX) 25 #if defined(OS_POSIX)
27 #include <dlfcn.h> 26 #include <dlfcn.h>
28 #include <fcntl.h> 27 #include <fcntl.h>
29 #include <sys/resource.h> 28 #include <sys/resource.h>
(...skipping 26 matching lines...) Expand all
56 } 55 }
57 56
58 // Signals children they should die now. 57 // Signals children they should die now.
59 void SignalChildren(const char* filename) { 58 void SignalChildren(const char* filename) {
60 FILE *fp = fopen(filename, "w"); 59 FILE *fp = fopen(filename, "w");
61 fclose(fp); 60 fclose(fp);
62 } 61 }
63 62
64 } // namespace 63 } // namespace
65 64
66 class ProcessUtilTest : public base::MultiProcessTest { 65 class ProcessUtilTest : public MultiProcessTest {
67 #if defined(OS_POSIX) 66 #if defined(OS_POSIX)
68 public: 67 public:
69 // Spawn a child process that counts how many file descriptors are open. 68 // Spawn a child process that counts how many file descriptors are open.
70 int CountOpenFDsInChild(); 69 int CountOpenFDsInChild();
71 #endif 70 #endif
72 }; 71 };
73 72
74 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { 73 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) {
75 return 0; 74 return 0;
76 } 75 }
77 76
78 TEST_F(ProcessUtilTest, SpawnChild) { 77 TEST_F(ProcessUtilTest, SpawnChild) {
79 base::ProcessHandle handle = this->SpawnChild("SimpleChildProcess", false); 78 base::ProcessHandle handle = this->SpawnChild("SimpleChildProcess");
80 ASSERT_NE(base::kNullProcessHandle, handle); 79 ASSERT_NE(base::kNullProcessHandle, handle);
81 EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000)); 80 EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000));
82 base::CloseProcessHandle(handle); 81 base::CloseProcessHandle(handle);
83 } 82 }
84 83
85 MULTIPROCESS_TEST_MAIN(SlowChildProcess) { 84 MULTIPROCESS_TEST_MAIN(SlowChildProcess) {
86 WaitToDie("SlowChildProcess.die"); 85 WaitToDie("SlowChildProcess.die");
87 return 0; 86 return 0;
88 } 87 }
89 88
90 TEST_F(ProcessUtilTest, KillSlowChild) { 89 TEST_F(ProcessUtilTest, KillSlowChild) {
91 remove("SlowChildProcess.die"); 90 remove("SlowChildProcess.die");
92 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false); 91 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess");
93 ASSERT_NE(base::kNullProcessHandle, handle); 92 ASSERT_NE(base::kNullProcessHandle, handle);
94 SignalChildren("SlowChildProcess.die"); 93 SignalChildren("SlowChildProcess.die");
95 EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000)); 94 EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000));
96 base::CloseProcessHandle(handle); 95 base::CloseProcessHandle(handle);
97 remove("SlowChildProcess.die"); 96 remove("SlowChildProcess.die");
98 } 97 }
99 98
100 TEST_F(ProcessUtilTest, DidProcessCrash) { 99 TEST_F(ProcessUtilTest, DidProcessCrash) {
101 remove("SlowChildProcess.die"); 100 remove("SlowChildProcess.die");
102 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false); 101 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess");
103 ASSERT_NE(base::kNullProcessHandle, handle); 102 ASSERT_NE(base::kNullProcessHandle, handle);
104 103
105 bool child_exited = true; 104 bool child_exited = true;
106 EXPECT_FALSE(base::DidProcessCrash(&child_exited, handle)); 105 EXPECT_FALSE(base::DidProcessCrash(&child_exited, handle));
107 EXPECT_FALSE(child_exited); 106 EXPECT_FALSE(child_exited);
108 107
109 SignalChildren("SlowChildProcess.die"); 108 SignalChildren("SlowChildProcess.die");
110 EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000)); 109 EXPECT_TRUE(base::WaitForSingleProcess(handle, 5000));
111 110
112 EXPECT_FALSE(base::DidProcessCrash(&child_exited, handle)); 111 EXPECT_FALSE(base::DidProcessCrash(&child_exited, handle));
113 base::CloseProcessHandle(handle); 112 base::CloseProcessHandle(handle);
114 remove("SlowChildProcess.die"); 113 remove("SlowChildProcess.die");
115 } 114 }
116 115
117 // Ensure that the priority of a process is restored correctly after 116 // Ensure that the priority of a process is restored correctly after
118 // backgrounding and restoring. 117 // backgrounding and restoring.
119 // Note: a platform may not be willing or able to lower the priority of 118 // Note: a platform may not be willing or able to lower the priority of
120 // a process. The calls to SetProcessBackground should be noops then. 119 // a process. The calls to SetProcessBackground should be noops then.
121 TEST_F(ProcessUtilTest, SetProcessBackgrounded) { 120 TEST_F(ProcessUtilTest, SetProcessBackgrounded) {
122 base::ProcessHandle handle = this->SpawnChild("SimpleChildProcess", false); 121 base::ProcessHandle handle = this->SpawnChild("SimpleChildProcess");
123 base::Process process(handle); 122 base::Process process(handle);
124 int old_priority = process.GetPriority(); 123 int old_priority = process.GetPriority();
125 process.SetProcessBackgrounded(true); 124 process.SetProcessBackgrounded(true);
126 process.SetProcessBackgrounded(false); 125 process.SetProcessBackgrounded(false);
127 int new_priority = process.GetPriority(); 126 int new_priority = process.GetPriority();
128 EXPECT_EQ(old_priority, new_priority); 127 EXPECT_EQ(old_priority, new_priority);
129 } 128 }
130 129
131 // TODO(estade): if possible, port these 2 tests. 130 // TODO(estade): if possible, port these 2 tests.
132 #if defined(OS_WIN) 131 #if defined(OS_WIN)
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 720
722 TEST_F(OutOfMemoryTest, PsychoticallyBigObjCObject) { 721 TEST_F(OutOfMemoryTest, PsychoticallyBigObjCObject) {
723 ASSERT_DEATH(while ((value_ = 722 ASSERT_DEATH(while ((value_ =
724 base::AllocatePsychoticallyBigObjCObject())) {}, ""); 723 base::AllocatePsychoticallyBigObjCObject())) {}, "");
725 } 724 }
726 725
727 #endif // !ARCH_CPU_64_BITS 726 #endif // !ARCH_CPU_64_BITS
728 #endif // OS_MACOSX 727 #endif // OS_MACOSX
729 728
730 #endif // !defined(OS_WIN) 729 #endif // !defined(OS_WIN)
OLDNEW
« no previous file with comments | « base/multiprocess_test.h ('k') | base/shared_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698