blob: ab212ec5a3ec0e91e06500639a9881fc6b861e7f [file] [log] [blame]
Viet-Trung Luuae70e572015-05-22 15:21:26 -07001// 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 Luua1e901b2015-09-17 18:15:08 -07007#include <utility>
8
Viet-Trung Luuae70e572015-05-22 15:21:26 -07009#include "base/logging.h"
Viet-Trung Luu01800ae2016-02-05 14:45:47 -080010#include "mojo/edk/embedder/simple_platform_support.h"
Viet-Trung Luub66c27e2016-02-02 13:45:51 -080011#include "mojo/edk/platform/platform_pipe.h"
Viet-Trung Luuae70e572015-05-22 15:21:26 -070012#include "mojo/edk/system/raw_channel.h"
Viet-Trung Luuae70e572015-05-22 15:21:26 -070013
Viet-Trung Luub66c27e2016-02-02 13:45:51 -080014using mojo::platform::PlatformPipe;
Viet-Trung Luu6a1f1a82015-10-30 15:18:01 -070015using mojo::util::MakeRefCounted;
16
Viet-Trung Luuae70e572015-05-22 15:21:26 -070017namespace mojo {
18namespace system {
19namespace test {
20
21ChannelTestBase::ChannelTestBase()
Viet-Trung Luu01800ae2016-02-05 14:45:47 -080022 : platform_support_(embedder::CreateSimplePlatformSupport()),
23 io_thread_(TestIOThread::StartMode::AUTO) {}
Viet-Trung Luuae70e572015-05-22 15:21:26 -070024
Viet-Trung Luu01800ae2016-02-05 14:45:47 -080025ChannelTestBase::~ChannelTestBase() {}
Viet-Trung Luuae70e572015-05-22 15:21:26 -070026
27void ChannelTestBase::SetUp() {
Viet-Trung Luu2d07e272015-12-02 12:47:51 -080028 io_thread_.PostTaskAndWait([this]() { SetUpOnIOThread(); });
Viet-Trung Luuae70e572015-05-22 15:21:26 -070029}
30
Viet-Trung Luub6d3b3c2015-05-26 10:36:20 -070031void ChannelTestBase::CreateChannelOnIOThread(unsigned i) {
Viet-Trung Luuabe8f822015-11-24 14:18:17 -080032 CHECK(io_thread()->IsCurrentAndRunning());
Viet-Trung Luub6d3b3c2015-05-26 10:36:20 -070033
34 CHECK(!channels_[i]);
Viet-Trung Luu01800ae2016-02-05 14:45:47 -080035 channels_[i] = MakeRefCounted<Channel>(platform_support_.get());
Viet-Trung Luuae70e572015-05-22 15:21:26 -070036}
37
Viet-Trung Luub6d3b3c2015-05-26 10:36:20 -070038void ChannelTestBase::InitChannelOnIOThread(unsigned i) {
Viet-Trung Luuabe8f822015-11-24 14:18:17 -080039 CHECK(io_thread()->IsCurrentAndRunning());
Viet-Trung Luuae70e572015-05-22 15:21:26 -070040
Viet-Trung Luub6d3b3c2015-05-26 10:36:20 -070041 CHECK(raw_channels_[i]);
42 CHECK(channels_[i]);
Viet-Trung Luuaf46d422015-12-15 12:35:14 -080043 channels_[i]->Init(io_thread()->task_runner().Clone(),
44 io_thread()->platform_handle_watcher(),
45 std::move(raw_channels_[i]));
Viet-Trung Luuae70e572015-05-22 15:21:26 -070046}
47
Viet-Trung Luub6d3b3c2015-05-26 10:36:20 -070048void ChannelTestBase::CreateAndInitChannelOnIOThread(unsigned i) {
49 CreateChannelOnIOThread(i);
50 InitChannelOnIOThread(i);
51}
52
53void ChannelTestBase::ShutdownChannelOnIOThread(unsigned i) {
Viet-Trung Luuabe8f822015-11-24 14:18:17 -080054 CHECK(io_thread()->IsCurrentAndRunning());
Viet-Trung Luuae70e572015-05-22 15:21:26 -070055
Viet-Trung Luub6d3b3c2015-05-26 10:36:20 -070056 CHECK(channels_[i]);
57 channels_[i]->Shutdown();
Viet-Trung Luuae70e572015-05-22 15:21:26 -070058}
59
Anand K. Mistry457228e2015-08-27 08:30:02 +100060void ChannelTestBase::ShutdownAndReleaseChannelOnIOThread(unsigned i) {
61 ShutdownChannelOnIOThread(i);
62 channels_[i] = nullptr;
63}
64
Viet-Trung Luuae70e572015-05-22 15:21:26 -070065void ChannelTestBase::SetUpOnIOThread() {
Viet-Trung Luuabe8f822015-11-24 14:18:17 -080066 CHECK(io_thread()->IsCurrentAndRunning());
Viet-Trung Luuae70e572015-05-22 15:21:26 -070067
Viet-Trung Luub66c27e2016-02-02 13:45:51 -080068 PlatformPipe channel_pair;
Viet-Trung Luu2ae2bcc2016-02-01 14:50:04 -080069 raw_channels_[0] = RawChannel::Create(channel_pair.handle0.Pass());
70 raw_channels_[1] = RawChannel::Create(channel_pair.handle1.Pass());
Viet-Trung Luuae70e572015-05-22 15:21:26 -070071}
72
73} // namespace test
74} // namespace system
75} // namespace mojo