Chromium Code Reviews| Index: runtime/vm/zone_test.cc |
| diff --git a/runtime/vm/zone_test.cc b/runtime/vm/zone_test.cc |
| index 4cb9231c74d539bd6486eff29c5adafbd536c833..a952d5f0dbd1bdc183e8cdde525087e37c558c6b 100644 |
| --- a/runtime/vm/zone_test.cc |
| +++ b/runtime/vm/zone_test.cc |
| @@ -169,4 +169,70 @@ TEST_CASE(PrintToString) { |
| EXPECT_STREQ("Hello World!", result); |
| } |
| +#ifndef RELEASE |
| +UNIT_TEST_CASE(PrintZoneMemoryInfoToJSON) { |
| +#if defined(DEBUG) |
| + FLAG_trace_zones = true; |
| +#endif |
| + Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL, |
| + NULL); |
| + Thread* thread = Thread::Current(); |
| + EXPECT(thread->zone() == NULL); |
| + { |
| + StackZone zone(thread); |
| + EXPECT(thread->zone() != NULL); |
| + |
| + intptr_t allocated_size = 0; |
| + const intptr_t kNumElements = 1000; |
| + |
| + zone.GetZone()->Alloc<uint32_t>(kNumElements); |
| + allocated_size += sizeof(uint32_t) * kNumElements; |
| + |
| + EXPECT_LE(allocated_size, zone.SizeInBytes()); |
| + { |
| + JSONStream stream; |
| + { |
| + JSONObject obj(&stream); |
| + // Get the JSON formated zone information. |
| + zone.GetZone()->PrintToJSONObject(&obj); |
| + } |
| + const char* json = stream.ToCString(); |
| + char address_buf[64]; |
| + char size_buf[64]; |
| + |
| + // Ensure that address and size matches actual values. |
| + snprintf(address_buf, sizeof(address_buf), "\"address\":\"0x%" Px "\"", |
| + reinterpret_cast<uword>(zone.GetZone())); |
| + 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
|
| + |
| + EXPECT_SUBSTRING(address_buf, json); |
| + EXPECT_SUBSTRING(size_buf, json); |
| + } |
| + |
| + // Expand the zone to ensure that JSON is updated accordingly. |
| + zone.GetZone()->Alloc<uint32_t>(kNumElements); |
| + allocated_size += sizeof(uint32_t) * kNumElements; |
| + EXPECT_LE(allocated_size, zone.SizeInBytes()); |
| + { |
| + JSONStream stream; |
| + { |
| + JSONObject obj(&stream); |
| + zone.GetZone()->PrintToJSONObject(&obj); |
| + } |
| + const char* json = stream.ToCString(); |
| + char address_buf[64]; |
| + char size_buf[64]; |
| + |
| + snprintf(address_buf, sizeof(address_buf), "\"address\":\"0x%" Px "\"", |
| + reinterpret_cast<uword>(zone.GetZone())); |
| + snprintf(size_buf, sizeof(size_buf), "\"size\":%ld", zone.SizeInBytes()); |
| + |
| + EXPECT_SUBSTRING(address_buf, json); |
| + EXPECT_SUBSTRING(size_buf, json); |
| + } |
| + } |
| + EXPECT(thread->zone() == NULL); |
| + Dart_ShutdownIsolate(); |
| +} |
| +#endif |
| } // namespace dart |