OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/process_info_snapshot.h" | 5 #include "chrome/browser/process_info_snapshot.h" |
6 | 6 |
7 #include <sys/types.h> // For |uid_t| (and |pid_t|). | 7 #include <sys/types.h> // For |uid_t| (and |pid_t|). |
8 #include <unistd.h> // For |getpid()|, |getuid()|, etc. | 8 #include <unistd.h> // For |getpid()|, |getuid()|, etc. |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/mac/mac_util.h" |
15 #include "base/posix/eintr_wrapper.h" | 16 #include "base/posix/eintr_wrapper.h" |
16 #include "base/process/kill.h" | 17 #include "base/process/kill.h" |
17 #include "base/process/launch.h" | 18 #include "base/process/launch.h" |
18 #include "base/process/process_handle.h" | 19 #include "base/process/process_handle.h" |
19 #include "base/process/process_metrics.h" | 20 #include "base/process/process_metrics.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 typedef testing::Test ProcessInfoSnapshotMacTest; | 23 typedef testing::Test ProcessInfoSnapshotMacTest; |
23 | 24 |
24 TEST_F(ProcessInfoSnapshotMacTest, FindPidOneTest) { | 25 TEST_F(ProcessInfoSnapshotMacTest, FindPidOneTest) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 ProcessInfoSnapshot snapshot; | 71 ProcessInfoSnapshot snapshot; |
71 ASSERT_TRUE(snapshot.Sample(pid_list)); | 72 ASSERT_TRUE(snapshot.Sample(pid_list)); |
72 | 73 |
73 // Find our process. | 74 // Find our process. |
74 ProcessInfoSnapshot::ProcInfoEntry proc_info; | 75 ProcessInfoSnapshot::ProcInfoEntry proc_info; |
75 ASSERT_TRUE(snapshot.GetProcInfo(pid, &proc_info)); | 76 ASSERT_TRUE(snapshot.GetProcInfo(pid, &proc_info)); |
76 EXPECT_EQ(pid, proc_info.pid); | 77 EXPECT_EQ(pid, proc_info.pid); |
77 EXPECT_EQ(ppid, proc_info.ppid); | 78 EXPECT_EQ(ppid, proc_info.ppid); |
78 EXPECT_EQ(uid, proc_info.uid); | 79 EXPECT_EQ(uid, proc_info.uid); |
79 EXPECT_EQ(euid, proc_info.euid); | 80 EXPECT_EQ(euid, proc_info.euid); |
80 EXPECT_GE(proc_info.rss, 100u); // Sanity check: we're running, so we | 81 // Sanity check: we're running, so we should occupy at least 100 kilobytes. |
81 // should occupy at least 100 kilobytes. | 82 EXPECT_GE(proc_info.rss, 100u); |
82 EXPECT_GE(proc_info.vsize, 1024u); // Sanity check: our |vsize| is presumably | 83 // Sanity check: our |vsize| is presumably at least a megabyte. |
83 // at least a megabyte. | 84 EXPECT_GE(proc_info.vsize, 1024u); |
84 EXPECT_GE(proc_info.rshrd, 1024u); // Shared memory should also > 1 MB. | 85 |
85 EXPECT_GE(proc_info.rprvt, 1024u); // Same with private memory. | 86 // Collection of some memory statistics is broken in OSX 10.9+. |
| 87 // http://crbug.com/383553 |
| 88 if (!base::mac::IsOSMavericksOrLater()) { |
| 89 // Shared memory should also > 1 MB. |
| 90 EXPECT_GE(proc_info.rshrd, 1024u); |
| 91 // Same with private memory. |
| 92 EXPECT_GE(proc_info.rprvt, 1024u); |
| 93 } |
86 | 94 |
87 // Find our parent. | 95 // Find our parent. |
88 ASSERT_TRUE(snapshot.GetProcInfo(ppid, &proc_info)); | 96 ASSERT_TRUE(snapshot.GetProcInfo(ppid, &proc_info)); |
89 EXPECT_EQ(ppid, proc_info.pid); | 97 EXPECT_EQ(ppid, proc_info.pid); |
90 EXPECT_NE(static_cast<int64>(proc_info.ppid), 0); | 98 EXPECT_NE(static_cast<int64>(proc_info.ppid), 0); |
91 EXPECT_EQ(uid, proc_info.uid); // This (and the following) should be true | 99 EXPECT_EQ(uid, proc_info.uid); // This (and the following) should be true |
92 EXPECT_EQ(euid, proc_info.euid); // under reasonable circumstances. | 100 EXPECT_EQ(euid, proc_info.euid); // under reasonable circumstances. |
93 // Can't say anything definite about its |rss|. | 101 // Can't say anything definite about its |rss|. |
94 EXPECT_GT(proc_info.vsize, 0u); // Its |vsize| should be nonzero though. | 102 EXPECT_GT(proc_info.vsize, 0u); // Its |vsize| should be nonzero though. |
95 } | 103 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 ProcessInfoSnapshot::ProcInfoEntry proc_info; | 139 ProcessInfoSnapshot::ProcInfoEntry proc_info; |
132 ASSERT_TRUE(snapshot.GetProcInfo(process_handle, &proc_info)); | 140 ASSERT_TRUE(snapshot.GetProcInfo(process_handle, &proc_info)); |
133 // Effective user ID should be 0 (root). | 141 // Effective user ID should be 0 (root). |
134 EXPECT_EQ(proc_info.euid, 0u); | 142 EXPECT_EQ(proc_info.euid, 0u); |
135 // Real user ID should match the calling process's user id. | 143 // Real user ID should match the calling process's user id. |
136 EXPECT_EQ(proc_info.uid, geteuid()); | 144 EXPECT_EQ(proc_info.uid, geteuid()); |
137 | 145 |
138 ASSERT_TRUE(base::KillProcess(process_handle, 0, true)); | 146 ASSERT_TRUE(base::KillProcess(process_handle, 0, true)); |
139 PCHECK(IGNORE_EINTR(close(fds[0])) == 0); | 147 PCHECK(IGNORE_EINTR(close(fds[0])) == 0); |
140 } | 148 } |
OLD | NEW |