Files
sdk/pkg/vm_service/test/coverage_leaf_function_test.dart
T
Ben Konyi fa8ea6dfaa [ package:vm_service ] Update tests to be compatible with pub run test
Will allow for tests to be enabled in google3 as pub or portions of pub
are used to run VM tests.

Previously the test harness was configured to look for a URI with a data: scheme to determine if it was being run via pub run test (pub generates its own harness and spawns the test from that). We were parsing the test URI out of this data URI, which wouldn't work correctly in google3.

This change assumes that if Platform.script.scheme == 'data', the test is being run via pub from the root directory of the package. In that case, we can assume there is a 'test' directory and simply use 'test/$scriptName'as the path for the testee process.

TEST=N/A

Change-Id: I589605ebc7001adc9d8595ca8347c0af329b9c28
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184541
Reviewed-by: Gary Roumanis <grouma@google.com>
2021-02-12 07:12:54 +00:00

120 lines
3.6 KiB
Dart

// 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 file.
import 'dart:developer';
import 'package:test/test.dart';
import 'package:vm_service/vm_service.dart';
import 'common/service_test_common.dart';
import 'common/test_helper.dart';
String leafFunction() {
return "some constant";
}
void testFunction() {
debugger();
leafFunction();
debugger();
}
bool allRangesCompiled(coverage) {
for (int i = 0; i < coverage['ranges'].length; i++) {
if (!coverage['ranges'][i]['compiled']) {
return false;
}
}
return true;
}
var tests = <IsolateTest>[
hasStoppedAtBreakpoint,
(VmService service, IsolateRef isolateRef) async {
final isolateId = isolateRef.id!;
final isolate = await service.getIsolate(isolateId);
final stack = await service.getStack(isolateId);
// Make sure we are in the right place.
expect(stack.frames!.length, greaterThanOrEqualTo(1));
expect(stack.frames![0].function!.name, 'testFunction');
final Library root =
await service.getObject(isolateId, isolate.rootLib!.id!) as Library;
FuncRef funcRef =
root.functions!.singleWhere((f) => f.name == 'leafFunction');
Func func = await service.getObject(isolateId, funcRef.id!) as Func;
final expectedRange = {
'scriptIndex': 0,
'startPos': 397,
'endPos': 447,
'compiled': true,
'coverage': {
'hits': [],
'misses': [397]
}
};
final location = func.location!;
final report = await service.getSourceReport(
isolateId, [SourceReportKind.kCoverage],
scriptId: location.script!.id,
tokenPos: location.tokenPos,
endTokenPos: location.endTokenPos,
forceCompile: true);
expect(report.ranges!.length, 1);
expect(report.ranges![0].toJson(), expectedRange);
expect(report.scripts!.length, 1);
expect(
report.scripts![0].uri, endsWith('coverage_leaf_function_test.dart'));
},
resumeIsolate,
hasStoppedAtBreakpoint,
(VmService service, IsolateRef isolateRef) async {
final isolateId = isolateRef.id!;
final isolate = await service.getIsolate(isolateId);
final stack = await service.getStack(isolateId);
// Make sure we are in the right place.
expect(stack.frames!.length, greaterThanOrEqualTo(1));
expect(stack.frames![0].function!.name, 'testFunction');
final Library root =
await service.getObject(isolateId, isolate.rootLib!.id!) as Library;
FuncRef funcRef =
root.functions!.singleWhere((f) => f.name == 'leafFunction');
Func func = await service.getObject(isolateId, funcRef.id!) as Func;
var expectedRange = {
'scriptIndex': 0,
'startPos': 397,
'endPos': 447,
'compiled': true,
'coverage': {
'hits': [397],
'misses': []
}
};
final location = func.location!;
final report = await service.getSourceReport(
isolateId, [SourceReportKind.kCoverage],
scriptId: location.script!.id,
tokenPos: location.tokenPos,
endTokenPos: location.endTokenPos,
forceCompile: true);
expect(report.ranges!.length, 1);
expect(report.ranges![0].toJson(), expectedRange);
expect(report.scripts!.length, 1);
expect(
report.scripts![0].uri, endsWith('coverage_leaf_function_test.dart'));
},
];
main([args = const <String>[]]) => runIsolateTests(
args,
tests,
'coverage_leaf_function_test.dart',
testeeConcurrent: testFunction,
);