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

Commit 977c72f

Browse files
committed
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 flutter/flutter#143379
1 parent 61510db commit 977c72f

File tree

6 files changed

+62
-8
lines changed

6 files changed

+62
-8
lines changed

fml/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ source_set("fml") {
6464
"paths.cc",
6565
"paths.h",
6666
"posix_wrappers.h",
67+
"process.h",
6768
"raster_thread_merger.cc",
6869
"raster_thread_merger.h",
6970
"shared_thread_merger.cc",
@@ -251,6 +252,7 @@ source_set("fml") {
251252
"platform/win/native_library_win.cc",
252253
"platform/win/paths_win.cc",
253254
"platform/win/posix_wrappers_win.cc",
255+
"platform/win/process_win.cc",
254256
]
255257
} else {
256258
sources += [
@@ -260,6 +262,7 @@ source_set("fml") {
260262
"platform/posix/native_library_posix.cc",
261263
"platform/posix/paths_posix.cc",
262264
"platform/posix/posix_wrappers_posix.cc",
265+
"platform/posix/process_posix.cc",
263266
]
264267
}
265268
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <unistd.h>
6+
7+
namespace fml {
8+
9+
int GetCurrentProcId() {
10+
return static_cast<int>(getpid());
11+
}
12+
13+
} // namespace fml

fml/platform/win/process_win.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <windows.h>
6+
7+
namespace fml {
8+
9+
int GetCurrentProcId() {
10+
return static_cast<int>(::GetCurrentProcessId());
11+
}
12+
13+
} // namespace fml

fml/process.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_FML_PROCESS_H_
6+
#define FLUTTER_FML_PROCESS_H_
7+
8+
namespace fml {
9+
10+
int GetCurrentProcId();
11+
12+
} // namespace fml
13+
14+
#endif // FLUTTER_FML_PROCESS_H_

impeller/compiler/compiler_test.cc

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,39 @@
33
// found in the LICENSE file.
44

55
#include "impeller/compiler/compiler_test.h"
6+
#include "flutter/fml/paths.h"
7+
#include "flutter/fml/process.h"
68

79
#include <algorithm>
10+
#include <filesystem>
811

912
namespace impeller {
1013
namespace compiler {
1114
namespace testing {
1215

13-
static fml::UniqueFD CreateIntermediatesDirectory() {
16+
static std::string GetIntermediatesPath() {
1417
auto test_name = flutter::testing::GetCurrentTestName();
1518
std::replace(test_name.begin(), test_name.end(), '/', '_');
1619
std::replace(test_name.begin(), test_name.end(), '.', '_');
17-
return fml::OpenDirectory(flutter::testing::OpenFixturesDirectory(),
18-
test_name.c_str(),
19-
true, // create if necessary
20-
fml::FilePermission::kReadWrite);
20+
std::stringstream dir_name;
21+
dir_name << test_name << "_" << std::to_string(fml::GetCurrentProcId());
22+
return fml::paths::JoinPaths(
23+
{flutter::testing::GetFixturesPath(), dir_name.str()});
2124
}
2225

23-
CompilerTest::CompilerTest()
24-
: intermediates_directory_(CreateIntermediatesDirectory()) {
26+
CompilerTest::CompilerTest() : intermediates_path_(GetIntermediatesPath()) {
27+
intermediates_directory_ =
28+
fml::OpenDirectory(intermediates_path_.c_str(),
29+
true, // create if necessary
30+
fml::FilePermission::kReadWrite);
2531
FML_CHECK(intermediates_directory_.is_valid());
2632
}
2733

28-
CompilerTest::~CompilerTest() = default;
34+
CompilerTest::~CompilerTest() {
35+
intermediates_directory_.reset();
36+
37+
std::filesystem::remove_all(std::filesystem::path(intermediates_path_));
38+
}
2939

3040
static std::string ReflectionHeaderName(const char* fixture_name) {
3141
std::stringstream stream;

impeller/compiler/compiler_test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class CompilerTest : public ::testing::TestWithParam<TargetPlatform> {
3636
const char* entry_point_name = "main") const;
3737

3838
private:
39+
std::string intermediates_path_;
3940
fml::UniqueFD intermediates_directory_;
4041

4142
CompilerTest(const CompilerTest&) = delete;

0 commit comments

Comments
 (0)