From 2bd3af44b917904413f0d34ea00201cba8dd8229 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 29 Feb 2024 00:49:30 +0000 Subject: [PATCH 1/2] Support gtest-parallel when running Impeller unit tests ImpellerC tests that use a temporary directory will append the current process ID to the directory name to avoid collisions. The temporary directory will also be deleted after each test case completes. See https://github.com/flutter/flutter/issues/143379 --- fml/BUILD.gn | 3 +++ fml/platform/posix/process_posix.cc | 13 +++++++++++++ fml/platform/win/process_win.cc | 13 +++++++++++++ fml/process.h | 14 ++++++++++++++ impeller/compiler/compiler_test.cc | 26 ++++++++++++++++++-------- impeller/compiler/compiler_test.h | 1 + 6 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 fml/platform/posix/process_posix.cc create mode 100644 fml/platform/win/process_win.cc create mode 100644 fml/process.h diff --git a/fml/BUILD.gn b/fml/BUILD.gn index 0a3eeb1130ce9..c448e02c3cabf 100644 --- a/fml/BUILD.gn +++ b/fml/BUILD.gn @@ -64,6 +64,7 @@ source_set("fml") { "paths.cc", "paths.h", "posix_wrappers.h", + "process.h", "raster_thread_merger.cc", "raster_thread_merger.h", "shared_thread_merger.cc", @@ -251,6 +252,7 @@ source_set("fml") { "platform/win/native_library_win.cc", "platform/win/paths_win.cc", "platform/win/posix_wrappers_win.cc", + "platform/win/process_win.cc", ] } else { sources += [ @@ -260,6 +262,7 @@ source_set("fml") { "platform/posix/native_library_posix.cc", "platform/posix/paths_posix.cc", "platform/posix/posix_wrappers_posix.cc", + "platform/posix/process_posix.cc", ] } } diff --git a/fml/platform/posix/process_posix.cc b/fml/platform/posix/process_posix.cc new file mode 100644 index 0000000000000..38262ffb3536c --- /dev/null +++ b/fml/platform/posix/process_posix.cc @@ -0,0 +1,13 @@ +// 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 + +namespace fml { + +int GetCurrentProcId() { + return static_cast(getpid()); +} + +} // namespace fml diff --git a/fml/platform/win/process_win.cc b/fml/platform/win/process_win.cc new file mode 100644 index 0000000000000..96749326a40f0 --- /dev/null +++ b/fml/platform/win/process_win.cc @@ -0,0 +1,13 @@ +// 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 + +namespace fml { + +int GetCurrentProcId() { + return static_cast(::GetCurrentProcessId()); +} + +} // namespace fml diff --git a/fml/process.h b/fml/process.h new file mode 100644 index 0000000000000..2ca6ebb48e1c0 --- /dev/null +++ b/fml/process.h @@ -0,0 +1,14 @@ +// 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_FML_PROCESS_H_ +#define FLUTTER_FML_PROCESS_H_ + +namespace fml { + +int GetCurrentProcId(); + +} // namespace fml + +#endif // FLUTTER_FML_PROCESS_H_ diff --git a/impeller/compiler/compiler_test.cc b/impeller/compiler/compiler_test.cc index b19a84176cf36..06e2602611104 100644 --- a/impeller/compiler/compiler_test.cc +++ b/impeller/compiler/compiler_test.cc @@ -3,29 +3,39 @@ // found in the LICENSE file. #include "impeller/compiler/compiler_test.h" +#include "flutter/fml/paths.h" +#include "flutter/fml/process.h" #include +#include namespace impeller { namespace compiler { namespace testing { -static fml::UniqueFD CreateIntermediatesDirectory() { +static std::string GetIntermediatesPath() { auto test_name = flutter::testing::GetCurrentTestName(); std::replace(test_name.begin(), test_name.end(), '/', '_'); std::replace(test_name.begin(), test_name.end(), '.', '_'); - return fml::OpenDirectory(flutter::testing::OpenFixturesDirectory(), - test_name.c_str(), - true, // create if necessary - fml::FilePermission::kReadWrite); + std::stringstream dir_name; + dir_name << test_name << "_" << std::to_string(fml::GetCurrentProcId()); + return fml::paths::JoinPaths( + {flutter::testing::GetFixturesPath(), dir_name.str()}); } -CompilerTest::CompilerTest() - : intermediates_directory_(CreateIntermediatesDirectory()) { +CompilerTest::CompilerTest() : intermediates_path_(GetIntermediatesPath()) { + intermediates_directory_ = + fml::OpenDirectory(intermediates_path_.c_str(), + true, // create if necessary + fml::FilePermission::kReadWrite); FML_CHECK(intermediates_directory_.is_valid()); } -CompilerTest::~CompilerTest() = default; +CompilerTest::~CompilerTest() { + intermediates_directory_.reset(); + + std::filesystem::remove_all(std::filesystem::path(intermediates_path_)); +} static std::string ReflectionHeaderName(const char* fixture_name) { std::stringstream stream; diff --git a/impeller/compiler/compiler_test.h b/impeller/compiler/compiler_test.h index fdee8a598e80e..3eb0101893115 100644 --- a/impeller/compiler/compiler_test.h +++ b/impeller/compiler/compiler_test.h @@ -36,6 +36,7 @@ class CompilerTest : public ::testing::TestWithParam { const char* entry_point_name = "main") const; private: + std::string intermediates_path_; fml::UniqueFD intermediates_directory_; CompilerTest(const CompilerTest&) = delete; From 7b2e140d5bab8deef18de893952c12cac02d4837 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 4 Mar 2024 19:39:16 +0000 Subject: [PATCH 2/2] licenses --- ci/licenses_golden/licenses_flutter | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 51dfd586513dd..abfa134415caf 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -34705,6 +34705,7 @@ ORIGIN: ../../../flutter/fml/platform/posix/mapping_posix.cc + ../../../flutter/ ORIGIN: ../../../flutter/fml/platform/posix/native_library_posix.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/posix/paths_posix.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/posix/posix_wrappers_posix.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/fml/platform/posix/process_posix.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/posix/shared_mutex_posix.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/posix/shared_mutex_posix.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/win/command_line_win.cc + ../../../flutter/LICENSE @@ -34717,9 +34718,11 @@ ORIGIN: ../../../flutter/fml/platform/win/message_loop_win.h + ../../../flutter/ ORIGIN: ../../../flutter/fml/platform/win/native_library_win.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/win/paths_win.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/win/posix_wrappers_win.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/fml/platform/win/process_win.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/win/wstring_conversion.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/win/wstring_conversion.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/posix_wrappers.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/fml/process.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/raster_thread_merger.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/raster_thread_merger.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/shared_thread_merger.cc + ../../../flutter/LICENSE @@ -37546,6 +37549,7 @@ FILE: ../../../flutter/fml/platform/posix/mapping_posix.cc FILE: ../../../flutter/fml/platform/posix/native_library_posix.cc FILE: ../../../flutter/fml/platform/posix/paths_posix.cc FILE: ../../../flutter/fml/platform/posix/posix_wrappers_posix.cc +FILE: ../../../flutter/fml/platform/posix/process_posix.cc FILE: ../../../flutter/fml/platform/posix/shared_mutex_posix.cc FILE: ../../../flutter/fml/platform/posix/shared_mutex_posix.h FILE: ../../../flutter/fml/platform/win/command_line_win.cc @@ -37558,9 +37562,11 @@ FILE: ../../../flutter/fml/platform/win/message_loop_win.h FILE: ../../../flutter/fml/platform/win/native_library_win.cc FILE: ../../../flutter/fml/platform/win/paths_win.cc FILE: ../../../flutter/fml/platform/win/posix_wrappers_win.cc +FILE: ../../../flutter/fml/platform/win/process_win.cc FILE: ../../../flutter/fml/platform/win/wstring_conversion.cc FILE: ../../../flutter/fml/platform/win/wstring_conversion.h FILE: ../../../flutter/fml/posix_wrappers.h +FILE: ../../../flutter/fml/process.h FILE: ../../../flutter/fml/raster_thread_merger.cc FILE: ../../../flutter/fml/raster_thread_merger.h FILE: ../../../flutter/fml/shared_thread_merger.cc