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

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

Issue 2042363003: Allow data pipe producer/consumer handles to be transferred during two-phase operations. (Closed) Base URL: https://github.com/domokit/mojo.git@work790_dp_cancel_two_phase
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/edk/system/handle_table.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/core_unittest.cc
diff --git a/mojo/edk/system/core_unittest.cc b/mojo/edk/system/core_unittest.cc
index 5877f3b863ca0ff222c7ed31539daccefa2e689e..33e90b7a4362a2bb64c958e0b35b03769f786500 100644
--- a/mojo/edk/system/core_unittest.cc
+++ b/mojo/edk/system/core_unittest.cc
@@ -1642,20 +1642,48 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) {
ch = ch_received;
ch_received = MOJO_HANDLE_INVALID;
- // Make sure that |ph| can't be sent if it's in a two-phase write.
+ // Sending |ph| during a two-phase write cancels the two-phase write.
void* write_ptr = nullptr;
num_bytes = 0;
ASSERT_EQ(MOJO_RESULT_OK,
core()->BeginWriteData(ph, MakeUserPointer(&write_ptr),
MakeUserPointer(&num_bytes),
MOJO_WRITE_DATA_FLAG_NONE));
+ ASSERT_TRUE(write_ptr);
ASSERT_GE(num_bytes, 1u);
- EXPECT_EQ(MOJO_RESULT_BUSY,
+ EXPECT_EQ(MOJO_RESULT_OK,
core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello),
kHelloSize, MakeUserPointer(&ph), 1,
MOJO_WRITE_MESSAGE_FLAG_NONE));
+ ph = MOJO_HANDLE_INVALID;
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ NullUserPointer()));
+ num_bytes = kBufferSize;
+ num_handles = MOJO_ARRAYSIZE(handles);
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->ReadMessage(
+ h_passing[1], UserPointer<void>(buffer),
+ MakeUserPointer(&num_bytes), MakeUserPointer(handles),
+ MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(kHelloSize, num_bytes);
+ EXPECT_STREQ(kHello, buffer);
+ EXPECT_EQ(1u, num_handles);
+ ph = handles[0];
+ EXPECT_NE(ph, MOJO_HANDLE_INVALID);
+ // The two-phase write is over, so trying to complete it will fail.
+ EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, core()->EndWriteData(ph, 0));
+ // And we can begin a two-phase write on the new handle.
+ write_ptr = nullptr;
+ num_bytes = 0;
+ ASSERT_EQ(MOJO_RESULT_OK,
+ core()->BeginWriteData(ph, MakeUserPointer(&write_ptr),
+ MakeUserPointer(&num_bytes),
+ MOJO_WRITE_DATA_FLAG_NONE));
+ ASSERT_TRUE(write_ptr);
+ ASSERT_GE(num_bytes, 1u);
- // But |ch| can, even if |ph| is in a two-phase write.
+ // |ch| can be sent, even if |ph| is in a two-phase write.
EXPECT_EQ(MOJO_RESULT_OK,
core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello),
kHelloSize, MakeUserPointer(&ch), 1,
@@ -1691,19 +1719,48 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) {
MOJO_HANDLE_SIGNAL_READ_THRESHOLD,
hss.satisfiable_signals);
- // Make sure that |ch| can't be sent if it's in a two-phase read.
+ // Sending |ch| during a two-phase read cancels the two-phase read.
const void* read_ptr = nullptr;
- num_bytes = 1;
+ num_bytes = 0;
ASSERT_EQ(MOJO_RESULT_OK,
core()->BeginReadData(ch, MakeUserPointer(&read_ptr),
MakeUserPointer(&num_bytes),
MOJO_READ_DATA_FLAG_NONE));
- EXPECT_EQ(MOJO_RESULT_BUSY,
+ ASSERT_TRUE(read_ptr);
+ EXPECT_EQ(1u, num_bytes);
+ EXPECT_EQ(MOJO_RESULT_OK,
core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello),
kHelloSize, MakeUserPointer(&ch), 1,
MOJO_WRITE_MESSAGE_FLAG_NONE));
+ ch = MOJO_HANDLE_INVALID;
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ NullUserPointer()));
+ num_bytes = kBufferSize;
+ num_handles = MOJO_ARRAYSIZE(handles);
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->ReadMessage(
+ h_passing[1], UserPointer<void>(buffer),
+ MakeUserPointer(&num_bytes), MakeUserPointer(handles),
+ MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(kHelloSize, num_bytes);
+ EXPECT_STREQ(kHello, buffer);
+ EXPECT_EQ(1u, num_handles);
+ ch = handles[0];
+ EXPECT_NE(ch, MOJO_HANDLE_INVALID);
+ // The two-phase read is over, so trying to complete it will fail.
+ EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, core()->EndReadData(ch, 1));
+ // And we can begin a two-phase read on the new handle.
+ read_ptr = nullptr;
+ num_bytes = 0;
+ ASSERT_EQ(MOJO_RESULT_OK,
+ core()->BeginReadData(ch, MakeUserPointer(&read_ptr),
+ MakeUserPointer(&num_bytes),
+ MOJO_READ_DATA_FLAG_NONE));
+ ASSERT_TRUE(read_ptr);
+ EXPECT_EQ(1u, num_bytes);
- // But |ph| can, even if |ch| is in a two-phase read.
+ // |ph| can be sent, even if |ch| is in a two-phase write.
EXPECT_EQ(MOJO_RESULT_OK,
core()->WriteMessage(h_passing[0], UserPointer<const void>(kWorld),
kWorldSize, MakeUserPointer(&ph), 1,
« no previous file with comments | « no previous file | mojo/edk/system/handle_table.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698