Flutter Engine
The Flutter Engine
engine_unittests.cc
Go to the documentation of this file.
1// Copyright 2020 The Flutter 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 "flutter/shell/platform/fuchsia/flutter/engine.h"
6
7#include "flutter/shell/common/thread_host.h"
8
9#include "gtest/gtest.h"
10
11using namespace flutter;
12
13namespace flutter_runner {
14namespace testing {
15namespace {
16
17std::string GetCurrentTestName() {
18 return ::testing::UnitTest::GetInstance()->current_test_info()->name();
19}
20
21} // namespace
22
23TEST(EngineTest, ThreadNames) {
24 std::string prefix = GetCurrentTestName();
26
27 char thread_name[ZX_MAX_NAME_LEN];
28 zx::thread::self()->get_property(ZX_PROP_NAME, thread_name,
29 sizeof(thread_name));
30 EXPECT_EQ(std::string(thread_name), prefix + std::string(".platform"));
31 EXPECT_EQ(engine_thread_host.platform_thread, nullptr);
32
33 engine_thread_host.raster_thread->GetTaskRunner()->PostTask([&prefix]() {
34 char thread_name[ZX_MAX_NAME_LEN];
35 zx::thread::self()->get_property(ZX_PROP_NAME, thread_name,
36 sizeof(thread_name));
37 EXPECT_EQ(std::string(thread_name), prefix + std::string(".raster"));
38 });
39 engine_thread_host.raster_thread->Join();
40
41 engine_thread_host.ui_thread->GetTaskRunner()->PostTask([&prefix]() {
42 char thread_name[ZX_MAX_NAME_LEN];
43 zx::thread::self()->get_property(ZX_PROP_NAME, thread_name,
44 sizeof(thread_name));
45 EXPECT_EQ(std::string(thread_name), prefix + std::string(".ui"));
46 });
47 engine_thread_host.ui_thread->Join();
48
49 engine_thread_host.io_thread->GetTaskRunner()->PostTask([&prefix]() {
50 char thread_name[ZX_MAX_NAME_LEN];
51 zx::thread::self()->get_property(ZX_PROP_NAME, thread_name,
52 sizeof(thread_name));
53 EXPECT_EQ(std::string(thread_name), prefix + std::string(".io"));
54 });
55 engine_thread_host.io_thread->Join();
56}
57
58} // namespace testing
59} // namespace flutter_runner
static flutter::ThreadHost CreateThreadHost(const std::string &name_prefix, const std::shared_ptr< sys::ServiceDirectory > &runner_services=nullptr)
Definition: engine.cc:136
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition: testing.cc:15
TEST(EngineTest, ThreadNames)
The collection of all the threads used by the engine.
Definition: thread_host.h:21
std::unique_ptr< fml::Thread > io_thread
Definition: thread_host.h:86
std::unique_ptr< fml::Thread > platform_thread
Definition: thread_host.h:83
std::unique_ptr< fml::Thread > raster_thread
Definition: thread_host.h:85
std::unique_ptr< fml::Thread > ui_thread
Definition: thread_host.h:84