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

Side by Side Diff: base/synchronization/waitable_event_unittest.cc

Issue 2761993004: Revert of Ensure consistent return ordering in base::WaitableEvent::WaitMany (Closed)
Patch Set: Created 3 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
« no previous file with comments | « base/synchronization/waitable_event_posix.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/synchronization/waitable_event.h" 5 #include "base/synchronization/waitable_event.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm>
10
11 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
12 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
13 #include "base/time/time.h" 11 #include "base/time/time.h"
14 #include "build/build_config.h" 12 #include "build/build_config.h"
15 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
16 14
17 namespace base { 15 namespace base {
18 16
19 TEST(WaitableEventTest, ManualBasics) { 17 TEST(WaitableEventTest, ManualBasics) {
20 WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL, 18 WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 ev[4]->Signal(); 71 ev[4]->Signal();
74 EXPECT_EQ(WaitableEvent::WaitMany(ev, 5), 4u); 72 EXPECT_EQ(WaitableEvent::WaitMany(ev, 5), 4u);
75 73
76 ev[0]->Signal(); 74 ev[0]->Signal();
77 EXPECT_EQ(WaitableEvent::WaitMany(ev, 5), 0u); 75 EXPECT_EQ(WaitableEvent::WaitMany(ev, 5), 0u);
78 76
79 for (unsigned i = 0; i < 5; ++i) 77 for (unsigned i = 0; i < 5; ++i)
80 delete ev[i]; 78 delete ev[i];
81 } 79 }
82 80
83 TEST(WaitableEventTest, WaitManyLeftToRight) {
84 WaitableEvent* ev[5];
85 for (size_t i = 0; i < 5; ++i) {
86 ev[i] = new WaitableEvent(WaitableEvent::ResetPolicy::AUTOMATIC,
87 WaitableEvent::InitialState::NOT_SIGNALED);
88 }
89
90 // Test for consistent left-to-right return behavior across all permutations
91 // of the input array. This is to verify that only the indices -- and not
92 // the WaitableEvents' addresses -- are relevant in determining who wins when
93 // multiple events are signaled.
94
95 std::sort(ev, ev + 5);
96 do {
97 ev[0]->Signal();
98 ev[1]->Signal();
99 EXPECT_EQ(0u, WaitableEvent::WaitMany(ev, 5));
100
101 ev[2]->Signal();
102 EXPECT_EQ(1u, WaitableEvent::WaitMany(ev, 5));
103 EXPECT_EQ(2u, WaitableEvent::WaitMany(ev, 5));
104
105 ev[3]->Signal();
106 ev[4]->Signal();
107 ev[0]->Signal();
108 EXPECT_EQ(0u, WaitableEvent::WaitMany(ev, 5));
109 EXPECT_EQ(3u, WaitableEvent::WaitMany(ev, 5));
110 ev[2]->Signal();
111 EXPECT_EQ(2u, WaitableEvent::WaitMany(ev, 5));
112 EXPECT_EQ(4u, WaitableEvent::WaitMany(ev, 5));
113 } while (std::next_permutation(ev, ev + 5));
114
115 for (size_t i = 0; i < 5; ++i)
116 delete ev[i];
117 }
118
119 class WaitableEventSignaler : public PlatformThread::Delegate { 81 class WaitableEventSignaler : public PlatformThread::Delegate {
120 public: 82 public:
121 WaitableEventSignaler(TimeDelta delay, WaitableEvent* event) 83 WaitableEventSignaler(TimeDelta delay, WaitableEvent* event)
122 : delay_(delay), 84 : delay_(delay),
123 event_(event) { 85 event_(event) {
124 } 86 }
125 87
126 void ThreadMain() override { 88 void ThreadMain() override {
127 PlatformThread::Sleep(delay_); 89 PlatformThread::Sleep(delay_);
128 event_->Signal(); 90 event_->Signal();
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 start_time = TimeTicks::Now(); 195 start_time = TimeTicks::Now();
234 PlatformThread::Create(0, &signaler, &thread); 196 PlatformThread::Create(0, &signaler, &thread);
235 197
236 EXPECT_TRUE(ev.TimedWaitUntil(TimeTicks::Max())); 198 EXPECT_TRUE(ev.TimedWaitUntil(TimeTicks::Max()));
237 EXPECT_GE(TimeTicks::Now() - start_time, delay); 199 EXPECT_GE(TimeTicks::Now() - start_time, delay);
238 200
239 PlatformThread::Join(thread); 201 PlatformThread::Join(thread);
240 } 202 }
241 203
242 } // namespace base 204 } // namespace base
OLDNEW
« no previous file with comments | « base/synchronization/waitable_event_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698