| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/edk/system/channel.h" | 5 #include "mojo/edk/system/channel.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "mojo/edk/system/channel_endpoint.h" | 9 #include "mojo/edk/system/channel_endpoint.h" |
| 10 #include "mojo/edk/system/channel_endpoint_id.h" | 10 #include "mojo/edk/system/channel_endpoint_id.h" |
| 11 #include "mojo/edk/system/channel_test_base.h" | 11 #include "mojo/edk/system/channel_test_base.h" |
| 12 #include "mojo/edk/system/message_pipe.h" | 12 #include "mojo/edk/system/message_pipe.h" |
| 13 #include "mojo/edk/system/ref_ptr.h" |
| 13 #include "mojo/edk/system/test_utils.h" | 14 #include "mojo/edk/system/test_utils.h" |
| 14 #include "mojo/edk/system/waiter.h" | 15 #include "mojo/edk/system/waiter.h" |
| 15 | 16 |
| 16 namespace mojo { | 17 namespace mojo { |
| 17 namespace system { | 18 namespace system { |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 using ChannelTest = test::ChannelTestBase; | 21 using ChannelTest = test::ChannelTestBase; |
| 21 | 22 |
| 22 void DoNothing() {} | 23 void DoNothing() {} |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 *mutable_channel(0) = nullptr; | 35 *mutable_channel(0) = nullptr; |
| 35 } | 36 } |
| 36 | 37 |
| 37 // ChannelTest.CloseBeforeAttachAndRun ----------------------------------------- | 38 // ChannelTest.CloseBeforeAttachAndRun ----------------------------------------- |
| 38 | 39 |
| 39 TEST_F(ChannelTest, CloseBeforeRun) { | 40 TEST_F(ChannelTest, CloseBeforeRun) { |
| 40 PostMethodToIOThreadAndWait(FROM_HERE, | 41 PostMethodToIOThreadAndWait(FROM_HERE, |
| 41 &ChannelTest::CreateAndInitChannelOnIOThread, 0); | 42 &ChannelTest::CreateAndInitChannelOnIOThread, 0); |
| 42 | 43 |
| 43 RefPtr<ChannelEndpoint> channel_endpoint; | 44 RefPtr<ChannelEndpoint> channel_endpoint; |
| 44 scoped_refptr<MessagePipe> mp( | 45 auto mp = MessagePipe::CreateLocalProxy(&channel_endpoint); |
| 45 MessagePipe::CreateLocalProxy(&channel_endpoint)); | |
| 46 | 46 |
| 47 mp->Close(0); | 47 mp->Close(0); |
| 48 | 48 |
| 49 channel(0)->SetBootstrapEndpoint(std::move(channel_endpoint)); | 49 channel(0)->SetBootstrapEndpoint(std::move(channel_endpoint)); |
| 50 | 50 |
| 51 PostMethodToIOThreadAndWait(FROM_HERE, | 51 PostMethodToIOThreadAndWait(FROM_HERE, |
| 52 &ChannelTest::ShutdownChannelOnIOThread, 0); | 52 &ChannelTest::ShutdownChannelOnIOThread, 0); |
| 53 | 53 |
| 54 channel(0)->AssertHasOneRef(); | 54 channel(0)->AssertHasOneRef(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 // ChannelTest.ShutdownAfterAttachAndRun --------------------------------------- | 57 // ChannelTest.ShutdownAfterAttachAndRun --------------------------------------- |
| 58 | 58 |
| 59 TEST_F(ChannelTest, ShutdownAfterAttach) { | 59 TEST_F(ChannelTest, ShutdownAfterAttach) { |
| 60 PostMethodToIOThreadAndWait(FROM_HERE, | 60 PostMethodToIOThreadAndWait(FROM_HERE, |
| 61 &ChannelTest::CreateAndInitChannelOnIOThread, 0); | 61 &ChannelTest::CreateAndInitChannelOnIOThread, 0); |
| 62 | 62 |
| 63 RefPtr<ChannelEndpoint> channel_endpoint; | 63 RefPtr<ChannelEndpoint> channel_endpoint; |
| 64 scoped_refptr<MessagePipe> mp( | 64 auto mp = MessagePipe::CreateLocalProxy(&channel_endpoint); |
| 65 MessagePipe::CreateLocalProxy(&channel_endpoint)); | |
| 66 | 65 |
| 67 channel(0)->SetBootstrapEndpoint(std::move(channel_endpoint)); | 66 channel(0)->SetBootstrapEndpoint(std::move(channel_endpoint)); |
| 68 | 67 |
| 69 Waiter waiter; | 68 Waiter waiter; |
| 70 waiter.Init(); | 69 waiter.Init(); |
| 71 ASSERT_EQ( | 70 ASSERT_EQ( |
| 72 MOJO_RESULT_OK, | 71 MOJO_RESULT_OK, |
| 73 mp->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 72 mp->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
| 74 | 73 |
| 75 // Don't wait for the shutdown to run ... | 74 // Don't wait for the shutdown to run ... |
| (...skipping 13 matching lines...) Expand all Loading... |
| 89 channel(0)->AssertHasOneRef(); | 88 channel(0)->AssertHasOneRef(); |
| 90 } | 89 } |
| 91 | 90 |
| 92 // ChannelTest.WaitAfterAttachRunAndShutdown ----------------------------------- | 91 // ChannelTest.WaitAfterAttachRunAndShutdown ----------------------------------- |
| 93 | 92 |
| 94 TEST_F(ChannelTest, WaitAfterAttachRunAndShutdown) { | 93 TEST_F(ChannelTest, WaitAfterAttachRunAndShutdown) { |
| 95 PostMethodToIOThreadAndWait(FROM_HERE, | 94 PostMethodToIOThreadAndWait(FROM_HERE, |
| 96 &ChannelTest::CreateAndInitChannelOnIOThread, 0); | 95 &ChannelTest::CreateAndInitChannelOnIOThread, 0); |
| 97 | 96 |
| 98 RefPtr<ChannelEndpoint> channel_endpoint; | 97 RefPtr<ChannelEndpoint> channel_endpoint; |
| 99 scoped_refptr<MessagePipe> mp( | 98 auto mp = MessagePipe::CreateLocalProxy(&channel_endpoint); |
| 100 MessagePipe::CreateLocalProxy(&channel_endpoint)); | |
| 101 | 99 |
| 102 channel(0)->SetBootstrapEndpoint(std::move(channel_endpoint)); | 100 channel(0)->SetBootstrapEndpoint(std::move(channel_endpoint)); |
| 103 | 101 |
| 104 PostMethodToIOThreadAndWait(FROM_HERE, | 102 PostMethodToIOThreadAndWait(FROM_HERE, |
| 105 &ChannelTest::ShutdownChannelOnIOThread, 0); | 103 &ChannelTest::ShutdownChannelOnIOThread, 0); |
| 106 | 104 |
| 107 Waiter waiter; | 105 Waiter waiter; |
| 108 waiter.Init(); | 106 waiter.Init(); |
| 109 HandleSignalsState hss; | 107 HandleSignalsState hss; |
| 110 EXPECT_EQ( | 108 EXPECT_EQ( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 123 TEST_F(ChannelTest, EndpointChannelShutdownRace) { | 121 TEST_F(ChannelTest, EndpointChannelShutdownRace) { |
| 124 const size_t kIterations = 1000; | 122 const size_t kIterations = 1000; |
| 125 | 123 |
| 126 for (size_t i = 0; i < kIterations; i++) { | 124 for (size_t i = 0; i < kIterations; i++) { |
| 127 // Need a new set of |RawChannel|s on every iteration. | 125 // Need a new set of |RawChannel|s on every iteration. |
| 128 SetUp(); | 126 SetUp(); |
| 129 PostMethodToIOThreadAndWait( | 127 PostMethodToIOThreadAndWait( |
| 130 FROM_HERE, &ChannelTest::CreateAndInitChannelOnIOThread, 0); | 128 FROM_HERE, &ChannelTest::CreateAndInitChannelOnIOThread, 0); |
| 131 | 129 |
| 132 RefPtr<ChannelEndpoint> channel_endpoint; | 130 RefPtr<ChannelEndpoint> channel_endpoint; |
| 133 scoped_refptr<MessagePipe> mp( | 131 auto mp = MessagePipe::CreateLocalProxy(&channel_endpoint); |
| 134 MessagePipe::CreateLocalProxy(&channel_endpoint)); | |
| 135 | 132 |
| 136 channel(0)->SetBootstrapEndpoint(std::move(channel_endpoint)); | 133 channel(0)->SetBootstrapEndpoint(std::move(channel_endpoint)); |
| 137 | 134 |
| 138 io_thread()->PostTask( | 135 io_thread()->PostTask( |
| 139 FROM_HERE, base::Bind(&ChannelTest::ShutdownAndReleaseChannelOnIOThread, | 136 FROM_HERE, base::Bind(&ChannelTest::ShutdownAndReleaseChannelOnIOThread, |
| 140 base::Unretained(this), 0)); | 137 base::Unretained(this), 0)); |
| 141 mp->Close(0); | 138 mp->Close(0); |
| 142 | 139 |
| 143 // Wait for the IO thread to finish shutting down the channel. | 140 // Wait for the IO thread to finish shutting down the channel. |
| 144 io_thread()->PostTaskAndWait(FROM_HERE, base::Bind(&DoNothing)); | 141 io_thread()->PostTaskAndWait(FROM_HERE, base::Bind(&DoNothing)); |
| 145 EXPECT_FALSE(channel(0)); | 142 EXPECT_FALSE(channel(0)); |
| 146 } | 143 } |
| 147 } | 144 } |
| 148 | 145 |
| 149 // TODO(vtl): More. ------------------------------------------------------------ | 146 // TODO(vtl): More. ------------------------------------------------------------ |
| 150 | 147 |
| 151 } // namespace | 148 } // namespace |
| 152 } // namespace system | 149 } // namespace system |
| 153 } // namespace mojo | 150 } // namespace mojo |
| OLD | NEW |