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

Side by Side Diff: base/process_util_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
« no previous file with comments | « base/process_util_posix.cc ('k') | chrome/browser/browser_resources.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/eintr_wrapper.h" 8 #include "base/eintr_wrapper.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/multiprocess_test.h" 10 #include "base/multiprocess_test.h"
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 EXPECT_FALSE(GetAppOutput(CommandLine(FilePath("false")), &output)); 280 EXPECT_FALSE(GetAppOutput(CommandLine(FilePath("false")), &output));
281 281
282 std::vector<std::string> argv; 282 std::vector<std::string> argv;
283 argv.push_back("/bin/echo"); 283 argv.push_back("/bin/echo");
284 argv.push_back("-n"); 284 argv.push_back("-n");
285 argv.push_back("foobar42"); 285 argv.push_back("foobar42");
286 EXPECT_TRUE(GetAppOutput(CommandLine(argv), &output)); 286 EXPECT_TRUE(GetAppOutput(CommandLine(argv), &output));
287 EXPECT_STREQ("foobar42", output.c_str()); 287 EXPECT_STREQ("foobar42", output.c_str());
288 } 288 }
289 289
290 TEST_F(ProcessUtilTest, GetAppOutputRestricted) {
291 // Unfortunately, since we can't rely on the path, we need to know where
292 // everything is. So let's use /bin/sh, which is on every POSIX system, and
293 // its built-ins.
294 std::vector<std::string> argv;
295 argv.push_back("/bin/sh"); // argv[0]
296 argv.push_back("-c"); // argv[1]
297
298 // On success, should set |output|. We use |/bin/sh -c 'exit 0'| instead of
299 // |true| since the location of the latter may be |/bin| or |/usr/bin| (and we
300 // need absolute paths).
301 argv.push_back("exit 0"); // argv[2]; equivalent to "true"
302 std::string output = "abc";
303 EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 100));
304 EXPECT_STREQ("", output.c_str());
305
306 // On failure, should not touch |output|. As above, but for |false|.
307 argv[2] = "exit 1"; // equivalent to "false"
308 output = "abc";
309 EXPECT_FALSE(GetAppOutputRestricted(CommandLine(argv),
310 &output, 100));
311 EXPECT_STREQ("abc", output.c_str());
312
313 // Amount of output exactly equal to space allowed.
314 argv[2] = "echo 123456789"; // (the sh built-in doesn't take "-n")
315 output.clear();
316 EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 10));
317 EXPECT_STREQ("123456789\n", output.c_str());
318
319 // Amount of output greater than space allowed.
320 output.clear();
321 EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 5));
322 EXPECT_STREQ("12345", output.c_str());
323
324 // Amount of output less than space allowed.
325 output.clear();
326 EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 15));
327 EXPECT_STREQ("123456789\n", output.c_str());
328
329 // Zero space allowed.
330 output = "abc";
331 EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 0));
332 EXPECT_STREQ("", output.c_str());
333 }
334
290 #if defined(OS_LINUX) 335 #if defined(OS_LINUX)
291 TEST_F(ProcessUtilTest, GetParentProcessId) { 336 TEST_F(ProcessUtilTest, GetParentProcessId) {
292 base::ProcessId ppid = GetParentProcessId(GetCurrentProcId()); 337 base::ProcessId ppid = GetParentProcessId(GetCurrentProcId());
293 EXPECT_EQ(ppid, getppid()); 338 EXPECT_EQ(ppid, getppid());
294 } 339 }
295 340
296 TEST_F(ProcessUtilTest, ParseProcStatCPU) { 341 TEST_F(ProcessUtilTest, ParseProcStatCPU) {
297 // /proc/self/stat for a process running "top". 342 // /proc/self/stat for a process running "top".
298 const char kTopStat[] = "960 (top) S 16230 960 16230 34818 960 " 343 const char kTopStat[] = "960 (top) S 16230 960 16230 34818 960 "
299 "4202496 471 0 0 0 " 344 "4202496 471 0 0 0 "
(...skipping 10 matching lines...) Expand all
310 "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 " 355 "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 "
311 "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0"; 356 "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0";
312 357
313 EXPECT_EQ(0, ParseProcStatCPU(kSelfStat)); 358 EXPECT_EQ(0, ParseProcStatCPU(kSelfStat));
314 } 359 }
315 #endif 360 #endif
316 361
317 #endif // defined(OS_POSIX) 362 #endif // defined(OS_POSIX)
318 363
319 } // namespace base 364 } // namespace base
OLDNEW
« no previous file with comments | « base/process_util_posix.cc ('k') | chrome/browser/browser_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698