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

Side by Side Diff: base/process/process_util_unittest.cc

Issue 1543293004: Switch to standard integer types in base/process/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ssize_t Created 5 years 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/process_unittest.cc ('k') | no next file » | 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) 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 #define _CRT_SECURE_NO_WARNINGS 5 #define _CRT_SECURE_NO_WARNINGS
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
7 #include <limits> 10 #include <limits>
8 11
9 #include "base/command_line.h" 12 #include "base/command_line.h"
10 #include "base/debug/alias.h" 13 #include "base/debug/alias.h"
11 #include "base/debug/stack_trace.h" 14 #include "base/debug/stack_trace.h"
12 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
14 #include "base/files/scoped_file.h" 17 #include "base/files/scoped_file.h"
15 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/macros.h"
16 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
17 #include "base/path_service.h" 21 #include "base/path_service.h"
18 #include "base/posix/eintr_wrapper.h" 22 #include "base/posix/eintr_wrapper.h"
19 #include "base/process/kill.h" 23 #include "base/process/kill.h"
20 #include "base/process/launch.h" 24 #include "base/process/launch.h"
21 #include "base/process/memory.h" 25 #include "base/process/memory.h"
22 #include "base/process/process.h" 26 #include "base/process/process.h"
23 #include "base/process/process_metrics.h" 27 #include "base/process/process_metrics.h"
24 #include "base/strings/string_number_conversions.h" 28 #include "base/strings/string_number_conversions.h"
25 #include "base/strings/utf_string_conversions.h" 29 #include "base/strings/utf_string_conversions.h"
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 420 }
417 421
418 static const char kEventToTriggerHandleSwitch[] = "event-to-trigger-handle"; 422 static const char kEventToTriggerHandleSwitch[] = "event-to-trigger-handle";
419 423
420 MULTIPROCESS_TEST_MAIN(TriggerEventChildProcess) { 424 MULTIPROCESS_TEST_MAIN(TriggerEventChildProcess) {
421 std::string handle_value_string = 425 std::string handle_value_string =
422 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 426 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
423 kEventToTriggerHandleSwitch); 427 kEventToTriggerHandleSwitch);
424 CHECK(!handle_value_string.empty()); 428 CHECK(!handle_value_string.empty());
425 429
426 uint64 handle_value_uint64; 430 uint64_t handle_value_uint64;
427 CHECK(base::StringToUint64(handle_value_string, &handle_value_uint64)); 431 CHECK(base::StringToUint64(handle_value_string, &handle_value_uint64));
428 // Give ownership of the handle to |event|. 432 // Give ownership of the handle to |event|.
429 base::WaitableEvent event(base::win::ScopedHandle( 433 base::WaitableEvent event(base::win::ScopedHandle(
430 reinterpret_cast<HANDLE>(handle_value_uint64))); 434 reinterpret_cast<HANDLE>(handle_value_uint64)));
431 435
432 event.Signal(); 436 event.Signal();
433 437
434 return 0; 438 return 0;
435 } 439 }
436 440
437 TEST_F(ProcessUtilTest, InheritSpecifiedHandles) { 441 TEST_F(ProcessUtilTest, InheritSpecifiedHandles) {
438 // Manually create the event, so that it can be inheritable. 442 // Manually create the event, so that it can be inheritable.
439 SECURITY_ATTRIBUTES security_attributes = {}; 443 SECURITY_ATTRIBUTES security_attributes = {};
440 security_attributes.nLength = static_cast<DWORD>(sizeof(security_attributes)); 444 security_attributes.nLength = static_cast<DWORD>(sizeof(security_attributes));
441 security_attributes.lpSecurityDescriptor = NULL; 445 security_attributes.lpSecurityDescriptor = NULL;
442 security_attributes.bInheritHandle = true; 446 security_attributes.bInheritHandle = true;
443 447
444 // Takes ownership of the event handle. 448 // Takes ownership of the event handle.
445 base::WaitableEvent event(base::win::ScopedHandle( 449 base::WaitableEvent event(base::win::ScopedHandle(
446 CreateEvent(&security_attributes, true, false, NULL))); 450 CreateEvent(&security_attributes, true, false, NULL)));
447 base::HandlesToInheritVector handles_to_inherit; 451 base::HandlesToInheritVector handles_to_inherit;
448 handles_to_inherit.push_back(event.handle()); 452 handles_to_inherit.push_back(event.handle());
449 base::LaunchOptions options; 453 base::LaunchOptions options;
450 options.handles_to_inherit = &handles_to_inherit; 454 options.handles_to_inherit = &handles_to_inherit;
451 455
452 base::CommandLine cmd_line = MakeCmdLine("TriggerEventChildProcess"); 456 base::CommandLine cmd_line = MakeCmdLine("TriggerEventChildProcess");
453 cmd_line.AppendSwitchASCII(kEventToTriggerHandleSwitch, 457 cmd_line.AppendSwitchASCII(
454 base::Uint64ToString(reinterpret_cast<uint64>(event.handle()))); 458 kEventToTriggerHandleSwitch,
459 base::Uint64ToString(reinterpret_cast<uint64_t>(event.handle())));
455 460
456 // This functionality actually requires Vista or later. Make sure that it 461 // This functionality actually requires Vista or later. Make sure that it
457 // fails properly on XP. 462 // fails properly on XP.
458 if (base::win::GetVersion() < base::win::VERSION_VISTA) { 463 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
459 EXPECT_FALSE(base::LaunchProcess(cmd_line, options).IsValid()); 464 EXPECT_FALSE(base::LaunchProcess(cmd_line, options).IsValid());
460 return; 465 return;
461 } 466 }
462 467
463 // Launch the process and wait for it to trigger the event. 468 // Launch the process and wait for it to trigger the event.
464 ASSERT_TRUE(base::LaunchProcess(cmd_line, options).IsValid()); 469 ASSERT_TRUE(base::LaunchProcess(cmd_line, options).IsValid());
465 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); 470 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout()));
466 } 471 }
467 #endif // defined(OS_WIN) 472 #endif // defined(OS_WIN)
468 473
469 #if defined(OS_POSIX) 474 #if defined(OS_POSIX)
470 475
471 namespace { 476 namespace {
472 477
473 // Returns the maximum number of files that a process can have open. 478 // Returns the maximum number of files that a process can have open.
474 // Returns 0 on error. 479 // Returns 0 on error.
475 int GetMaxFilesOpenInProcess() { 480 int GetMaxFilesOpenInProcess() {
476 struct rlimit rlim; 481 struct rlimit rlim;
477 if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) { 482 if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
478 return 0; 483 return 0;
479 } 484 }
480 485
481 // rlim_t is a uint64 - clip to maxint. We do this since FD #s are ints 486 // rlim_t is a uint64_t - clip to maxint. We do this since FD #s are ints
482 // which are all 32 bits on the supported platforms. 487 // which are all 32 bits on the supported platforms.
483 rlim_t max_int = static_cast<rlim_t>(std::numeric_limits<int32>::max()); 488 rlim_t max_int = static_cast<rlim_t>(std::numeric_limits<int32_t>::max());
484 if (rlim.rlim_cur > max_int) { 489 if (rlim.rlim_cur > max_int) {
485 return max_int; 490 return max_int;
486 } 491 }
487 492
488 return rlim.rlim_cur; 493 return rlim.rlim_cur;
489 } 494 }
490 495
491 const int kChildPipe = 20; // FD # for write end of pipe in child process. 496 const int kChildPipe = 20; // FD # for write end of pipe in child process.
492 497
493 #if defined(OS_MACOSX) 498 #if defined(OS_MACOSX)
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 options.current_directory = base::FilePath("/dev/null"); 1125 options.current_directory = base::FilePath("/dev/null");
1121 1126
1122 base::Process process(SpawnChildWithOptions("SimpleChildProcess", options)); 1127 base::Process process(SpawnChildWithOptions("SimpleChildProcess", options));
1123 ASSERT_TRUE(process.IsValid()); 1128 ASSERT_TRUE(process.IsValid());
1124 1129
1125 int exit_code = kSuccess; 1130 int exit_code = kSuccess;
1126 EXPECT_TRUE(process.WaitForExit(&exit_code)); 1131 EXPECT_TRUE(process.WaitForExit(&exit_code));
1127 EXPECT_NE(kSuccess, exit_code); 1132 EXPECT_NE(kSuccess, exit_code);
1128 } 1133 }
1129 #endif 1134 #endif
OLDNEW
« no previous file with comments | « base/process/process_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698