OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // VMOptions=--error_on_bad_type --error_on_bad_override | 4 // VMOptions=--error_on_bad_type --error_on_bad_override |
5 | 5 |
6 import 'package:observatory/service_io.dart'; | 6 import 'package:observatory/service_io.dart'; |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 import 'test_helper.dart'; | 8 import 'test_helper.dart'; |
9 import 'service_test_common.dart'; | 9 import 'service_test_common.dart'; |
10 import 'dart:developer'; | 10 import 'dart:developer'; |
(...skipping 27 matching lines...) Expand all Loading... |
38 bool allRangesCompiled(coverage) { | 38 bool allRangesCompiled(coverage) { |
39 for (int i = 0; i < coverage['ranges'].length; i++) { | 39 for (int i = 0; i < coverage['ranges'].length; i++) { |
40 if (!coverage['ranges'][i]['compiled']) { | 40 if (!coverage['ranges'][i]['compiled']) { |
41 return false; | 41 return false; |
42 } | 42 } |
43 } | 43 } |
44 return true; | 44 return true; |
45 } | 45 } |
46 | 46 |
47 var tests = [ | 47 var tests = [ |
48 hasStoppedAtBreakpoint, | |
49 (Isolate isolate) async { | |
50 var stack = await isolate.getStack(); | |
51 | 48 |
52 // Make sure we are in the right place. | 49 hasStoppedAtBreakpoint, |
53 expect(stack.type, equals('Stack')); | |
54 expect(stack['frames'].length, greaterThanOrEqualTo(2)); | |
55 expect(stack['frames'][0].function.name, equals('myFunction')); | |
56 expect(stack['frames'][0].function.dartOwner.name, equals('MyClass')); | |
57 | 50 |
58 var func = stack['frames'][0].function; | 51 (Isolate isolate) async { |
59 expect(func.name, equals('myFunction')); | 52 var stack = await isolate.getStack(); |
60 await func.load(); | |
61 | 53 |
62 var expectedRange = { | 54 // Make sure we are in the right place. |
63 'scriptIndex': 0, | 55 expect(stack.type, equals('Stack')); |
64 'startPos': 39, | 56 expect(stack['frames'].length, greaterThanOrEqualTo(2)); |
65 'endPos': 88, | 57 expect(stack['frames'][0].function.name, equals('myFunction')); |
66 'compiled': true, | 58 expect(stack['frames'][0].function.dartOwner.name, equals('MyClass')); |
67 'coverage': { | |
68 'hits': [54, 72, 82], | |
69 'misses': [60] | |
70 } | |
71 }; | |
72 | 59 |
73 // Full script | 60 var func = stack['frames'][0].function; |
74 var params = { | 61 expect(func.name, equals('myFunction')); |
75 'reports': ['Coverage'], | 62 await func.load(); |
76 'scriptId': func.location.script.id | |
77 }; | |
78 var coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); | |
79 expect(coverage['type'], equals('SourceReport')); | |
80 expect(coverage['ranges'].length, 6); | |
81 expect(coverage['ranges'][0], equals(expectedRange)); | |
82 expect(coverage['scripts'].length, 1); | |
83 expect( | |
84 coverage['scripts'][0]['uri'], endsWith('get_source_report_test.dart')); | |
85 expect(allRangesCompiled(coverage), isFalse); | |
86 | 63 |
87 // Force compilation. | 64 var expectedRange = { |
88 params = { | 65 'scriptIndex': 0, |
89 'reports': ['Coverage'], | 66 'startPos': 39, |
90 'scriptId': func.location.script.id, | 67 'endPos': 88, |
91 'forceCompile': true | 68 'compiled': true, |
92 }; | 69 'coverage': {'hits': [54, 72, 82], 'misses': [60]} |
| 70 }; |
| 71 |
| 72 // Full script |
| 73 var params = { 'reports' : ['Coverage'], |
| 74 'scriptId' : func.location.script.id }; |
| 75 var coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); |
| 76 expect(coverage['type'], equals('SourceReport')); |
| 77 expect(coverage['ranges'].length, 6); |
| 78 expect(coverage['ranges'][0], equals(expectedRange)); |
| 79 expect(coverage['scripts'].length, 1); |
| 80 expect(coverage['scripts'][0]['uri'], |
| 81 endsWith('get_source_report_test.dart')); |
| 82 expect(allRangesCompiled(coverage), isFalse); |
| 83 |
| 84 // Force compilation. |
| 85 params = { 'reports' : ['Coverage'], |
| 86 'scriptId' : func.location.script.id, |
| 87 'forceCompile' : true }; |
| 88 coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); |
| 89 expect(coverage['type'], equals('SourceReport')); |
| 90 expect(coverage['ranges'].length, 6); |
| 91 expect(allRangesCompiled(coverage), isTrue); |
| 92 |
| 93 // One function |
| 94 params = { 'reports' : ['Coverage'], |
| 95 'scriptId' : func.location.script.id, |
| 96 'tokenPos' : func.location.tokenPos, |
| 97 'endTokenPos' : func.location.endTokenPos }; |
| 98 coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); |
| 99 expect(coverage['type'], equals('SourceReport')); |
| 100 expect(coverage['ranges'].length, 1); |
| 101 expect(coverage['ranges'][0], equals(expectedRange)); |
| 102 expect(coverage['scripts'].length, 1); |
| 103 expect(coverage['scripts'][0]['uri'], |
| 104 endsWith('get_source_report_test.dart')); |
| 105 |
| 106 // Full isolate |
| 107 params = { 'reports' : ['Coverage'] }; |
| 108 coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); |
| 109 expect(coverage['type'], equals('SourceReport')); |
| 110 expect(coverage['ranges'].length, greaterThan(1)); |
| 111 expect(coverage['scripts'].length, greaterThan(1)); |
| 112 |
| 113 // Multiple reports (make sure enum list parameter parsing works). |
| 114 params = { 'reports' : ['_CallSites', 'Coverage', 'PossibleBreakpoints'], |
| 115 'scriptId' : func.location.script.id, |
| 116 'tokenPos' : func.location.tokenPos, |
| 117 'endTokenPos' : func.location.endTokenPos }; |
| 118 coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); |
| 119 expect(coverage['type'], equals('SourceReport')); |
| 120 expect(coverage['ranges'].length, 1); |
| 121 var range = coverage['ranges'][0]; |
| 122 expect(range.containsKey('callSites'), isTrue); |
| 123 expect(range.containsKey('coverage'), isTrue); |
| 124 expect(range.containsKey('possibleBreakpoints'), isTrue); |
| 125 |
| 126 // missing scriptId with tokenPos. |
| 127 bool caughtException = false; |
| 128 try { |
| 129 params = { 'reports' : ['Coverage'], |
| 130 'tokenPos' : func.location.tokenPos }; |
93 coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); | 131 coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); |
94 expect(coverage['type'], equals('SourceReport')); | 132 } on ServerRpcException catch(e) { |
95 expect(coverage['ranges'].length, 6); | 133 caughtException = true; |
96 expect(allRangesCompiled(coverage), isTrue); | 134 expect(e.code, equals(ServerRpcException.kInvalidParams)); |
| 135 expect(e.message, |
| 136 "getSourceReport: the 'tokenPos' parameter requires the " |
| 137 "\'scriptId\' parameter"); |
| 138 } |
| 139 expect(caughtException, isTrue); |
97 | 140 |
98 // One function | 141 // missing scriptId with endTokenPos. |
99 params = { | 142 caughtException = false; |
100 'reports': ['Coverage'], | 143 try { |
101 'scriptId': func.location.script.id, | 144 params = { 'reports' : ['Coverage'], |
102 'tokenPos': func.location.tokenPos, | 145 'endTokenPos' : func.location.endTokenPos }; |
103 'endTokenPos': func.location.endTokenPos | |
104 }; | |
105 coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); | 146 coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); |
106 expect(coverage['type'], equals('SourceReport')); | 147 } on ServerRpcException catch(e) { |
107 expect(coverage['ranges'].length, 1); | 148 caughtException = true; |
108 expect(coverage['ranges'][0], equals(expectedRange)); | 149 expect(e.code, equals(ServerRpcException.kInvalidParams)); |
109 expect(coverage['scripts'].length, 1); | 150 expect(e.message, |
110 expect( | 151 "getSourceReport: the 'endTokenPos' parameter requires the " |
111 coverage['scripts'][0]['uri'], endsWith('get_source_report_test.dart')); | 152 "\'scriptId\' parameter"); |
| 153 } |
| 154 expect(caughtException, isTrue); |
| 155 }, |
112 | 156 |
113 // Full isolate | |
114 params = { | |
115 'reports': ['Coverage'] | |
116 }; | |
117 coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); | |
118 expect(coverage['type'], equals('SourceReport')); | |
119 expect(coverage['ranges'].length, greaterThan(1)); | |
120 expect(coverage['scripts'].length, greaterThan(1)); | |
121 | |
122 // Multiple reports (make sure enum list parameter parsing works). | |
123 params = { | |
124 'reports': ['_CallSites', 'Coverage', 'PossibleBreakpoints'], | |
125 'scriptId': func.location.script.id, | |
126 'tokenPos': func.location.tokenPos, | |
127 'endTokenPos': func.location.endTokenPos | |
128 }; | |
129 coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); | |
130 expect(coverage['type'], equals('SourceReport')); | |
131 expect(coverage['ranges'].length, 1); | |
132 var range = coverage['ranges'][0]; | |
133 expect(range.containsKey('callSites'), isTrue); | |
134 expect(range.containsKey('coverage'), isTrue); | |
135 expect(range.containsKey('possibleBreakpoints'), isTrue); | |
136 | |
137 // missing scriptId with tokenPos. | |
138 bool caughtException = false; | |
139 try { | |
140 params = { | |
141 'reports': ['Coverage'], | |
142 'tokenPos': func.location.tokenPos | |
143 }; | |
144 coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); | |
145 } on ServerRpcException catch (e) { | |
146 caughtException = true; | |
147 expect(e.code, equals(ServerRpcException.kInvalidParams)); | |
148 expect( | |
149 e.message, | |
150 "getSourceReport: the 'tokenPos' parameter requires the " | |
151 "\'scriptId\' parameter"); | |
152 } | |
153 expect(caughtException, isTrue); | |
154 | |
155 // missing scriptId with endTokenPos. | |
156 caughtException = false; | |
157 try { | |
158 params = { | |
159 'reports': ['Coverage'], | |
160 'endTokenPos': func.location.endTokenPos | |
161 }; | |
162 coverage = await isolate.invokeRpcNoUpgrade('getSourceReport', params); | |
163 } on ServerRpcException catch (e) { | |
164 caughtException = true; | |
165 expect(e.code, equals(ServerRpcException.kInvalidParams)); | |
166 expect( | |
167 e.message, | |
168 "getSourceReport: the 'endTokenPos' parameter requires the " | |
169 "\'scriptId\' parameter"); | |
170 } | |
171 expect(caughtException, isTrue); | |
172 }, | |
173 ]; | 157 ]; |
174 | 158 |
175 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); | 159 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); |
OLD | NEW |