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

Unified Diff: mojo/edk/system/data_pipe_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: convert remaining MP tests and simplify RawChannel destruction 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/data_pipe_unittest.cc
diff --git a/third_party/mojo/src/mojo/edk/system/data_pipe_impl_unittest.cc b/mojo/edk/system/data_pipe_unittest.cc
similarity index 96%
copy from third_party/mojo/src/mojo/edk/system/data_pipe_impl_unittest.cc
copy to mojo/edk/system/data_pipe_unittest.cc
index 3b0470bb1b19a67d1b71f118a7f7b2f273d47bbc..81e54ae40a0c1a04f86c9d359f8c90a5d475a2d5 100644
--- a/third_party/mojo/src/mojo/edk/system/data_pipe_impl_unittest.cc
+++ b/mojo/edk/system/data_pipe_unittest.cc
@@ -2,10 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// This file contains tests that are shared between different implementations of
-// |DataPipeImpl|.
-
-#include "mojo/edk/system/data_pipe_impl.h"
+//#include "mojo/edk/system/data_pipe_impl.h"
#include <stdint.h>
@@ -17,16 +14,19 @@
#include "base/test/test_io_thread.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
#include "mojo/edk/embedder/simple_platform_support.h"
-#include "mojo/edk/system/channel.h"
-#include "mojo/edk/system/channel_endpoint.h"
-#include "mojo/edk/system/data_pipe.h"
-#include "mojo/edk/system/data_pipe_consumer_dispatcher.h"
-#include "mojo/edk/system/data_pipe_producer_dispatcher.h"
+//#include "mojo/edk/system/channel.h"
+//#include "mojo/edk/system/channel_endpoint.h"
+//#include "mojo/edk/system/data_pipe.h"
+//#include "mojo/edk/system/data_pipe_consumer_dispatcher.h"
+//#include "mojo/edk/system/data_pipe_producer_dispatcher.h"
#include "mojo/edk/system/memory.h"
-#include "mojo/edk/system/message_pipe.h"
-#include "mojo/edk/system/raw_channel.h"
+//#include "mojo/edk/system/message_pipe.h"
+//#include "mojo/edk/system/raw_channel.h"
#include "mojo/edk/system/test_utils.h"
#include "mojo/edk/system/waiter.h"
+#include "mojo/edk/test/scoped_ipc_support.h"
+#include "mojo/public/c/system/data_pipe.h"
+#include "mojo/public/c/system/functions.h"
#include "mojo/public/cpp/system/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -34,9 +34,9 @@ namespace mojo {
namespace system {
namespace {
-const MojoHandleSignals kAllSignals = MOJO_HANDLE_SIGNAL_READABLE |
- MOJO_HANDLE_SIGNAL_WRITABLE |
- MOJO_HANDLE_SIGNAL_PEER_CLOSED;
+const MojoHandleSignals kSignalAll = MOJO_HANDLE_SIGNAL_READABLE |
+ MOJO_HANDLE_SIGNAL_WRITABLE |
+ MOJO_HANDLE_SIGNAL_PEER_CLOSED;
const uint32_t kSizeOfOptions =
static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions));
@@ -45,7 +45,7 @@ const uint32_t kSizeOfOptions =
// iterations (separated by a short sleep).
// TODO(vtl): Get rid of this.
const size_t kMaxPoll = 100;
-
+/*
// DataPipeImplTestHelper ------------------------------------------------------
class DataPipeImplTestHelper {
@@ -284,7 +284,7 @@ class RemoteDataPipeImplTestHelper : public DataPipeImplTestHelper {
message_pipe(dest_i)->RemoveAwakable(0, &waiter, &hss);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfied_signals);
- EXPECT_EQ(kAllSignals, hss.satisfiable_signals);
+ EXPECT_EQ(kSignalAll, hss.satisfiable_signals);
char read_buffer[100] = {};
uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
DispatcherVector read_dispatchers;
@@ -593,14 +593,78 @@ TYPED_TEST(DataPipeImplTest, CreateAndMaybeTransfer) {
this->Reset();
}
}
+*/
+
+class DataPipeTest : public testing::Test {
+ public:
+ DataPipeTest()
+ : test_io_thread_(base::TestIOThread::kAutoStart) {}
+ ~DataPipeTest() override {}
+
+ protected:
+ base::TestIOThread& test_io_thread() { return test_io_thread_; }
+ scoped_refptr<base::TaskRunner> test_io_task_runner() {
+ return test_io_thread_.task_runner();
+ }
+
+ private:
+ base::MessageLoop message_loop_;
+ base::TestIOThread test_io_thread_;
-TYPED_TEST(DataPipeImplTest, SimpleReadWrite) {
+ MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeTest);
+};
+
+//TYPED_TEST(DataPipeImplTest, SimpleReadWrite) {
+TEST_F(DataPipeTest, SimpleReadWrite) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
1000 * sizeof(int32_t) // |capacity_num_bytes|.
};
+
+ mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner());
+
+ MojoHandle producer_handle, consumer_handle;
+ ASSERT_EQ(MOJO_RESULT_OK,
+ MojoCreateDataPipe(&options, &producer_handle, &consumer_handle));
+
+ // We can write to a data pipe handle immediately.
+ int32_t elements[10] = {};
+ uint32_t num_bytes = 0;
+
+ num_bytes =
+ static_cast<uint32_t>(MOJO_ARRAYSIZE(elements) * sizeof(elements[0]));
+
+ elements[0] = 123;
+ elements[1] = 456;
+ num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ MojoWriteData(producer_handle, &elements[0], &num_bytes,
+ MOJO_WRITE_DATA_FLAG_NONE));
+
+ // Now wait for the other side to become readable.
+ MojoHandleSignalsState state;
+ EXPECT_EQ(MOJO_RESULT_OK, MojoWait(consumer_handle,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE, &state));
+ EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, state.satisfied_signals);
+
+ elements[0] = -1;
+ elements[1] = -1;
+ EXPECT_EQ(MOJO_RESULT_OK,
+ MojoReadData(consumer_handle, &elements[0], &num_bytes,
+ MOJO_READ_DATA_FLAG_NONE));
+ EXPECT_EQ(static_cast<uint32_t>(2u * sizeof(elements[0])), num_bytes);
+ EXPECT_EQ(elements[0], 123);
+ EXPECT_EQ(elements[1], 456);
+
+ EXPECT_EQ(MOJO_RESULT_OK, MojoClose(producer_handle));
+ EXPECT_EQ(MOJO_RESULT_OK, MojoClose(consumer_handle));
+}
+
+ /*
this->Create(options);
this->DoTransfer();
@@ -1647,7 +1711,7 @@ TYPED_TEST(DataPipeImplTest, AllOrNone) {
this->ConsumerClose();
}
-TYPED_TEST(DataPipeImplTest, TwoPhaseAllOrNone) {
+TYPED_TEST(DataPipeImplTest, DISABLED_TwoPhaseAllOrNone) {
const MojoCreateDataPipeOptions options = {
kSizeOfOptions, // |struct_size|.
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
@@ -2393,7 +2457,7 @@ TYPED_TEST(DataPipeImplTest, TwoPhaseMoreInvalidArguments) {
this->ProducerClose();
this->ConsumerClose();
}
-
+*/
} // namespace
} // namespace system
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698