Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6381b15

Browse files
authored
Fix broken shell_unittests on Fuchsia (#20422)
Fixes flutter/flutter#53399
1 parent b7122a1 commit 6381b15

File tree

5 files changed

+52
-32
lines changed

5 files changed

+52
-32
lines changed

fml/file.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,21 @@ fml::UniqueFD CreateDirectory(const fml::UniqueFD& base_directory,
4444
return CreateDirectory(base_directory, components, permission, 0);
4545
}
4646

47-
ScopedTemporaryDirectory::ScopedTemporaryDirectory() {
48-
path_ = CreateTemporaryDirectory();
47+
ScopedTemporaryDirectory::ScopedTemporaryDirectory()
48+
: path_(CreateTemporaryDirectory()) {
4949
if (path_ != "") {
5050
dir_fd_ = OpenDirectory(path_.c_str(), false, FilePermission::kRead);
5151
}
5252
}
5353

5454
ScopedTemporaryDirectory::~ScopedTemporaryDirectory() {
55+
// POSIX requires the directory to be empty before UnlinkDirectory.
56+
if (path_ != "") {
57+
if (!RemoveFilesInDirectory(dir_fd_)) {
58+
FML_LOG(ERROR) << "Could not clean directory: " << path_;
59+
}
60+
}
61+
5562
// Windows has to close UniqueFD first before UnlinkDirectory
5663
dir_fd_.reset();
5764
if (path_ != "") {

shell/common/BUILD.gn

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ if (enable_unittests) {
158158
test_enable_metal = false
159159
}
160160

161+
config("test_enable_gl_config") {
162+
defines = [ "SHELL_ENABLE_GL" ]
163+
}
164+
165+
config("test_enable_vulkan_config") {
166+
defines = [ "SHELL_ENABLE_VULKAN" ]
167+
}
168+
161169
shell_gpu_configuration("shell_unittests_gpu_configuration") {
162170
enable_software = test_enable_software
163171
enable_vulkan = test_enable_vulkan
@@ -208,7 +216,7 @@ if (enable_unittests) {
208216
"//third_party/skia",
209217
]
210218

211-
defines = []
219+
public_configs = []
212220

213221
# SwiftShader only supports x86/x64_64
214222
if (target_cpu == "x86" || target_cpu == "x64") {
@@ -218,9 +226,9 @@ if (enable_unittests) {
218226
"shell_test_platform_view_gl.h",
219227
]
220228

221-
public_deps += [ "//flutter/testing:opengl" ]
229+
public_configs += [ ":test_enable_gl_config" ]
222230

223-
defines += [ "SHELL_ENABLE_GL" ]
231+
public_deps += [ "//flutter/testing:opengl" ]
224232
}
225233
}
226234

@@ -230,12 +238,12 @@ if (enable_unittests) {
230238
"shell_test_platform_view_vulkan.h",
231239
]
232240

241+
public_configs += [ ":test_enable_vulkan_config" ]
242+
233243
public_deps += [
234244
"//flutter/testing:vulkan",
235245
"//flutter/vulkan",
236246
]
237-
238-
defines += [ "SHELL_ENABLE_VULKAN" ]
239247
}
240248

241249
public_deps_legacy_and_next = [

shell/common/shell_unittests.cc

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@
3232
#include "flutter/shell/common/vsync_waiter_fallback.h"
3333
#include "flutter/shell/version/version.h"
3434
#include "flutter/testing/testing.h"
35-
#include "rapidjson/writer.h"
35+
#include "third_party/rapidjson/include/rapidjson/writer.h"
3636
#include "third_party/skia/include/core/SkPictureRecorder.h"
3737
#include "third_party/tonic/converter/dart_converter.h"
3838

39+
#ifdef SHELL_ENABLE_VULKAN
40+
#include "flutter/vulkan/vulkan_application.h" // nogncheck
41+
#endif
42+
3943
namespace flutter {
4044
namespace testing {
4145

@@ -576,16 +580,16 @@ TEST_F(ShellTest, ReportTimingsIsCalledSoonerInNonReleaseMode) {
576580
DestroyShell(std::move(shell));
577581

578582
fml::TimePoint finish = fml::TimePoint::Now();
579-
fml::TimeDelta ellapsed = finish - start;
583+
fml::TimeDelta elapsed = finish - start;
580584

581585
#if FLUTTER_RELEASE
582586
// Our batch time is 1000ms. Hopefully the 800ms limit is relaxed enough to
583587
// make it not too flaky.
584-
ASSERT_TRUE(ellapsed >= fml::TimeDelta::FromMilliseconds(800));
588+
ASSERT_TRUE(elapsed >= fml::TimeDelta::FromMilliseconds(800));
585589
#else
586590
// Our batch time is 100ms. Hopefully the 500ms limit is relaxed enough to
587591
// make it not too flaky.
588-
ASSERT_TRUE(ellapsed <= fml::TimeDelta::FromMilliseconds(500));
592+
ASSERT_TRUE(elapsed <= fml::TimeDelta::FromMilliseconds(500));
589593
#endif
590594
}
591595

@@ -797,8 +801,15 @@ TEST_F(ShellTest, SetResourceCacheSize) {
797801
RunEngine(shell.get(), std::move(configuration));
798802
PumpOneFrame(shell.get());
799803

804+
// The Vulkan and GL backends set different default values for the resource
805+
// cache size.
806+
#ifdef SHELL_ENABLE_VULKAN
807+
EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell),
808+
vulkan::kGrCacheMaxByteSize);
809+
#else
800810
EXPECT_EQ(GetRasterizerResourceCacheBytesSync(*shell),
801811
static_cast<size_t>(24 * (1 << 20)));
812+
#endif
802813

803814
fml::TaskRunner::RunNowOrPostTask(
804815
shell->GetTaskRunners().GetPlatformTaskRunner(), [&shell]() {
@@ -1231,15 +1242,17 @@ TEST_F(ShellTest, CanDecompressImageFromAsset) {
12311242
}
12321243

12331244
TEST_F(ShellTest, OnServiceProtocolGetSkSLsWorks) {
1245+
fml::ScopedTemporaryDirectory base_dir;
1246+
ASSERT_TRUE(base_dir.fd().is_valid());
1247+
PersistentCache::SetCacheDirectoryPath(base_dir.path());
1248+
PersistentCache::ResetCacheForProcess();
1249+
12341250
// Create 2 dummy SkSL cache file IE (base32 encoding of A), II (base32
12351251
// encoding of B) with content x and y.
1236-
fml::ScopedTemporaryDirectory temp_dir;
1237-
PersistentCache::SetCacheDirectoryPath(temp_dir.path());
1238-
PersistentCache::ResetCacheForProcess();
1239-
std::vector<std::string> components = {"flutter_engine",
1240-
GetFlutterEngineVersion(), "skia",
1241-
GetSkiaVersion(), "sksl"};
1242-
auto sksl_dir = fml::CreateDirectory(temp_dir.fd(), components,
1252+
std::vector<std::string> components = {
1253+
"flutter_engine", GetFlutterEngineVersion(), "skia", GetSkiaVersion(),
1254+
PersistentCache::kSkSLSubdirName};
1255+
auto sksl_dir = fml::CreateDirectory(base_dir.fd(), components,
12431256
fml::FilePermission::kReadWrite);
12441257
const std::string x = "x";
12451258
const std::string y = "y";
@@ -1270,9 +1283,6 @@ TEST_F(ShellTest, OnServiceProtocolGetSkSLsWorks) {
12701283
(expected_json2 == buffer.GetString());
12711284
ASSERT_TRUE(json_is_expected) << buffer.GetString() << " is not equal to "
12721285
<< expected_json1 << " or " << expected_json2;
1273-
1274-
// Cleanup files
1275-
fml::RemoveFilesInDirectory(temp_dir.fd());
12761286
}
12771287

12781288
TEST_F(ShellTest, RasterizerScreenshot) {

testing/fuchsia/run_tests.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ reboot() {
5050
--timeout-seconds $ssh_timeout_seconds \
5151
--identity-file $pkey
5252

53-
echo "$(date) START:REBOOT ------------------------------------------"
53+
echo "$(date) START:REBOOT ----------------------------------------"
5454
# note: this will set an exit code of 255, which we can ignore.
5555
./fuchsia_ctl -d $device_name ssh -c "dm reboot-recovery" \
5656
--identity-file $pkey || true
57-
echo "$(date) END:REBOOT --------------------------------------------"
57+
echo "$(date) END:REBOOT ------------------------------------------"
5858
}
5959

6060
trap reboot EXIT
@@ -103,7 +103,7 @@ echo "$(date) DONE:txt_tests ----------------------------------------"
103103
# once it passes on Fuchsia.
104104
# TODO(https://github.com/flutter/flutter/issues/58211): Re-enable MessageLoop
105105
# test once it passes on Fuchsia.
106-
echo "$(date) START:fml_tests ----------------------------------------"
106+
echo "$(date) START:fml_tests ---------------------------------------"
107107
./fuchsia_ctl -d $device_name test \
108108
-f fml_tests-0.far \
109109
-t fml_tests \
@@ -163,22 +163,17 @@ echo "$(date) START:ui_tests ----------------------------------------"
163163
--packages-directory packages
164164
echo "$(date) DONE:ui_tests -----------------------------------------"
165165

166-
# TODO(https://github.com/flutter/flutter/issues/53399): Re-enable
167-
# OnServiceProtocolGetSkSLsWorks, CanLoadSkSLsFromAsset, and
168-
# CanRemoveOldPersistentCache once they pass on Fuchsia.
169166
echo "$(date) START:shell_tests -------------------------------------"
170167
./fuchsia_ctl -d $device_name test \
171168
-f shell_tests-0.far \
172169
-t shell_tests \
173-
-a "--gtest_filter=-ShellTest.CacheSkSLWorks:ShellTest.SetResourceCacheSize*:ShellTest.OnServiceProtocolGetSkSLsWorks:ShellTest.CanLoadSkSLsFromAsset:ShellTest.CanRemoveOldPersistentCache" \
174170
--identity-file $pkey \
175171
--timeout-seconds $test_timeout_seconds \
176172
--packages-directory packages
177173

178174
./fuchsia_ctl -d $device_name test \
179175
-f shell_tests_next-0.far \
180176
-t shell_tests_next \
181-
-a "--gtest_filter=-ShellTest.CacheSkSLWorks:ShellTest.SetResourceCacheSize*:ShellTest.OnServiceProtocolGetSkSLsWorks:ShellTest.CanLoadSkSLsFromAsset:ShellTest.CanRemoveOldPersistentCache" \
182177
--identity-file $pkey \
183178
--timeout-seconds $test_timeout_seconds \
184179
--packages-directory packages

vulkan/vulkan_application.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ VulkanApplication::VulkanApplication(
107107
}
108108

109109
instance_ = {instance, [this](VkInstance i) {
110-
FML_LOG(INFO) << "Destroying Vulkan instance";
110+
FML_DLOG(INFO) << "Destroying Vulkan instance";
111111
vk.DestroyInstance(i, nullptr);
112112
}};
113113

114114
if (enable_instance_debugging) {
115115
auto debug_report = std::make_unique<VulkanDebugReport>(vk, instance_);
116116
if (!debug_report->IsValid()) {
117-
FML_LOG(INFO) << "Vulkan debugging was enabled but could not be setup "
118-
"for this instance.";
117+
FML_DLOG(INFO) << "Vulkan debugging was enabled but could not be setup "
118+
"for this instance.";
119119
} else {
120120
debug_report_ = std::move(debug_report);
121121
FML_DLOG(INFO) << "Debug reporting is enabled.";

0 commit comments

Comments
 (0)