From 5b8089a3cc846bf8e173ee5bf75635165ea0c62e Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Wed, 16 Oct 2019 16:29:55 -0700 Subject: [PATCH] Use the fixtures mechanism for txt unit-tests and benchmarks. (flutter/engine#13180) These tests and benchmarks can now be run without needing additional flags on the command line. --- engine/src/flutter/testing/run_tests.py | 5 +- engine/src/flutter/third_party/txt/BUILD.gn | 72 ++++++++++++++++++- .../txt/benchmarks/txt_run_all_benchmarks.cc | 8 +-- .../txt/tests/txt_run_all_unittests.cc | 10 +-- 4 files changed, 79 insertions(+), 16 deletions(-) diff --git a/engine/src/flutter/testing/run_tests.py b/engine/src/flutter/testing/run_tests.py index fbcd858ce5..3596c84f5e 100755 --- a/engine/src/flutter/testing/run_tests.py +++ b/engine/src/flutter/testing/run_tests.py @@ -21,7 +21,6 @@ fonts_dir = os.path.join(buildroot_dir, 'flutter', 'third_party', 'txt', 'third_ roboto_font_path = os.path.join(fonts_dir, 'Roboto-Regular.ttf') dart_tests_dir = os.path.join(buildroot_dir, 'flutter', 'testing', 'dart',) -fonts_dir_flag = '--font-directory=%s' % fonts_dir time_sensitve_test_flag = '--gtest_filter="-*TimeSensitiveTest*"' def IsMac(): @@ -112,7 +111,7 @@ def RunCCTests(build_dir, filter): # https://github.com/flutter/flutter/issues/36296 if IsLinux(): - RunEngineExecutable(build_dir, 'txt_unittests', filter, [ fonts_dir_flag ] + shuffle_flags) + RunEngineExecutable(build_dir, 'txt_unittests', filter, shuffle_flags) def RunEngineBenchmarks(build_dir, filter): @@ -123,7 +122,7 @@ def RunEngineBenchmarks(build_dir, filter): RunEngineExecutable(build_dir, 'fml_benchmarks', filter) if IsLinux(): - RunEngineExecutable(build_dir, 'txt_benchmarks', filter, [ fonts_dir_flag ]) + RunEngineExecutable(build_dir, 'txt_benchmarks', filter) diff --git a/engine/src/flutter/third_party/txt/BUILD.gn b/engine/src/flutter/third_party/txt/BUILD.gn index 1bcc6988d8..f9f14c7bf1 100644 --- a/engine/src/flutter/third_party/txt/BUILD.gn +++ b/engine/src/flutter/third_party/txt/BUILD.gn @@ -13,6 +13,7 @@ # limitations under the License. import("$flutter_root/common/config.gni") +import("$flutter_root/testing/testing.gni") declare_args() { flutter_use_fontconfig = false @@ -185,6 +186,72 @@ source_set("txt_test_utils") { ] } +test_fixtures("txt_fixtures") { + fixtures = [ + "third_party/fonts/Bold.ttf", + "third_party/fonts/Bold.ttx", + "third_party/fonts/BoldItalic.ttf", + "third_party/fonts/BoldItalic.ttx", + "third_party/fonts/ColorEmojiFont.ttf", + "third_party/fonts/ColorEmojiFont.ttx", + "third_party/fonts/ColorTextMixedEmojiFont.ttf", + "third_party/fonts/ColorTextMixedEmojiFont.ttx", + "third_party/fonts/DroidSerif.ttf", + "third_party/fonts/Emoji.ttf", + "third_party/fonts/Emoji.ttx", + "third_party/fonts/HomemadeApple.ttf", + "third_party/fonts/Italic.ttf", + "third_party/fonts/Italic.ttx", + "third_party/fonts/Ja.ttf", + "third_party/fonts/Ja.ttx", + "third_party/fonts/Katibeh-Regular.ttf", + "third_party/fonts/Ko.ttf", + "third_party/fonts/Ko.ttx", + "third_party/fonts/MultiAxis.ttf", + "third_party/fonts/MultiAxis.ttx", + "third_party/fonts/NoCmapFormat14.ttf", + "third_party/fonts/NoCmapFormat14.ttx", + "third_party/fonts/NoGlyphFont.ttf", + "third_party/fonts/NoGlyphFont.ttx", + "third_party/fonts/NotoColorEmoji.ttf", + "third_party/fonts/NotoNaskhArabic-Regular.ttf", + "third_party/fonts/NotoSansCJK-Regular.ttc", + "third_party/fonts/Regular.ttf", + "third_party/fonts/Regular.ttx", + "third_party/fonts/Roboto-Black.ttf", + "third_party/fonts/Roboto-BlackItalic.ttf", + "third_party/fonts/Roboto-Bold.ttf", + "third_party/fonts/Roboto-BoldItalic.ttf", + "third_party/fonts/Roboto-Italic.ttf", + "third_party/fonts/Roboto-Light.ttf", + "third_party/fonts/Roboto-LightItalic.ttf", + "third_party/fonts/Roboto-Medium.ttf", + "third_party/fonts/Roboto-MediumItalic.ttf", + "third_party/fonts/Roboto-Regular.ttf", + "third_party/fonts/Roboto-Thin.ttf", + "third_party/fonts/Roboto-ThinItalic.ttf", + "third_party/fonts/SourceHanSerifCN-Bold.otf", + "third_party/fonts/SourceHanSerifCN-Regular.otf", + "third_party/fonts/TextEmojiFont.ttf", + "third_party/fonts/TextEmojiFont.ttx", + "third_party/fonts/UnicodeBMPOnly.ttf", + "third_party/fonts/UnicodeBMPOnly.ttx", + "third_party/fonts/UnicodeBMPOnly2.ttf", + "third_party/fonts/UnicodeBMPOnly2.ttx", + "third_party/fonts/UnicodeUCS4.ttf", + "third_party/fonts/UnicodeUCS4.ttx", + "third_party/fonts/VariationSelectorTest-Regular.ttf", + "third_party/fonts/VariationSelectorTest-Regular.ttx", + "third_party/fonts/ZhHans.ttf", + "third_party/fonts/ZhHans.ttx", + "third_party/fonts/ZhHant.ttf", + "third_party/fonts/ZhHant.ttx", + "third_party/fonts/ahem.ttf", + "third_party/fonts/emoji.xml", + "third_party/fonts/itemize.xml", + ] +} + executable("txt_unittests") { testonly = true @@ -229,7 +296,8 @@ executable("txt_unittests") { deps = [ ":txt", ":txt_test_utils", - "//third_party/googletest:gtest", + "$flutter_root/testing:testing_lib", + ":txt_fixtures", ] + txt_common_executable_deps } @@ -247,6 +315,8 @@ executable("txt_benchmarks") { deps = [ ":txt", ":txt_test_utils", + "$flutter_root/testing:testing_lib", "//third_party/benchmark", + ":txt_fixtures", ] + txt_common_executable_deps } diff --git a/engine/src/flutter/third_party/txt/benchmarks/txt_run_all_benchmarks.cc b/engine/src/flutter/third_party/txt/benchmarks/txt_run_all_benchmarks.cc index 69fcace0c8..69da7b6a06 100644 --- a/engine/src/flutter/third_party/txt/benchmarks/txt_run_all_benchmarks.cc +++ b/engine/src/flutter/third_party/txt/benchmarks/txt_run_all_benchmarks.cc @@ -16,6 +16,7 @@ #include "flutter/fml/icu_util.h" #include "flutter/fml/logging.h" +#include "flutter/testing/testing.h" #include "flutter/third_party/txt/tests/txt_test_utils.h" #include "third_party/benchmark/include/benchmark/benchmark_api.h" @@ -24,12 +25,9 @@ int main(int argc, char** argv) { ::benchmark::Initialize(&argc, argv); fml::CommandLine cmd = fml::CommandLineFromArgcArgv(argc, argv); txt::SetCommandLine(cmd); - std::string dir = txt::GetCommandLineForProcess().GetOptionValueWithDefault( - "font-directory", ""); - txt::SetFontDir(dir); + txt::SetFontDir(flutter::testing::GetFixturesPath()); if (txt::GetFontDir().length() <= 0) { - FML_LOG(ERROR) << "Font directory must be specified with " - "--font-directory=\"\" to run this test."; + FML_LOG(ERROR) << "Font directory not set via txt::SetFontDir."; return EXIT_FAILURE; } FML_DCHECK(txt::GetFontDir().length() > 0); diff --git a/engine/src/flutter/third_party/txt/tests/txt_run_all_unittests.cc b/engine/src/flutter/third_party/txt/tests/txt_run_all_unittests.cc index 992a167f04..4b2eda9872 100644 --- a/engine/src/flutter/third_party/txt/tests/txt_run_all_unittests.cc +++ b/engine/src/flutter/third_party/txt/tests/txt_run_all_unittests.cc @@ -17,7 +17,7 @@ #include "flutter/fml/command_line.h" #include "flutter/fml/icu_util.h" #include "flutter/fml/logging.h" -#include "gtest/gtest.h" +#include "flutter/testing/testing.h" #include "third_party/skia/include/core/SkGraphics.h" #include "txt_test_utils.h" @@ -26,16 +26,12 @@ int main(int argc, char** argv) { fml::CommandLine cmd = fml::CommandLineFromArgcArgv(argc, argv); txt::SetCommandLine(cmd); - std::string dir = txt::GetCommandLineForProcess().GetOptionValueWithDefault( - "font-directory", ""); - txt::SetFontDir(dir); + txt::SetFontDir(flutter::testing::GetFixturesPath()); if (txt::GetFontDir().length() <= 0) { - FML_LOG(ERROR) << "Font directory must be specified with " - "--font-directory=\"\" to run this test."; + FML_LOG(ERROR) << "Font directory not set via txt::SetFontDir."; return EXIT_FAILURE; } FML_DCHECK(txt::GetFontDir().length() > 0); - fml::icu::InitializeICU("icudtl.dat"); SkGraphics::Init(); testing::InitGoogleTest(&argc, argv);