Skip to content

Commit

Permalink
[CFE] Allow crash test minimizer to work in more scenarios
Browse files Browse the repository at this point in the history
This change allows to reproduce and minimize the bug in
https://dart-review.googlesource.com/c/sdk/+/385441/2 via this
(mouthful) of a command:

```
out/ReleaseX64/dart pkg/front_end/test/crashing_test_case_minimizer.dart --platform=out/ReleaseX64/vm_platform_strong.dill --invalidate=package:_fe_analyzer_shared/src/messages/codes.dart --invalidate=package:front_end/src/type_inference/assignable_errors.dart --initial-only-outline --load-from-component-before-invalidate --invalidate-all-at-once --packages=.dart_tool/package_config.json pkg/front_end/lib/src/type_inference/assignable_errors.dart
```

Which - after renames - creates a reproduction like this:

```
# 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.

# Reproduce a crash.

type: newworld
worlds:
  - entry:
      - a.dart
    sources:
      a.dart: |
        import 'b.dart';
      b.dart: |
        export 'c.dart';
      c.dart: |
        class Message {}
        typedef SummaryTemplate = Message Function(int, int, num, num, num);
    expectedLibraryCount: 3

  - entry:
      - a.dart
    worldType: updated
    expectInitializeFromDill: false
    invalidate:
      - c.dart
      - a.dart
    expectedLibraryCount: 3
    advancedInvalidation: bodiesOnly
```

(this was already reproduced and fixed in
https://dart-review.googlesource.com/c/sdk/+/385720 but still)

Change-Id: I63d5510b1b848309cc4c74a15cdc1f33400d4861
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385740
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Jens Johansen <[email protected]>
  • Loading branch information
jensjoha authored and Commit Queue committed Sep 18, 2024
1 parent f24162c commit ab85479
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 40 deletions.
28 changes: 18 additions & 10 deletions pkg/front_end/test/crashing_test_case_minimizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'crashing_test_case_minimizer_impl.dart';
// parser on it and verifies that no syntax errors have been introduced.

Future<void> main(List<String> arguments) async {
String? filename;
List<String> filenames = [];
Uri? loadJson;
for (String arg in arguments) {
if (arg.startsWith("--json=")) {
Expand All @@ -41,8 +41,17 @@ Future<void> main(List<String> arguments) async {
} else if (arg.startsWith("--platform=")) {
String platform = arg.substring("--platform=".length);
settings.platformUri = Uri.base.resolve(platform);
} else if (arg.startsWith("--packages=")) {
String packages = arg.substring("--packages=".length);
settings.packagesFileUri = Uri.base.resolve(packages);
} else if (arg == "--no-platform") {
settings.noPlatform = true;
} else if (arg == "--initial-only-outline") {
settings.initialOnlyOutline = true;
} else if (arg == "--load-from-component-before-invalidate") {
settings.loadFromComponentBeforeInvalidate = true;
} else if (arg == "--invalidate-all-at-once") {
settings.invalidateAllAtOnce = true;
} else if (arg.startsWith("--invalidate=")) {
for (String s in arg.substring("--invalidate=".length).split(",")) {
settings.invalidate.add(Uri.base.resolve(s));
Expand Down Expand Up @@ -79,11 +88,8 @@ Future<void> main(List<String> arguments) async {
} else {
throw "Unknown option $arg";
}
} else if (filename != null) {
throw "Already got '$filename', '$arg' is also a filename; "
"can only get one";
} else {
filename = arg;
filenames.add(arg);
}
}
if (settings.noPlatform) {
Expand All @@ -101,12 +107,14 @@ Future<void> main(List<String> arguments) async {
throw "The platform file '${settings.platformUri}' doesn't exist";
}
}
if (filename == null) {
throw "Need file to operate on";
if (filenames.isEmpty) {
throw "Need file(s) to operate on";
}
for (String filename in filenames) {
File file = new File(filename);
if (!file.existsSync()) throw "File $filename doesn't exist.";
settings.entryUris.add(file.absolute.uri);
}
File file = new File(filename);
if (!file.existsSync()) throw "File $filename doesn't exist.";
settings.mainUri = file.absolute.uri;
}

TestMinimizer testMinimizer = new TestMinimizer(settings);
Expand Down
Loading

0 comments on commit ab85479

Please sign in to comment.