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

Side by Side Diff: sandbox/win/src/threadpool_unittest.cc

Issue 1851213002: Remove sandbox on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nacl compile issues Created 4 years, 8 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
« no previous file with comments | « sandbox/win/src/target_services.cc ('k') | sandbox/win/src/top_level_dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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 <stdint.h>
6
7 #include "sandbox/win/src/win2k_threadpool.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 void __stdcall EmptyCallBack(void*, unsigned char) {
11 }
12
13 void __stdcall TestCallBack(void* context, unsigned char) {
14 HANDLE event = reinterpret_cast<HANDLE>(context);
15 ::SetEvent(event);
16 }
17
18 namespace sandbox {
19
20 // Test that register and unregister work, part 1.
21 TEST(IPCTest, ThreadPoolRegisterTest1) {
22 Win2kThreadPool thread_pool;
23
24 EXPECT_EQ(0u, thread_pool.OutstandingWaits());
25
26 HANDLE event1 = ::CreateEventW(NULL, FALSE, FALSE, NULL);
27 HANDLE event2 = ::CreateEventW(NULL, FALSE, FALSE, NULL);
28
29 uint32_t context = 0;
30 EXPECT_FALSE(thread_pool.RegisterWait(0, event1, EmptyCallBack, &context));
31 EXPECT_EQ(0u, thread_pool.OutstandingWaits());
32
33 EXPECT_TRUE(thread_pool.RegisterWait(this, event1, EmptyCallBack, &context));
34 EXPECT_EQ(1u, thread_pool.OutstandingWaits());
35 EXPECT_TRUE(thread_pool.RegisterWait(this, event2, EmptyCallBack, &context));
36 EXPECT_EQ(2u, thread_pool.OutstandingWaits());
37
38 EXPECT_TRUE(thread_pool.UnRegisterWaits(this));
39 EXPECT_EQ(0u, thread_pool.OutstandingWaits());
40
41 EXPECT_EQ(TRUE, ::CloseHandle(event1));
42 EXPECT_EQ(TRUE, ::CloseHandle(event2));
43 }
44
45 // Test that register and unregister work, part 2.
46 TEST(IPCTest, ThreadPoolRegisterTest2) {
47 Win2kThreadPool thread_pool;
48
49 HANDLE event1 = ::CreateEventW(NULL, FALSE, FALSE, NULL);
50 HANDLE event2 = ::CreateEventW(NULL, FALSE, FALSE, NULL);
51
52 uint32_t context = 0;
53 uint32_t c1 = 0;
54 uint32_t c2 = 0;
55
56 EXPECT_TRUE(thread_pool.RegisterWait(&c1, event1, EmptyCallBack, &context));
57 EXPECT_EQ(1u, thread_pool.OutstandingWaits());
58 EXPECT_TRUE(thread_pool.RegisterWait(&c2, event2, EmptyCallBack, &context));
59 EXPECT_EQ(2u, thread_pool.OutstandingWaits());
60
61 EXPECT_TRUE(thread_pool.UnRegisterWaits(&c2));
62 EXPECT_EQ(1u, thread_pool.OutstandingWaits());
63 EXPECT_TRUE(thread_pool.UnRegisterWaits(&c2));
64 EXPECT_EQ(1u, thread_pool.OutstandingWaits());
65
66 EXPECT_TRUE(thread_pool.UnRegisterWaits(&c1));
67 EXPECT_EQ(0u, thread_pool.OutstandingWaits());
68
69 EXPECT_EQ(TRUE, ::CloseHandle(event1));
70 EXPECT_EQ(TRUE, ::CloseHandle(event2));
71 }
72
73 // Test that the thread pool has at least a thread that services an event.
74 // Test that when the event is un-registered is no longer serviced.
75 TEST(IPCTest, ThreadPoolSignalAndWaitTest) {
76 Win2kThreadPool thread_pool;
77
78 // The events are auto reset and start not signaled.
79 HANDLE event1 = ::CreateEventW(NULL, FALSE, FALSE, NULL);
80 HANDLE event2 = ::CreateEventW(NULL, FALSE, FALSE, NULL);
81
82 EXPECT_TRUE(thread_pool.RegisterWait(this, event1, TestCallBack, event2));
83
84 EXPECT_EQ(WAIT_OBJECT_0, ::SignalObjectAndWait(event1, event2, 5000, FALSE));
85 EXPECT_EQ(WAIT_OBJECT_0, ::SignalObjectAndWait(event1, event2, 5000, FALSE));
86
87 EXPECT_TRUE(thread_pool.UnRegisterWaits(this));
88 EXPECT_EQ(0u, thread_pool.OutstandingWaits());
89
90 EXPECT_EQ(static_cast<DWORD>(WAIT_TIMEOUT),
91 ::SignalObjectAndWait(event1, event2, 1000, FALSE));
92
93 EXPECT_EQ(TRUE, ::CloseHandle(event1));
94 EXPECT_EQ(TRUE, ::CloseHandle(event2));
95 }
96
97 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/target_services.cc ('k') | sandbox/win/src/top_level_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698