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

Side by Side Diff: base/process_util_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698