diff --git a/BUILD.gn b/BUILD.gn index 7a102d594bf570c401e4a55e5682fd014a56ab81..837d70d1ef39f0c801b0059f2305b7d947b421bb 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -152,9 +152,6 @@ group("unittests") { "//flutter/runtime:no_dart_plugin_registrant_unittests", "//flutter/runtime:runtime_unittests", "//flutter/shell/common:shell_unittests", - "//flutter/shell/platform/embedder:embedder_a11y_unittests", - "//flutter/shell/platform/embedder:embedder_proctable_unittests", - "//flutter/shell/platform/embedder:embedder_unittests", "//flutter/testing:testing_unittests", "//flutter/testing/dart", "//flutter/testing/smoke_test_failure", @@ -162,6 +159,15 @@ group("unittests") { "//flutter/third_party/txt:txt_unittests", ] + # ohos does not support vulkan + if (!is_ohos) { + public_deps += [ + "//flutter/shell/platform/embedder:embedder_a11y_unittests", + "//flutter/shell/platform/embedder:embedder_proctable_unittests", + "//flutter/shell/platform/embedder:embedder_unittests", + ] + } + # The accessibility library only supports Mac and Windows at the moment. if (is_mac || is_win) { public_deps += @@ -181,7 +187,7 @@ group("unittests") { [ "//flutter/shell/platform/darwin:flutter_channels_unittests" ] } - if (!is_win && !is_fuchsia) { + if (!is_win && !is_fuchsia && !is_ohos) { public_deps += [ "//flutter/shell/platform/android/external_view_embedder:android_external_view_embedder_unittests", "//flutter/shell/platform/android/jni:jni_unittests", diff --git a/fml/BUILD.gn b/fml/BUILD.gn index 03d286857c2d7308c91dca9f445e59e484069b50..8bc353b936eaa87a0daa1baf851b1950d0fab479 100644 --- a/fml/BUILD.gn +++ b/fml/BUILD.gn @@ -364,6 +364,10 @@ if (enable_unittests) { "time/time_delta_unittest.cc", "time/time_point_unittest.cc", "time/time_unittest.cc", + "platform/ohos/timerfd_unittests.cc", + "platform/ohos/paths_ohos_unittests.cc", + "platform/ohos/napi_util_unittests.cc", + "platform/ohos/message_loop_ohos_unittests.cc" ] if (is_mac) { diff --git a/fml/platform/ohos/napi_util_unittests.cc b/fml/platform/ohos/napi_util_unittests.cc new file mode 100644 index 0000000000000000000000000000000000000000..5680db51e9ec285b18c36c666dd81d3311399286 --- /dev/null +++ b/fml/platform/ohos/napi_util_unittests.cc @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "flutter/fml/platform/ohos/napi_util.h" +#include "gtest/gtest.h" + +namespace fml { +namespace { +TEST(NapiUtilTest, NapiUtil01) { + napi_env env = nullptr; + napi_value value = nullptr; + EXPECT_EQ(napi::NapiIsNull(env, value), true); +} + +TEST(NapiUtilTest, NapiUtil02) { + napi_env env = nullptr; + napi_value value = nullptr; + std::string str = "test"; + EXPECT_EQ(napi::GetString(env, value,str), napi::ERROR_TYPE); +} + +TEST(NapiUtilTest, NapiUtil03) { + napi_env env = nullptr; + napi_value value = nullptr; + std::vector vectorStr = {}; + EXPECT_NE(napi::GetArrayString(env, value, vectorStr), napi::SUCCESS); +} + +TEST(NapiUtilTest, NapiUtil04) { + napi_env env = nullptr; + napi_value value = nullptr; + void** message = nullptr; + size_t lenth = 0; + EXPECT_NE(napi::GetArrayBuffer(env, value, message, &lenth), napi::SUCCESS); +} + +TEST(NapiUtilTest, NapiUtil05) { + napi_env env = nullptr; + napi_value value = nullptr; + EXPECT_EQ(napi::NapiIsType(env, value, napi_number), false); +} + +TEST(NapiUtilTest, NapiUtil06) { + napi_env env = nullptr; + napi_ref ref_napi_obj = nullptr; + EXPECT_GT(napi::InvokeJsMethod(env, ref_napi_obj, nullptr, 0, nullptr), 0); +} + +} // namespace +} // namespace fml \ No newline at end of file diff --git a/fml/platform/ohos/paths_ohos_unittests.cc b/fml/platform/ohos/paths_ohos_unittests.cc new file mode 100644 index 0000000000000000000000000000000000000000..3ab18fc8d6440f37d26a7fe4005c29e7e7a2f5c6 --- /dev/null +++ b/fml/platform/ohos/paths_ohos_unittests.cc @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "flutter/fml/platform/ohos/paths_ohos.h" + +#include "gtest/gtest.h" + +namespace fml { +namespace { +TEST(PathsTest, PathsOhosTest01) { + fml::paths::InitializeOhosCachesPath("test"); + fml::UniqueFD resultFD = fml::paths::GetCachesDirectory(); + EXPECT_FALSE(resultFD.is_valid()); +} + + +} // namespace +} // namespace fml \ No newline at end of file diff --git a/fml/platform/ohos/timerfd_unittests.cc b/fml/platform/ohos/timerfd_unittests.cc new file mode 100644 index 0000000000000000000000000000000000000000..26b505db3a3465084629fe0b88b1b9f7e3650d49 --- /dev/null +++ b/fml/platform/ohos/timerfd_unittests.cc @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include "flutter/fml/platform/ohos/timerfd.h" + +#include "gtest/gtest.h" + +using fml::TimePoint; +namespace fml { +namespace { + +class MockFileDescriptor { +public: + MockFileDescriptor() { + pipe(fd_); + } + + ~MockFileDescriptor() { + close(fd_[0]); + close(fd_[1]); + } + + int get_read_fd() const { return fd_[0]; } + int get_write_fd() const { return fd_[1]; } + + void write_fire_count(uint64_t count) { + write(fd_[1], &count, sizeof(count)); + } + +private: + int fd_[2]; +}; +TEST(TimerfdTest, TimerRearmTest) { + TimePoint timeP; + EXPECT_EQ(TimerRearm(0, timeP), false); +} + +TEST(TimerDrainTest, ReadsFireCountSuccessfully) { + { + MockFileDescriptor mock_fd; + uint64_t expected_count = 1; + mock_fd.write_fire_count(expected_count); + EXPECT_TRUE(TimerDrain(mock_fd.get_read_fd())); + } +} + +TEST(TimerfdTest, TimerFdCreateTest) { + EXPECT_TRUE(timerfd_create(0, 0)); +} + +TEST(TimerfdTest, TimerFdSettimeTest) { + EXPECT_EQ(timerfd_settime(0, 0, nullptr, nullptr), -1); +} + +} // namespace +} // namespace fml \ No newline at end of file diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index 7fa0c1b23ae702ec61d968210891c412fdc6f482..2f8b67095e0e5ba42ac68e68c4f625f00f6b1b01 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -185,6 +185,10 @@ if (enable_unittests) { "fixtures/shelltest_screenshot.png", "fixtures/hello_loop_2.gif", ] + + if (is_ohos) { + dest = "/data/flutter_unittests/common" + } } shell_host_executable("shell_benchmarks") { @@ -284,16 +288,12 @@ if (enable_unittests) { testonly = true sources = [ - "animator_unittests.cc", "canvas_spy_unittests.cc", "context_options_unittests.cc", "engine_unittests.cc", - "input_events_unittests.cc", - "persistent_cache_unittests.cc", "pipeline_unittests.cc", "rasterizer_unittests.cc", "resource_cache_limit_calculator_unittests.cc", - "shell_unittests.cc", "switches_unittests.cc", "variable_refresh_rate_display_unittests.cc", "vsync_waiter_unittests.cc", @@ -310,6 +310,15 @@ if (enable_unittests) { "//third_party/googletest:gmock", ] + if (!is_ohos) { + sources += [ + "animator_unittests.cc", + "input_events_unittests.cc", + "persistent_cache_unittests.cc", + "shell_unittests.cc", + ] + } + if (is_fuchsia) { sources += [ "shell_fuchsia_unittests.cc" ] @@ -319,7 +328,7 @@ if (enable_unittests) { "$fuchsia_sdk_root/pkg:fidl_cpp", "$fuchsia_sdk_root/pkg:sys_cpp", ] - } else { + } else if (!is_ohos) { # TODO(63837): This test is hard-coded to use a TestGLSurface so it cannot run on fuchsia. sources += [ "shell_io_manager_unittests.cc" ] diff --git a/shell/config.gni b/shell/config.gni index 85dd360cbc036d5c4276303906ecb56fbcab19ac..4db04f8b5c834f51ceed3be23d295e548416cde7 100644 --- a/shell/config.gni +++ b/shell/config.gni @@ -17,6 +17,6 @@ declare_args() { test_enable_metal = shell_enable_metal # The Vulkan unittests are combined with the GL unittests. - test_enable_vulkan = is_fuchsia || shell_enable_gl + test_enable_vulkan = (is_fuchsia || shell_enable_gl) && !is_ohos test_enable_software = shell_enable_software } diff --git a/shell/gpu/gpu_surface_vulkan.cc b/shell/gpu/gpu_surface_vulkan.cc index ba8383c1343cf63020cb05440406d3b285fe206a..7743289f593248bb944aa77fbe40634c7ea11f1d 100644 --- a/shell/gpu/gpu_surface_vulkan.cc +++ b/shell/gpu/gpu_surface_vulkan.cc @@ -98,6 +98,7 @@ sk_sp GPUSurfaceVulkan::CreateSurfaceFromVulkanImage( const VkImage image, const VkFormat format, const SkISize& size) { +#ifdef SK_VULKAN GrVkImageInfo image_info = { .fImage = image, .fImageTiling = VK_IMAGE_TILING_OPTIMAL, @@ -126,6 +127,9 @@ sk_sp GPUSurfaceVulkan::CreateSurfaceFromVulkanImage( SkColorSpace::MakeSRGB(), // color space &surface_properties // surface properties ); +#else + return nullptr; +#endif // SK_VULKAN } SkColorType GPUSurfaceVulkan::ColorTypeFromFormat(const VkFormat format) { diff --git a/shell/platform/embedder/BUILD.gn b/shell/platform/embedder/BUILD.gn index 56335f45afd715add78c6f571d03c3d1239f4886..261d879c753e9ebf078dbd20d70292f25e84cc06 100644 --- a/shell/platform/embedder/BUILD.gn +++ b/shell/platform/embedder/BUILD.gn @@ -217,7 +217,7 @@ test_fixtures("fixtures") { ] } -if (enable_unittests) { +if (enable_unittests && !is_ohos) { source_set("embedder_unittests_library") { testonly = true diff --git a/testing/testing.gni b/testing/testing.gni index 3fadcbbc71e16935c24d2c6de108479ad09902e2..4a8cef4968ccae333617488e9e55f1d7fa23148b 100644 --- a/testing/testing.gni +++ b/testing/testing.gni @@ -331,7 +331,12 @@ template("test_fixtures") { copy_fixtures_target_name = "_cf_$target_name" copy_fixtures(copy_fixtures_target_name) { fixtures = invoker.fixtures - dest = dest + # dest = dest + if (is_ohos) { + dest = target_gen_dir + } else { + dest = dest + } forward_variables_from(invoker, [ "deps" ]) } test_public_deps += [ ":$copy_fixtures_target_name" ] diff --git a/vulkan/vulkan_window.cc b/vulkan/vulkan_window.cc index a7067fff3f907a68bd8ac570e6fe2328fe79c0bc..25608f54afff6e503044a2deff3293ded7d1d3c5 100644 --- a/vulkan/vulkan_window.cc +++ b/vulkan/vulkan_window.cc @@ -116,6 +116,7 @@ GrDirectContext* VulkanWindow::GetSkiaGrContext() { } bool VulkanWindow::CreateSkiaGrContext() { +#ifdef SK_VULKAN GrVkBackendContext backend_context; if (!CreateSkiaBackendContext(&backend_context)) { @@ -136,6 +137,9 @@ bool VulkanWindow::CreateSkiaGrContext() { skia_gr_context_ = context; return true; +#else + return false; +#endif } bool VulkanWindow::CreateSkiaBackendContext(GrVkBackendContext* context) {