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

Unified Diff: chrome/browser/process_info_snapshot_mac_unittest.cc

Issue 6052005: Proposal: Use /usr/bin/top in about:memory... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/process_info_snapshot_mac_unittest.cc
===================================================================
--- chrome/browser/process_info_snapshot_mac_unittest.cc (revision 71029)
+++ chrome/browser/process_info_snapshot_mac_unittest.cc (working copy)
@@ -10,7 +10,9 @@
#include <vector>
#include "base/command_line.h"
+#include "base/eintr_wrapper.h"
#include "base/file_path.h"
+#include "base/logging.h"
#include "base/process_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -77,6 +79,8 @@
// should occupy at least 100 kilobytes.
EXPECT_GE(proc_info.vsize, 1024u); // Sanity check: our |vsize| is presumably
// at least a megabyte.
+ EXPECT_GE(proc_info.rshrd, 1024u); // Shared memory should also > 1 MB.
+ EXPECT_GE(proc_info.rprvt, 1024u); // Same with private memory.
// Find our parent.
ASSERT_TRUE(snapshot.GetProcInfo(ppid, &proc_info));
@@ -88,12 +92,33 @@
EXPECT_GT(proc_info.vsize, 0u); // Its |vsize| should be nonzero though.
}
+// To verify that ProcessInfoSnapshot is getting the actual uid and effective
+// uid, this test runs top. top should have a uid of the caller and effective
+// uid of 0 (root).
TEST_F(ProcessInfoSnapshotMacTest, EffectiveVsRealUserIDTest) {
- // Run top which has a uid of the caller and effective uid of 0.
+ // Create a pipe to be able to read top's output.
+ int fds[2];
+ PCHECK(pipe(fds) == 0);
+ base::file_handle_mapping_vector fds_to_remap;
+ fds_to_remap.push_back(std::make_pair(fds[1], 1));
+
+ // Hook up top's stderr to the test process' stderr.
+ fds_to_remap.push_back(std::make_pair(fileno(stderr), 2));
+
+ std::vector<std::string> argv;
+ argv.push_back("/usr/bin/top");
+ argv.push_back("-l");
+ argv.push_back("0");
+
base::ProcessHandle process_handle;
- ASSERT_TRUE(base::LaunchApp(CommandLine(FilePath("/usr/bin/top")),
- false, false, &process_handle));
+ ASSERT_TRUE(base::LaunchApp(argv, fds_to_remap, false, &process_handle));
+ PCHECK(HANDLE_EINTR(close(fds[1])) == 0);
+ // Wait until there's some output form top. This is an easy way to tell that
+ // the exec() call is done and top is actually running.
+ char buf[1];
+ PCHECK(HANDLE_EINTR(read(fds[0], buf, 1)) == 1);
+
std::vector<base::ProcessId> pid_list;
pid_list.push_back(process_handle);
ProcessInfoSnapshot snapshot;
@@ -107,4 +132,5 @@
EXPECT_EQ(proc_info.uid, geteuid());
ASSERT_TRUE(base::KillProcess(process_handle, 0, true));
+ PCHECK(HANDLE_EINTR(close(fds[0])) == 0);
}
« 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