| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // VMOptions=--error_on_bad_type --error_on_bad_override |
| 5 |
| 6 import 'package:observatory/service_io.dart'; |
| 7 import 'package:unittest/unittest.dart'; |
| 8 import 'test_helper.dart'; |
| 9 |
| 10 class Pair { |
| 11 var x, y; |
| 12 } |
| 13 |
| 14 var p1; |
| 15 var p2; |
| 16 |
| 17 buildGraph() { |
| 18 p1 = new Pair(); |
| 19 p2 = new Pair(); |
| 20 |
| 21 // Adds to both reachable and retained size. |
| 22 p1.x = new List(); |
| 23 p2.x = new List(); |
| 24 |
| 25 // Adds to reachable size only. |
| 26 p1.y = p2.y = new List(); |
| 27 } |
| 28 |
| 29 getReachableSize(ServiceObject obj) { |
| 30 return obj.isolate.getReachableSize(obj).then((Instance obj) { |
| 31 return int.parse(obj.valueAsString); |
| 32 }); |
| 33 } |
| 34 |
| 35 getRetainedSize(ServiceObject obj) { |
| 36 return obj.isolate.getRetainedSize(obj).then((Instance obj) { |
| 37 return int.parse(obj.valueAsString); |
| 38 }); |
| 39 } |
| 40 |
| 41 var tests = [ |
| 42 (Isolate isolate) async { |
| 43 Instance p1 = await rootLibraryFieldValue(isolate, "p1"); |
| 44 Instance p2 = await rootLibraryFieldValue(isolate, "p2"); |
| 45 |
| 46 // In general, shallow <= retained <= reachable. In this program, |
| 47 // 0 < shallow < retained < reachable. |
| 48 |
| 49 int p1_shallow = p1.size; |
| 50 int p1_retained = await getRetainedSize(p1); |
| 51 int p1_reachable = await getReachableSize(p1); |
| 52 |
| 53 expect(0, lessThan(p1_shallow)); |
| 54 expect(p1_shallow, lessThan(p1_retained)); |
| 55 expect(p1_retained, lessThan(p1_reachable)); |
| 56 |
| 57 int p2_shallow = p2.size; |
| 58 int p2_retained = await getRetainedSize(p2); |
| 59 int p2_reachable = await getReachableSize(p2); |
| 60 |
| 61 expect(0, lessThan(p2_shallow)); |
| 62 expect(p2_shallow, lessThan(p2_retained)); |
| 63 expect(p2_retained, lessThan(p2_reachable)); |
| 64 |
| 65 expect(p1_shallow, equals(p2_shallow)); |
| 66 expect(p1_retained, equals(p2_retained)); |
| 67 expect(p1_reachable, equals(p2_reachable)); |
| 68 }, |
| 69 ]; |
| 70 |
| 71 main(args) => runIsolateTests(args, tests, testeeBefore: buildGraph); |
| OLD | NEW |