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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 ASSERT_TRUE(lock_child_.IsValid()); | 158 ASSERT_TRUE(lock_child_.IsValid()); |
159 | 159 |
160 // Wait for the child to lock the file. | 160 // Wait for the child to lock the file. |
161 ASSERT_TRUE(WaitForEventOrTimeout(kSignalLockFileLocked)); | 161 ASSERT_TRUE(WaitForEventOrTimeout(kSignalLockFileLocked)); |
162 } | 162 } |
163 | 163 |
164 // Signal the child to exit cleanly. | 164 // Signal the child to exit cleanly. |
165 void ExitChildCleanly() { | 165 void ExitChildCleanly() { |
166 ASSERT_TRUE(SignalEvent(kSignalExit)); | 166 ASSERT_TRUE(SignalEvent(kSignalExit)); |
167 int rv = -1; | 167 int rv = -1; |
168 ASSERT_TRUE(lock_child_.WaitForExitWithTimeout( | 168 ASSERT_TRUE(WaitForMultiprocessTestChildExit( |
169 TestTimeouts::action_timeout(), &rv)); | 169 lock_child_, TestTimeouts::action_timeout(), &rv)); |
170 ASSERT_EQ(0, rv); | 170 ASSERT_EQ(0, rv); |
171 } | 171 } |
172 | 172 |
173 base::ScopedTempDir temp_dir_; | 173 base::ScopedTempDir temp_dir_; |
174 base::File lock_file_; | 174 base::File lock_file_; |
175 base::Process lock_child_; | 175 base::Process lock_child_; |
176 | 176 |
177 private: | 177 private: |
178 DISALLOW_COPY_AND_ASSIGN(FileLockingTest); | 178 DISALLOW_COPY_AND_ASSIGN(FileLockingTest); |
179 }; | 179 }; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 ASSERT_EQ(File::FILE_OK, lock_file_.Lock()); | 213 ASSERT_EQ(File::FILE_OK, lock_file_.Lock()); |
214 ASSERT_EQ(File::FILE_OK, lock_file_.Unlock()); | 214 ASSERT_EQ(File::FILE_OK, lock_file_.Unlock()); |
215 } | 215 } |
216 | 216 |
217 // Test that killing the process releases the lock. This should cover crashing. | 217 // Test that killing the process releases the lock. This should cover crashing. |
218 TEST_F(FileLockingTest, UnlockOnTerminate) { | 218 TEST_F(FileLockingTest, UnlockOnTerminate) { |
219 // The child will wait for an exit which never arrives. | 219 // The child will wait for an exit which never arrives. |
220 StartChildAndSignalLock(kExitUnlock); | 220 StartChildAndSignalLock(kExitUnlock); |
221 | 221 |
222 ASSERT_NE(File::FILE_OK, lock_file_.Lock()); | 222 ASSERT_NE(File::FILE_OK, lock_file_.Lock()); |
223 ASSERT_TRUE(lock_child_.Terminate(0, true)); | 223 ASSERT_TRUE(TerminateMultiProcessTestChild(lock_child_, 0, true)); |
224 ASSERT_EQ(File::FILE_OK, lock_file_.Lock()); | 224 ASSERT_EQ(File::FILE_OK, lock_file_.Lock()); |
225 ASSERT_EQ(File::FILE_OK, lock_file_.Unlock()); | 225 ASSERT_EQ(File::FILE_OK, lock_file_.Unlock()); |
226 } | 226 } |
OLD | NEW |