OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
6 #include <winternl.h> | 6 #include <winternl.h> |
7 | 7 |
| 8 #include "base/base_switches.h" |
| 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/scoped_native_library.h" |
| 12 #include "base/test/multiprocess_test.h" |
| 13 #include "base/test/test_timeouts.h" |
8 #include "base/win/scoped_handle.h" | 14 #include "base/win/scoped_handle.h" |
9 | 15 |
10 #include <utility> | |
11 | |
12 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "testing/multiprocess_func_list.h" |
13 | 18 |
14 namespace base { | 19 namespace base { |
15 namespace win { | 20 namespace win { |
16 | 21 |
| 22 namespace testing { |
| 23 extern "C" bool __declspec(dllexport) RunTest(); |
| 24 } // namespace testing |
| 25 |
17 TEST(ScopedHandleTest, ScopedHandle) { | 26 TEST(ScopedHandleTest, ScopedHandle) { |
18 // Any illegal error code will do. We just need to test that it is preserved | 27 // Any illegal error code will do. We just need to test that it is preserved |
19 // by ScopedHandle to avoid bug 528394. | 28 // by ScopedHandle to avoid bug 528394. |
20 const DWORD magic_error = 0x12345678; | 29 const DWORD magic_error = 0x12345678; |
21 | 30 |
22 HANDLE handle = ::CreateMutex(nullptr, false, nullptr); | 31 HANDLE handle = ::CreateMutex(nullptr, false, nullptr); |
23 // Call SetLastError after creating the handle. | 32 // Call SetLastError after creating the handle. |
24 ::SetLastError(magic_error); | 33 ::SetLastError(magic_error); |
25 base::win::ScopedHandle handle_holder(handle); | 34 base::win::ScopedHandle handle_holder(handle); |
26 EXPECT_EQ(magic_error, ::GetLastError()); | 35 EXPECT_EQ(magic_error, ::GetLastError()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 ASSERT_NE(HANDLE(nullptr), handle); | 92 ASSERT_NE(HANDLE(nullptr), handle); |
84 | 93 |
85 ASSERT_DEATH({ | 94 ASSERT_DEATH({ |
86 base::win::ScopedHandle handle_holder; | 95 base::win::ScopedHandle handle_holder; |
87 handle_holder.handle_ = handle; | 96 handle_holder.handle_ = handle; |
88 }, ""); | 97 }, ""); |
89 | 98 |
90 ASSERT_TRUE(::CloseHandle(handle)); | 99 ASSERT_TRUE(::CloseHandle(handle)); |
91 } | 100 } |
92 | 101 |
| 102 TEST(ScopedHandleTest, MultiProcess) { |
| 103 // Initializing ICU in the child process causes a scoped handle to be created |
| 104 // before the test gets a chance to test the race condition, so disable ICU |
| 105 // for the child process here. |
| 106 CommandLine command_line(base::GetMultiProcessTestChildBaseCommandLine()); |
| 107 command_line.AppendSwitch(switches::kTestDoNotInitializeIcu); |
| 108 |
| 109 base::Process test_child_process = base::SpawnMultiProcessTestChild( |
| 110 "ActiveVerifierChildProcess", command_line, LaunchOptions()); |
| 111 |
| 112 int rv = -1; |
| 113 ASSERT_TRUE(test_child_process.WaitForExitWithTimeout( |
| 114 TestTimeouts::action_timeout(), &rv)); |
| 115 EXPECT_EQ(0, rv); |
| 116 } |
| 117 |
| 118 MULTIPROCESS_TEST_MAIN(ActiveVerifierChildProcess) { |
| 119 ScopedNativeLibrary module(FilePath(L"scoped_handle_test_dll.dll")); |
| 120 |
| 121 if (!module.is_valid()) |
| 122 return 1; |
| 123 auto run_test_function = reinterpret_cast<decltype(&testing::RunTest)>( |
| 124 module.GetFunctionPointer("RunTest")); |
| 125 if (!run_test_function) |
| 126 return 1; |
| 127 if (!run_test_function()) |
| 128 return 1; |
| 129 |
| 130 return 0; |
| 131 } |
| 132 |
93 } // namespace win | 133 } // namespace win |
94 } // namespace base | 134 } // namespace base |
OLD | NEW |