Skip to content

Commit 92002aa

Browse files
jensjohaCommit Queue
authored andcommitted
[CFE] Run coverage update on weekly bot and print a diff
This CL will make the weekly bot run tests with coverage and update the coverage, then printing the diff. It runs: * All front_end suits * python3 tools/test.py -cfasta -mrelease -rnone language * All "_test.dart" files inside pkg/{_fe_analyzer_shared,front_end,frontend_server,kernel}/test We can add more later if we find it useful, although I get something like ``` $ git diff --stat [...] 104 files changed, 359 insertions(+), 979 deletions(-) $ git diff | wc -l 7118 ``` so I'm unsure if it will be interesting or just too much data. Change-Id: Ia0438e618371eff6739b8787accbc8d1425ad548 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448582 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 666a5c9 commit 92002aa

File tree

3 files changed

+121
-41
lines changed

3 files changed

+121
-41
lines changed

pkg/front_end/test/run_all_coverage.dart

Lines changed: 90 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ import 'utils/io_utils.dart';
1212
final Uri repoDirUri = computeRepoDirUri();
1313

1414
Future<void> main() async {
15+
Directory coverageTmpDir = await runAllCoverageTests(silent: false);
16+
17+
// Don't include the not-compiled stuff as we've (mostly) asked the VM to
18+
// force compile everything and that the remaining stuff is (mostly) mixins
19+
// and const classes etc that shouldn't (necessarily) be compiled but is
20+
// potentially covered in other ways.
21+
await coverageMerger.mergeFromDirUri(
22+
repoDirUri.resolve(".dart_tool/package_config.json"),
23+
coverageTmpDir.uri,
24+
silent: false,
25+
extraCoverageIgnores: const [],
26+
extraCoverageBlockIgnores: const [],
27+
);
28+
}
29+
30+
Future<Directory> runAllCoverageTests({required bool silent}) async {
1531
String dartExtension = "";
1632
if (Platform.isWindows) {
1733
dartExtension = ".exe";
@@ -24,28 +40,33 @@ Future<void> main() async {
2440
"cfe_coverage",
2541
);
2642
print("Using $coverageTmpDir for coverage.");
27-
List<List<String>> runThese = [];
28-
void addSuiteSkipVm(String suitePath) {
29-
runThese.add([
30-
dart.toFilePath(),
31-
"--enable-asserts",
32-
suitePath,
33-
"-DskipVm=true",
34-
"--coverage=${coverageTmpDir.path}/",
35-
]);
43+
List<List<String>> runTheseSeveralAtATime = [];
44+
List<List<String>> runTheseOneAtATime = [];
45+
void addSuiteSkipVm(String suitePath, {required int shards}) {
46+
for (int shard = 1; shard <= shards; shard++) {
47+
runTheseSeveralAtATime.add([
48+
dart.toFilePath(),
49+
"--enable-asserts",
50+
suitePath,
51+
"-DskipVm=true",
52+
"--coverage=${coverageTmpDir.path}/",
53+
"--shards=$shards",
54+
"--shard=$shard",
55+
]);
56+
}
3657
}
3758

3859
void addWithCoverageArgument(String script) {
39-
runThese.add([
60+
runTheseSeveralAtATime.add([
4061
dart.toFilePath(),
4162
"--enable-asserts",
4263
script,
4364
"--coverage=${coverageTmpDir.path}/",
4465
]);
4566
}
4667

47-
addSuiteSkipVm("pkg/front_end/test/strong_suite.dart");
48-
addSuiteSkipVm("pkg/front_end/test/modular_suite.dart");
68+
addSuiteSkipVm("pkg/front_end/test/strong_suite.dart", shards: 4);
69+
addSuiteSkipVm("pkg/front_end/test/modular_suite.dart", shards: 1);
4970

5071
addWithCoverageArgument("pkg/front_end/test/messages_suite.dart");
5172
addWithCoverageArgument("pkg/front_end/test/outline_suite.dart");
@@ -68,15 +89,16 @@ Future<void> main() async {
6889
addWithCoverageArgument("pkg/front_end/test/spelling_test_src_suite.dart");
6990
addWithCoverageArgument("pkg/front_end/test/compile_platform_coverage.dart");
7091

71-
runThese.add([
92+
// These two each use all available CPUs.
93+
runTheseOneAtATime.add([
7294
"python3",
7395
"tools/test.py",
7496
"-cfasta",
7597
"-mrelease",
7698
"-rnone",
7799
"language",
78100
]);
79-
runThese.add([
101+
runTheseOneAtATime.add([
80102
dart.toFilePath(),
81103
repoDirUri
82104
.resolve("pkg/front_end/test/run_our_tests_with_coverage.dart")
@@ -88,35 +110,63 @@ Future<void> main() async {
88110
);
89111
environment["CFE_COVERAGE"] = "${coverageTmpDir.path}/";
90112

91-
for (List<String> runThis in runThese) {
113+
final int processes = Platform.numberOfProcessors;
114+
int processesLeft = processes;
115+
int processesRunning = 0;
116+
Completer<void> completer = new Completer();
117+
118+
for (List<String> runThis in runTheseSeveralAtATime) {
119+
while (processesLeft <= 0) {
120+
await completer.future;
121+
}
122+
processesLeft--;
123+
processesRunning++;
92124
print("Starting $runThis");
93-
Process p = await Process.start(
94-
runThis.first,
95-
runThis.skip(1).toList(),
96-
environment: environment,
125+
unawaited(
126+
_run(silent, runThis, environment).then((runExitCode) {
127+
print("$runThis finished with exit code $runExitCode.");
128+
processesRunning--;
129+
processesLeft++;
130+
Completer<void> oldCompleter = completer;
131+
completer = new Completer();
132+
oldCompleter.complete();
133+
}),
97134
);
98-
p.stdout.transform(utf8.decoder).transform(const LineSplitter()).listen((
99-
String line,
100-
) {
101-
print("stdout> $line");
102-
});
103-
p.stderr.transform(utf8.decoder).transform(const LineSplitter()).listen((
104-
String line,
105-
) {
106-
print("stderr> $line");
107-
});
108-
print("Exit code = ${await p.exitCode}");
135+
}
136+
while (processesRunning > 0) {
137+
await completer.future;
109138
}
110139

111-
// Don't include the not-compiled stuff as we've (mostly) asked the VM to
112-
// force compile everything and that the remaining stuff is (mostly) mixins
113-
// and const classes etc that shouldn't (necessarily) be compiled but is
114-
// potentially covered in other ways.
115-
await coverageMerger.mergeFromDirUri(
116-
repoDirUri.resolve(".dart_tool/package_config.json"),
117-
coverageTmpDir.uri,
118-
silent: false,
119-
extraCoverageIgnores: const [],
120-
extraCoverageBlockIgnores: const [],
140+
for (List<String> runThis in runTheseOneAtATime) {
141+
print("Starting $runThis");
142+
print(
143+
"Finished with exit code "
144+
"${await _run(silent, runThis, environment)}",
145+
);
146+
}
147+
148+
return coverageTmpDir;
149+
}
150+
151+
Future<int> _run(
152+
bool silent,
153+
List<String> runThis,
154+
Map<String, String> environment,
155+
) async {
156+
Process p = await Process.start(
157+
runThis.first,
158+
runThis.skip(1).toList(),
159+
environment: environment,
121160
);
161+
p.stdout.transform(utf8.decoder).transform(const LineSplitter()).listen((
162+
String line,
163+
) {
164+
if (!silent) print("stdout> $line");
165+
});
166+
p.stderr.transform(utf8.decoder).transform(const LineSplitter()).listen((
167+
String line,
168+
) {
169+
print("stderr> $line");
170+
});
171+
return await p.exitCode;
122172
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:io' show Directory;
6+
7+
import '../tool/coverage_merger.dart' show mergeFromDirUri;
8+
import 'run_all_coverage.dart' show runAllCoverageTests;
9+
10+
Future<void> main() async {
11+
Directory coverageTmpDir = await runAllCoverageTests(silent: true);
12+
13+
await mergeFromDirUri(
14+
Uri.base.resolve(".dart_tool/package_config.json"),
15+
coverageTmpDir.uri,
16+
silent: true,
17+
extraCoverageIgnores: ["coverage-ignore(suite):"],
18+
extraCoverageBlockIgnores: ["coverage-ignore-block(suite):"],
19+
addAndRemoveCommentsInFiles: true,
20+
);
21+
}

pkg/front_end/test/weekly_tester.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'dart:async' show Future;
66
import 'dart:convert' show LineSplitter, utf8;
7-
import 'dart:io' show File, Platform, Process;
7+
import 'dart:io' show File, Platform, Process, ProcessResult;
88

99
Future<void> main(List<String> args) async {
1010
// General idea: Launch - in separate processes - whatever we want to run
@@ -109,6 +109,15 @@ Future<void> main(List<String> args) async {
109109
}
110110
shouldThrow = true;
111111
}
112+
113+
// Now run all coverage and print a diff.
114+
WrappedProcess coverageProcess = await run([
115+
Platform.script.resolve("run_all_coverage_update.dart").toString(),
116+
], "coverage update");
117+
await coverageProcess.process.exitCode;
118+
ProcessResult coverageDiffResult = Process.runSync("git", ["diff"]);
119+
print(coverageDiffResult.stdout);
120+
112121
if (shouldThrow) throw "There were failures!";
113122
}
114123

0 commit comments

Comments
 (0)