@@ -12,6 +12,22 @@ import 'utils/io_utils.dart';
1212final  Uri  repoDirUri =  computeRepoDirUri ();
1313
1414Future <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}
0 commit comments