Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "mojo/edk/system/channel_test_base.h" |
| 6 | |
Viet-Trung Luu | a1e901b | 2015-09-17 18:15:08 -0700 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 9 | #include "base/logging.h" |
Viet-Trung Luu | 01800ae | 2016-02-05 14:45:47 -0800 | [diff] [blame] | 10 | #include "mojo/edk/embedder/simple_platform_support.h" |
Viet-Trung Luu | b66c27e | 2016-02-02 13:45:51 -0800 | [diff] [blame] | 11 | #include "mojo/edk/platform/platform_pipe.h" |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 12 | #include "mojo/edk/system/raw_channel.h" |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 13 | |
Viet-Trung Luu | b66c27e | 2016-02-02 13:45:51 -0800 | [diff] [blame] | 14 | using mojo::platform::PlatformPipe; |
Viet-Trung Luu | 6a1f1a8 | 2015-10-30 15:18:01 -0700 | [diff] [blame] | 15 | using mojo::util::MakeRefCounted; |
| 16 | |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 17 | namespace mojo { |
| 18 | namespace system { |
| 19 | namespace test { |
| 20 | |
| 21 | ChannelTestBase::ChannelTestBase() |
Viet-Trung Luu | 01800ae | 2016-02-05 14:45:47 -0800 | [diff] [blame] | 22 | : platform_support_(embedder::CreateSimplePlatformSupport()), |
| 23 | io_thread_(TestIOThread::StartMode::AUTO) {} |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 24 | |
Viet-Trung Luu | 01800ae | 2016-02-05 14:45:47 -0800 | [diff] [blame] | 25 | ChannelTestBase::~ChannelTestBase() {} |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 26 | |
| 27 | void ChannelTestBase::SetUp() { |
Viet-Trung Luu | 2d07e27 | 2015-12-02 12:47:51 -0800 | [diff] [blame] | 28 | io_thread_.PostTaskAndWait([this]() { SetUpOnIOThread(); }); |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Viet-Trung Luu | b6d3b3c | 2015-05-26 10:36:20 -0700 | [diff] [blame] | 31 | void ChannelTestBase::CreateChannelOnIOThread(unsigned i) { |
Viet-Trung Luu | abe8f82 | 2015-11-24 14:18:17 -0800 | [diff] [blame] | 32 | CHECK(io_thread()->IsCurrentAndRunning()); |
Viet-Trung Luu | b6d3b3c | 2015-05-26 10:36:20 -0700 | [diff] [blame] | 33 | |
| 34 | CHECK(!channels_[i]); |
Viet-Trung Luu | 01800ae | 2016-02-05 14:45:47 -0800 | [diff] [blame] | 35 | channels_[i] = MakeRefCounted<Channel>(platform_support_.get()); |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Viet-Trung Luu | b6d3b3c | 2015-05-26 10:36:20 -0700 | [diff] [blame] | 38 | void ChannelTestBase::InitChannelOnIOThread(unsigned i) { |
Viet-Trung Luu | abe8f82 | 2015-11-24 14:18:17 -0800 | [diff] [blame] | 39 | CHECK(io_thread()->IsCurrentAndRunning()); |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 40 | |
Viet-Trung Luu | b6d3b3c | 2015-05-26 10:36:20 -0700 | [diff] [blame] | 41 | CHECK(raw_channels_[i]); |
| 42 | CHECK(channels_[i]); |
Viet-Trung Luu | af46d42 | 2015-12-15 12:35:14 -0800 | [diff] [blame] | 43 | channels_[i]->Init(io_thread()->task_runner().Clone(), |
| 44 | io_thread()->platform_handle_watcher(), |
| 45 | std::move(raw_channels_[i])); |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Viet-Trung Luu | b6d3b3c | 2015-05-26 10:36:20 -0700 | [diff] [blame] | 48 | void ChannelTestBase::CreateAndInitChannelOnIOThread(unsigned i) { |
| 49 | CreateChannelOnIOThread(i); |
| 50 | InitChannelOnIOThread(i); |
| 51 | } |
| 52 | |
| 53 | void ChannelTestBase::ShutdownChannelOnIOThread(unsigned i) { |
Viet-Trung Luu | abe8f82 | 2015-11-24 14:18:17 -0800 | [diff] [blame] | 54 | CHECK(io_thread()->IsCurrentAndRunning()); |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 55 | |
Viet-Trung Luu | b6d3b3c | 2015-05-26 10:36:20 -0700 | [diff] [blame] | 56 | CHECK(channels_[i]); |
| 57 | channels_[i]->Shutdown(); |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Anand K. Mistry | 457228e | 2015-08-27 08:30:02 +1000 | [diff] [blame] | 60 | void ChannelTestBase::ShutdownAndReleaseChannelOnIOThread(unsigned i) { |
| 61 | ShutdownChannelOnIOThread(i); |
| 62 | channels_[i] = nullptr; |
| 63 | } |
| 64 | |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 65 | void ChannelTestBase::SetUpOnIOThread() { |
Viet-Trung Luu | abe8f82 | 2015-11-24 14:18:17 -0800 | [diff] [blame] | 66 | CHECK(io_thread()->IsCurrentAndRunning()); |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 67 | |
Viet-Trung Luu | b66c27e | 2016-02-02 13:45:51 -0800 | [diff] [blame] | 68 | PlatformPipe channel_pair; |
Viet-Trung Luu | 2ae2bcc | 2016-02-01 14:50:04 -0800 | [diff] [blame] | 69 | raw_channels_[0] = RawChannel::Create(channel_pair.handle0.Pass()); |
| 70 | raw_channels_[1] = RawChannel::Create(channel_pair.handle1.Pass()); |
Viet-Trung Luu | ae70e57 | 2015-05-22 15:21:26 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | } // namespace test |
| 74 | } // namespace system |
| 75 | } // namespace mojo |