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

Unified Diff: base/synchronization/waitable_event_unittest.cc

Issue 2758853002: Ensure consistent return ordering in base::WaitableEvent::WaitMany (Closed)
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/synchronization/waitable_event_posix.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/synchronization/waitable_event_unittest.cc
diff --git a/base/synchronization/waitable_event_unittest.cc b/base/synchronization/waitable_event_unittest.cc
index c0e280aa9740642058d3d3e9ee109b3a1c5e5e8a..3aa1af1619bdaf1a918118f23d6fb7c3493cc439 100644
--- a/base/synchronization/waitable_event_unittest.cc
+++ b/base/synchronization/waitable_event_unittest.cc
@@ -6,6 +6,8 @@
#include <stddef.h>
+#include <algorithm>
+
#include "base/compiler_specific.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
@@ -78,6 +80,42 @@ TEST(WaitableEventTest, WaitManyShortcut) {
delete ev[i];
}
+TEST(WaitableEventTest, WaitManyLeftToRight) {
+ WaitableEvent* ev[5];
+ for (size_t i = 0; i < 5; ++i) {
+ ev[i] = new WaitableEvent(WaitableEvent::ResetPolicy::AUTOMATIC,
+ WaitableEvent::InitialState::NOT_SIGNALED);
+ }
+
+ // Test for consistent left-to-right return behavior across all permutations
+ // of the input array. This is to verify that only the indices -- and not
+ // the WaitableEvents' addresses -- are relevant in determining who wins when
+ // multiple events are signaled.
+
+ std::sort(ev, ev + 5);
+ do {
+ ev[0]->Signal();
+ ev[1]->Signal();
+ EXPECT_EQ(0u, WaitableEvent::WaitMany(ev, 5));
+
+ ev[2]->Signal();
+ EXPECT_EQ(1u, WaitableEvent::WaitMany(ev, 5));
+ EXPECT_EQ(2u, WaitableEvent::WaitMany(ev, 5));
+
+ ev[3]->Signal();
+ ev[4]->Signal();
+ ev[0]->Signal();
+ EXPECT_EQ(0u, WaitableEvent::WaitMany(ev, 5));
+ EXPECT_EQ(3u, WaitableEvent::WaitMany(ev, 5));
+ ev[2]->Signal();
+ EXPECT_EQ(2u, WaitableEvent::WaitMany(ev, 5));
+ EXPECT_EQ(4u, WaitableEvent::WaitMany(ev, 5));
+ } while (std::next_permutation(ev, ev + 5));
+
+ for (size_t i = 0; i < 5; ++i)
+ delete ev[i];
+}
+
class WaitableEventSignaler : public PlatformThread::Delegate {
public:
WaitableEventSignaler(TimeDelta delay, WaitableEvent* event)
« 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