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

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

Issue 1052723003: NaCl: create a separate namespace for Mojo handles. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
Index: mojo/edk/system/core_unittest.cc
diff --git a/mojo/edk/system/core_unittest.cc b/mojo/edk/system/core_unittest.cc
index b78930110bcbaafcbd1ff8c27d7fd0e1cc6f8b10..1a791c2d9b996d886b6db64a76d1bb4235c66c7a 100644
--- a/mojo/edk/system/core_unittest.cc
+++ b/mojo/edk/system/core_unittest.cc
@@ -13,6 +13,7 @@
#include "base/time/time.h"
#include "mojo/edk/system/awakable.h"
#include "mojo/edk/system/core_test_base.h"
+#include "mojo/edk/system/dispatcher.h"
namespace mojo {
namespace system {
@@ -1310,6 +1311,172 @@ TEST_F(CoreTest, AsyncWait) {
EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
}
+MojoResult CreateCoreWithInitialHandle(Core* srcCore,
viettrungluu 2015/04/01 23:36:19 No camelCased variable names, please.
Nick Bray (chromium) 2015/04/04 00:09:09 These changes are an artifact of how I bootstrappe
+ MojoHandle srcHandle,
+ Core** dstCore,
+ MojoHandle* dstHandle) {
+ *dstCore = nullptr;
+ *dstHandle = MOJO_HANDLE_INVALID;
+
+ if (srcCore == nullptr) {
+ return MOJO_RESULT_INVALID_ARGUMENT;
+ }
+ if (srcHandle == MOJO_HANDLE_INVALID) {
+ return MOJO_RESULT_INVALID_ARGUMENT;
+ }
+ scoped_refptr<Dispatcher> d = srcCore->PopDispatcher(srcHandle);
+ if (d.get() == nullptr) {
+ // HACK this could also be because the handle does not exist.
+ return MOJO_RESULT_BUSY;
+ }
+
+ Core* createdCore = new Core(srcCore->platform_support());
+ MojoHandle createdHandle = createdCore->AddDispatcher(d);
+ DCHECK(createdHandle != MOJO_HANDLE_INVALID);
+
+ *dstCore = createdCore;
+ *dstHandle = createdHandle;
+ return MOJO_RESULT_OK;
+}
+
+TEST_F(CoreTest, RemoteCore) {
+ Core* core0 = new Core(new embedder::SimplePlatformSupport());
viettrungluu 2015/04/01 23:36:19 Put this in a scoped_ptr. Also include base/memor
+
viettrungluu 2015/04/01 23:36:19 Add an ASSERT_TRUE(core0); here if you like.
+ MojoHandle h[2];
+ MojoHandleSignalsState hss[2];
+ // uint32_t result_index;
viettrungluu 2015/04/01 23:36:19 Delete.
+
+ // Create the initial message pipe.
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core0->CreateMessagePipe(NullUserPointer(), MakeUserPointer(&h[0]),
+ MakeUserPointer(&h[1])));
+
+ EXPECT_NE(MOJO_HANDLE_INVALID, h[0]);
viettrungluu 2015/04/01 23:36:19 It's unlikely that you'll want to continue the tes
+ EXPECT_NE(MOJO_HANDLE_INVALID, h[1]);
+
+ // Move one of the endpoints to another core.
+ Core* core1 = nullptr;
viettrungluu 2015/04/01 23:36:19 scoped_ptr here too.
+ EXPECT_EQ(MOJO_RESULT_OK,
+ CreateCoreWithInitialHandle(core0, h[1], &core1, &h[1]));
+ EXPECT_NE(nullptr, core1);
+ EXPECT_NE(MOJO_HANDLE_INVALID, h[1]);
+
+ // Try to read anyway.
+ char buffer[1] = {'a'};
+ uint32_t buffer_size = 1;
+ EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
+ core0->ReadMessage(h[0], UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size), NullUserPointer(),
+ NullUserPointer(), MOJO_READ_MESSAGE_FLAG_NONE));
+ // Check that it left its inputs alone.
+ EXPECT_EQ('a', buffer[0]);
+ EXPECT_EQ(1u, buffer_size);
+
+ // Both should be writable.
+ hss[0] = kEmptyMojoHandleSignalsState;
+ EXPECT_EQ(MOJO_RESULT_OK, core0->Wait(h[0], MOJO_HANDLE_SIGNAL_WRITABLE,
+ 1000000000, MakeUserPointer(&hss[0])));
+ EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals);
+ EXPECT_EQ(kAllSignals, hss[0].satisfiable_signals);
+ hss[0] = kEmptyMojoHandleSignalsState;
+ EXPECT_EQ(MOJO_RESULT_OK, core1->Wait(h[1], MOJO_HANDLE_SIGNAL_WRITABLE,
+ 1000000000, MakeUserPointer(&hss[0])));
+ EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals);
+ EXPECT_EQ(kAllSignals, hss[0].satisfiable_signals);
+
+ // Write to |h[1]|.
+ buffer[0] = 'b';
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ core1->WriteMessage(h[1], UserPointer<const void>(buffer), 1,
+ NullUserPointer(), 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+
+ // Read from |h[0]|.
+ // First, get only the size.
+ buffer_size = 0;
+ EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
+ core0->ReadMessage(h[0], NullUserPointer(),
+ MakeUserPointer(&buffer_size), NullUserPointer(),
+ NullUserPointer(), MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(1u, buffer_size);
+ // Then actually read it.
+ buffer[0] = 'c';
+ buffer_size = 1;
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core0->ReadMessage(h[0], UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size), NullUserPointer(),
+ NullUserPointer(), MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ('b', buffer[0]);
+ EXPECT_EQ(1u, buffer_size);
+
+ // |h[0]| should no longer be readable.
+ hss[0] = kEmptyMojoHandleSignalsState;
+ EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
+ core0->Wait(h[0], MOJO_HANDLE_SIGNAL_READABLE, 0,
+ MakeUserPointer(&hss[0])));
+ EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals);
+ EXPECT_EQ(kAllSignals, hss[0].satisfiable_signals);
+
+ // Write to |h[0]|.
+ buffer[0] = 'd';
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ core0->WriteMessage(h[0], UserPointer<const void>(buffer), 1,
+ NullUserPointer(), 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+
+ // Close |h[0]|.
+ EXPECT_EQ(MOJO_RESULT_OK, core0->Close(h[0]));
+
+ // Check that |h[1]| is no longer writable (and will never be).
+ hss[0] = kEmptyMojoHandleSignalsState;
+ EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
+ core1->Wait(h[1], MOJO_HANDLE_SIGNAL_WRITABLE, 1000000000,
+ MakeUserPointer(&hss[0])));
+ EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
+ hss[0].satisfied_signals);
+ EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
+ hss[0].satisfiable_signals);
+
+ // Check that |h[1]| is still readable (for the moment).
+ hss[0] = kEmptyMojoHandleSignalsState;
+ EXPECT_EQ(MOJO_RESULT_OK, core1->Wait(h[1], MOJO_HANDLE_SIGNAL_READABLE,
+ 1000000000, MakeUserPointer(&hss[0])));
+ EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
+ hss[0].satisfied_signals);
+ EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
+ hss[0].satisfiable_signals);
+
+ // Discard a message from |h[1]|.
+ EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
+ core1->ReadMessage(h[1], NullUserPointer(), NullUserPointer(),
+ NullUserPointer(), NullUserPointer(),
+ MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
+
+ // |h[1]| is no longer readable (and will never be).
+ hss[0] = kFullMojoHandleSignalsState;
+ EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
+ core1->Wait(h[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ MakeUserPointer(&hss[0])));
+ EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss[0].satisfied_signals);
+ EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss[0].satisfiable_signals);
+
+ // Try writing to |h[1]|.
+ buffer[0] = 'e';
+ EXPECT_EQ(
+ MOJO_RESULT_FAILED_PRECONDITION,
+ core1->WriteMessage(h[1], UserPointer<const void>(buffer), 1,
+ NullUserPointer(), 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+
+ EXPECT_EQ(MOJO_RESULT_OK, core1->Close(h[1]));
+
+ // Clean up
+ // EXPECT_EQ(MOJO_RESULT_OK, core0->Close(h[0]));
+ // EXPECT_EQ(MOJO_RESULT_OK, core1->Close(h[1]));
+
+ delete core0;
+ delete core1;
+}
+
// TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|.
} // namespace

Powered by Google App Engine
This is Rietveld 408576698