Skip to content

Commit

Permalink
[vm/infra] Improve IL testing framework
Browse files Browse the repository at this point in the history
* Add support for dumping flow graphs in JSON (to make it machine
readable);
* Add support for controlling which functions are dumped through
a pragma annotation:
`@pragma('vm:testing:print-flow-graph'[, "passes filter"])`
* Replace simple matching DSL with programmatic matching
* Support obfuscated builds

Fixes #47340

TEST=vm/dart{,_2}/aot_prefer_equality_comparison_il_test

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-x64-try
Change-Id: Ie067ba451d311e6019a8c3a88c012231b0c50eb5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/219240
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
  • Loading branch information
mraleph authored and commit-bot@chromium.org committed Nov 16, 2021
1 parent c8595fd commit a643e53
Show file tree
Hide file tree
Showing 19 changed files with 955 additions and 319 deletions.
9 changes: 7 additions & 2 deletions pkg/test_runner/lib/src/compiler_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,9 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration
if (_configuration.useQemu) '--no-use-integer-division',
if (arguments.contains('--print-flow-graph-optimized'))
'--redirect-isolate-log-to=$tempDir/out.il',
if (arguments.contains('--print-flow-graph-optimized') &&
(_configuration.isMinified || arguments.contains('--obfuscate')))
'--save-obfuscation_map=$tempDir/renames.json',
..._replaceDartFiles(arguments, tempKernelFile(tempDir)),
];

Expand All @@ -844,6 +847,7 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration
var args = [
arguments.firstWhere((arg) => arg.endsWith('_il_test.dart')),
'$tempDir/out.il',
if (arguments.contains('--obfuscate')) '$tempDir/renames.json',
];

return CompilationCommand('compare_il', tempDir, bootstrapDependencies(),
Expand Down Expand Up @@ -965,9 +969,10 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration
List<String> computeCompilerArguments(
TestFile testFile, List<String> vmOptions, List<String> args) {
return [
if (testFile.ilMatches.isNotEmpty) ...[
if (testFile.isVmIntermediateLanguageTest) ...[
'--print-flow-graph-optimized',
'--print-flow-graph-filter=${testFile.ilMatches.join(',')}'
'--print-flow-graph-as-json',
'--print-flow-graph-filter=@pragma',
],
if (_enableAsserts) '--enable_asserts',
...filterVmOptions(vmOptions),
Expand Down
17 changes: 6 additions & 11 deletions pkg/test_runner/lib/src/test_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ class TestFile extends _TestFileBase {
throw FormatException('Unknown feature "$name" in test $filePath');
});

var ilMatches = filePath.endsWith('_il_test.dart')
? _parseStringOption(filePath, contents, r'MatchIL\[AOT\]',
allowMultiple: true)
: const <String>[];
final isVmIntermediateLanguageTest = filePath.endsWith('_il_test.dart');

// VM options.
var vmOptions = <List<String>>[];
Expand Down Expand Up @@ -341,7 +338,7 @@ class TestFile extends _TestFileBase {
sharedObjects: sharedObjects,
otherResources: otherResources,
experiments: experiments,
ilMatches: ilMatches);
isVmIntermediateLanguageTest: isVmIntermediateLanguageTest);
}

/// A special fake test file for representing a VM unit test written in C++.
Expand All @@ -363,7 +360,7 @@ class TestFile extends _TestFileBase {
sharedObjects = [],
otherResources = [],
experiments = [],
ilMatches = [],
isVmIntermediateLanguageTest = false,
super(null, null, []);

TestFile._(Path suiteDirectory, Path path, List<StaticError> expectedErrors,
Expand All @@ -384,7 +381,7 @@ class TestFile extends _TestFileBase {
this.sharedObjects,
this.otherResources,
this.experiments,
this.ilMatches = const <String>[]})
this.isVmIntermediateLanguageTest = false})
: super(suiteDirectory, path, expectedErrors) {
assert(!isMultitest || dartOptions.isEmpty);
}
Expand All @@ -403,6 +400,7 @@ class TestFile extends _TestFileBase {
final bool hasRuntimeError;
final bool hasStaticWarning;
final bool hasCrash;
final bool isVmIntermediateLanguageTest;

/// The features that a test configuration must support in order to run this
/// test.
Expand All @@ -411,9 +409,6 @@ class TestFile extends _TestFileBase {
/// requirements, the test is implicitly skipped.
final List<Feature> requirements;

/// List of functions which will have their IL verified (in AOT mode).
final List<String> ilMatches;

final List<String> sharedOptions;
final List<String> dartOptions;
final List<String> dart2jsOptions;
Expand Down Expand Up @@ -479,6 +474,7 @@ class _MultitestFile extends _TestFileBase implements TestFile {
final bool hasStaticWarning;
final bool hasSyntaxError;
bool get hasCrash => _origin.hasCrash;
bool get isVmIntermediateLanguageTest => _origin.isVmIntermediateLanguageTest;

_MultitestFile(this._origin, Path path, this.multitestKey,
List<StaticError> expectedErrors,
Expand All @@ -493,7 +489,6 @@ class _MultitestFile extends _TestFileBase implements TestFile {
String get packages => _origin.packages;

List<Feature> get requirements => _origin.requirements;
List<String> get ilMatches => _origin.ilMatches;
List<String> get dart2jsOptions => _origin.dart2jsOptions;
List<String> get dartOptions => _origin.dartOptions;
List<String> get ddcOptions => _origin.ddcOptions;
Expand Down
Loading

0 comments on commit a643e53

Please sign in to comment.