[CI] remove check for exact golden files. (#166031)

Instead make sure at least 1 png is generated.

---------

Co-authored-by: Matan Lurey <matanlurey@users.noreply.github.com>
This commit is contained in:
Jonah Williams
2025-03-27 20:19:24 -07:00
committed by GitHub
parent bfe95d3819
commit 202d6b7994
18 changed files with 24 additions and 1278 deletions

View File

@@ -59,7 +59,7 @@ performance implications. See [#49801][pr_49801] for an example.
#### Linux Embedding
> [!NOTE]
> [!NOTE]
> The Linux embedding instead follows idiomatic GObject-based C style.
Use of C++ in the [Linux embedding][] is discouraged in that embedding to avoid
@@ -215,14 +215,10 @@ in postsubmit.
### Skia Gold
The Flutter engine uses [Skia Gold][skia_gold] for image comparison tests which fail if:
- The image is different from an accepted baseline.
- An image is not uploaded but is expected to be (see
[`dir_contents_diff`][dir_contents_diff]).
The Flutter engine uses [Skia Gold][skia_gold] for image comparison tests which
fail if the image is different from an accepted baseline image.
[skia_gold]: https://flutter-engine-gold.skia.org/
[dir_contents_diff]: ./tools/dir_contents_diff/
Any untriaged failures will block presubmit and postsubmit tests.

View File

@@ -176,7 +176,7 @@ TEST_P(AiksTest, DrawAtlasPlusWideGamut) {
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}
TEST_P(AiksTest, DlAtlasGeometryNoBlend) {
TEST_P(AiksTest, DlAtlasGeometryNoBlendRenamed) {
auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
DlAtlasGeometry geom(atlas->impeller_texture(), transforms.data(),

View File

@@ -97,7 +97,6 @@ workspace:
- tools/clangd_check
- tools/compare_goldens
- tools/const_finder
- tools/dir_contents_diff
- tools/engine_tool
- tools/header_guard_check
- tools/gen_web_locale_keymap

File diff suppressed because it is too large Load Diff

View File

@@ -14,7 +14,6 @@ resolution: workspace
dependencies:
args: any
dir_contents_diff: any
engine_repo_tools: any
meta: any
path: any

View File

@@ -968,7 +968,6 @@ def build_dart_host_test_list():
os.path.join('flutter', 'tools', 'build_bucket_golden_scraper'),
os.path.join('flutter', 'tools', 'clang_tidy'),
os.path.join('flutter', 'tools', 'const_finder'),
os.path.join('flutter', 'tools', 'dir_contents_diff'),
os.path.join('flutter', 'tools', 'engine_tool'),
os.path.join('flutter', 'tools', 'githooks'),
os.path.join('flutter', 'tools', 'header_guard_check'),
@@ -1061,6 +1060,23 @@ class DirectoryChange():
os.chdir(self.old_cwd)
def contains_png_recursive(directory):
"""
Recursively checks if a directory contains at least one .png file.
Args:
directory: The path to the directory to check.
Returns:
True if a .png file is found, False otherwise.
"""
for _, _, files in os.walk(directory):
for filename in files:
if filename.lower().endswith('.png'):
return True
return False
def run_impeller_golden_tests(build_dir: str, require_skia_gold: bool = False):
"""
Executes the impeller golden image tests from in the `variant` build.
@@ -1079,19 +1095,9 @@ def run_impeller_golden_tests(build_dir: str, require_skia_gold: bool = False):
extra_env.update(vulkan_validation_env(build_dir))
run_cmd([tests_path, f'--working_dir={temp_dir}'], cwd=build_dir, env=extra_env)
dart_bin = os.path.join(build_dir, 'dart-sdk', 'bin', 'dart')
golden_path = os.path.join('testing', 'impeller_golden_tests_output.txt')
script_path = os.path.join('tools', 'dir_contents_diff', 'bin', 'dir_contents_diff.dart')
diff_result = subprocess.run(
f'{dart_bin} {script_path} {golden_path} {temp_dir}',
check=False,
shell=True,
stdout=subprocess.PIPE,
cwd=os.path.join(BUILDROOT_DIR, 'flutter')
)
if diff_result.returncode != 0:
print_divider('<')
print(diff_result.stdout.decode())
raise RuntimeError('impeller_golden_tests diff failure')
if not contains_png_recursive(temp_dir):
raise RuntimeError('impeller_golden_tests diff failure - no PNGs found!')
if not require_skia_gold:
print_divider('<')

View File

@@ -1,12 +0,0 @@
# dir_contents_diff
This tool will compare the contents of a directory to a file that lists the
contents of the directory, printing out a patch to apply if they differ.
The exit code is 0 if there is no difference.
## Usage
```sh
dart run ./bin/dir_contents_diff.dart <golden file path> <dir path>
```

View File

@@ -1,11 +0,0 @@
// 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.
import 'dart:io' show exitCode;
import 'package:dir_contents_diff/dir_contents_diff.dart';
void main(List<String> args) {
exitCode = run(args);
}

View File

@@ -1,103 +0,0 @@
// 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.
import 'dart:convert' show utf8;
import 'dart:io';
String _basename(String path) {
return path.split(Platform.pathSeparator).last;
}
String _generateDirListing(String dirPath) {
final Directory dir = Directory(dirPath);
final List<FileSystemEntity> entities = dir.listSync();
entities.sort((FileSystemEntity a, FileSystemEntity b) => a.path.compareTo(b.path));
return entities.map((FileSystemEntity entity) => _basename(entity.path)).join('\n');
}
String _strReplaceRange(String inputStr, int start, int end, String replacement) {
return inputStr.substring(0, start) + replacement + inputStr.substring(end);
}
String _redirectPatch(String patch) {
final RegExp inputPathExp = RegExp(r'^--- a(.*)', multiLine: true);
final RegExp outputPathExp = RegExp(r'^\+\+\+ b(.*)', multiLine: true);
final Match? inputPathMatch = inputPathExp.firstMatch(patch);
final Match? outputPathMatch = outputPathExp.firstMatch(patch);
assert(inputPathMatch != null);
assert(outputPathMatch != null);
if (inputPathMatch != null && outputPathMatch != null) {
return _strReplaceRange(
patch,
outputPathMatch.start + 5, // +5 to account for '+++ b'
outputPathMatch.end,
inputPathMatch.group(1)!,
);
}
throw Exception('Unable to find input and output paths');
}
File _makeTempFile(String prefix) {
final Directory systemTempDir = Directory.systemTemp;
final String filename = '$prefix-${DateTime.now().millisecondsSinceEpoch}';
final String path = '${systemTempDir.path}${Platform.pathSeparator}$filename';
final File result = File(path);
result.createSync();
return result;
}
/// Run the diff of the contents of a directory at [dirPath] and the contents of
/// a file at [goldenPath]. Returns 0 if there is no diff. Be aware that the
/// CWD should be inside of the git repository for the patch to be correct.
int dirContentsDiff(String goldenPath, String dirPath) {
if (!File(goldenPath).existsSync()) {
throw Exception('unable to find `$goldenPath`');
}
if (!Directory(dirPath).existsSync()) {
throw Exception('unable to find `$dirPath`');
}
int result = 0;
final File tempFile = _makeTempFile('dir_contents_diff');
try {
final String dirListing = _generateDirListing(dirPath);
tempFile.writeAsStringSync(dirListing);
final ProcessResult diffResult = Process.runSync(
'git',
<String>[
'diff',
// If you manually edit the golden file, many text editors will add
// trailing whitespace. This flag ignores that because honestly it's
// not a significant part of this test.
'--ignore-space-at-eol',
'-p',
goldenPath,
tempFile.path,
],
runInShell: true,
stdoutEncoding: utf8,
);
if (diffResult.exitCode != 0) {
print('Unexpected diff in $goldenPath, use `git apply` with the following patch.\n');
print(_redirectPatch(diffResult.stdout as String));
result = 1;
}
} finally {
tempFile.deleteSync();
}
return result;
}
/// The main entrypoint for the program, returns `exitCode`.
int run(List<String> args) {
if (args.length != 2) {
throw Exception('usage: <path to golden> <path to directory>');
}
final String goldenPath = args[0];
final String dirPath = args[1];
return dirContentsDiff(goldenPath, dirPath);
}

View File

@@ -1,14 +0,0 @@
name: dir_contents_diff
publish_to: none
# Required for workspace support.
environment:
sdk: ^3.7.0-0
# This package is managed as part of the engine workspace.
resolution: workspace
dev_dependencies:
engine_repo_tools: any
path: any
test: any

View File

@@ -1,78 +0,0 @@
// 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.
import 'dart:io' as io;
import 'package:engine_repo_tools/engine_repo_tools.dart';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';
void main() {
// Find a path to `dir_contents_diff.dart` from the working directory.
final String pkgPath = p.join(Engine.findWithin().flutterDir.path, 'tools', 'dir_contents_diff');
final String binPath = p.join(pkgPath, 'bin', 'dir_contents_diff.dart');
// As a sanity check, ensure that the file exists.
if (!io.File(binPath).existsSync()) {
io.stderr.writeln('Unable to find $binPath');
io.exitCode = 1;
return;
}
// Runs `../bin/dir_contents_diff.dart` with the given arguments.
(int, String) runSync(String goldenPath, String dirPath) {
final io.ProcessResult result = io.Process.runSync(io.Platform.resolvedExecutable, <String>[
binPath,
goldenPath,
dirPath,
]);
return (result.exitCode, result.stdout ?? result.stderr);
}
test('lists files and diffs successfully', () {
final String goldenPath = p.join(pkgPath, 'test', 'file_ok.txt');
final String dirPath = p.join(pkgPath, 'test', 'fixtures');
final (int exitCode, String output) = runSync(goldenPath, dirPath);
if (exitCode != 0) {
io.stderr.writeln('Expected exit code 0, got $exitCode');
io.stderr.writeln(output);
}
expect(exitCode, 0);
});
test('lists files and diffs successfully, even with an EOF newline', () {
final String goldenPath = p.join(pkgPath, 'test', 'file_ok_eof_newline.txt');
final String dirPath = p.join(pkgPath, 'test', 'fixtures');
final (int exitCode, String output) = runSync(goldenPath, dirPath);
if (exitCode != 0) {
io.stderr.writeln('Expected exit code 0, got $exitCode');
io.stderr.writeln(output);
}
expect(exitCode, 0);
});
test('diff fails when an expected file is missing', () {
final String goldenPath = p.join(pkgPath, 'test', 'file_bad_missing.txt');
final String dirPath = p.join(pkgPath, 'test', 'fixtures');
final (int exitCode, String output) = runSync(goldenPath, dirPath);
if (exitCode == 0) {
io.stderr.writeln('Expected non-zero exit code, got $exitCode');
io.stderr.writeln(output);
}
expect(exitCode, 1);
expect(output, contains('+a.txt'));
});
test('diff fails when an unexpected file is present', () {
final String goldenPath = p.join(pkgPath, 'test', 'file_bad_unexpected.txt');
final String dirPath = p.join(pkgPath, 'test', 'fixtures');
final (int exitCode, String output) = runSync(goldenPath, dirPath);
if (exitCode == 0) {
io.stderr.writeln('Expected non-zero exit code, got $exitCode');
io.stderr.writeln(output);
}
expect(exitCode, 1);
expect(output, contains('-c.txt'));
});
}

View File

@@ -1,3 +0,0 @@
a.txt
b.txt
c.txt

View File

@@ -1,2 +0,0 @@
a.txt
b.txt

View File

@@ -1 +0,0 @@
Will be referenced by a test.

View File

@@ -1 +0,0 @@
Will be referenced by a test.

View File

@@ -40,7 +40,6 @@ ALL_PACKAGES = [
os.path.join(ENGINE_DIR, 'tools', 'clangd_check'),
os.path.join(ENGINE_DIR, 'tools', 'compare_goldens'),
os.path.join(ENGINE_DIR, 'tools', 'const_finder'),
os.path.join(ENGINE_DIR, 'tools', 'dir_contents_diff'),
os.path.join(ENGINE_DIR, 'tools', 'engine_tool'),
os.path.join(ENGINE_DIR, 'tools', 'gen_web_locale_keymap'),
os.path.join(ENGINE_DIR, 'tools', 'githooks'),