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

Side by Side Diff: chrome/browser/process_info_snapshot_mac_unittest.cc

Issue 333008: Mac: Implement about:memory. (Closed)
Patch Set: Merged ToT. Created 11 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
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 "chrome/browser/process_info_snapshot.h"
6
7 #include <sys/types.h> // For |uid_t| (and |pid_t|).
8 #include <unistd.h> // For |getpid()|, |getuid()|, etc.
9
10 #include <vector>
11
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 typedef testing::Test ProcessInfoSnapshotMacTest;
15
16 TEST_F(ProcessInfoSnapshotMacTest, FindPidOneTest) {
17 // Sample process with PID 1, which should exist and presumably belong to
18 // root.
19 std::vector<base::ProcessId> pid_list;
20 pid_list.push_back(1);
21 ProcessInfoSnapshot snapshot;
22 ASSERT_TRUE(snapshot.Sample(pid_list));
23
24 ProcessInfoSnapshot::ProcInfoEntry proc_info;
25 ASSERT_TRUE(snapshot.GetProcInfo(1, &proc_info));
26 EXPECT_EQ(1, static_cast<int64>(proc_info.pid));
27 EXPECT_EQ(0, static_cast<int64>(proc_info.ppid));
28 EXPECT_EQ(0, static_cast<int64>(proc_info.uid));
29 EXPECT_EQ(0, static_cast<int64>(proc_info.euid));
30 EXPECT_GE(proc_info.rss, 0u);
31 EXPECT_GT(proc_info.vsize, 0u);
32
33 // Try out the |Get...OfPID()|, but don't examine the results, since they
34 // depend on how we map |ProcInfoEntry| to |...KBytes|.
35 base::CommittedKBytes usage;
36 EXPECT_TRUE(snapshot.GetCommittedKBytesOfPID(1, &usage));
37 base::WorkingSetKBytes ws_usage;
38 EXPECT_TRUE(snapshot.GetWorkingSetKBytesOfPID(1, &ws_usage));
39
40 // Make sure it hasn't picked up some other PID (say, 2).
41 EXPECT_FALSE(snapshot.GetProcInfo(2, &proc_info));
42
43 // Make sure PID 2 still isn't there (in case I mess up my use of std::map).
44 EXPECT_FALSE(snapshot.GetProcInfo(2, &proc_info));
45
46 // Test |Reset()|.
47 snapshot.Reset();
48 EXPECT_FALSE(snapshot.GetProcInfo(1, &proc_info));
49 }
50
51 TEST_F(ProcessInfoSnapshotMacTest, FindPidSelfTest) {
52 // Sample this process and its parent.
53 base::ProcessId pid = static_cast<base::ProcessId>(getpid());
54 base::ProcessId ppid = static_cast<base::ProcessId>(getppid());
55 uid_t uid = getuid();
56 uid_t euid = geteuid();
57 EXPECT_NE(static_cast<int64>(ppid), 0);
58
59 std::vector<base::ProcessId> pid_list;
60 pid_list.push_back(pid);
61 pid_list.push_back(ppid);
62 ProcessInfoSnapshot snapshot;
63 ASSERT_TRUE(snapshot.Sample(pid_list));
64
65 // Find our process.
66 ProcessInfoSnapshot::ProcInfoEntry proc_info;
67 ASSERT_TRUE(snapshot.GetProcInfo(pid, &proc_info));
68 EXPECT_EQ(pid, proc_info.pid);
69 EXPECT_EQ(ppid, proc_info.ppid);
70 EXPECT_EQ(uid, proc_info.uid);
71 EXPECT_EQ(euid, proc_info.euid);
72 EXPECT_GE(proc_info.rss, 100u); // Sanity check: we're running, so we
73 // should occupy at least 100 kilobytes.
74 EXPECT_GE(proc_info.vsize, 1024u); // Sanity check: our |vsize| is presumably
75 // at least a megabyte.
76
77 // Find our parent.
78 ASSERT_TRUE(snapshot.GetProcInfo(ppid, &proc_info));
79 EXPECT_EQ(ppid, proc_info.pid);
80 EXPECT_NE(static_cast<int64>(proc_info.ppid), 0);
81 EXPECT_EQ(uid, proc_info.uid); // This (and the following) should be true
82 EXPECT_EQ(euid, proc_info.euid); // under reasonable circumstances.
83 // Can't say anything definite about its |rss|.
84 EXPECT_GT(proc_info.vsize, 0u); // Its |vsize| should be nonzero though.
85 }
OLDNEW
« no previous file with comments | « chrome/browser/process_info_snapshot_mac.cc ('k') | chrome/browser/resources/about_memory_mac.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698