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 |
11 namespace dart { | 11 namespace dart { |
12 | 12 |
13 DECLARE_DEBUG_FLAG(bool, trace_zone_sizes); | 13 DECLARE_DEBUG_FLAG(bool, trace_zones); |
14 | 14 |
15 UNIT_TEST_CASE(AllocateZone) { | 15 UNIT_TEST_CASE(AllocateZone) { |
16 #if defined(DEBUG) | 16 #if defined(DEBUG) |
17 FLAG_trace_zone_sizes = true; | 17 FLAG_trace_zones = true; |
18 #endif | 18 #endif |
19 Isolate* isolate = Isolate::Init(NULL); | 19 Isolate* isolate = Isolate::Init(NULL); |
20 EXPECT(Isolate::Current() == isolate); | 20 EXPECT(Isolate::Current() == isolate); |
21 EXPECT(isolate->current_zone() == NULL); | 21 EXPECT(isolate->current_zone() == NULL); |
22 { | 22 { |
23 StackZone stack_zone(isolate); | 23 StackZone stack_zone(isolate); |
24 EXPECT(isolate->current_zone() != NULL); | 24 EXPECT(isolate->current_zone() != NULL); |
25 Zone* zone = stack_zone.GetZone(); | 25 Zone* zone = stack_zone.GetZone(); |
26 intptr_t allocated_size = 0; | 26 intptr_t allocated_size = 0; |
27 | 27 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 EXPECT_LE(allocated_size, zone->SizeInBytes()); | 69 EXPECT_LE(allocated_size, zone->SizeInBytes()); |
70 } | 70 } |
71 EXPECT(isolate->current_zone() == NULL); | 71 EXPECT(isolate->current_zone() == NULL); |
72 isolate->Shutdown(); | 72 isolate->Shutdown(); |
73 delete isolate; | 73 delete isolate; |
74 } | 74 } |
75 | 75 |
76 | 76 |
77 UNIT_TEST_CASE(AllocGeneric_Success) { | 77 UNIT_TEST_CASE(AllocGeneric_Success) { |
78 #if defined(DEBUG) | 78 #if defined(DEBUG) |
79 FLAG_trace_zone_sizes = true; | 79 FLAG_trace_zones = true; |
80 #endif | 80 #endif |
81 Isolate* isolate = Isolate::Init(NULL); | 81 Isolate* isolate = Isolate::Init(NULL); |
82 EXPECT(Isolate::Current() == isolate); | 82 EXPECT(Isolate::Current() == isolate); |
83 EXPECT(isolate->current_zone() == NULL); | 83 EXPECT(isolate->current_zone() == NULL); |
84 { | 84 { |
85 StackZone zone(isolate); | 85 StackZone zone(isolate); |
86 EXPECT(isolate->current_zone() != NULL); | 86 EXPECT(isolate->current_zone() != NULL); |
87 intptr_t allocated_size = 0; | 87 intptr_t allocated_size = 0; |
88 | 88 |
89 const intptr_t kNumElements = 1000; | 89 const intptr_t kNumElements = 1000; |
90 zone.GetZone()->Alloc<uint32_t>(kNumElements); | 90 zone.GetZone()->Alloc<uint32_t>(kNumElements); |
91 allocated_size += sizeof(uint32_t) * kNumElements; | 91 allocated_size += sizeof(uint32_t) * kNumElements; |
92 EXPECT_LE(allocated_size, zone.SizeInBytes()); | 92 EXPECT_LE(allocated_size, zone.SizeInBytes()); |
93 } | 93 } |
94 EXPECT(isolate->current_zone() == NULL); | 94 EXPECT(isolate->current_zone() == NULL); |
95 isolate->Shutdown(); | 95 isolate->Shutdown(); |
96 delete isolate; | 96 delete isolate; |
97 } | 97 } |
98 | 98 |
99 | 99 |
100 // This test is expected to crash. | 100 // This test is expected to crash. |
101 UNIT_TEST_CASE(AllocGeneric_Overflow) { | 101 UNIT_TEST_CASE(AllocGeneric_Overflow) { |
102 #if defined(DEBUG) | 102 #if defined(DEBUG) |
103 FLAG_trace_zone_sizes = true; | 103 FLAG_trace_zones = true; |
104 #endif | 104 #endif |
105 Isolate* isolate = Isolate::Init(NULL); | 105 Isolate* isolate = Isolate::Init(NULL); |
106 EXPECT(Isolate::Current() == isolate); | 106 EXPECT(Isolate::Current() == isolate); |
107 EXPECT(isolate->current_zone() == NULL); | 107 EXPECT(isolate->current_zone() == NULL); |
108 { | 108 { |
109 StackZone zone(isolate); | 109 StackZone zone(isolate); |
110 EXPECT(isolate->current_zone() != NULL); | 110 EXPECT(isolate->current_zone() != NULL); |
111 | 111 |
112 const intptr_t kNumElements = (kIntptrMax / sizeof(uint32_t)) + 1; | 112 const intptr_t kNumElements = (kIntptrMax / sizeof(uint32_t)) + 1; |
113 zone.GetZone()->Alloc<uint32_t>(kNumElements); | 113 zone.GetZone()->Alloc<uint32_t>(kNumElements); |
114 } | 114 } |
115 isolate->Shutdown(); | 115 isolate->Shutdown(); |
116 delete isolate; | 116 delete isolate; |
117 } | 117 } |
118 | 118 |
119 | 119 |
120 UNIT_TEST_CASE(ZoneAllocated) { | 120 UNIT_TEST_CASE(ZoneAllocated) { |
121 #if defined(DEBUG) | 121 #if defined(DEBUG) |
122 FLAG_trace_zone_sizes = true; | 122 FLAG_trace_zones = true; |
123 #endif | 123 #endif |
124 Isolate* isolate = Isolate::Init(NULL); | 124 Isolate* isolate = Isolate::Init(NULL); |
125 EXPECT(Isolate::Current() == isolate); | 125 EXPECT(Isolate::Current() == isolate); |
126 EXPECT(isolate->current_zone() == NULL); | 126 EXPECT(isolate->current_zone() == NULL); |
127 static int marker; | 127 static int marker; |
128 | 128 |
129 class SimpleZoneObject : public ZoneAllocated { | 129 class SimpleZoneObject : public ZoneAllocated { |
130 public: | 130 public: |
131 SimpleZoneObject() : slot(marker++) { } | 131 SimpleZoneObject() : slot(marker++) { } |
132 virtual int GetSlot() { return slot; } | 132 virtual int GetSlot() { return slot; } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 164 } |
165 | 165 |
166 | 166 |
167 TEST_CASE(PrintToString) { | 167 TEST_CASE(PrintToString) { |
168 StackZone zone(Isolate::Current()); | 168 StackZone zone(Isolate::Current()); |
169 const char* result = zone.GetZone()->PrintToString("Hello %s!", "World"); | 169 const char* result = zone.GetZone()->PrintToString("Hello %s!", "World"); |
170 EXPECT_STREQ("Hello World!", result); | 170 EXPECT_STREQ("Hello World!", result); |
171 } | 171 } |
172 | 172 |
173 } // namespace dart | 173 } // namespace dart |
OLD | NEW |