Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: runtime/vm/zone_test.cc

Issue 2974233002: VM: Re-format to use at most one newline between functions (Closed)
Patch Set: Rebase and merge Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/zone.cc ('k') | runtime/vm/zone_text_buffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "vm/zone.h"
5 #include "platform/assert.h" 6 #include "platform/assert.h"
6 #include "vm/dart.h" 7 #include "vm/dart.h"
7 #include "vm/isolate.h" 8 #include "vm/isolate.h"
8 #include "vm/unit_test.h" 9 #include "vm/unit_test.h"
9 #include "vm/zone.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 VM_UNIT_TEST_CASE(AllocateZone) { 13 VM_UNIT_TEST_CASE(AllocateZone) {
14 #if defined(DEBUG) 14 #if defined(DEBUG)
15 FLAG_trace_zones = true; 15 FLAG_trace_zones = true;
16 #endif 16 #endif
17 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, 17 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
18 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); 18 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
19 Thread* thread = Thread::Current(); 19 Thread* thread = Thread::Current();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 reinterpret_cast<uint8_t*>(zone->AllocUnsafe(kSegmentSize + kWordSize)); 64 reinterpret_cast<uint8_t*>(zone->AllocUnsafe(kSegmentSize + kWordSize));
65 EXPECT(buffer != NULL); 65 EXPECT(buffer != NULL);
66 buffer[(kSegmentSize + kWordSize) - 1] = 0; 66 buffer[(kSegmentSize + kWordSize) - 1] = 0;
67 allocated_size += (kSegmentSize + kWordSize); 67 allocated_size += (kSegmentSize + kWordSize);
68 EXPECT_LE(allocated_size, zone->SizeInBytes()); 68 EXPECT_LE(allocated_size, zone->SizeInBytes());
69 } 69 }
70 EXPECT(thread->zone() == NULL); 70 EXPECT(thread->zone() == NULL);
71 Dart_ShutdownIsolate(); 71 Dart_ShutdownIsolate();
72 } 72 }
73 73
74
75 VM_UNIT_TEST_CASE(AllocGeneric_Success) { 74 VM_UNIT_TEST_CASE(AllocGeneric_Success) {
76 #if defined(DEBUG) 75 #if defined(DEBUG)
77 FLAG_trace_zones = true; 76 FLAG_trace_zones = true;
78 #endif 77 #endif
79 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, 78 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
80 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); 79 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
81 Thread* thread = Thread::Current(); 80 Thread* thread = Thread::Current();
82 EXPECT(thread->zone() == NULL); 81 EXPECT(thread->zone() == NULL);
83 { 82 {
84 StackZone zone(thread); 83 StackZone zone(thread);
85 EXPECT(thread->zone() != NULL); 84 EXPECT(thread->zone() != NULL);
86 uintptr_t allocated_size = 0; 85 uintptr_t allocated_size = 0;
87 86
88 const intptr_t kNumElements = 1000; 87 const intptr_t kNumElements = 1000;
89 zone.GetZone()->Alloc<uint32_t>(kNumElements); 88 zone.GetZone()->Alloc<uint32_t>(kNumElements);
90 allocated_size += sizeof(uint32_t) * kNumElements; 89 allocated_size += sizeof(uint32_t) * kNumElements;
91 EXPECT_LE(allocated_size, zone.SizeInBytes()); 90 EXPECT_LE(allocated_size, zone.SizeInBytes());
92 } 91 }
93 EXPECT(thread->zone() == NULL); 92 EXPECT(thread->zone() == NULL);
94 Dart_ShutdownIsolate(); 93 Dart_ShutdownIsolate();
95 } 94 }
96 95
97
98 // This test is expected to crash. 96 // This test is expected to crash.
99 VM_UNIT_TEST_CASE(AllocGeneric_Overflow) { 97 VM_UNIT_TEST_CASE(AllocGeneric_Overflow) {
100 #if defined(DEBUG) 98 #if defined(DEBUG)
101 FLAG_trace_zones = true; 99 FLAG_trace_zones = true;
102 #endif 100 #endif
103 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, 101 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
104 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); 102 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
105 Thread* thread = Thread::Current(); 103 Thread* thread = Thread::Current();
106 EXPECT(thread->zone() == NULL); 104 EXPECT(thread->zone() == NULL);
107 { 105 {
108 StackZone zone(thread); 106 StackZone zone(thread);
109 EXPECT(thread->zone() != NULL); 107 EXPECT(thread->zone() != NULL);
110 108
111 const intptr_t kNumElements = (kIntptrMax / sizeof(uint32_t)) + 1; 109 const intptr_t kNumElements = (kIntptrMax / sizeof(uint32_t)) + 1;
112 zone.GetZone()->Alloc<uint32_t>(kNumElements); 110 zone.GetZone()->Alloc<uint32_t>(kNumElements);
113 } 111 }
114 Dart_ShutdownIsolate(); 112 Dart_ShutdownIsolate();
115 } 113 }
116 114
117
118 VM_UNIT_TEST_CASE(ZoneAllocated) { 115 VM_UNIT_TEST_CASE(ZoneAllocated) {
119 #if defined(DEBUG) 116 #if defined(DEBUG)
120 FLAG_trace_zones = true; 117 FLAG_trace_zones = true;
121 #endif 118 #endif
122 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, 119 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data,
123 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); 120 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
124 Thread* thread = Thread::Current(); 121 Thread* thread = Thread::Current();
125 EXPECT(thread->zone() == NULL); 122 EXPECT(thread->zone() == NULL);
126 static int marker; 123 static int marker;
127 124
(...skipping 27 matching lines...) Expand all
155 // Make sure we can write to the members of the zone objects. 152 // Make sure we can write to the members of the zone objects.
156 first->slot = 42; 153 first->slot = 42;
157 second->slot = 87; 154 second->slot = 87;
158 EXPECT_EQ(42, first->slot); 155 EXPECT_EQ(42, first->slot);
159 EXPECT_EQ(87, second->slot); 156 EXPECT_EQ(87, second->slot);
160 } 157 }
161 EXPECT(thread->zone() == NULL); 158 EXPECT(thread->zone() == NULL);
162 Dart_ShutdownIsolate(); 159 Dart_ShutdownIsolate();
163 } 160 }
164 161
165
166 TEST_CASE(PrintToString) { 162 TEST_CASE(PrintToString) {
167 StackZone zone(Thread::Current()); 163 StackZone zone(Thread::Current());
168 const char* result = zone.GetZone()->PrintToString("Hello %s!", "World"); 164 const char* result = zone.GetZone()->PrintToString("Hello %s!", "World");
169 EXPECT_STREQ("Hello World!", result); 165 EXPECT_STREQ("Hello World!", result);
170 } 166 }
171 167
172
173 VM_UNIT_TEST_CASE(NativeScopeZoneAllocation) { 168 VM_UNIT_TEST_CASE(NativeScopeZoneAllocation) {
174 ASSERT(ApiNativeScope::Current() == NULL); 169 ASSERT(ApiNativeScope::Current() == NULL);
175 ASSERT(Thread::Current() == NULL); 170 ASSERT(Thread::Current() == NULL);
176 EXPECT_EQ(0UL, ApiNativeScope::current_memory_usage()); 171 EXPECT_EQ(0UL, ApiNativeScope::current_memory_usage());
177 { 172 {
178 ApiNativeScope scope; 173 ApiNativeScope scope;
179 EXPECT_EQ(scope.zone()->CapacityInBytes(), 174 EXPECT_EQ(scope.zone()->CapacityInBytes(),
180 ApiNativeScope::current_memory_usage()); 175 ApiNativeScope::current_memory_usage());
181 (void)Dart_ScopeAllocate(2048); 176 (void)Dart_ScopeAllocate(2048);
182 EXPECT_EQ(scope.zone()->CapacityInBytes(), 177 EXPECT_EQ(scope.zone()->CapacityInBytes(),
183 ApiNativeScope::current_memory_usage()); 178 ApiNativeScope::current_memory_usage());
184 } 179 }
185 EXPECT_EQ(0UL, ApiNativeScope::current_memory_usage()); 180 EXPECT_EQ(0UL, ApiNativeScope::current_memory_usage());
186 } 181 }
187 182
188 } // namespace dart 183 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/zone.cc ('k') | runtime/vm/zone_text_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698