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

Commit 6625bd1

Browse files
authored
Clean up testing/benchmark (#26313)
1 parent cb3ee34 commit 6625bd1

File tree

9 files changed

+194
-66
lines changed

9 files changed

+194
-66
lines changed

DEPS

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,21 @@ deps = {
398398
'src/third_party/pkg/archive':
399399
Var('github_git') + '/brendan-duncan/archive.git' + '@' + '3.1.2',
400400

401+
'src/third_party/pkg/equatable':
402+
Var('github_git') + '/felangel/equatable.git' + '@' + '0ba67c72db8bed75877fc1caafa74112ee0bd921', # 2.0.2
403+
401404
'src/third_party/pkg/file':
402405
Var('github_git') + '/google/file.dart.git' + '@' + '427bb20ccc852425d67f2880da2a9b4707c266b4', # 6.1.0
403406

407+
'src/third_party/pkg/flutter_packages':
408+
Var('github_git') + '/flutter/packages.git' + '@' + '5617d089f26dd52da3bf05c9fa4620ef11a7419b', # various
409+
410+
'src/third_party/pkg/gcloud':
411+
Var('github_git') + '/dart-lang/gcloud.git' + '@' + '92a33a9d95ea94a4354b052a28b98088d660e0e7', # 0.8.0-dev
412+
413+
'src/third_party/pkg/googleapis':
414+
Var('github_git') + '/google/googleapis.dart.git' + '@' + '07f01b7aa6985e4cafd0fd4b98724841bc9e85a1', # various
415+
404416
'src/third_party/pkg/platform':
405417
Var('github_git') + '/google/platform.dart.git' + '@' + 'f63fd0bc3021354a0687dc935962c9acc003f47e', # 3.0.1
406418

ci/analyze.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ analyze \
8282
--options "$FLUTTER_DIR/analysis_options.yaml" \
8383
"$FLUTTER_DIR/testing/litetest"
8484

85+
echo "Analyzing testing/benchmark"
86+
analyze \
87+
--packages="$FLUTTER_DIR/testing/benchmark/.dart_tool/package_config.json" \
88+
--options "$FLUTTER_DIR/analysis_options.yaml" \
89+
"$FLUTTER_DIR/testing/benchmark"
90+
8591
echo "Analyzing testing/smoke_test_failure"
8692
analyze \
8793
--packages="$FLUTTER_DIR/testing/smoke_test_failure/.dart_tool/package_config.json" \

ci/licenses_golden/tool_signature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Signature: a62660b42e470ade57e05b076bff1222
1+
Signature: 8e5901632fdea212b4f49528f19c5f74
22

testing/benchmark/bin/parse_and_send.dart

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,63 @@
33
// found in the LICENSE file.
44

55
// @dart = 2.6
6+
67
import 'dart:convert';
78
import 'dart:io';
89

9-
import 'package:git/git.dart';
1010
import 'package:metrics_center/metrics_center.dart';
11+
import 'package:path/path.dart' as p;
1112

12-
Future<String> _getGitRevision() async {
13-
final GitDir gitDir = await GitDir.fromExisting('../../');
13+
Future<ProcessResult> runGit(
14+
List<String> args, {
15+
String processWorkingDir,
16+
}) async {
17+
return Process.run(
18+
'git',
19+
args,
20+
workingDirectory: processWorkingDir,
21+
runInShell: true,
22+
);
23+
}
24+
25+
Future<List<String>> getGitLog() async {
26+
final String gitRoot = p.absolute('../..');
1427
// Somehow gitDir.currentBranch() doesn't work in Cirrus with "fatal: 'HEAD' -
1528
// not a valid ref". Therefore, we use "git log" to get the revision manually.
16-
final ProcessResult logResult =
17-
await gitDir.runCommand(<String>['log', '--pretty=format:%H', '-n', '1']);
29+
final ProcessResult logResult = await runGit(
30+
<String>['log', '--pretty=format:%H %ct', '-n', '1'],
31+
processWorkingDir: gitRoot,
32+
);
1833
if (logResult.exitCode != 0) {
1934
throw 'Unexpected exit code ${logResult.exitCode}';
2035
}
21-
return logResult.stdout.toString();
36+
return logResult.stdout.toString().trim().split(' ');
2237
}
2338

24-
Future<List<FlutterEngineMetricPoint>> _parse(String jsonFileName) async {
25-
final String gitRevision = await _getGitRevision();
26-
final List<MetricPoint> rawPoints =
27-
await GoogleBenchmarkParser.parse(jsonFileName);
39+
class PointsAndDate {
40+
PointsAndDate(this.points, this.date);
41+
42+
final List<FlutterEngineMetricPoint> points;
43+
final String date;
44+
}
45+
46+
Future<PointsAndDate> parse(String jsonFileName) async {
47+
final List<String> gitLog = await getGitLog();
48+
final String gitRevision = gitLog[0];
49+
final String gitCommitDate = gitLog[1];
50+
final List<MetricPoint> rawPoints = await GoogleBenchmarkParser.parse(
51+
jsonFileName,
52+
);
2853
final List<FlutterEngineMetricPoint> points = <FlutterEngineMetricPoint>[];
29-
for (MetricPoint rawPoint in rawPoints) {
54+
for (final MetricPoint rawPoint in rawPoints) {
3055
points.add(FlutterEngineMetricPoint(
3156
rawPoint.tags[kNameKey],
3257
rawPoint.value,
3358
gitRevision,
3459
moreTags: rawPoint.tags,
3560
));
3661
}
37-
return points;
62+
return PointsAndDate(points, gitCommitDate);
3863
}
3964

4065
Future<FlutterDestination> connectFlutterDestination() async {
@@ -49,7 +74,7 @@ Future<FlutterDestination> connectFlutterDestination() async {
4974
isTesting: isTesting,
5075
);
5176
}
52-
return await FlutterDestination.makeFromCredentialsJson(
77+
return FlutterDestination.makeFromCredentialsJson(
5378
jsonDecode(Platform.environment['BENCHMARK_GCP_CREDENTIALS'])
5479
as Map<String, dynamic>,
5580
isTesting: isTesting,
@@ -60,13 +85,19 @@ Future<void> main(List<String> args) async {
6085
if (args.length != 1) {
6186
throw 'Must have one argument: <benchmark_json_file>';
6287
}
63-
final List<FlutterEngineMetricPoint> points = await _parse(args[0]);
88+
final PointsAndDate pointsAndDate = await parse(args[0]);
6489

6590
// The data will be sent to the Datastore of the GCP project specified through
6691
// environment variable BENCHMARK_GCP_CREDENTIALS, or TOKEN_PATH/GCP_PROJECT.
6792
// The engine Cirrus job has currently configured the GCP project to
6893
// flutter-cirrus for test. We'll eventually migrate to flutter-infra project
6994
// once the test is done.
7095
final FlutterDestination destination = await connectFlutterDestination();
71-
await destination.update(points);
96+
await destination.update(
97+
pointsAndDate.points,
98+
DateTime.fromMillisecondsSinceEpoch(
99+
int.parse(pointsAndDate.date) * 1000,
100+
isUtc: true,
101+
),
102+
);
72103
}

testing/benchmark/pubspec.yaml

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,72 @@
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+
15
name: flutter_engine_benchmark
6+
publish_to: none
7+
environment:
8+
sdk: ">=2.2.2 <3.0.0"
29

3-
dependencies:
4-
git: any
10+
# Do not add any dependencies that require more than what is provided in
11+
# //third_party/pkg, //third_party/dart/pkg, or
12+
# //third_party/dart/third_party/pkg. In particular, package:test is not usable
13+
# here.
514

6-
metrics_center: 0.0.9
15+
# If you do add packages here, make sure you can run `pub get --offline`, and
16+
# check the .packages and .package_config to make sure all the paths are
17+
# relative to this directory into //third_party/dart
18+
19+
dependencies:
20+
metrics_center: any
21+
path: any
722

823
dev_dependencies:
9-
test: any
10-
pedantic: ^1.8.0
24+
litetest: any
1125

12-
environment:
13-
sdk: ">=2.2.2 <3.0.0"
26+
dependency_overrides:
27+
_discoveryapis_commons:
28+
path: ../../../third_party/pkg/googleapis/discoveryapis_commons
29+
async_helper:
30+
path: ../../../third_party/dart/pkg/async_helper
31+
async:
32+
path: ../../../third_party/dart/third_party/pkg/async
33+
charcode:
34+
path: ../../../third_party/dart/third_party/pkg/charcode
35+
collection:
36+
path: ../../../third_party/dart/third_party/pkg/collection
37+
convert:
38+
path: ../../../third_party/dart/third_party/pkg/convert
39+
crypto :
40+
path: ../../../third_party/dart/third_party/pkg/crypto
41+
equatable:
42+
path: ../../../third_party/pkg/equatable
43+
expect:
44+
path: ../../../third_party/dart/pkg/expect
45+
gcloud:
46+
path: ../../../third_party/pkg/gcloud
47+
googleapis:
48+
path: ../../../third_party/pkg/googleapis/generated/googleapis
49+
googleapis_auth:
50+
path: ../../../third_party/pkg/googleapis/googleapis_auth
51+
http:
52+
path: ../../../third_party/dart/third_party/pkg/http
53+
http_parser:
54+
path: ../../../third_party/dart/third_party/pkg/http_parser
55+
litetest:
56+
path: ../litetest
57+
meta:
58+
path: ../../../third_party/dart/pkg/meta
59+
metrics_center:
60+
path: ../../../third_party/pkg/flutter_packages/packages/metrics_center
61+
path:
62+
path: ../../../third_party/dart/third_party/pkg/path
63+
pedantic:
64+
path: ../../../third_party/dart/third_party/pkg/pedantic
65+
source_span:
66+
path: ../../../third_party/dart/third_party/pkg/source_span
67+
string_scanner:
68+
path: ../../../third_party/dart/third_party/pkg/string_scanner
69+
term_glyph:
70+
path: ../../../third_party/dart/third_party/pkg/term_glyph
71+
typed_data:
72+
path: ../../../third_party/dart/third_party/pkg/typed_data

testing/benchmark/test/parse_and_send_test.dart

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,52 @@
33
// found in the LICENSE file.
44

55
// @dart = 2.6
6-
import 'dart:convert';
6+
77
import 'dart:io';
88

9-
import 'package:gcloud/src/datastore_impl.dart';
10-
import 'package:googleapis_auth/auth_io.dart';
11-
import 'package:path/path.dart' as path;
12-
import 'package:test/test.dart';
9+
import 'package:litetest/litetest.dart';
10+
import 'package:metrics_center/metrics_center.dart';
11+
import 'package:path/path.dart' as p;
12+
13+
import '../bin/parse_and_send.dart' as pas;
1314

1415
void main() {
15-
// In order to run these tests, one should download a service account
16-
// credentials json from a test GCP project, and put that json as
17-
// `secret/test_gcp_credentials.json`. There's a `flutter-test` project for
18-
// Flutter team members.
19-
test('parse_and_send with example json does not crash.', () async {
20-
final String testCred =
21-
File('secret/test_gcp_credentials.json').readAsStringSync();
22-
Process.runSync('dart', <String>[
23-
'bin/parse_and_send.dart',
24-
'example/txt_benchmarks.json',
25-
], environment: <String, String>{
26-
'BENCHMARK_GCP_CREDENTIALS': testCred,
27-
'IS_TESTING': 'true',
28-
});
16+
test('runGit() succeeds', () async {
17+
// Check that git --version runs successfully
18+
final ProcessResult result = await pas.runGit(<String>['--version']);
19+
expect(result.exitCode, equals(0));
2920
});
3021

31-
test('parse_and_send succeeds with access token.', () async {
32-
final dynamic testCred =
33-
jsonDecode(File('secret/test_gcp_credentials.json').readAsStringSync())
34-
as Map<String, dynamic>;
35-
final AutoRefreshingAuthClient client = await clientViaServiceAccount(
36-
ServiceAccountCredentials.fromJson(testCred),
37-
DatastoreImpl.SCOPES,
22+
test('getGitLog() succeeds', () async {
23+
final List<String> gitLog = await pas.getGitLog();
24+
25+
// Check that gitLog[0] is a hash
26+
final RegExp sha1re = RegExp(r'[a-f0-9]{40}');
27+
expect(sha1re.hasMatch(gitLog[0]), true);
28+
29+
// Check that gitLog[1] is an int
30+
final int secondsSinceEpoch = int.tryParse(gitLog[1]);
31+
expect(secondsSinceEpoch, isNotNull);
32+
33+
// Check that gitLog[1] is a sensible Unix Epoch
34+
final int millisecondsSinceEpoch = secondsSinceEpoch * 1000;
35+
final DateTime commitDate = DateTime.fromMillisecondsSinceEpoch(
36+
millisecondsSinceEpoch,
37+
isUtc: true,
3838
);
39-
final String tokenPath =
40-
path.join(Directory.systemTemp.absolute.path, 'parse_and_send_token');
41-
File(tokenPath).writeAsStringSync(client.credentials.accessToken.data);
42-
final ProcessResult result = Process.runSync('dart', <String>[
43-
'bin/parse_and_send.dart',
44-
'example/txt_benchmarks.json',
45-
], environment: <String, String>{
46-
'TOKEN_PATH': tokenPath,
47-
'GCP_PROJECT': testCred['project_id'] as String,
48-
'IS_TESTING': 'true',
49-
});
50-
expect(result.exitCode, 0);
39+
expect(commitDate.year > 2000, true);
40+
expect(commitDate.year < 3000, true);
41+
});
42+
43+
test('parse() succeeds', () async {
44+
// Check that the results of parse() on ../example/txt_benchmarks.json
45+
// is as expeted.
46+
final String exampleJson = p.join('example', 'txt_benchmarks.json');
47+
final pas.PointsAndDate pad = await pas.parse(exampleJson);
48+
final List<FlutterEngineMetricPoint> points = pad.points;
49+
50+
expect(points[0].value, equals(101.0));
51+
expect(points[2].value, equals(4460.0));
52+
expect(points[4].value, equals(6548.0));
5153
});
5254
}

testing/run_tests.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,21 @@ def RunLitetestTests(build_dir):
520520
cwd=test_dir)
521521

522522

523+
def RunBenchmarkTests(build_dir):
524+
test_dir = os.path.join(buildroot_dir, 'flutter', 'testing', 'benchmark')
525+
dart_tests = glob.glob('%s/test/*_test.dart' % test_dir)
526+
for dart_test_file in dart_tests:
527+
opts = [
528+
'--disable-dart-dev',
529+
dart_test_file]
530+
RunEngineExecutable(
531+
build_dir,
532+
os.path.join('dart-sdk', 'bin', 'dart'),
533+
None,
534+
flags=opts,
535+
cwd=test_dir)
536+
537+
523538
def main():
524539
parser = argparse.ArgumentParser()
525540

@@ -560,10 +575,10 @@ def main():
560575
assert not IsWindows(), "Dart tests can't be run on windows. https://github.com/flutter/flutter/issues/36301."
561576
dart_filter = args.dart_filter.split(',') if args.dart_filter else None
562577
RunDartSmokeTest(build_dir, args.verbose_dart_snapshot)
578+
RunLitetestTests(build_dir)
563579
RunDartTests(build_dir, dart_filter, args.verbose_dart_snapshot)
564580
RunConstFinderTests(build_dir)
565581
RunFrontEndServerTests(build_dir)
566-
RunLitetestTests(build_dir)
567582

568583
if 'java' in types:
569584
assert not IsWindows(), "Android engine files can't be compiled on Windows."
@@ -579,6 +594,7 @@ def main():
579594

580595
# https://github.com/flutter/flutter/issues/36300
581596
if 'benchmarks' in types and not IsWindows():
597+
RunBenchmarkTests(build_dir)
582598
RunEngineBenchmarks(build_dir, engine_filter)
583599

584600
if ('engine' in types or 'font-subset' in types) and args.variant != 'host_release':

tools/licenses/lib/main.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,13 +1665,14 @@ class _RepositoryPkgDirectory extends _RepositoryDirectory {
16651665
@override
16661666
bool shouldRecurse(fs.IoNode entry) {
16671667
return entry.name != 'archive' // contains nothing that ends up in the binary executable
1668+
&& entry.name != 'equatable'
16681669
&& entry.name != 'file'
1669-
&& entry.name != 'image'
1670-
&& entry.name != 'petitparser'
1670+
&& entry.name != 'flutter_packages'
1671+
&& entry.name != 'gcloud'
1672+
&& entry.name != 'googleapis'
16711673
&& entry.name != 'platform'
16721674
&& entry.name != 'process'
1673-
&& entry.name != 'vector_math'
1674-
&& entry.name != 'xml';
1675+
&& entry.name != 'vector_math';
16751676
}
16761677

16771678
@override

tools/pub_get_offline.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
ALL_PACKAGES = [
1818
os.path.join("src", "flutter", "flutter_frontend_server"),
19+
os.path.join("src", "flutter", "testing", "benchmark"),
1920
os.path.join("src", "flutter", "testing", "litetest"),
2021
os.path.join("src", "flutter", "testing", "smoke_test_failure"),
2122
os.path.join("src", "flutter", "testing", "symbols"),

0 commit comments

Comments
 (0)