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

Unified Diff: mojo/edk/system/wait_set_dispatcher_unittest.cc

Issue 1504733002: Implementation of WaitSet for new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-waitset-implementation
Patch Set: Add gyp rules. Created 5 years 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 | « mojo/edk/system/wait_set_dispatcher.cc ('k') | mojo/mojo_edk.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/wait_set_dispatcher_unittest.cc
diff --git a/third_party/mojo/src/mojo/edk/system/wait_set_dispatcher_unittest.cc b/mojo/edk/system/wait_set_dispatcher_unittest.cc
similarity index 81%
copy from third_party/mojo/src/mojo/edk/system/wait_set_dispatcher_unittest.cc
copy to mojo/edk/system/wait_set_dispatcher_unittest.cc
index 86f5e3663e3bc7f15e4345876e5602be75d6d7fe..8321e65dcdb940f90929cb59e862e749a5f41164 100644
--- a/third_party/mojo/src/mojo/edk/system/wait_set_dispatcher_unittest.cc
+++ b/mojo/edk/system/wait_set_dispatcher_unittest.cc
@@ -2,20 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "third_party/mojo/src/mojo/edk/system/wait_set_dispatcher.h"
+#include "mojo/edk/system/wait_set_dispatcher.h"
#include <algorithm>
#include "base/memory/ref_counted.h"
+#include "mojo/edk/system/message_pipe_dispatcher.h"
+#include "mojo/edk/system/test_utils.h"
+#include "mojo/edk/system/waiter.h"
#include "mojo/public/cpp/system/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/mojo/src/mojo/edk/system/message_pipe.h"
-#include "third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher.h"
-#include "third_party/mojo/src/mojo/edk/system/test_utils.h"
-#include "third_party/mojo/src/mojo/edk/system/waiter.h"
namespace mojo {
-namespace system {
+namespace edk {
namespace {
class WaitSetDispatcherTest : public ::testing::Test {
@@ -24,17 +23,7 @@ class WaitSetDispatcherTest : public ::testing::Test {
~WaitSetDispatcherTest() override {}
void SetUp() override {
- dispatcher0_ = MessagePipeDispatcher::Create(
- MessagePipeDispatcher::kDefaultCreateOptions);
- dispatcher1_ = MessagePipeDispatcher::Create(
- MessagePipeDispatcher::kDefaultCreateOptions);
-
- scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
- dispatcher0_->Init(mp, 0);
- dispatcher1_->Init(mp, 1);
-
- dispatchers_to_close_.push_back(dispatcher0_);
- dispatchers_to_close_.push_back(dispatcher1_);
+ CreateMessagePipe(&dispatcher0_, &dispatcher1_);
}
void TearDown() override {
@@ -50,10 +39,7 @@ class WaitSetDispatcherTest : public ::testing::Test {
MojoResult dispatcher_result = MOJO_RESULT_UNKNOWN;
DispatcherVector dispatchers;
MojoResult result = wait_set->GetReadyDispatchers(
- MakeUserPointer(&count),
- &dispatchers,
- MakeUserPointer(&dispatcher_result),
- MakeUserPointer(context));
+ &count, &dispatchers, &dispatcher_result, context);
if (result == MOJO_RESULT_OK) {
CHECK_EQ(1u, dispatchers.size());
*ready_dispatcher = dispatchers[0];
@@ -62,6 +48,20 @@ class WaitSetDispatcherTest : public ::testing::Test {
return result;
}
+ void CreateMessagePipe(scoped_refptr<MessagePipeDispatcher>* d0,
+ scoped_refptr<MessagePipeDispatcher>* d1) {
+ *d0 = MessagePipeDispatcher::Create(
+ MessagePipeDispatcher::kDefaultCreateOptions);
+ *d1 = MessagePipeDispatcher::Create(
+ MessagePipeDispatcher::kDefaultCreateOptions);
+ (*d0)->InitNonTransferable(pipe_id_generator_);
+ (*d1)->InitNonTransferable(pipe_id_generator_);
+ pipe_id_generator_++;
+
+ dispatchers_to_close_.push_back(*d0);
+ dispatchers_to_close_.push_back(*d1);
+ }
+
void CloseOnShutdown(const scoped_refptr<Dispatcher>& dispatcher) {
dispatchers_to_close_.push_back(dispatcher);
}
@@ -70,11 +70,16 @@ class WaitSetDispatcherTest : public ::testing::Test {
scoped_refptr<MessagePipeDispatcher> dispatcher0_;
scoped_refptr<MessagePipeDispatcher> dispatcher1_;
+ private:
+ static uint64_t pipe_id_generator_;
DispatcherVector dispatchers_to_close_;
DISALLOW_COPY_AND_ASSIGN(WaitSetDispatcherTest);
};
+// static
+uint64_t WaitSetDispatcherTest::pipe_id_generator_ = 1;
+
TEST_F(WaitSetDispatcherTest, Basic) {
scoped_refptr<WaitSetDispatcher> wait_set = new WaitSetDispatcher();
CloseOnShutdown(wait_set);
@@ -124,10 +129,9 @@ TEST_F(WaitSetDispatcherTest, Basic) {
char buffer[] = "abcd";
w.Init();
ASSERT_EQ(MOJO_RESULT_OK,
- dispatcher1_->WriteMessage(UserPointer<const void>(buffer),
- sizeof(buffer), nullptr,
- MOJO_WRITE_MESSAGE_FLAG_NONE));
- EXPECT_EQ(MOJO_RESULT_OK, w.Wait(0, nullptr));
+ dispatcher1_->WriteMessage(buffer, sizeof(buffer), nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, nullptr));
woken_dispatcher = nullptr;
context = 0;
EXPECT_EQ(MOJO_RESULT_OK,
@@ -172,10 +176,9 @@ TEST_F(WaitSetDispatcherTest, HandleWithoutRemoving) {
char buffer[] = "abcd";
w.Init();
ASSERT_EQ(MOJO_RESULT_OK,
- dispatcher1_->WriteMessage(UserPointer<const void>(buffer),
- sizeof(buffer), nullptr,
+ dispatcher1_->WriteMessage(buffer, sizeof(buffer), nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
- EXPECT_EQ(MOJO_RESULT_OK, w.Wait(0, nullptr));
+ EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, nullptr));
woken_dispatcher = nullptr;
context = 0;
EXPECT_EQ(MOJO_RESULT_OK,
@@ -187,10 +190,8 @@ TEST_F(WaitSetDispatcherTest, HandleWithoutRemoving) {
char read_buffer[sizeof(buffer) + 5];
uint32_t num_bytes = sizeof(read_buffer);
ASSERT_EQ(MOJO_RESULT_OK,
- dispatcher0_->ReadMessage(UserPointer<void>(read_buffer),
- MakeUserPointer(&num_bytes),
- nullptr, nullptr,
- MOJO_READ_MESSAGE_FLAG_NONE));
+ dispatcher0_->ReadMessage(read_buffer, &num_bytes, nullptr,
+ nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(buffer), num_bytes);
// No dispatchers are ready.
@@ -211,19 +212,9 @@ TEST_F(WaitSetDispatcherTest, MultipleReady) {
scoped_refptr<WaitSetDispatcher> wait_set = new WaitSetDispatcher();
CloseOnShutdown(wait_set);
- scoped_refptr<MessagePipeDispatcher> mp1_dispatcher0 =
- MessagePipeDispatcher::Create(
- MessagePipeDispatcher::kDefaultCreateOptions);
- scoped_refptr<MessagePipeDispatcher> mp1_dispatcher1 =
- MessagePipeDispatcher::Create(
- MessagePipeDispatcher::kDefaultCreateOptions);
- CloseOnShutdown(mp1_dispatcher0);
- CloseOnShutdown(mp1_dispatcher1);
- {
- scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal());
- mp1_dispatcher0->Init(mp, 0);
- mp1_dispatcher1->Init(mp, 1);
- }
+ scoped_refptr<MessagePipeDispatcher> mp1_dispatcher0;
+ scoped_refptr<MessagePipeDispatcher> mp1_dispatcher1;
+ CreateMessagePipe(&mp1_dispatcher0, &mp1_dispatcher1);
ASSERT_EQ(MOJO_RESULT_OK,
wait_set->AddWaitingDispatcher(dispatcher0_,
@@ -260,10 +251,10 @@ TEST_F(WaitSetDispatcherTest, MultipleReady) {
uint32_t count = 4;
MojoResult results[4];
EXPECT_EQ(MOJO_RESULT_OK,
- wait_set->GetReadyDispatchers(MakeUserPointer(&count),
+ wait_set->GetReadyDispatchers(&count,
&dispatchers_vector,
- MakeUserPointer(results),
- MakeUserPointer<uintptr_t>(nullptr)));
+ results,
+ nullptr));
EXPECT_EQ(3u, count);
std::sort(dispatchers_vector.begin(), dispatchers_vector.end());
DispatcherVector expected_dispatchers;
@@ -281,10 +272,10 @@ TEST_F(WaitSetDispatcherTest, MultipleReady) {
count = 4;
dispatchers_vector.clear();
EXPECT_EQ(MOJO_RESULT_OK,
- wait_set->GetReadyDispatchers(MakeUserPointer(&count),
+ wait_set->GetReadyDispatchers(&count,
&dispatchers_vector,
- MakeUserPointer(results),
- MakeUserPointer<uintptr_t>(nullptr)));
+ results,
+ nullptr));
EXPECT_EQ(3u, count);
std::sort(dispatchers_vector.begin(), dispatchers_vector.end());
EXPECT_EQ(expected_dispatchers, dispatchers_vector);
@@ -300,10 +291,10 @@ TEST_F(WaitSetDispatcherTest, MultipleReady) {
count = 4;
dispatchers_vector.clear();
EXPECT_EQ(MOJO_RESULT_OK,
- wait_set->GetReadyDispatchers(MakeUserPointer(&count),
+ wait_set->GetReadyDispatchers(&count,
&dispatchers_vector,
- MakeUserPointer(results),
- MakeUserPointer<uintptr_t>(nullptr)));
+ results,
+ nullptr));
EXPECT_EQ(2u, count);
std::sort(dispatchers_vector.begin(), dispatchers_vector.end());
EXPECT_EQ(expected_dispatchers, dispatchers_vector);
@@ -312,9 +303,18 @@ TEST_F(WaitSetDispatcherTest, MultipleReady) {
char buffer[] = "abcd";
w.Init();
ASSERT_EQ(MOJO_RESULT_OK,
- dispatcher1_->WriteMessage(UserPointer<const void>(buffer),
- sizeof(buffer), nullptr,
- MOJO_WRITE_MESSAGE_FLAG_NONE));
+ dispatcher1_->WriteMessage(buffer, sizeof(buffer), nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
+ {
+ Waiter mp_w;
+ mp_w.Init();
+ // Wait for |dispatcher0_| to be readable.
+ if (dispatcher0_->AddAwakable(&mp_w, MOJO_HANDLE_SIGNAL_READABLE, 0,
+ nullptr) == MOJO_RESULT_OK) {
+ EXPECT_EQ(MOJO_RESULT_OK, mp_w.Wait(MOJO_DEADLINE_INDEFINITE, 0));
+ dispatcher0_->RemoveAwakable(&mp_w, nullptr);
+ }
+ }
expected_dispatchers.push_back(dispatcher0_);
std::sort(expected_dispatchers.begin(), expected_dispatchers.end());
EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
@@ -324,10 +324,10 @@ TEST_F(WaitSetDispatcherTest, MultipleReady) {
count = 4;
dispatchers_vector.clear();
EXPECT_EQ(MOJO_RESULT_OK,
- wait_set->GetReadyDispatchers(MakeUserPointer(&count),
+ wait_set->GetReadyDispatchers(&count,
&dispatchers_vector,
- MakeUserPointer(results),
- MakeUserPointer<uintptr_t>(nullptr)));
+ results,
+ nullptr));
EXPECT_EQ(3u, count);
std::sort(dispatchers_vector.begin(), dispatchers_vector.end());
EXPECT_EQ(expected_dispatchers, dispatchers_vector);
@@ -394,9 +394,9 @@ TEST_F(WaitSetDispatcherTest, ClosedDispatchers) {
EXPECT_EQ(MOJO_RESULT_OK,
wait_set->AddAwakable(&w, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss));
dispatcher0_->Close();
- EXPECT_EQ(MOJO_RESULT_OK, w.Wait(0, nullptr));
- EXPECT_TRUE(wait_set->GetHandleSignalsState().satisfies(
- MOJO_HANDLE_SIGNAL_READABLE));
+ EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, nullptr));
+ EXPECT_TRUE(
+ wait_set->GetHandleSignalsState().satisfies(MOJO_HANDLE_SIGNAL_READABLE));
scoped_refptr<Dispatcher> woken_dispatcher;
EXPECT_EQ(MOJO_RESULT_CANCELLED,
GetOneReadyDispatcher(wait_set, &woken_dispatcher, nullptr));
@@ -415,9 +415,9 @@ TEST_F(WaitSetDispatcherTest, ClosedDispatchers) {
EXPECT_EQ(MOJO_RESULT_OK,
wait_set->AddWaitingDispatcher(dispatcher1_,
MOJO_HANDLE_SIGNAL_READABLE, 0));
- EXPECT_EQ(MOJO_RESULT_OK, w.Wait(0, nullptr));
- EXPECT_TRUE(wait_set->GetHandleSignalsState().satisfies(
- MOJO_HANDLE_SIGNAL_READABLE));
+ EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, nullptr));
+ EXPECT_TRUE(
+ wait_set->GetHandleSignalsState().satisfies(MOJO_HANDLE_SIGNAL_READABLE));
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
GetOneReadyDispatcher(wait_set, &woken_dispatcher, nullptr));
EXPECT_EQ(dispatcher1_, woken_dispatcher);
@@ -455,5 +455,5 @@ TEST_F(WaitSetDispatcherTest, NestedSets) {
}
} // namespace
-} // namespace system
+} // namespace edk
} // namespace mojo
« no previous file with comments | « mojo/edk/system/wait_set_dispatcher.cc ('k') | mojo/mojo_edk.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698