diff --git a/BUILD.gn b/BUILD.gn index d4bf45f18d962c38d87486537064896560ac29c1..25006866ca8962d2e7f2b5fe7de21480387268f0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -136,6 +136,7 @@ if (is_fuchsia) { "//flutter/flow:flow_tests", "//flutter/fml:fml_tests", "//flutter/runtime:runtime_tests", + "//flutter/shell/common:shell_tests", "//flutter/shell/platform/fuchsia/flutter:flutter_runner_scenic_tests", "//flutter/shell/platform/fuchsia/flutter:flutter_runner_tests", ] diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 4d6a80080708d1d9f6c0ff6f2b3a4a8590bb797c..d450f8e85afae1cbe5296cf28a7f9f5505512b28 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -578,6 +578,8 @@ FILE: ../../../flutter/shell/common/shell_test_platform_view.cc FILE: ../../../flutter/shell/common/shell_test_platform_view.h FILE: ../../../flutter/shell/common/shell_test_platform_view_gl.cc FILE: ../../../flutter/shell/common/shell_test_platform_view_gl.h +FILE: ../../../flutter/shell/common/shell_test_platform_view_vulkan.cc +FILE: ../../../flutter/shell/common/shell_test_platform_view_vulkan.h FILE: ../../../flutter/shell/common/shell_unittests.cc FILE: ../../../flutter/shell/common/skia_event_tracer_impl.cc FILE: ../../../flutter/shell/common/skia_event_tracer_impl.h diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index b68c20b15be8ce61c5790e0511e72faa3de8bba1..970638ea8dac68f58aa7e163df263f74a108639f 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -2,9 +2,30 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("//flutter/common/config.gni") import("//flutter/shell/gpu/gpu.gni") import("//flutter/testing/testing.gni") +if (is_fuchsia) { + import("//build/fuchsia/sdk.gni") + import("//flutter/tools/fuchsia/fuchsia_archive.gni") +} + +config("vulkan_config") { + if (using_fuchsia_sdk) { + include_dirs = [ "$fuchsia_sdk_root/vulkan/include" ] + } else if (is_fuchsia) { + include_dirs = + [ "//third_party/vulkan_loader_and_validation_layers/include" ] + } else { + include_dirs = [ "//third_party/vulkan/src" ] + } + + if (is_fuchsia) { + defines = [ "VK_USE_PLATFORM_FUCHSIA=1" ] + } +} + # Template to generate a dart embedder resource.cc file. # Required invoker inputs: # String output (name of output file) @@ -143,12 +164,19 @@ template("shell_host_executable") { } } -if (current_toolchain == host_toolchain) { +if (enable_unittests) { + declare_args() { + test_enable_vulkan = is_fuchsia + test_enable_gl = !is_fuchsia + test_enable_software = true + test_enable_metal = false + } + shell_gpu_configuration("shell_unittests_gpu_configuration") { - enable_software = true - enable_vulkan = false - enable_gl = true - enable_metal = false + enable_software = test_enable_software + enable_vulkan = test_enable_vulkan + enable_gl = test_enable_gl + enable_metal = test_enable_metal } test_fixtures("shell_unittests_fixtures") { @@ -168,8 +196,6 @@ if (current_toolchain == host_toolchain) { "shell_test.h", "shell_test_platform_view.cc", "shell_test_platform_view.h", - "shell_test_platform_view_gl.cc", - "shell_test_platform_view_gl.h", "shell_unittests.cc", "vsync_waiters_test.cc", "vsync_waiters_test.h", @@ -184,8 +210,64 @@ if (current_toolchain == host_toolchain) { "//flutter/lib/ui:ui", "//flutter/shell", "//flutter/testing:dart", - "//flutter/testing:opengl", ] + + if (!defined(defines)) { + defines = [] + } + + # SwiftShader only supports x86/x64_64 + if (target_cpu == "x86" || target_cpu == "x64") { + if (test_enable_gl) { + sources += [ + "shell_test_platform_view_gl.cc", + "shell_test_platform_view_gl.h", + ] + + deps += [ "//flutter/testing:opengl" ] + + defines += [ "SHELL_ENABLE_GL" ] + } + + if (test_enable_vulkan) { + sources += [ + "shell_test_platform_view_vulkan.cc", + "shell_test_platform_view_vulkan.h", + ] + + deps += [ + "//flutter/testing:vulkan", + "//flutter/vulkan", + ] + + defines += [ "SHELL_ENABLE_VULKAN" ] + } + } + } + + if (is_fuchsia) { + fuchsia_test_archive("shell_tests") { + deps = [ + ":shell_unittests", + ":shell_unittests_fixtures", + ] + + binary = "shell_unittests" + + # TODO(gw280): https://github.com/flutter/flutter/issues/50294 + # Right now we need to manually specify all the fixtures that are + # declared in the test_fixtures() call above. + resources = [ + { + path = "$target_gen_dir/assets/kernel_blob.bin" + dest = "assets/kernel_blob.bin" + }, + { + path = "$target_gen_dir/assets/shelltest_screenshot.png" + dest = "assets/shelltest_screenshot.png" + }, + ] + } } shell_host_executable("shell_benchmarks") { diff --git a/shell/common/animator_unittests.cc b/shell/common/animator_unittests.cc index 0932c1ab56a0c15a49e9009c36992bfa3418fafe..3907cee3b89ab85db0ff4c527f67432bdfc35d44 100644 --- a/shell/common/animator_unittests.cc +++ b/shell/common/animator_unittests.cc @@ -52,9 +52,10 @@ TEST_F(ShellTest, VSyncTargetTime) { shell = Shell::Create( task_runners, settings, [vsync_clock, &create_vsync_waiter](Shell& shell) { - return ShellTestPlatformView::Create(shell, shell.GetTaskRunners(), - vsync_clock, - std::move(create_vsync_waiter)); + return ShellTestPlatformView::Create( + shell, shell.GetTaskRunners(), vsync_clock, + std::move(create_vsync_waiter), + ShellTestPlatformView::BackendType::kDefaultBackend); }, [](Shell& shell) { return std::make_unique(shell, shell.GetTaskRunners()); diff --git a/shell/common/shell_test.cc b/shell/common/shell_test.cc index ab07b9b78563ad3ed40b083aae18d294346c4a39..fecab7b34f9055082eb3c3da1eebb35f3b06491e 100644 --- a/shell/common/shell_test.cc +++ b/shell/common/shell_test.cc @@ -254,9 +254,10 @@ std::unique_ptr ShellTest::CreateShell(Settings settings, return Shell::Create( task_runners, settings, [vsync_clock, &create_vsync_waiter](Shell& shell) { - return ShellTestPlatformView::Create(shell, shell.GetTaskRunners(), - vsync_clock, - std::move(create_vsync_waiter)); + return ShellTestPlatformView::Create( + shell, shell.GetTaskRunners(), vsync_clock, + std::move(create_vsync_waiter), + ShellTestPlatformView::BackendType::kDefaultBackend); }, [](Shell& shell) { return std::make_unique(shell, shell.GetTaskRunners()); diff --git a/shell/common/shell_test_platform_view.cc b/shell/common/shell_test_platform_view.cc index 694ac3eddc6152d6303abce37aa0c1908a7b18bd..cfd43308bfc104b2c8276b210407b486b1dbe580 100644 --- a/shell/common/shell_test_platform_view.cc +++ b/shell/common/shell_test_platform_view.cc @@ -3,7 +3,13 @@ // found in the LICENSE file. #include "flutter/shell/common/shell_test_platform_view.h" + +#ifdef SHELL_ENABLE_GL #include "flutter/shell/common/shell_test_platform_view_gl.h" +#endif // SHELL_ENABLE_GL +#ifdef SHELL_ENABLE_VULKAN +#include "flutter/shell/common/shell_test_platform_view_vulkan.h" +#endif // SHELL_ENABLE_VULKAN namespace flutter { namespace testing { @@ -12,9 +18,26 @@ std::unique_ptr ShellTestPlatformView::Create( PlatformView::Delegate& delegate, TaskRunners task_runners, std::shared_ptr vsync_clock, - CreateVsyncWaiter create_vsync_waiter) { - return std::make_unique( - delegate, task_runners, vsync_clock, create_vsync_waiter); + CreateVsyncWaiter create_vsync_waiter, + BackendType backend) { + // TODO(gw280): https://github.com/flutter/flutter/issues/50298 + // Make this fully runtime configurable + switch (backend) { + case BackendType::kDefaultBackend: +#ifdef SHELL_ENABLE_GL + case BackendType::kGLBackend: + return std::make_unique( + delegate, task_runners, vsync_clock, create_vsync_waiter); +#endif // SHELL_ENABLE_GL +#ifdef SHELL_ENABLE_VULKAN + case BackendType::kVulkanBackend: + return std::make_unique( + delegate, task_runners, vsync_clock, create_vsync_waiter); +#endif // SHELL_ENABLE_VULKAN + default: + FML_LOG(FATAL) << "No backends supported for ShellTestPlatformView"; + return nullptr; + } } } // namespace testing diff --git a/shell/common/shell_test_platform_view.h b/shell/common/shell_test_platform_view.h index c53a2b4473230ace24c91a744f627adc592f4644..c7aefe86b33bc8c6a418bf88ac096c34bc646420 100644 --- a/shell/common/shell_test_platform_view.h +++ b/shell/common/shell_test_platform_view.h @@ -13,11 +13,18 @@ namespace testing { class ShellTestPlatformView : public PlatformView { public: + enum class BackendType { + kGLBackend, + kVulkanBackend, + kDefaultBackend, + }; + static std::unique_ptr Create( PlatformView::Delegate& delegate, TaskRunners task_runners, std::shared_ptr vsync_clock, - CreateVsyncWaiter create_vsync_waiter); + CreateVsyncWaiter create_vsync_waiter, + BackendType backend); virtual void SimulateVSync() = 0; diff --git a/shell/common/shell_test_platform_view_vulkan.cc b/shell/common/shell_test_platform_view_vulkan.cc new file mode 100644 index 0000000000000000000000000000000000000000..b582931748839abce4029f6f3341eba9b2f4bcec --- /dev/null +++ b/shell/common/shell_test_platform_view_vulkan.cc @@ -0,0 +1,49 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/common/shell_test_platform_view_vulkan.h" +#include "flutter/shell/gpu/gpu_surface_vulkan.h" + +namespace flutter { +namespace testing { + +ShellTestPlatformViewVulkan::ShellTestPlatformViewVulkan( + PlatformView::Delegate& delegate, + TaskRunners task_runners, + std::shared_ptr vsync_clock, + CreateVsyncWaiter create_vsync_waiter) + : ShellTestPlatformView(delegate, std::move(task_runners)), + create_vsync_waiter_(std::move(create_vsync_waiter)), + vsync_clock_(vsync_clock), + proc_table_(fml::MakeRefCounted()) {} + +ShellTestPlatformViewVulkan::~ShellTestPlatformViewVulkan() = default; + +std::unique_ptr ShellTestPlatformViewVulkan::CreateVSyncWaiter() { + return create_vsync_waiter_(); +} + +void ShellTestPlatformViewVulkan::SimulateVSync() { + vsync_clock_->SimulateVSync(); +} + +// |PlatformView| +std::unique_ptr ShellTestPlatformViewVulkan::CreateRenderingSurface() { + return std::make_unique(this, nullptr, true); +} + +// |PlatformView| +PointerDataDispatcherMaker ShellTestPlatformViewVulkan::GetDispatcherMaker() { + return [](DefaultPointerDataDispatcher::Delegate& delegate) { + return std::make_unique(delegate); + }; +} + +// |GPUSurfaceVulkanDelegate| +fml::RefPtr ShellTestPlatformViewVulkan::vk() { + return proc_table_; +} + +} // namespace testing +} // namespace flutter diff --git a/shell/common/shell_test_platform_view_vulkan.h b/shell/common/shell_test_platform_view_vulkan.h new file mode 100644 index 0000000000000000000000000000000000000000..c201ff1a9f27f9d7cb02077994e0e7b50089bf27 --- /dev/null +++ b/shell/common/shell_test_platform_view_vulkan.h @@ -0,0 +1,51 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_VULKAN_H_ +#define FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_VULKAN_H_ + +#include "flutter/shell/common/shell_test_platform_view.h" +#include "flutter/shell/gpu/gpu_surface_vulkan_delegate.h" + +namespace flutter { +namespace testing { + +class ShellTestPlatformViewVulkan : public ShellTestPlatformView, + public GPUSurfaceVulkanDelegate { + public: + ShellTestPlatformViewVulkan(PlatformView::Delegate& delegate, + TaskRunners task_runners, + std::shared_ptr vsync_clock, + CreateVsyncWaiter create_vsync_waiter); + + ~ShellTestPlatformViewVulkan() override; + + void SimulateVSync() override; + + private: + CreateVsyncWaiter create_vsync_waiter_; + + std::shared_ptr vsync_clock_; + + fml::RefPtr proc_table_; + + // |PlatformView| + std::unique_ptr CreateRenderingSurface() override; + + // |PlatformView| + std::unique_ptr CreateVSyncWaiter() override; + + // |PlatformView| + PointerDataDispatcherMaker GetDispatcherMaker() override; + + // |GPUSurfaceVulkanDelegate| + fml::RefPtr vk() override; + + FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformViewVulkan); +}; + +} // namespace testing +} // namespace flutter + +#endif // FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_VULKAN_H_ diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index d35851d2cc3b75a892249f03df4b9453ddb27195..26963e1c146be5635a4357568c261b6b6977ed55 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -135,7 +135,8 @@ TEST_F(ShellTest, [task_runners = shell.GetTaskRunners()]() { return static_cast>( std::make_unique(task_runners)); - }); + }, + ShellTestPlatformView::BackendType::kDefaultBackend); }, [](Shell& shell) { return std::make_unique(shell, shell.GetTaskRunners()); diff --git a/shell/platform/fuchsia/BUILD.gn b/shell/platform/fuchsia/BUILD.gn index 4166a7ed4840522fb45c53180567743b5b13653a..9afc96bc02d4079f04a85d17e36e339396fd33a6 100644 --- a/shell/platform/fuchsia/BUILD.gn +++ b/shell/platform/fuchsia/BUILD.gn @@ -8,8 +8,6 @@ import("//flutter/tools/fuchsia/dart.gni") import("//flutter/tools/fuchsia/fuchsia_host_bundle.gni") if (using_fuchsia_sdk) { - testonly = true - product_suffix = "" is_product = false diff --git a/testing/BUILD.gn b/testing/BUILD.gn index fcd46f13646943a915fe2bc312814afe3b76af01..e7c968caab3b953fe239458b795d2206c47cc4ce 100644 --- a/testing/BUILD.gn +++ b/testing/BUILD.gn @@ -75,73 +75,88 @@ source_set("skia") { ] } -if (current_toolchain == host_toolchain) { - source_set("opengl") { - testonly = true - - configs += [ "//third_party/swiftshader_flutter:swiftshader_config" ] - - sources = [ - "test_gl_surface.cc", - "test_gl_surface.h", - ] - - deps = [ - ":skia", - "//flutter/fml", - "//third_party/swiftshader_flutter:swiftshader", - ] - } +if (enable_unittests) { + # SwiftShader only supports x86/x64_64 + if (target_cpu == "x86" || target_cpu == "x64") { + source_set("opengl") { + testonly = true + + configs += [ "//third_party/swiftshader_flutter:swiftshader_config" ] + + sources = [ + "test_gl_surface.cc", + "test_gl_surface.h", + ] + + deps = [ + ":skia", + "//flutter/fml", + "//third_party/swiftshader_flutter:swiftshader_gl", + ] + } + + source_set("vulkan") { + testonly = true - # All targets on all platforms should be able to use the Metal utilities. On - # platforms where Metal is not available, the tests must be skipped or - # implemented to use another available client rendering API. This is usually - # either OpenGL which is portably implemented via SwiftShader or the software - # backend. This way, all tests compile on all platforms but the Metal backend - # is exercised on platforms where Metal itself is available. - source_set("metal") { - testonly = true - - sources = [ - "test_metal_surface.cc", - "test_metal_surface.h", - ] - - defines = [] - - if (shell_enable_metal) { - sources += [ "test_metal_surface_impl.mm" ] - defines += [ "TESTING_ENABLE_METAL" ] + configs += [ "//third_party/swiftshader_flutter:swiftshader_config" ] + + deps = [ + ":skia", + "//flutter/fml", + "//third_party/swiftshader_flutter:swiftshader_vulkan", + ] } - deps = [ - ":skia", - "//flutter/fml", - ] - } + # All targets on all platforms should be able to use the Metal utilities. On + # platforms where Metal is not available, the tests must be skipped or + # implemented to use another available client rendering API. This is usually + # either OpenGL which is portably implemented via SwiftShader or the software + # backend. This way, all tests compile on all platforms but the Metal backend + # is exercised on platforms where Metal itself is available. + source_set("metal") { + testonly = true + + sources = [ + "test_metal_surface.cc", + "test_metal_surface.h", + ] + + defines = [] + + if (shell_enable_metal) { + sources += [ "test_metal_surface_impl.mm" ] + defines += [ "TESTING_ENABLE_METAL" ] + } + + deps = [ + ":skia", + "//flutter/fml", + ] + } - test_fixtures("testing_fixtures") { - fixtures = [] - } + test_fixtures("testing_fixtures") { + fixtures = [] + } - # The //flutter/testing library provides utility methods to other test targets. - # This test target tests the testing utilities. - executable("testing_unittests") { - testonly = true - - sources = [ - "mock_canvas_unittests.cc", - "test_metal_surface_unittests.cc", - ] - - deps = [ - ":dart", - ":metal", - ":opengl", - ":skia", - ":testing", - ":testing_fixtures", - ":testing_lib", - ] + # The //flutter/testing library provides utility methods to other test targets. + # This test target tests the testing utilities. + executable("testing_unittests") { + testonly = true + + sources = [ + "mock_canvas_unittests.cc", + "test_metal_surface_unittests.cc", + ] + + deps = [ + ":dart", + ":metal", + ":opengl", + ":skia", + ":testing", + ":testing_fixtures", + ":testing_lib", + ] + } } } diff --git a/testing/fuchsia/run_tests.sh b/testing/fuchsia/run_tests.sh index 176d3a7b798c7b80cda69b92061778affe4638d7..e142ef620bc1e7c5a46a1751964496a7ac33d5d3 100755 --- a/testing/fuchsia/run_tests.sh +++ b/testing/fuchsia/run_tests.sh @@ -63,3 +63,8 @@ done ./fuchsia_ctl -d $device_name test \ -f runtime_tests-0.far \ -t runtime_tests + +./fuchsia_ctl -d $device_name test \ + -f shell_tests-0.far \ + -t shell_tests \ + -a "--gtest_filter=-ShellTest.HandlesActualIphoneXsInputEvents:ShellTest.CacheSkSLWorks:ShellTest.SetResourceCacheSize*:ShellTest.Screenshot" diff --git a/testing/fuchsia/test_fars b/testing/fuchsia/test_fars index 1360800ae0241ac06a2d810981f8f76011bc0edb..2c94af9c779561c30c431a31f216fe49b6f67a90 100644 --- a/testing/fuchsia/test_fars +++ b/testing/fuchsia/test_fars @@ -3,3 +3,4 @@ flutter_runner_scenic_tests-0.far fml_tests-0.far flow_tests-0.far runtime_tests-0.far +shell_tests-0.far diff --git a/testing/testing.gni b/testing/testing.gni index f8b64c0baf60719b65462eb4efdeb2dce2d39534..5e06cd049cfd7c18533a95bda7c45f52d08abcbe 100644 --- a/testing/testing.gni +++ b/testing/testing.gni @@ -9,6 +9,11 @@ import("//third_party/dart/build/dart/dart_action.gni") is_aot_test = flutter_runtime_mode == "profile" || flutter_runtime_mode == "release" +# Unit tests targets are only enabled for host machines and Fuchsia right now +declare_args() { + enable_unittests = current_toolchain == host_toolchain || is_fuchsia +} + # Creates a translation unit that defines the flutter::testing::GetFixturesPath # method that tests can use to locate their fixtures. # diff --git a/vulkan/BUILD.gn b/vulkan/BUILD.gn index 07aba7f930e1a06192e0e1a0628a56c96d45f66f..13781b5a66141bbc10c742fd2faaa905017ba08d 100644 --- a/vulkan/BUILD.gn +++ b/vulkan/BUILD.gn @@ -56,8 +56,7 @@ source_set("vulkan") { "vulkan_native_surface_android.h", "vulkan_swapchain.cc", ] - } - if (is_fuchsia) { + } else { sources += [ "vulkan_swapchain_stub.cc" ] }