| 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/raw_channel.h" | 5 #include "mojo/edk/system/raw_channel.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
| 18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
| 19 #include "base/threading/simple_thread.h" | |
| 20 #include "mojo/edk/embedder/platform_channel_pair.h" | 19 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 21 #include "mojo/edk/embedder/platform_handle.h" | 20 #include "mojo/edk/embedder/platform_handle.h" |
| 22 #include "mojo/edk/embedder/scoped_platform_handle.h" | 21 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 23 #include "mojo/edk/system/message_in_transit.h" | 22 #include "mojo/edk/system/message_in_transit.h" |
| 24 #include "mojo/edk/system/mutex.h" | 23 #include "mojo/edk/system/mutex.h" |
| 25 #include "mojo/edk/system/test_utils.h" | 24 #include "mojo/edk/system/test_utils.h" |
| 26 #include "mojo/edk/system/transport_data.h" | 25 #include "mojo/edk/system/transport_data.h" |
| 27 #include "mojo/edk/test/scoped_test_dir.h" | 26 #include "mojo/edk/test/scoped_test_dir.h" |
| 27 #include "mojo/edk/test/simple_test_thread.h" |
| 28 #include "mojo/edk/test/test_io_thread.h" | 28 #include "mojo/edk/test/test_io_thread.h" |
| 29 #include "mojo/edk/test/test_utils.h" | 29 #include "mojo/edk/test/test_utils.h" |
| 30 #include "mojo/edk/util/make_unique.h" | 30 #include "mojo/edk/util/make_unique.h" |
| 31 #include "mojo/edk/util/scoped_file.h" | 31 #include "mojo/edk/util/scoped_file.h" |
| 32 #include "mojo/public/cpp/system/macros.h" | 32 #include "mojo/public/cpp/system/macros.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 34 | 34 |
| 35 namespace mojo { | 35 namespace mojo { |
| 36 namespace system { | 36 namespace system { |
| 37 namespace { | 37 namespace { |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) | 301 for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) |
| 302 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), size)); | 302 EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), size)); |
| 303 delegate.Wait(); | 303 delegate.Wait(); |
| 304 | 304 |
| 305 io_thread()->PostTaskAndWait( | 305 io_thread()->PostTaskAndWait( |
| 306 FROM_HERE, base::Bind(&RawChannel::Shutdown, base::Unretained(rc.get()))); | 306 FROM_HERE, base::Bind(&RawChannel::Shutdown, base::Unretained(rc.get()))); |
| 307 } | 307 } |
| 308 | 308 |
| 309 // RawChannelTest.WriteMessageAndOnReadMessage --------------------------------- | 309 // RawChannelTest.WriteMessageAndOnReadMessage --------------------------------- |
| 310 | 310 |
| 311 class RawChannelWriterThread : public base::SimpleThread { | 311 class RawChannelWriterThread : public mojo::test::SimpleTestThread { |
| 312 public: | 312 public: |
| 313 RawChannelWriterThread(RawChannel* raw_channel, size_t write_count) | 313 RawChannelWriterThread(RawChannel* raw_channel, size_t write_count) |
| 314 : base::SimpleThread("raw_channel_writer_thread"), | 314 : raw_channel_(raw_channel), left_to_write_(write_count) {} |
| 315 raw_channel_(raw_channel), | |
| 316 left_to_write_(write_count) {} | |
| 317 | 315 |
| 318 ~RawChannelWriterThread() override { Join(); } | 316 ~RawChannelWriterThread() override { Join(); } |
| 319 | 317 |
| 320 private: | 318 private: |
| 321 void Run() override { | 319 void Run() override { |
| 322 static const int kMaxRandomMessageSize = 25000; | 320 static const int kMaxRandomMessageSize = 25000; |
| 323 | 321 |
| 324 while (left_to_write_-- > 0) { | 322 while (left_to_write_-- > 0) { |
| 325 EXPECT_TRUE(raw_channel_->WriteMessage(MakeTestMessage( | 323 EXPECT_TRUE(raw_channel_->WriteMessage(MakeTestMessage( |
| 326 static_cast<uint32_t>(test::RandomInt(1, kMaxRandomMessageSize))))); | 324 static_cast<uint32_t>(test::RandomInt(1, kMaxRandomMessageSize))))); |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 FROM_HERE, | 836 FROM_HERE, |
| 839 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_read.get()))); | 837 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_read.get()))); |
| 840 io_thread()->PostTaskAndWait( | 838 io_thread()->PostTaskAndWait( |
| 841 FROM_HERE, | 839 FROM_HERE, |
| 842 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_write.get()))); | 840 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_write.get()))); |
| 843 } | 841 } |
| 844 | 842 |
| 845 } // namespace | 843 } // namespace |
| 846 } // namespace system | 844 } // namespace system |
| 847 } // namespace mojo | 845 } // namespace mojo |
| OLD | NEW |