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

Side by Side Diff: content/common/process_watcher_unittest.cc

Issue 8674003: Move the ProcessWatcher methods out of content/common/process_watcher into base/process_util, alo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/common/process_watcher.h"
6
7 #include <sys/wait.h>
8
9 #include "base/eintr_wrapper.h"
10 #include "base/process_util.h"
11 #include "base/test/multiprocess_test.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/multiprocess_func_list.h"
14
15 class ProcessWatcherTest : public base::MultiProcessTest {
16 };
17
18 namespace {
19
20 bool IsProcessDead(base::ProcessHandle child) {
21 // waitpid() will actually reap the process which is exactly NOT what we
22 // want to test for. The good thing is that if it can't find the process
23 // we'll get a nice value for errno which we can test for.
24 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG));
25 return result == -1 && errno == ECHILD;
26 }
27
28 } // namespace
29
30 TEST_F(ProcessWatcherTest, DelayedTermination) {
31 base::ProcessHandle child_process =
32 SpawnChild("process_watcher_test_never_die", false);
33 ASSERT_TRUE(child_process);
34 ProcessWatcher::EnsureProcessTerminated(child_process);
35 base::WaitForSingleProcess(child_process, 5000);
36
37 // Check that process was really killed.
38 EXPECT_TRUE(IsProcessDead(child_process));
39 base::CloseProcessHandle(child_process);
40 }
41
42 MULTIPROCESS_TEST_MAIN(process_watcher_test_never_die) {
43 while (1) {
44 sleep(500);
45 }
46 return 0;
47 }
48
49 TEST_F(ProcessWatcherTest, ImmediateTermination) {
50 base::ProcessHandle child_process =
51 SpawnChild("process_watcher_test_die_immediately", false);
52 ASSERT_TRUE(child_process);
53 // Give it time to die.
54 sleep(2);
55 ProcessWatcher::EnsureProcessTerminated(child_process);
56
57 // Check that process was really killed.
58 EXPECT_TRUE(IsProcessDead(child_process));
59 base::CloseProcessHandle(child_process);
60 }
61
62 MULTIPROCESS_TEST_MAIN(process_watcher_test_die_immediately) {
63 return 0;
64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698