Files
sdk/runtime/observatory/tests/service/inbound_references_test.dart
T
Daco Harkes 043ea3b4f4 [vm/service] Fix tests in obfuscation
Added entry-point pragmas to prevent obfuscation of global vars.

Removed expectation checking for standard library `Expando` class name.

Closes: https://github.com/dart-lang/sdk/issues/45422

TEST=Fixes various service_2 tests in obfuscation mode.

Change-Id: I91bb856c7f1ff44afe1cceec8e94e3b97ab56e44
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-obfuscate-linux-release-x64-try
Fixed: 45422
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192681
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2021-03-23 13:28:36 +00:00

60 lines
1.8 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.
library inbound_references_test;
import 'package:observatory/service_io.dart';
import 'package:test/test.dart';
import 'test_helper.dart';
@pragma("vm:entry-point") // Prevent obfuscation
class Node {
// Make sure this field is not removed by the tree shaker.
@pragma("vm:entry-point") // Prevent obfuscation
var edge;
}
class Edge {}
@pragma("vm:entry-point") // Prevent obfuscation
var n, e, array;
void script() {
n = new Node();
e = new Edge();
n.edge = e;
array = new List<dynamic>.filled(2, null);
array[0] = n;
array[1] = e;
}
var tests = <IsolateTest>[
(Isolate isolate) async {
Library lib = await isolate.rootLibrary.load() as Library;
Field field = lib.variables.where((v) => v.name == 'e').single;
await field.load();
Instance e = field.staticValue as Instance;
ServiceMap response =
await isolate.getInboundReferences(e, 100) as ServiceMap;
List references = response['references'];
hasReferenceSuchThat(predicate) {
expect(references.any(predicate), isTrue);
}
// Assert e is referenced by at least n, array, and the top-level
// field e.
hasReferenceSuchThat((r) =>
r['parentField'] != null &&
r['parentField'].name == 'edge' &&
r['source'].isInstance &&
r['source'].clazz.name == 'Node');
hasReferenceSuchThat(
(r) => r['parentListIndex'] == 1 && r['source'].isList);
hasReferenceSuchThat(
(r) => r['source'] is Field && r['source'].name == 'e');
}
];
main(args) => runIsolateTests(args, tests, testeeBefore: script);