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

Side by Side Diff: sandbox/mac/bootstrap_sandbox_unittest.mm

Issue 2733323002: Changing multiprocess test SpawnChild to return a struct. (Closed)
Patch Set: Fixed bots. Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "sandbox/mac/bootstrap_sandbox.h" 5 #include "sandbox/mac/bootstrap_sandbox.h"
6 6
7 #include <CoreFoundation/CoreFoundation.h> 7 #include <CoreFoundation/CoreFoundation.h>
8 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 #include <mach/mach.h> 9 #include <mach/mach.h>
10 #include <servers/bootstrap.h> 10 #include <servers/bootstrap.h>
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 void RunChildWithPolicy(int policy_id, 98 void RunChildWithPolicy(int policy_id,
99 const char* child_name, 99 const char* child_name,
100 base::ProcessHandle* out_pid) { 100 base::ProcessHandle* out_pid) {
101 std::unique_ptr<PreExecDelegate> pre_exec_delegate( 101 std::unique_ptr<PreExecDelegate> pre_exec_delegate(
102 sandbox_->NewClient(policy_id)); 102 sandbox_->NewClient(policy_id));
103 103
104 base::LaunchOptions options; 104 base::LaunchOptions options;
105 options.pre_exec_delegate = pre_exec_delegate.get(); 105 options.pre_exec_delegate = pre_exec_delegate.get();
106 106
107 base::Process process = SpawnChildWithOptions(child_name, options); 107 base::SpawnChildResult spawn_result =
108 SpawnChildWithOptions(child_name, options);
109 base::Process process = std::move(spawn_result.process);
108 ASSERT_TRUE(process.IsValid()); 110 ASSERT_TRUE(process.IsValid());
109 int code = 0; 111 int code = 0;
110 EXPECT_TRUE(process.WaitForExit(&code)); 112 EXPECT_TRUE(process.WaitForExit(&code));
111 EXPECT_EQ(0, code); 113 EXPECT_EQ(0, code);
112 if (out_pid) 114 if (out_pid)
113 *out_pid = process.Pid(); 115 *out_pid = process.Pid();
114 } 116 }
115 117
116 protected: 118 protected:
117 std::unique_ptr<BootstrapSandbox> sandbox_; 119 std::unique_ptr<BootstrapSandbox> sandbox_;
118 }; 120 };
119 121
120 const char kNotificationTestMain[] = "PostNotification"; 122 const char kNotificationTestMain[] = "PostNotification";
121 123
122 // Run the test without the sandbox. 124 // Run the test without the sandbox.
123 TEST_F(BootstrapSandboxTest, DistributedNotifications_Unsandboxed) { 125 TEST_F(BootstrapSandboxTest, DistributedNotifications_Unsandboxed) {
124 base::scoped_nsobject<DistributedNotificationObserver> observer( 126 base::scoped_nsobject<DistributedNotificationObserver> observer(
125 [[DistributedNotificationObserver alloc] init]); 127 [[DistributedNotificationObserver alloc] init]);
126 128
127 base::Process process = SpawnChild(kNotificationTestMain); 129 base::SpawnChildResult spawn_result = SpawnChild(kNotificationTestMain);
130 base::Process process = std::move(spawn_result.process);
128 ASSERT_TRUE(process.IsValid()); 131 ASSERT_TRUE(process.IsValid());
129 int code = 0; 132 int code = 0;
130 EXPECT_TRUE(process.WaitForExit(&code)); 133 EXPECT_TRUE(process.WaitForExit(&code));
131 EXPECT_EQ(0, code); 134 EXPECT_EQ(0, code);
132 135
133 [observer waitForNotification]; 136 [observer waitForNotification];
134 EXPECT_EQ(1, [observer receivedCount]); 137 EXPECT_EQ(1, [observer receivedCount]);
135 EXPECT_EQ(process.Pid(), [[observer object] intValue]); 138 EXPECT_EQ(process.Pid(), [[observer object] intValue]);
136 } 139 }
137 140
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 // Set up the policy and register the port. 467 // Set up the policy and register the port.
465 BootstrapSandboxPolicy policy(BaselinePolicy()); 468 BootstrapSandboxPolicy policy(BaselinePolicy());
466 policy.rules["sync"] = Rule(port); 469 policy.rules["sync"] = Rule(port);
467 sandbox_->RegisterSandboxPolicy(kTestPolicyId, policy); 470 sandbox_->RegisterSandboxPolicy(kTestPolicyId, policy);
468 471
469 // Launch the child. 472 // Launch the child.
470 std::unique_ptr<PreExecDelegate> pre_exec_delegate( 473 std::unique_ptr<PreExecDelegate> pre_exec_delegate(
471 sandbox_->NewClient(kTestPolicyId)); 474 sandbox_->NewClient(kTestPolicyId));
472 base::LaunchOptions options; 475 base::LaunchOptions options;
473 options.pre_exec_delegate = pre_exec_delegate.get(); 476 options.pre_exec_delegate = pre_exec_delegate.get();
474 base::Process process = SpawnChildWithOptions("ChildOutliveSandbox", options); 477 base::SpawnChildResult spawn_result =
478 SpawnChildWithOptions("ChildOutliveSandbox", options);
479 base::Process process = std::move(spawn_result.process);
475 ASSERT_TRUE(process.IsValid()); 480 ASSERT_TRUE(process.IsValid());
476 481
477 // Synchronize with the child. 482 // Synchronize with the child.
478 mach_msg_empty_rcv_t rcv_msg; 483 mach_msg_empty_rcv_t rcv_msg;
479 bzero(&rcv_msg, sizeof(rcv_msg)); 484 bzero(&rcv_msg, sizeof(rcv_msg));
480 kern_return_t kr = mach_msg(&rcv_msg.header, MACH_RCV_MSG, 0, 485 kern_return_t kr = mach_msg(&rcv_msg.header, MACH_RCV_MSG, 0,
481 sizeof(rcv_msg), port, 486 sizeof(rcv_msg), port,
482 TestTimeouts::tiny_timeout().InMilliseconds(), MACH_PORT_NULL); 487 TestTimeouts::tiny_timeout().InMilliseconds(), MACH_PORT_NULL);
483 ASSERT_EQ(KERN_SUCCESS, kr) << mach_error_string(kr); 488 ASSERT_EQ(KERN_SUCCESS, kr) << mach_error_string(kr);
484 489
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 kr = mach_msg_receive(&rcv_msg.header); 545 kr = mach_msg_receive(&rcv_msg.header);
541 MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_msg_receive"; 546 MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_msg_receive";
542 547
543 // Try to message the sandbox. 548 // Try to message the sandbox.
544 bootstrap_look_up(bootstrap_port, "test", &port); 549 bootstrap_look_up(bootstrap_port, "test", &port);
545 550
546 return 0; 551 return 0;
547 } 552 }
548 553
549 } // namespace sandbox 554 } // namespace sandbox
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698