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

Side by Side Diff: base/win/scoped_handle_test_dll.cc

Issue 1779333003: Add test for multithreaded ActiveVerifier behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@handlecreate
Patch Set: nits Created 4 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/win/scoped_handle_test_dll.h"
6
7 #include <windows.h>
8
9 #include "base/process/memory.h"
10 #include "base/win/scoped_handle.h"
11
12 namespace base {
13 namespace win {
14 namespace testing {
15
16 namespace {
17
18 // Note, this must use all native functions to avoid instantiating the
19 // ActiveVerifier. e.g. can't use base::Thread or even base::PlatformThread.
20
21 DWORD __stdcall ThreadFunc(void* params) {
22 HANDLE handle = ::CreateMutex(nullptr, false, nullptr);
23 HANDLE event = reinterpret_cast<HANDLE>(params);
24 ::WaitForSingleObject(event, INFINITE);
25 ScopedHandle handle_holder(handle);
26 return 0;
27 }
28
29 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.
30 std::vector<HANDLE> threads_;
31
32 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.
33
34 for (size_t i = 0; i < 1000; i++) {
35 HANDLE thread_handle =
36 ::CreateThread(nullptr, 0, ThreadFunc,
37 reinterpret_cast<void*>(start_event), 0, nullptr);
38 threads_.push_back(thread_handle);
39 }
40 ::SetEvent(start_event);
41 for (const auto& thread : threads_) {
42 ::WaitForSingleObject(thread, INFINITE);
43 ::CloseHandle(thread);
44 }
45
46 return Result::SUCCESS;
47 }
48
49 Result InternalRunLocationTest() {
50 // Create a new handle and then set LastError again.
51 HANDLE handle = ::CreateMutex(nullptr, false, nullptr);
52 if (!handle)
53 return Result::ERROR_COULD_NOT_CREATE_EVENT;
54 ScopedHandle handle_holder(handle);
55
56 HMODULE module = GetHandleVerifierModuleForTesting();
57 if (!module)
58 return Result::ERROR_COULD_NOT_GET_HANDLE_VERIFIER_MODULE;
59
60 // Get my module
61 HMODULE my_module = GetModuleFromAddress(InternalRunLocationTest);
62 if (!my_module)
63 return Result::ERROR_COULD_NOT_GET_MY_MODULE;
64
65 #if defined(COMPONENT_BUILD)
66 if (my_module != module)
67 return Result::ERROR_WRONG_MODULE;
68 #else
69 if (my_module == module)
70 return Result::ERROR_WRONG_MODULE;
71 #endif
72 return Result::SUCCESS;
73 }
74
75 } // namespace
76
77 Result RunTest() {
78 Result result = InternalRunThreadTest();
79 if (result != Result::SUCCESS)
80 return result;
81 return InternalRunLocationTest();
82 }
83
scottmg 2016/03/11 19:02:18 TIL DllMain() is optional. Huh.
Will Harris 2016/03/11 20:35:32 Ack.
84 } // testing
85 } // win
86 } // base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698