From 7dbf8eed3b251bfaada52ae8e231efd4c21089a6 Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Tue, 27 Aug 2019 09:56:53 +0000 Subject: [PATCH] [cfe] Support sharding in pkg/testing tests Splits strong_test into 4 shards. This test took 4+ minutes locally with the fast_strong_test and analyze_test ticking in at ~1:45. This change makes local testing of frontend unittests take 2 instead of 4 minutes in total. Change-Id: Id6015de86d547b209a699b1e5196b3edad1e6977 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114501 Reviewed-by: Jens Johansen --- .../test/sourcemap/sourcemaps_ddc_suite.dart | 2 +- .../test/sourcemap/sourcemaps_ddk_suite.dart | 2 +- .../test/sourcemap/stacktrace_ddc_suite.dart | 2 +- .../test/sourcemap/stacktrace_ddk_suite.dart | 2 +- pkg/front_end/test/fasta/expression_test.dart | 2 +- pkg/front_end/test/fasta/fast_strong_test.dart | 3 ++- pkg/front_end/test/fasta/incremental_test.dart | 2 +- pkg/front_end/test/fasta/messages_test.dart | 2 +- pkg/front_end/test/fasta/outline_test.dart | 2 +- .../test/fasta/parser/parser_suite.dart | 2 +- .../test/fasta/scanner/scanner_suite.dart | 2 +- pkg/front_end/test/fasta/strong1_test.dart | 9 +++++++++ pkg/front_end/test/fasta/strong2_test.dart | 9 +++++++++ pkg/front_end/test/fasta/strong3_test.dart | 9 +++++++++ pkg/front_end/test/fasta/strong4_test.dart | 9 +++++++++ .../{strong_test.dart => strong_tester.dart} | 17 +++++++++++++++-- .../test/fasta/text_serialization_test.dart | 2 +- .../fasta/type_promotion_look_ahead_test.dart | 2 +- .../test/incremental_bulk_compiler_full.dart | 2 +- .../incremental_bulk_compiler_smoke_test.dart | 2 +- .../test/incremental_load_from_dill_test.dart | 2 +- pkg/front_end/test/lint_test.dart | 2 +- pkg/front_end/test/old_dill_test.dart | 2 +- .../test/spelling_test_not_src_test.dart | 2 +- pkg/front_end/test/spelling_test_src_test.dart | 2 +- pkg/front_end/testing.json | 2 +- pkg/testing/lib/src/chain.dart | 15 ++++++++++++++- pkg/testing/lib/src/run.dart | 5 +++-- 28 files changed, 90 insertions(+), 26 deletions(-) create mode 100644 pkg/front_end/test/fasta/strong1_test.dart create mode 100644 pkg/front_end/test/fasta/strong2_test.dart create mode 100644 pkg/front_end/test/fasta/strong3_test.dart create mode 100644 pkg/front_end/test/fasta/strong4_test.dart rename pkg/front_end/test/fasta/{strong_test.dart => strong_tester.dart} (55%) diff --git a/pkg/dev_compiler/test/sourcemap/sourcemaps_ddc_suite.dart b/pkg/dev_compiler/test/sourcemap/sourcemaps_ddc_suite.dart index d8b4fa64359..fbb7af42551 100644 --- a/pkg/dev_compiler/test/sourcemap/sourcemaps_ddc_suite.dart +++ b/pkg/dev_compiler/test/sourcemap/sourcemaps_ddc_suite.dart @@ -89,4 +89,4 @@ class DevCompilerRunner implements CompilerRunner { } void main(List arguments) => - runMe(arguments, createContext, "testing.json"); + runMe(arguments, createContext, configurationPath: "testing.json"); diff --git a/pkg/dev_compiler/test/sourcemap/sourcemaps_ddk_suite.dart b/pkg/dev_compiler/test/sourcemap/sourcemaps_ddk_suite.dart index 2aced38aefe..cec68873204 100644 --- a/pkg/dev_compiler/test/sourcemap/sourcemaps_ddk_suite.dart +++ b/pkg/dev_compiler/test/sourcemap/sourcemaps_ddk_suite.dart @@ -105,4 +105,4 @@ class DevCompilerRunner implements CompilerRunner { } void main(List arguments) => - runMe(arguments, createContext, "testing.json"); + runMe(arguments, createContext, configurationPath: "testing.json"); diff --git a/pkg/dev_compiler/test/sourcemap/stacktrace_ddc_suite.dart b/pkg/dev_compiler/test/sourcemap/stacktrace_ddc_suite.dart index 0ed9dfbab24..b2ddfde6b34 100644 --- a/pkg/dev_compiler/test/sourcemap/stacktrace_ddc_suite.dart +++ b/pkg/dev_compiler/test/sourcemap/stacktrace_ddc_suite.dart @@ -22,4 +22,4 @@ class StackTraceContext extends ChainContextWithCleanupHelper { } void main(List arguments) => - runMe(arguments, createContext, "testing.json"); + runMe(arguments, createContext, configurationPath: "testing.json"); diff --git a/pkg/dev_compiler/test/sourcemap/stacktrace_ddk_suite.dart b/pkg/dev_compiler/test/sourcemap/stacktrace_ddk_suite.dart index 515007e4eb6..8a23a6623e2 100644 --- a/pkg/dev_compiler/test/sourcemap/stacktrace_ddk_suite.dart +++ b/pkg/dev_compiler/test/sourcemap/stacktrace_ddk_suite.dart @@ -29,4 +29,4 @@ class StackTraceContext extends ChainContextWithCleanupHelper } void main(List arguments) => - runMe(arguments, createContext, "testing.json"); + runMe(arguments, createContext, configurationPath: "testing.json"); diff --git a/pkg/front_end/test/fasta/expression_test.dart b/pkg/front_end/test/fasta/expression_test.dart index 5c0a06e0d14..60fe038a463 100644 --- a/pkg/front_end/test/fasta/expression_test.dart +++ b/pkg/front_end/test/fasta/expression_test.dart @@ -433,4 +433,4 @@ Future createContext( } main([List arguments = const []]) => - runMe(arguments, createContext, "../../testing.json"); + runMe(arguments, createContext, configurationPath: "../../testing.json"); diff --git a/pkg/front_end/test/fasta/fast_strong_test.dart b/pkg/front_end/test/fasta/fast_strong_test.dart index 6c1464c42b3..26c0875ff81 100644 --- a/pkg/front_end/test/fasta/fast_strong_test.dart +++ b/pkg/front_end/test/fasta/fast_strong_test.dart @@ -18,4 +18,5 @@ Future createContext( } main([List arguments = const []]) => runMe(arguments, createContext, - "../../testing.json", Platform.script.resolve("strong_test.dart")); + configurationPath: "../../testing.json", + me: Platform.script.resolve("strong_tester.dart")); diff --git a/pkg/front_end/test/fasta/incremental_test.dart b/pkg/front_end/test/fasta/incremental_test.dart index 4208d17f82e..22b4568325e 100644 --- a/pkg/front_end/test/fasta/incremental_test.dart +++ b/pkg/front_end/test/fasta/incremental_test.dart @@ -246,4 +246,4 @@ Future createContext( } main([List arguments = const []]) => - runMe(arguments, createContext, "../../testing.json"); + runMe(arguments, createContext, configurationPath: "../../testing.json"); diff --git a/pkg/front_end/test/fasta/messages_test.dart b/pkg/front_end/test/fasta/messages_test.dart index e2f30c938e7..08e960ead33 100644 --- a/pkg/front_end/test/fasta/messages_test.dart +++ b/pkg/front_end/test/fasta/messages_test.dart @@ -663,4 +663,4 @@ String relativize(Uri uri) { } main([List arguments = const []]) => - runMe(arguments, createContext, "../../testing.json"); + runMe(arguments, createContext, configurationPath: "../../testing.json"); diff --git a/pkg/front_end/test/fasta/outline_test.dart b/pkg/front_end/test/fasta/outline_test.dart index 43e9cc97cb1..cc5ec1dbf54 100644 --- a/pkg/front_end/test/fasta/outline_test.dart +++ b/pkg/front_end/test/fasta/outline_test.dart @@ -14,4 +14,4 @@ Future createContext( } main([List arguments = const []]) => - runMe(arguments, createContext, "../../testing.json"); + runMe(arguments, createContext, configurationPath: "../../testing.json"); diff --git a/pkg/front_end/test/fasta/parser/parser_suite.dart b/pkg/front_end/test/fasta/parser/parser_suite.dart index 1caa6947ac7..e2321afeb09 100644 --- a/pkg/front_end/test/fasta/parser/parser_suite.dart +++ b/pkg/front_end/test/fasta/parser/parser_suite.dart @@ -41,4 +41,4 @@ class Parse extends Step { } main(List arguments) => - runMe(arguments, createContext, "../../../testing.json"); + runMe(arguments, createContext, configurationPath: "../../../testing.json"); diff --git a/pkg/front_end/test/fasta/scanner/scanner_suite.dart b/pkg/front_end/test/fasta/scanner/scanner_suite.dart index 0adddc1fb5a..1fb6f442e60 100644 --- a/pkg/front_end/test/fasta/scanner/scanner_suite.dart +++ b/pkg/front_end/test/fasta/scanner/scanner_suite.dart @@ -20,4 +20,4 @@ class ScannerContext extends ChainContext { } main(List arguments) => - runMe(arguments, createContext, "../../../testing.json"); + runMe(arguments, createContext, configurationPath: "../../../testing.json"); diff --git a/pkg/front_end/test/fasta/strong1_test.dart b/pkg/front_end/test/fasta/strong1_test.dart new file mode 100644 index 00000000000..cb30b7e5f63 --- /dev/null +++ b/pkg/front_end/test/fasta/strong1_test.dart @@ -0,0 +1,9 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE.md file. + +import 'strong_tester.dart'; + +main(List arguments) { + internalMain(arguments: arguments, shards: shardCount, shard: 0); +} diff --git a/pkg/front_end/test/fasta/strong2_test.dart b/pkg/front_end/test/fasta/strong2_test.dart new file mode 100644 index 00000000000..10fafaf03e7 --- /dev/null +++ b/pkg/front_end/test/fasta/strong2_test.dart @@ -0,0 +1,9 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE.md file. + +import 'strong_tester.dart'; + +main(List arguments) { + internalMain(arguments: arguments, shards: shardCount, shard: 1); +} diff --git a/pkg/front_end/test/fasta/strong3_test.dart b/pkg/front_end/test/fasta/strong3_test.dart new file mode 100644 index 00000000000..044c7e8a0ef --- /dev/null +++ b/pkg/front_end/test/fasta/strong3_test.dart @@ -0,0 +1,9 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE.md file. + +import 'strong_tester.dart'; + +main(List arguments) { + internalMain(arguments: arguments, shards: shardCount, shard: 2); +} diff --git a/pkg/front_end/test/fasta/strong4_test.dart b/pkg/front_end/test/fasta/strong4_test.dart new file mode 100644 index 00000000000..9e459e32de8 --- /dev/null +++ b/pkg/front_end/test/fasta/strong4_test.dart @@ -0,0 +1,9 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE.md file. + +import 'strong_tester.dart'; + +main(List arguments) { + internalMain(arguments: arguments, shards: shardCount, shard: 3); +} diff --git a/pkg/front_end/test/fasta/strong_test.dart b/pkg/front_end/test/fasta/strong_tester.dart similarity index 55% rename from pkg/front_end/test/fasta/strong_test.dart rename to pkg/front_end/test/fasta/strong_tester.dart index e8e430d0b48..402ff57ab09 100644 --- a/pkg/front_end/test/fasta/strong_test.dart +++ b/pkg/front_end/test/fasta/strong_tester.dart @@ -5,14 +5,27 @@ library fasta.test.strong_test; import 'dart:async' show Future; +import 'dart:io' show Platform; import 'testing/suite.dart'; +const int shardCount = 4; + Future createContext( Chain suite, Map environment) { environment[ENABLE_FULL_COMPILE] = ""; return FastaContext.create(suite, environment); } -main([List arguments = const []]) => - runMe(arguments, createContext, "../../testing.json"); +main(List arguments) { + internalMain(arguments: arguments); +} + +internalMain( + {List arguments = const [], int shards = 1, int shard = 0}) { + runMe(arguments, createContext, + configurationPath: "../../testing.json", + me: Platform.script.resolve('strong_tester.dart'), + shards: shards, + shard: shard); +} diff --git a/pkg/front_end/test/fasta/text_serialization_test.dart b/pkg/front_end/test/fasta/text_serialization_test.dart index 07ecb85d3db..fa51b542818 100644 --- a/pkg/front_end/test/fasta/text_serialization_test.dart +++ b/pkg/front_end/test/fasta/text_serialization_test.dart @@ -16,4 +16,4 @@ Future createContext( } main([List arguments = const []]) => - runMe(arguments, createContext, "../../testing.json"); + runMe(arguments, createContext, configurationPath: "../../testing.json"); diff --git a/pkg/front_end/test/fasta/type_promotion_look_ahead_test.dart b/pkg/front_end/test/fasta/type_promotion_look_ahead_test.dart index aa67171461a..398f5a146ca 100644 --- a/pkg/front_end/test/fasta/type_promotion_look_ahead_test.dart +++ b/pkg/front_end/test/fasta/type_promotion_look_ahead_test.dart @@ -227,4 +227,4 @@ class CheckTypePromotionResult } main([List arguments = const []]) => - runMe(arguments, createContext, "../../testing.json"); + runMe(arguments, createContext, configurationPath: "../../testing.json"); diff --git a/pkg/front_end/test/incremental_bulk_compiler_full.dart b/pkg/front_end/test/incremental_bulk_compiler_full.dart index cc73543ccee..ad1a7f3b77b 100644 --- a/pkg/front_end/test/incremental_bulk_compiler_full.dart +++ b/pkg/front_end/test/incremental_bulk_compiler_full.dart @@ -29,7 +29,7 @@ import 'package:testing/testing.dart' import 'incremental_utils.dart' as util; main([List arguments = const []]) => - runMe(arguments, createContext, "../testing.json"); + runMe(arguments, createContext, configurationPath: "../testing.json"); Future createContext( Chain suite, Map environment) async { diff --git a/pkg/front_end/test/incremental_bulk_compiler_smoke_test.dart b/pkg/front_end/test/incremental_bulk_compiler_smoke_test.dart index 539963572ce..866104c433c 100644 --- a/pkg/front_end/test/incremental_bulk_compiler_smoke_test.dart +++ b/pkg/front_end/test/incremental_bulk_compiler_smoke_test.dart @@ -9,7 +9,7 @@ import 'package:testing/testing.dart' show Chain, runMe; import 'incremental_bulk_compiler_full.dart' show Context; main([List arguments = const []]) => - runMe(arguments, createContext, "../testing.json"); + runMe(arguments, createContext, configurationPath: "../testing.json"); Future createContext( Chain suite, Map environment) async { diff --git a/pkg/front_end/test/incremental_load_from_dill_test.dart b/pkg/front_end/test/incremental_load_from_dill_test.dart index b88f426e0e4..f61627892bf 100644 --- a/pkg/front_end/test/incremental_load_from_dill_test.dart +++ b/pkg/front_end/test/incremental_load_from_dill_test.dart @@ -60,7 +60,7 @@ import 'package:front_end/src/fasta/fasta_codes.dart' show DiagnosticMessageFromJson, FormattedMessage; main([List arguments = const []]) => - runMe(arguments, createContext, "../testing.json"); + runMe(arguments, createContext, configurationPath: "../testing.json"); Future createContext( Chain suite, Map environment) async { diff --git a/pkg/front_end/test/lint_test.dart b/pkg/front_end/test/lint_test.dart index f39f95c7922..7f98a65ea48 100644 --- a/pkg/front_end/test/lint_test.dart +++ b/pkg/front_end/test/lint_test.dart @@ -32,7 +32,7 @@ import 'package:testing/testing.dart' show Chain, ChainContext, Result, Step, TestDescription, runMe; main([List arguments = const []]) => - runMe(arguments, createContext, "../testing.json"); + runMe(arguments, createContext, configurationPath: "../testing.json"); Future createContext( Chain suite, Map environment) async { diff --git a/pkg/front_end/test/old_dill_test.dart b/pkg/front_end/test/old_dill_test.dart index df757c40fa8..f8b22f8340a 100644 --- a/pkg/front_end/test/old_dill_test.dart +++ b/pkg/front_end/test/old_dill_test.dart @@ -20,7 +20,7 @@ Future main([List arguments = const []]) async { await checkDill(); return null; } - await runMe(arguments, createContext, "../testing.json"); + await runMe(arguments, createContext, configurationPath: "../testing.json"); await checkDill(); } diff --git a/pkg/front_end/test/spelling_test_not_src_test.dart b/pkg/front_end/test/spelling_test_not_src_test.dart index e1f675a963e..3dcf23e16c4 100644 --- a/pkg/front_end/test/spelling_test_not_src_test.dart +++ b/pkg/front_end/test/spelling_test_not_src_test.dart @@ -11,7 +11,7 @@ import 'spelling_test_base.dart'; import 'spell_checking_utils.dart' as spell; main([List arguments = const []]) => - runMe(arguments, createContext, "../testing.json"); + runMe(arguments, createContext, configurationPath: "../testing.json"); Future createContext( Chain suite, Map environment) async { diff --git a/pkg/front_end/test/spelling_test_src_test.dart b/pkg/front_end/test/spelling_test_src_test.dart index 73cdc8d4657..31b434c0f43 100644 --- a/pkg/front_end/test/spelling_test_src_test.dart +++ b/pkg/front_end/test/spelling_test_src_test.dart @@ -11,7 +11,7 @@ import 'spelling_test_base.dart'; import 'spell_checking_utils.dart' as spell; main([List arguments = const []]) => - runMe(arguments, createContext, "../testing.json"); + runMe(arguments, createContext, configurationPath: "../testing.json"); Future createContext( Chain suite, Map environment) async { diff --git a/pkg/front_end/testing.json b/pkg/front_end/testing.json index 8119cab2ab9..68ecc15c786 100644 --- a/pkg/front_end/testing.json +++ b/pkg/front_end/testing.json @@ -71,7 +71,7 @@ { "name": "strong", "kind": "Chain", - "source": "test/fasta/strong_test.dart", + "source": "test/fasta/strong_tester.dart", "path": "testcases/", "status": "testcases/strong.status", "pattern": [ diff --git a/pkg/testing/lib/src/chain.dart b/pkg/testing/lib/src/chain.dart index 1c0c748c2f6..83380731820 100644 --- a/pkg/testing/lib/src/chain.dart +++ b/pkg/testing/lib/src/chain.dart @@ -111,7 +111,11 @@ abstract class ChainContext { ExpectationSet get expectationSet => ExpectationSet.Default; - Future run(Chain suite, Set selectors) async { + Future run(Chain suite, Set selectors, + {int shards = 1, int shard = 0}) async { + assert(shards >= 1, "Invalid shards count: $shards"); + assert(0 <= shard && shard < shards, + "Invalid shard index: $shard, not in range [0,$shards[."); List partialSelectors = selectors .where((s) => s.endsWith('...')) .map((s) => s.substring(0, s.length - 3)) @@ -124,6 +128,15 @@ abstract class ChainContext { } List descriptions = await stream.toList(); descriptions.sort(); + if (shards > 1) { + List shardDescriptions = []; + for (int index = 0; index < descriptions.length; index++) { + if (index % shards == shard) { + shardDescriptions.add(descriptions[index]); + } + } + descriptions = shardDescriptions; + } Map unexpectedResults = {}; Map> unexpectedOutcomes = diff --git a/pkg/testing/lib/src/run.dart b/pkg/testing/lib/src/run.dart index 1d83c9b796c..d16cf30034f 100644 --- a/pkg/testing/lib/src/run.dart +++ b/pkg/testing/lib/src/run.dart @@ -55,7 +55,7 @@ Future computeTestRoot(String configurationPath, Uri base) { /// `testing.json` isn't located in the current working directory and is a path /// relative to [me] which defaults to `Platform.script`. Future runMe(List arguments, CreateContext f, - [String configurationPath, Uri me]) { + {String configurationPath, Uri me, int shards = 1, int shard = 0}) { me ??= Platform.script; return withErrorHandling(() async { TestRoot testRoot = await computeTestRoot(configurationPath, me); @@ -65,7 +65,8 @@ Future runMe(List arguments, CreateContext f, if (me == suite.source) { print("Running suite ${suite.name}..."); ChainContext context = await f(suite, cl.environment); - await context.run(suite, new Set.from(cl.selectors)); + await context.run(suite, new Set.from(cl.selectors), + shards: shards, shard: shard); } } });