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

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

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to mojo::edk namespace in preparation for runtim flag Created 5 years, 3 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
Index: mojo/edk/system/core_unittest.cc
diff --git a/third_party/mojo/src/mojo/edk/system/core_unittest.cc b/mojo/edk/system/core_unittest.cc
similarity index 97%
copy from third_party/mojo/src/mojo/edk/system/core_unittest.cc
copy to mojo/edk/system/core_unittest.cc
index 0ef0aa1260922a3bda97d322d32491ce3a919e70..5b75ab1f5638cbc5ced0c3249c58023c736a8aad 100644
--- a/third_party/mojo/src/mojo/edk/system/core_unittest.cc
+++ b/mojo/edk/system/core_unittest.cc
@@ -9,13 +9,14 @@
#include <limits>
#include "base/bind.h"
+#include "mojo/edk/embedder/embedder_internal.h"
#include "mojo/edk/system/awakable.h"
#include "mojo/edk/system/core_test_base.h"
#include "mojo/edk/system/test_utils.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
-namespace system {
+namespace edk {
namespace {
const MojoHandleSignalsState kEmptyMojoHandleSignalsState = {0u, 0u};
@@ -658,6 +659,11 @@ TEST_F(CoreTest, MessagePipe) {
// Close |h[0]|.
EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h[0]));
+ // Wait for |h[1]| to learn about the other end's closure.
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->Wait(h[1], MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1000000000,
+ MakeUserPointer(&hss[0])));
+
// Check that |h[1]| is no longer writable (and will never be).
hss[0] = kEmptyMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
@@ -899,6 +905,11 @@ TEST_F(CoreTest, DataPipe) {
MakeUserPointer(&num_bytes),
MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(2u, num_bytes);
+
+ // Wait for the data to arrive to the consumer.
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ MakeUserPointer(&hss)));
// Consumer should now be readable.
hss = kEmptyMojoHandleSignalsState;
@@ -952,13 +963,18 @@ TEST_F(CoreTest, DataPipe) {
static_cast<char*>(write_ptr)[1] = 'D';
static_cast<char*>(write_ptr)[2] = 'E';
EXPECT_EQ(MOJO_RESULT_OK, core()->EndWriteData(ph, 3u));
+
+ // Wait for the data to arrive to the consumer.
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ MakeUserPointer(&hss)));
// Query how much data we have.
num_bytes = 0;
EXPECT_EQ(MOJO_RESULT_OK,
core()->ReadData(ch, NullUserPointer(), MakeUserPointer(&num_bytes),
MOJO_READ_DATA_FLAG_QUERY));
- EXPECT_EQ(4u, num_bytes);
+ EXPECT_GE(num_bytes, 1u);
// Try to query with peek. Should fail.
num_bytes = 0;
@@ -982,29 +998,34 @@ TEST_F(CoreTest, DataPipe) {
core()->ReadData(ch, NullUserPointer(), MakeUserPointer(&num_bytes),
MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_PEEK));
- // Discard two characters.
- num_bytes = 2;
+ // Discard a character.
+ num_bytes = 1;
EXPECT_EQ(MOJO_RESULT_OK,
core()->ReadData(
ch, NullUserPointer(), MakeUserPointer(&num_bytes),
MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE));
- // Try a two-phase read of the remaining two bytes with peek. Should fail.
+ // Ensure the 3 bytes were read.
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ MakeUserPointer(&hss)));
+
+ // Try a two-phase read of the remaining three bytes with peek. Should fail.
const void* read_ptr = nullptr;
- num_bytes = 2;
+ num_bytes = 3;
ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
core()->BeginReadData(ch, MakeUserPointer(&read_ptr),
MakeUserPointer(&num_bytes),
MOJO_READ_DATA_FLAG_PEEK));
// Read the remaining two characters, in two-phase mode (all-or-none).
- num_bytes = 2;
+ num_bytes = 3;
ASSERT_EQ(MOJO_RESULT_OK,
core()->BeginReadData(ch, MakeUserPointer(&read_ptr),
MakeUserPointer(&num_bytes),
MOJO_READ_DATA_FLAG_ALL_OR_NONE));
// Note: Count on still being able to do the contiguous read here.
- ASSERT_EQ(2u, num_bytes);
+ ASSERT_EQ(3u, num_bytes);
// Discarding right now should fail.
num_bytes = 1;
@@ -1013,9 +1034,10 @@ TEST_F(CoreTest, DataPipe) {
MOJO_READ_DATA_FLAG_DISCARD));
// Actually check our data and end the two-phase read.
- EXPECT_EQ('D', static_cast<const char*>(read_ptr)[0]);
- EXPECT_EQ('E', static_cast<const char*>(read_ptr)[1]);
- EXPECT_EQ(MOJO_RESULT_OK, core()->EndReadData(ch, 2u));
+ EXPECT_EQ('C', static_cast<const char*>(read_ptr)[0]);
+ EXPECT_EQ('D', static_cast<const char*>(read_ptr)[1]);
+ EXPECT_EQ('E', static_cast<const char*>(read_ptr)[2]);
+ EXPECT_EQ(MOJO_RESULT_OK, core()->EndReadData(ch, 3u));
// Consumer should now be no longer readable.
hss = kFullMojoHandleSignalsState;
@@ -1031,6 +1053,11 @@ TEST_F(CoreTest, DataPipe) {
// Close the producer.
EXPECT_EQ(MOJO_RESULT_OK, core()->Close(ph));
+ // Wait for this to get to the consumer.
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->Wait(ch, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1000000000,
+ MakeUserPointer(&hss)));
+
// The consumer should now be never-readable.
hss = kFullMojoHandleSignalsState;
EXPECT_EQ(
@@ -1313,5 +1340,5 @@ TEST_F(CoreTest, AsyncWait) {
// TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|.
} // namespace
-} // namespace system
+} // namespace edk
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698