fa8ea6dfaa
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>
111 lines
3.0 KiB
Dart
111 lines
3.0 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 'package:test/test.dart';
|
|
import 'package:vm_service/vm_service.dart';
|
|
import 'common/test_helper.dart';
|
|
|
|
printSync() {
|
|
print('sync'); // Line 11
|
|
}
|
|
|
|
printAsync() async {
|
|
await null;
|
|
print('async'); // Line 16
|
|
}
|
|
|
|
printAsyncStar() async* {
|
|
await null;
|
|
print('async*'); // Line 21
|
|
}
|
|
|
|
printSyncStar() sync* {
|
|
print('sync*'); // Line 25
|
|
}
|
|
|
|
var testerReady = false;
|
|
testeeDo() {
|
|
// We block here rather than allowing the isolate to enter the
|
|
// paused-on-exit state before the tester gets a chance to set
|
|
// the breakpoints because we need the event loop to remain
|
|
// operational for the async bodies to run.
|
|
print('testee waiting');
|
|
while (!testerReady) {}
|
|
|
|
printSync();
|
|
final future = printAsync();
|
|
final stream = printAsyncStar();
|
|
final iterator = printSyncStar();
|
|
|
|
print('middle'); // Line 42
|
|
|
|
future.then((v) => print(v));
|
|
stream.toList();
|
|
iterator.toList();
|
|
}
|
|
|
|
Future testAsync(VmService service, IsolateRef isolateRef) async {
|
|
final isolateId = isolateRef.id!;
|
|
final isolate = await service.getIsolate(isolateId);
|
|
final Library lib =
|
|
(await service.getObject(isolateId, isolate.rootLib!.id!)) as Library;
|
|
final script = lib.scripts![0];
|
|
final scriptId = script.id!;
|
|
|
|
final bp1 = await service.addBreakpoint(isolateId, scriptId, 11);
|
|
expect(bp1, isNotNull);
|
|
expect(bp1 is Breakpoint, isTrue);
|
|
|
|
final bp2 = await service.addBreakpoint(isolateId, scriptId, 16);
|
|
expect(bp2, isNotNull);
|
|
expect(bp2 is Breakpoint, isTrue);
|
|
|
|
final bp3 = await service.addBreakpoint(isolateId, scriptId, 21);
|
|
expect(bp3, isNotNull);
|
|
expect(bp3 is Breakpoint, isTrue);
|
|
|
|
final bp4 = await service.addBreakpoint(isolateId, scriptId, 25);
|
|
expect(bp4, isNotNull);
|
|
expect(bp4 is Breakpoint, isTrue);
|
|
|
|
final bp5 = await service.addBreakpoint(isolateId, scriptId, 42);
|
|
expect(bp5, isNotNull);
|
|
expect(bp5 is Breakpoint, isTrue);
|
|
|
|
final hits = <Breakpoint>[];
|
|
await service.streamListen(EventStreams.kDebug);
|
|
|
|
// ignore: unawaited_futures
|
|
service
|
|
.evaluate(isolateId, lib.id!, 'testerReady = true')
|
|
.then((Response result) async {
|
|
Obj res = await service.getObject(isolateId, (result as InstanceRef).id!);
|
|
print(res);
|
|
expect((res as Instance).valueAsString, equals('true'));
|
|
});
|
|
|
|
final stream = service.onDebugEvent;
|
|
await for (Event event in stream) {
|
|
if (event.kind == EventKind.kPauseBreakpoint) {
|
|
assert(event.pauseBreakpoints!.isNotEmpty);
|
|
final bp = event.pauseBreakpoints!.first;
|
|
hits.add(bp);
|
|
await service.resume(isolateId);
|
|
|
|
if (hits.length == 5) break;
|
|
}
|
|
}
|
|
|
|
expect(hits, equals([bp1, bp5, bp4, bp2, bp3]));
|
|
}
|
|
|
|
final tests = <IsolateTest>[testAsync];
|
|
|
|
main([args = const <String>[]]) => runIsolateTests(
|
|
args,
|
|
tests,
|
|
'async_generator_breakpoint_test.dart',
|
|
testeeConcurrent: testeeDo,
|
|
);
|