OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file.h" | 6 #include "base/files/file.h" |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/test/multiprocess_test.h" | 10 #include "base/test/multiprocess_test.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 // Start a child process set to use the specified unlock action, and wait for | 146 // Start a child process set to use the specified unlock action, and wait for |
147 // it to lock the file. | 147 // it to lock the file. |
148 void StartChildAndSignalLock(const char* unlock_action) { | 148 void StartChildAndSignalLock(const char* unlock_action) { |
149 // Create a temporary dir and spin up a ChildLockExit subprocess against it. | 149 // Create a temporary dir and spin up a ChildLockExit subprocess against it. |
150 const FilePath temp_path = temp_dir_.GetPath(); | 150 const FilePath temp_path = temp_dir_.GetPath(); |
151 base::CommandLine child_command_line( | 151 base::CommandLine child_command_line( |
152 base::GetMultiProcessTestChildBaseCommandLine()); | 152 base::GetMultiProcessTestChildBaseCommandLine()); |
153 child_command_line.AppendSwitchPath(kTempDirFlag, temp_path); | 153 child_command_line.AppendSwitchPath(kTempDirFlag, temp_path); |
154 child_command_line.AppendSwitch(unlock_action); | 154 child_command_line.AppendSwitch(unlock_action); |
155 lock_child_ = | 155 |
156 base::SpawnMultiProcessTestChild(ChildMainString, child_command_line, | 156 base::SpawnChildResult spawn_result = base::SpawnMultiProcessTestChild( |
157 base::LaunchOptions()); | 157 ChildMainString, child_command_line, base::LaunchOptions()); |
| 158 lock_child_ = std::move(spawn_result.process); |
158 ASSERT_TRUE(lock_child_.IsValid()); | 159 ASSERT_TRUE(lock_child_.IsValid()); |
159 | 160 |
160 // Wait for the child to lock the file. | 161 // Wait for the child to lock the file. |
161 ASSERT_TRUE(WaitForEventOrTimeout(kSignalLockFileLocked)); | 162 ASSERT_TRUE(WaitForEventOrTimeout(kSignalLockFileLocked)); |
162 } | 163 } |
163 | 164 |
164 // Signal the child to exit cleanly. | 165 // Signal the child to exit cleanly. |
165 void ExitChildCleanly() { | 166 void ExitChildCleanly() { |
166 ASSERT_TRUE(SignalEvent(kSignalExit)); | 167 ASSERT_TRUE(SignalEvent(kSignalExit)); |
167 int rv = -1; | 168 int rv = -1; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // Test that killing the process releases the lock. This should cover crashing. | 218 // Test that killing the process releases the lock. This should cover crashing. |
218 TEST_F(FileLockingTest, UnlockOnTerminate) { | 219 TEST_F(FileLockingTest, UnlockOnTerminate) { |
219 // The child will wait for an exit which never arrives. | 220 // The child will wait for an exit which never arrives. |
220 StartChildAndSignalLock(kExitUnlock); | 221 StartChildAndSignalLock(kExitUnlock); |
221 | 222 |
222 ASSERT_NE(File::FILE_OK, lock_file_.Lock()); | 223 ASSERT_NE(File::FILE_OK, lock_file_.Lock()); |
223 ASSERT_TRUE(TerminateMultiProcessTestChild(lock_child_, 0, true)); | 224 ASSERT_TRUE(TerminateMultiProcessTestChild(lock_child_, 0, true)); |
224 ASSERT_EQ(File::FILE_OK, lock_file_.Lock()); | 225 ASSERT_EQ(File::FILE_OK, lock_file_.Lock()); |
225 ASSERT_EQ(File::FILE_OK, lock_file_.Unlock()); | 226 ASSERT_EQ(File::FILE_OK, lock_file_.Unlock()); |
226 } | 227 } |
OLD | NEW |