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

Side by Side Diff: mojo/edk/system/awakable_list_unittest.cc

Issue 2056763003: EDK: Change Awakable::Awake()'s context, etc., to be a uint64_t. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: doh Created 4 years, 6 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 | « mojo/edk/system/awakable_list.cc ('k') | mojo/edk/system/core.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a 5 // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a
6 // heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to 6 // heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to
7 // increase tolerance and reduce observed flakiness (though doing so reduces the 7 // increase tolerance and reduce observed flakiness (though doing so reduces the
8 // meaningfulness of the test). 8 // meaningfulness of the test).
9 9
10 #include "mojo/edk/system/awakable_list.h" 10 #include "mojo/edk/system/awakable_list.h"
11 11
12 #include "mojo/edk/platform/thread_utils.h" 12 #include "mojo/edk/platform/thread_utils.h"
13 #include "mojo/edk/system/handle_signals_state.h" 13 #include "mojo/edk/system/handle_signals_state.h"
14 #include "mojo/edk/system/test/timeouts.h" 14 #include "mojo/edk/system/test/timeouts.h"
15 #include "mojo/edk/system/waiter.h" 15 #include "mojo/edk/system/waiter.h"
16 #include "mojo/edk/system/waiter_test_utils.h" 16 #include "mojo/edk/system/waiter_test_utils.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 using mojo::platform::ThreadSleep; 19 using mojo::platform::ThreadSleep;
20 20
21 namespace mojo { 21 namespace mojo {
22 namespace system { 22 namespace system {
23 namespace { 23 namespace {
24 24
25 TEST(AwakableListTest, BasicCancel) { 25 TEST(AwakableListTest, BasicCancel) {
26 MojoResult result; 26 MojoResult result;
27 uint32_t context; 27 uint64_t context;
28 28
29 // Cancel immediately after thread start. 29 // Cancel immediately after thread start.
30 { 30 {
31 AwakableList awakable_list; 31 AwakableList awakable_list;
32 test::SimpleWaiterThread thread(&result, &context); 32 test::SimpleWaiterThread thread(&result, &context);
33 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); 33 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1);
34 thread.Start(); 34 thread.Start();
35 awakable_list.CancelAll(); 35 awakable_list.CancelAll();
36 // Double-remove okay: 36 // Double-remove okay:
37 awakable_list.Remove(thread.waiter()); 37 awakable_list.Remove(thread.waiter());
(...skipping 20 matching lines...) Expand all
58 thread.Start(); 58 thread.Start();
59 ThreadSleep(2 * test::EpsilonTimeout()); 59 ThreadSleep(2 * test::EpsilonTimeout());
60 awakable_list.CancelAll(); 60 awakable_list.CancelAll();
61 } // Join |thread|. 61 } // Join |thread|.
62 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); 62 EXPECT_EQ(MOJO_RESULT_CANCELLED, result);
63 EXPECT_EQ(3u, context); 63 EXPECT_EQ(3u, context);
64 } 64 }
65 65
66 TEST(AwakableListTest, BasicAwakeSatisfied) { 66 TEST(AwakableListTest, BasicAwakeSatisfied) {
67 MojoResult result; 67 MojoResult result;
68 uint32_t context; 68 uint64_t context;
69 69
70 // Awake immediately after thread start. 70 // Awake immediately after thread start.
71 { 71 {
72 AwakableList awakable_list; 72 AwakableList awakable_list;
73 test::SimpleWaiterThread thread(&result, &context); 73 test::SimpleWaiterThread thread(&result, &context);
74 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); 74 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1);
75 thread.Start(); 75 thread.Start();
76 awakable_list.AwakeForStateChange(HandleSignalsState( 76 awakable_list.AwakeForStateChange(HandleSignalsState(
77 MOJO_HANDLE_SIGNAL_READABLE, 77 MOJO_HANDLE_SIGNAL_READABLE,
78 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); 78 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE));
(...skipping 29 matching lines...) Expand all
108 MOJO_HANDLE_SIGNAL_READABLE, 108 MOJO_HANDLE_SIGNAL_READABLE,
109 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); 109 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE));
110 awakable_list.Remove(thread.waiter()); 110 awakable_list.Remove(thread.waiter());
111 } // Join |thread|. 111 } // Join |thread|.
112 EXPECT_EQ(MOJO_RESULT_OK, result); 112 EXPECT_EQ(MOJO_RESULT_OK, result);
113 EXPECT_EQ(3u, context); 113 EXPECT_EQ(3u, context);
114 } 114 }
115 115
116 TEST(AwakableListTest, BasicAwakeUnsatisfiable) { 116 TEST(AwakableListTest, BasicAwakeUnsatisfiable) {
117 MojoResult result; 117 MojoResult result;
118 uint32_t context; 118 uint64_t context;
119 119
120 // Awake (for unsatisfiability) immediately after thread start. 120 // Awake (for unsatisfiability) immediately after thread start.
121 { 121 {
122 AwakableList awakable_list; 122 AwakableList awakable_list;
123 test::SimpleWaiterThread thread(&result, &context); 123 test::SimpleWaiterThread thread(&result, &context);
124 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); 124 awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1);
125 thread.Start(); 125 thread.Start();
126 awakable_list.AwakeForStateChange(HandleSignalsState( 126 awakable_list.AwakeForStateChange(HandleSignalsState(
127 MOJO_HANDLE_SIGNAL_NONE, MOJO_HANDLE_SIGNAL_WRITABLE)); 127 MOJO_HANDLE_SIGNAL_NONE, MOJO_HANDLE_SIGNAL_WRITABLE));
128 awakable_list.Remove(thread.waiter()); 128 awakable_list.Remove(thread.waiter());
(...skipping 29 matching lines...) Expand all
158 } // Join |thread|. 158 } // Join |thread|.
159 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); 159 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result);
160 EXPECT_EQ(3u, context); 160 EXPECT_EQ(3u, context);
161 } 161 }
162 162
163 TEST(AwakableListTest, MultipleAwakables) { 163 TEST(AwakableListTest, MultipleAwakables) {
164 MojoResult result1; 164 MojoResult result1;
165 MojoResult result2; 165 MojoResult result2;
166 MojoResult result3; 166 MojoResult result3;
167 MojoResult result4; 167 MojoResult result4;
168 uint32_t context1; 168 uint64_t context1;
169 uint32_t context2; 169 uint64_t context2;
170 uint32_t context3; 170 uint64_t context3;
171 uint32_t context4; 171 uint64_t context4;
172 172
173 // Cancel two awakables. 173 // Cancel two awakables.
174 { 174 {
175 AwakableList awakable_list; 175 AwakableList awakable_list;
176 test::SimpleWaiterThread thread1(&result1, &context1); 176 test::SimpleWaiterThread thread1(&result1, &context1);
177 awakable_list.Add(thread1.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1); 177 awakable_list.Add(thread1.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1);
178 thread1.Start(); 178 thread1.Start();
179 test::SimpleWaiterThread thread2(&result2, &context2); 179 test::SimpleWaiterThread thread2(&result2, &context2);
180 awakable_list.Add(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 2); 180 awakable_list.Add(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 2);
181 thread2.Start(); 181 thread2.Start();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result3); 282 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result3);
283 EXPECT_EQ(9u, context3); 283 EXPECT_EQ(9u, context3);
284 EXPECT_EQ(MOJO_RESULT_CANCELLED, result4); 284 EXPECT_EQ(MOJO_RESULT_CANCELLED, result4);
285 EXPECT_EQ(10u, context4); 285 EXPECT_EQ(10u, context4);
286 } 286 }
287 287
288 class KeepAwakable : public Awakable { 288 class KeepAwakable : public Awakable {
289 public: 289 public:
290 KeepAwakable() : awake_count(0) {} 290 KeepAwakable() : awake_count(0) {}
291 291
292 bool Awake(MojoResult result, uintptr_t context) override { 292 bool Awake(MojoResult result, uint64_t context) override {
293 awake_count++; 293 awake_count++;
294 return true; 294 return true;
295 } 295 }
296 296
297 int awake_count; 297 int awake_count;
298 298
299 MOJO_DISALLOW_COPY_AND_ASSIGN(KeepAwakable); 299 MOJO_DISALLOW_COPY_AND_ASSIGN(KeepAwakable);
300 }; 300 };
301 301
302 class RemoveAwakable : public Awakable { 302 class RemoveAwakable : public Awakable {
303 public: 303 public:
304 RemoveAwakable() : awake_count(0) {} 304 RemoveAwakable() : awake_count(0) {}
305 305
306 bool Awake(MojoResult result, uintptr_t context) override { 306 bool Awake(MojoResult result, uint64_t context) override {
307 awake_count++; 307 awake_count++;
308 return false; 308 return false;
309 } 309 }
310 310
311 int awake_count; 311 int awake_count;
312 312
313 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoveAwakable); 313 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoveAwakable);
314 }; 314 };
315 315
316 TEST(AwakableListTest, KeepAwakablesReturningTrue) { 316 TEST(AwakableListTest, KeepAwakablesReturningTrue) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 EXPECT_EQ(keep1.awake_count, 2); 350 EXPECT_EQ(keep1.awake_count, 2);
351 EXPECT_EQ(remove2.awake_count, 1); 351 EXPECT_EQ(remove2.awake_count, 1);
352 352
353 remove_first.Remove(&keep0); 353 remove_first.Remove(&keep0);
354 remove_first.Remove(&keep1); 354 remove_first.Remove(&keep1);
355 } 355 }
356 356
357 } // namespace 357 } // namespace
358 } // namespace system 358 } // namespace system
359 } // namespace mojo 359 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/awakable_list.cc ('k') | mojo/edk/system/core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698