Index: base/win/scoped_handle_test_dll.cc |
diff --git a/base/win/scoped_handle_test_dll.cc b/base/win/scoped_handle_test_dll.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..603b47d932e55563d4cc8653fa88fa84964a1912 |
--- /dev/null |
+++ b/base/win/scoped_handle_test_dll.cc |
@@ -0,0 +1,86 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/win/scoped_handle_test_dll.h" |
+ |
+#include <windows.h> |
+ |
+#include "base/process/memory.h" |
+#include "base/win/scoped_handle.h" |
+ |
+namespace base { |
+namespace win { |
+namespace testing { |
+ |
+namespace { |
+ |
+// Note, this must use all native functions to avoid instantiating the |
+// ActiveVerifier. e.g. can't use base::Thread or even base::PlatformThread. |
+ |
+DWORD __stdcall ThreadFunc(void* params) { |
+ HANDLE handle = ::CreateMutex(nullptr, false, nullptr); |
+ HANDLE event = reinterpret_cast<HANDLE>(params); |
+ ::WaitForSingleObject(event, INFINITE); |
+ ScopedHandle handle_holder(handle); |
+ return 0; |
+} |
+ |
+Result InternalRunThreadTest() { |
scottmg
2016/03/11 19:02:18
This return value isn't useful.
Will Harris
2016/03/11 20:35:31
now it is, I check more.
|
+ std::vector<HANDLE> threads_; |
+ |
+ HANDLE start_event = ::CreateEvent(nullptr, true, false, nullptr); |
scottmg
2016/03/11 19:02:18
A comment here noting that `true` means we're goin
Will Harris
2016/03/11 20:35:31
Done.
|
+ |
+ for (size_t i = 0; i < 1000; i++) { |
+ HANDLE thread_handle = |
+ ::CreateThread(nullptr, 0, ThreadFunc, |
+ reinterpret_cast<void*>(start_event), 0, nullptr); |
+ threads_.push_back(thread_handle); |
+ } |
+ ::SetEvent(start_event); |
+ for (const auto& thread : threads_) { |
+ ::WaitForSingleObject(thread, INFINITE); |
+ ::CloseHandle(thread); |
+ } |
+ |
+ return Result::SUCCESS; |
+} |
+ |
+Result InternalRunLocationTest() { |
+ // Create a new handle and then set LastError again. |
+ HANDLE handle = ::CreateMutex(nullptr, false, nullptr); |
+ if (!handle) |
+ return Result::ERROR_COULD_NOT_CREATE_EVENT; |
+ ScopedHandle handle_holder(handle); |
+ |
+ HMODULE module = GetHandleVerifierModuleForTesting(); |
+ if (!module) |
+ return Result::ERROR_COULD_NOT_GET_HANDLE_VERIFIER_MODULE; |
+ |
+ // Get my module |
+ HMODULE my_module = GetModuleFromAddress(InternalRunLocationTest); |
+ if (!my_module) |
+ return Result::ERROR_COULD_NOT_GET_MY_MODULE; |
+ |
+#if defined(COMPONENT_BUILD) |
+ if (my_module != module) |
+ return Result::ERROR_WRONG_MODULE; |
+#else |
+ if (my_module == module) |
+ return Result::ERROR_WRONG_MODULE; |
+#endif |
+ return Result::SUCCESS; |
+} |
+ |
+} // namespace |
+ |
+Result RunTest() { |
+ Result result = InternalRunThreadTest(); |
+ if (result != Result::SUCCESS) |
+ return result; |
+ return InternalRunLocationTest(); |
+} |
+ |
scottmg
2016/03/11 19:02:18
TIL DllMain() is optional. Huh.
Will Harris
2016/03/11 20:35:32
Ack.
|
+} // testing |
+} // win |
+} // base |