OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 | 4 |
5 #include "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/dart.h" | 6 #include "vm/dart.h" |
7 #include "vm/isolate.h" | 7 #include "vm/isolate.h" |
8 #include "vm/unit_test.h" | 8 #include "vm/unit_test.h" |
9 #include "vm/zone.h" | 9 #include "vm/zone.h" |
10 | 10 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 Dart_ShutdownIsolate(); | 162 Dart_ShutdownIsolate(); |
163 } | 163 } |
164 | 164 |
165 | 165 |
166 TEST_CASE(PrintToString) { | 166 TEST_CASE(PrintToString) { |
167 StackZone zone(Thread::Current()); | 167 StackZone zone(Thread::Current()); |
168 const char* result = zone.GetZone()->PrintToString("Hello %s!", "World"); | 168 const char* result = zone.GetZone()->PrintToString("Hello %s!", "World"); |
169 EXPECT_STREQ("Hello World!", result); | 169 EXPECT_STREQ("Hello World!", result); |
170 } | 170 } |
171 | 171 |
172 #ifndef RELEASE | |
173 UNIT_TEST_CASE(PrintZoneMemoryInfoToJSON) { | |
174 #if defined(DEBUG) | |
175 FLAG_trace_zones = true; | |
176 #endif | |
177 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL, | |
178 NULL); | |
179 Thread* thread = Thread::Current(); | |
180 EXPECT(thread->zone() == NULL); | |
181 { | |
182 StackZone zone(thread); | |
183 EXPECT(thread->zone() != NULL); | |
184 | |
185 intptr_t allocated_size = 0; | |
186 const intptr_t kNumElements = 1000; | |
187 | |
188 zone.GetZone()->Alloc<uint32_t>(kNumElements); | |
189 allocated_size += sizeof(uint32_t) * kNumElements; | |
190 | |
191 EXPECT_LE(allocated_size, zone.SizeInBytes()); | |
192 { | |
193 JSONStream stream; | |
194 { | |
195 JSONObject obj(&stream); | |
196 // Get the JSON formated zone information. | |
197 zone.GetZone()->PrintToJSONObject(&obj); | |
198 } | |
199 const char* json = stream.ToCString(); | |
200 char address_buf[64]; | |
201 char size_buf[64]; | |
202 | |
203 // Ensure that address and size matches actual values. | |
204 snprintf(address_buf, sizeof(address_buf), "\"address\":\"0x%" Px "\"", | |
205 reinterpret_cast<uword>(zone.GetZone())); | |
206 snprintf(size_buf, sizeof(size_buf), "\"size\":%ld", zone.SizeInBytes()); | |
siva
2016/12/07 22:12:53
Ditto comment about using OS::SNPrint instead of s
| |
207 | |
208 EXPECT_SUBSTRING(address_buf, json); | |
209 EXPECT_SUBSTRING(size_buf, json); | |
210 } | |
211 | |
212 // Expand the zone to ensure that JSON is updated accordingly. | |
213 zone.GetZone()->Alloc<uint32_t>(kNumElements); | |
214 allocated_size += sizeof(uint32_t) * kNumElements; | |
215 EXPECT_LE(allocated_size, zone.SizeInBytes()); | |
216 { | |
217 JSONStream stream; | |
218 { | |
219 JSONObject obj(&stream); | |
220 zone.GetZone()->PrintToJSONObject(&obj); | |
221 } | |
222 const char* json = stream.ToCString(); | |
223 char address_buf[64]; | |
224 char size_buf[64]; | |
225 | |
226 snprintf(address_buf, sizeof(address_buf), "\"address\":\"0x%" Px "\"", | |
227 reinterpret_cast<uword>(zone.GetZone())); | |
228 snprintf(size_buf, sizeof(size_buf), "\"size\":%ld", zone.SizeInBytes()); | |
229 | |
230 EXPECT_SUBSTRING(address_buf, json); | |
231 EXPECT_SUBSTRING(size_buf, json); | |
232 } | |
233 } | |
234 EXPECT(thread->zone() == NULL); | |
235 Dart_ShutdownIsolate(); | |
236 } | |
237 #endif | |
172 } // namespace dart | 238 } // namespace dart |
OLD | NEW |