From c437107a4c7e4e5a9261404f621d4a04201cd6b4 Mon Sep 17 00:00:00 2001 From: Jens Johansen Date: Fri, 12 Jul 2024 11:11:16 +0000 Subject: [PATCH] [CFE/testing] Isolate v processes test script; make pkg:testing run more consistent with invalid shards info E.g. compile to aot: out/ReleaseX64/dart-sdk/bin/dart compile aot-snapshot pkg/front_end/test/isolates_v_processes.dart And run with a different number of isolates: $ out/ReleaseX64/dart-sdk/bin/dartaotruntime --deterministic pkg/front_end/test/isolates_v_processes.aot --isolates -j1 => 0:01:13.683401 $ out/ReleaseX64/dart-sdk/bin/dartaotruntime --deterministic pkg/front_end/test/isolates_v_processes.aot --isolates -j2 => 0:00:53.379932 $ out/ReleaseX64/dart-sdk/bin/dartaotruntime --deterministic pkg/front_end/test/isolates_v_processes.aot --isolates -j4 => 0:01:12.864165 (you might change `const bool doPrint = false;` to `true`, compile again, run with -j4 and see interesting stops when it runs) ...or you could try the same but using processes: $ out/ReleaseX64/dart-sdk/bin/dartaotruntime --deterministic pkg/front_end/test/isolates_v_processes.aot --processes -j1 => 0:01:17.590922 $ out/ReleaseX64/dart-sdk/bin/dartaotruntime --deterministic pkg/front_end/test/isolates_v_processes.aot --processes -j2 => 0:00:44.055109 $ out/ReleaseX64/dart-sdk/bin/dartaotruntime --deterministic pkg/front_end/test/isolates_v_processes.aot --processes -j4 => 0:00:26.360444 Change-Id: Ie161e7dfa0f29931af34058b7b043ce93b839218 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375481 Commit-Queue: Jens Johansen Reviewed-by: Johnni Winther --- pkg/front_end/presubmit_helper_spawn.dart | 2 +- pkg/front_end/test/isolates_v_processes.dart | 162 +++++++++++++++++++ pkg/testing/lib/src/chain.dart | 6 +- 3 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 pkg/front_end/test/isolates_v_processes.dart diff --git a/pkg/front_end/presubmit_helper_spawn.dart b/pkg/front_end/presubmit_helper_spawn.dart index edc89160e2b..f994f265117 100644 --- a/pkg/front_end/presubmit_helper_spawn.dart +++ b/pkg/front_end/presubmit_helper_spawn.dart @@ -225,7 +225,7 @@ class ErrorNotingLogger implements Logger { @override void noticeFrameworkCatchError(error, StackTrace stackTrace) { - print("Framework Catch Error: $error\n$StackTrace"); + print("Framework Catch Error: $error\n$stackTrace"); gotFailure = true; } } diff --git a/pkg/front_end/test/isolates_v_processes.dart b/pkg/front_end/test/isolates_v_processes.dart new file mode 100644 index 00000000000..795a3c29fb8 --- /dev/null +++ b/pkg/front_end/test/isolates_v_processes.dart @@ -0,0 +1,162 @@ +// Copyright (c) 2024, 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 file. + +import "dart:io"; +import "dart:isolate"; + +import "package:testing/src/suite.dart"; +import "package:testing/testing.dart"; +import 'package:testing/src/log.dart' show Logger, StdoutLogger; + +import "fasta/strong_suite.dart" as strong; + +const bool doPrint = false; + +enum What { + Process, + Isolate, + Direct, + Unknown; +} + +Future main(List args) async { + int j = 2; + int x = 0; + What what = What.Unknown; + + for (String arg in args) { + if (arg.startsWith("-j")) { + j = int.tryParse(arg.substring(2)) ?? (throw "invalid -j ($arg)"); + } else if (arg.startsWith("-x")) { + x = int.tryParse(arg.substring(2)) ?? (throw "invalid -x ($arg)"); + } else if (arg == "--isolates") { + what = What.Isolate; + } else if (arg == "--processes") { + what = What.Process; + } else if (arg == "--direct") { + what = What.Direct; + } + } + Stopwatch stopwatch = new Stopwatch()..start(); + switch (what) { + case What.Process: + await useProcesses(j); + case What.Isolate: + await useIsolates(j); + case What.Direct: + await useDirect(j, x); + case What.Unknown: + throw "Specify with --isolates or --processes and optionally -j"; + } + print("All done after ${stopwatch.elapsed}"); +} + +Future entry(List args) async { + await runMe( + ["-DskipVm=true", "-DsemiFuzz=false"], + strong.createContext, + me: Platform.script.resolve("fasta/strong_suite.dart"), + configurationPath: "../../testing.json", + shards: args[0], + shard: args[1], + logger: doPrint ? const StdoutLogger() : const DevNullLogger(), + ); +} + +Future useDirect(int shards, int shard) async { + List futures = []; + futures.add(entry([shards, shard])); + await Future.wait(futures); +} + +Future useIsolates(final int j) async { + Stopwatch stopwatch = new Stopwatch()..start(); + print("Using $j isolates..."); + List futures = []; + for (int i = 0; i <= j; i++) { + ReceivePort exitPort = new ReceivePort(); + futures.add(exitPort.first.then((_) { + if (i == j) { + print("Isolate #$i (checking startup cost) finished after " + "${stopwatch.elapsed}"); + } else { + print("Isolate #$i finished after ${stopwatch.elapsed}"); + } + })); + await Isolate.spawn(entry, [j, i], onExit: exitPort.sendPort); + } + await Future.wait(futures); +} + +Future useProcesses(final int j) async { + Stopwatch stopwatch = new Stopwatch()..start(); + print("Using $j processes..."); + String script = Platform.script.toFilePath(); + List futures = []; + for (int i = 0; i <= j; i++) { + futures.add(Process.run(Platform.resolvedExecutable, [ + script, + "--direct", + "-j$j", + "-x$i", + ]).then((_) { + if (i == j) { + print("Process #$i (checking startup cost) finished after " + "${stopwatch.elapsed}"); + } else { + print("Process #$i finished after ${stopwatch.elapsed}"); + } + })); + } + await Future.wait(futures); +} + +class DevNullLogger implements Logger { + const DevNullLogger(); + + @override + void logExpectedResult(Suite suite, TestDescription description, + Result result, Set expectedOutcomes) {} + + @override + void logMessage(Object message) {} + + @override + void logNumberedLines(String text) {} + + @override + void logProgress(String message) {} + + @override + void logStepComplete(int completed, int failed, int total, Suite suite, + TestDescription description, Step step) {} + + @override + void logStepStart(int completed, int failed, int total, Suite suite, + TestDescription description, Step step) {} + + @override + void logSuiteComplete(Suite suite) {} + + @override + void logSuiteStarted(Suite suite) {} + + @override + void logTestComplete(int completed, int failed, int total, Suite suite, + TestDescription description) {} + + @override + void logTestStart(int completed, int failed, int total, Suite suite, + TestDescription description) {} + + @override + void logUncaughtError(error, StackTrace stackTrace) {} + + @override + void logUnexpectedResult(Suite suite, TestDescription description, + Result result, Set expectedOutcomes) {} + + @override + void noticeFrameworkCatchError(error, StackTrace stackTrace) {} +} diff --git a/pkg/testing/lib/src/chain.dart b/pkg/testing/lib/src/chain.dart index 4c241098b14..aead8550835 100644 --- a/pkg/testing/lib/src/chain.dart +++ b/pkg/testing/lib/src/chain.dart @@ -134,7 +134,11 @@ abstract class ChainContext { [suite.statusFile!.toFilePath()], expectationSet); List descriptions = await list(suite); descriptions.sort(); - if (shards > 1) { + + /// Hack: If not running with asserts running the (invalid) configuration + /// shards=1 shard>0 should behave as when running with the (invalid) + /// configuration shards>1 shard>=shards, i.e. it should run nothing. + if (shards > 1 || shard >= shards) { List shardDescriptions = []; for (int index = 0; index < descriptions.length; index++) { if (index % shards == shard) {