From 7529fc8fb4b028a61fbd276cf8ddeb4c23327d37 Mon Sep 17 00:00:00 2001 From: jackey16 Date: Thu, 24 Oct 2024 14:10:12 +0800 Subject: [PATCH 1/2] fml unittests Signed-off-by: jackey16 --- BUILD.gn | 17 ++++-- fml/BUILD.gn | 4 ++ fml/platform/ohos/napi_util_unittests.cc | 62 ++++++++++++++++++++ fml/platform/ohos/paths_ohos_unittests.cc | 30 ++++++++++ fml/platform/ohos/timerfd_unittests.cc | 71 +++++++++++++++++++++++ shell/common/BUILD.gn | 23 ++++++-- shell/config.gni | 2 +- shell/gpu/gpu_surface_vulkan.cc | 4 ++ shell/platform/embedder/BUILD.gn | 2 +- testing/testing.gni | 7 ++- vulkan/vulkan_window.cc | 4 ++ 11 files changed, 214 insertions(+), 12 deletions(-) create mode 100644 fml/platform/ohos/napi_util_unittests.cc create mode 100644 fml/platform/ohos/paths_ohos_unittests.cc create mode 100644 fml/platform/ohos/timerfd_unittests.cc diff --git a/BUILD.gn b/BUILD.gn index 7a102d594b..ae20e29faa 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -152,9 +152,9 @@ 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/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 +162,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 +190,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 03d286857c..8bc353b936 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 0000000000..5680db51e9 --- /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 0000000000..3ab18fc8d6 --- /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 0000000000..26b505db3a --- /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 7fa0c1b23a..5ed391a56f 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,16 @@ if (enable_unittests) { testonly = true sources = [ - "animator_unittests.cc", + # "animator_unittests.cc", "canvas_spy_unittests.cc", "context_options_unittests.cc", "engine_unittests.cc", - "input_events_unittests.cc", - "persistent_cache_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", + # "shell_unittests.cc", "switches_unittests.cc", "variable_refresh_rate_display_unittests.cc", "vsync_waiter_unittests.cc", @@ -310,6 +314,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 +332,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 85dd360cbc..4db04f8b5c 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 ba8383c134..7743289f59 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 56335f45af..261d879c75 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 3fadcbbc71..4a8cef4968 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 a7067fff3f..25608f54af 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) { -- Gitee From 01e2e0a6e498df33d1c04b4c0075418105bf8faf Mon Sep 17 00:00:00 2001 From: jackey16 Date: Mon, 28 Oct 2024 17:23:25 +0800 Subject: [PATCH 2/2] test Signed-off-by: jackey16 --- BUILD.gn | 3 --- shell/common/BUILD.gn | 4 ---- 2 files changed, 7 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index ae20e29faa..837d70d1ef 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", diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index 5ed391a56f..2f8b67095e 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -288,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", -- Gitee