Files
sdk/pkg/analysis_server/test/benchmarks_test.dart
T
Sam Rawlins 4ef2725654 Add an analyzer_testing package
We intend to publish and maintain this as a set of testing-related
utilities for the analyzer packages and for analyzer plugins.

Work towards https://github.com/dart-lang/sdk/issues/55660

See the doc: https://docs.google.com/document/d/1jRtd8B1ijPAP6Pz89HRnyIZXw2VMjaZx0vRZTpoNO84/edit?tab=t.0#heading=h.2sz41a544qhi

Change-Id: I2764b1357a932fa955060b26d78038997eaa9536
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425080
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2025-05-02 06:58:49 -07:00

78 lines
2.2 KiB
Dart

// Copyright (c) 2014, 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.=> defineTests();
/// This tests the benchmarks in benchmark/benchmark.test, and ensures that our
/// benchmarks can run.
library;
import 'dart:convert';
import 'dart:io';
import 'package:analyzer_testing/package_root.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
void main() => defineTests();
String get _serverSourcePath {
return path.join(packageRoot, 'analysis_server');
}
void defineTests() {
group('benchmarks', () {
var benchmarks = _listBenchmarks();
test('can list', () {
expect(benchmarks, isNotEmpty);
});
const benchmarkIdsToSkip = {
'analysis-flutter-analyze',
'das-flutter',
'lsp-flutter',
};
// Since these benchmarks can take a while, allow skipping with an env
// variable.
var runBenchmarks =
Platform.environment['TEST_SERVER_BENCHMARKS'] != 'false';
var skipReason =
runBenchmarks
? null
: 'Skipped by TEST_SERVER_BENCHMARKS environment variable';
for (var benchmarkId in benchmarks) {
if (benchmarkIdsToSkip.contains(benchmarkId)) {
continue;
}
test(benchmarkId, () {
var r = Process.runSync(Platform.resolvedExecutable, [
path.join('benchmark', 'benchmarks.dart'),
'run',
'--repeat=1',
'--quick',
benchmarkId,
], workingDirectory: _serverSourcePath);
expect(
r.exitCode,
0,
reason: 'exit: ${r.exitCode}\n${r.stdout}\n${r.stderr}',
);
}, skip: skipReason);
}
});
}
List<String> _listBenchmarks() {
var result = Process.runSync(Platform.resolvedExecutable, [
path.join('benchmark', 'benchmarks.dart'),
'list',
'--machine',
], workingDirectory: _serverSourcePath);
var output = json.decode(result.stdout as String) as Map<Object?, Object?>;
var benchmarks = (output['benchmarks'] as List).cast<Map<Object?, Object?>>();
return benchmarks.map((b) => b['id']).cast<String>().toList();
}