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 "chrome_frame/crash_reporting/nt_loader.h" | 5 #include "chrome_frame/crash_reporting/nt_loader.h" |
6 | 6 |
7 #include <tlhelp32.h> | 7 #include <tlhelp32.h> |
8 #include <winnt.h> | 8 #include <winnt.h> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" |
11 #include "base/environment.h" | 13 #include "base/environment.h" |
12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
14 #include "base/string_util.h" | 16 #include "base/string_util.h" |
15 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
16 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
17 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
18 #include "base/win/scoped_handle.h" | 20 #include "base/win/scoped_handle.h" |
19 #include "chrome_frame/crash_reporting/crash_dll.h" | 21 #include "chrome_frame/crash_reporting/crash_dll.h" |
20 #include "gtest/gtest.h" | 22 #include "gtest/gtest.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 EXPECT_TRUE(OwnsCriticalSection(&cs)); | 76 EXPECT_TRUE(OwnsCriticalSection(&cs)); |
75 } | 77 } |
76 | 78 |
77 // Should no longer own it. | 79 // Should no longer own it. |
78 EXPECT_FALSE(OwnsCriticalSection(&cs)); | 80 EXPECT_FALSE(OwnsCriticalSection(&cs)); |
79 | 81 |
80 // Make another thread grab it. | 82 // Make another thread grab it. |
81 base::Thread other("Other threads"); | 83 base::Thread other("Other threads"); |
82 ASSERT_TRUE(other.Start()); | 84 ASSERT_TRUE(other.Start()); |
83 other.message_loop()->PostTask( | 85 other.message_loop()->PostTask( |
84 FROM_HERE, NewRunnableFunction(::EnterCriticalSection, &cs)); | 86 FROM_HERE, base::Bind(::EnterCriticalSection, &cs)); |
85 | 87 |
86 base::win::ScopedHandle event(::CreateEvent(NULL, FALSE, FALSE, NULL)); | 88 base::win::ScopedHandle event(::CreateEvent(NULL, FALSE, FALSE, NULL)); |
87 other.message_loop()->PostTask( | 89 other.message_loop()->PostTask( |
88 FROM_HERE, NewRunnableFunction(::SetEvent, event.Get())); | 90 FROM_HERE, base::IgnoreReturn<BOOL>(base::Bind(::SetEvent, event.Get()))); |
89 | 91 |
90 ASSERT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(event.Get(), INFINITE)); | 92 ASSERT_EQ(WAIT_OBJECT_0, ::WaitForSingleObject(event.Get(), INFINITE)); |
91 | 93 |
92 // We still shouldn't own it - the other thread does. | 94 // We still shouldn't own it - the other thread does. |
93 EXPECT_FALSE(OwnsCriticalSection(&cs)); | 95 EXPECT_FALSE(OwnsCriticalSection(&cs)); |
94 // And we shouldn't be able to enter it. | 96 // And we shouldn't be able to enter it. |
95 EXPECT_EQ(0, ::TryEnterCriticalSection(&cs)); | 97 EXPECT_EQ(0, ::TryEnterCriticalSection(&cs)); |
96 | 98 |
97 // Make the other thread release it. | 99 // Make the other thread release it. |
98 other.message_loop()->PostTask( | 100 other.message_loop()->PostTask( |
99 FROM_HERE, NewRunnableFunction(::LeaveCriticalSection, &cs)); | 101 FROM_HERE, base::Bind(::LeaveCriticalSection, &cs)); |
100 | 102 |
101 other.Stop(); | 103 other.Stop(); |
102 | 104 |
103 ::DeleteCriticalSection(&cs); | 105 ::DeleteCriticalSection(&cs); |
104 } | 106 } |
105 | 107 |
106 TEST(NtLoader, GetLoaderLock) { | 108 TEST(NtLoader, GetLoaderLock) { |
107 CRITICAL_SECTION* loader_lock = GetLoaderLock(); | 109 CRITICAL_SECTION* loader_lock = GetLoaderLock(); |
108 | 110 |
109 AssertIsCriticalSection(loader_lock); | 111 AssertIsCriticalSection(loader_lock); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 313 |
312 exceptions_handled = 0; | 314 exceptions_handled = 0; |
313 set_exception_function(OnCrashDuringUnloadLibrary); | 315 set_exception_function(OnCrashDuringUnloadLibrary); |
314 | 316 |
315 // We should crash during unload. | 317 // We should crash during unload. |
316 if (module != NULL) | 318 if (module != NULL) |
317 ::FreeLibrary(module); | 319 ::FreeLibrary(module); |
318 | 320 |
319 EXPECT_EQ(1, exceptions_handled); | 321 EXPECT_EQ(1, exceptions_handled); |
320 } | 322 } |
OLD | NEW |