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

Side by Side Diff: runtime/vm/virtual_memory_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/virtual_memory_macos.cc ('k') | runtime/vm/virtual_memory_win.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/virtual_memory.h"
5 #include "platform/assert.h" 6 #include "platform/assert.h"
6 #include "vm/unit_test.h" 7 #include "vm/unit_test.h"
7 #include "vm/virtual_memory.h"
8 8
9 namespace dart { 9 namespace dart {
10 10
11 bool IsZero(char* begin, char* end) { 11 bool IsZero(char* begin, char* end) {
12 for (char* current = begin; current < end; ++current) { 12 for (char* current = begin; current < end; ++current) {
13 if (*current != 0) { 13 if (*current != 0) {
14 return false; 14 return false;
15 } 15 }
16 } 16 }
17 return true; 17 return true;
18 } 18 }
19 19
20
21 VM_UNIT_TEST_CASE(AllocateVirtualMemory) { 20 VM_UNIT_TEST_CASE(AllocateVirtualMemory) {
22 const intptr_t kVirtualMemoryBlockSize = 64 * KB; 21 const intptr_t kVirtualMemoryBlockSize = 64 * KB;
23 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize); 22 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize);
24 EXPECT(vm != NULL); 23 EXPECT(vm != NULL);
25 EXPECT(vm->address() != NULL); 24 EXPECT(vm->address() != NULL);
26 EXPECT_EQ(kVirtualMemoryBlockSize, vm->size()); 25 EXPECT_EQ(kVirtualMemoryBlockSize, vm->size());
27 EXPECT_EQ(vm->start(), reinterpret_cast<uword>(vm->address())); 26 EXPECT_EQ(vm->start(), reinterpret_cast<uword>(vm->address()));
28 EXPECT_EQ(vm->start() + kVirtualMemoryBlockSize, vm->end()); 27 EXPECT_EQ(vm->start() + kVirtualMemoryBlockSize, vm->end());
29 EXPECT(vm->Contains(vm->start())); 28 EXPECT(vm->Contains(vm->start()));
30 EXPECT(vm->Contains(vm->start() + 1)); 29 EXPECT(vm->Contains(vm->start() + 1));
(...skipping 13 matching lines...) Expand all
44 buf[1] = 'c'; 43 buf[1] = 'c';
45 buf[2] = '/'; 44 buf[2] = '/';
46 buf[3] = 'd'; 45 buf[3] = 'd';
47 buf[4] = 'c'; 46 buf[4] = 'c';
48 buf[5] = 0; 47 buf[5] = 0;
49 EXPECT_STREQ("ac/dc", buf); 48 EXPECT_STREQ("ac/dc", buf);
50 49
51 delete vm; 50 delete vm;
52 } 51 }
53 52
54
55 VM_UNIT_TEST_CASE(FreeVirtualMemory) { 53 VM_UNIT_TEST_CASE(FreeVirtualMemory) {
56 // Reservations should always be handed back to OS upon destruction. 54 // Reservations should always be handed back to OS upon destruction.
57 const intptr_t kVirtualMemoryBlockSize = 10 * MB; 55 const intptr_t kVirtualMemoryBlockSize = 10 * MB;
58 const intptr_t kIterations = 900; // Enough to exhaust 32-bit address space. 56 const intptr_t kIterations = 900; // Enough to exhaust 32-bit address space.
59 for (intptr_t i = 0; i < kIterations; ++i) { 57 for (intptr_t i = 0; i < kIterations; ++i) {
60 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize); 58 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize);
61 vm->Commit(false, NULL); 59 vm->Commit(false, NULL);
62 delete vm; 60 delete vm;
63 } 61 }
64 // Check that truncation does not introduce leaks. 62 // Check that truncation does not introduce leaks.
(...skipping 16 matching lines...) Expand all
81 delete vm; 79 delete vm;
82 } 80 }
83 for (intptr_t i = 0; i < kIterations; ++i) { 81 for (intptr_t i = 0; i < kIterations; ++i) {
84 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize); 82 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize);
85 vm->Commit(false, NULL); 83 vm->Commit(false, NULL);
86 vm->Truncate(0, false); 84 vm->Truncate(0, false);
87 delete vm; 85 delete vm;
88 } 86 }
89 } 87 }
90 88
91
92 VM_UNIT_TEST_CASE(VirtualMemoryCommitPartial) { 89 VM_UNIT_TEST_CASE(VirtualMemoryCommitPartial) {
93 const intptr_t kVirtualMemoryBlockSize = 3 * MB; 90 const intptr_t kVirtualMemoryBlockSize = 3 * MB;
94 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize); 91 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize);
95 EXPECT(vm != NULL); 92 EXPECT(vm != NULL);
96 // Commit only the middle MB and write to it. 93 // Commit only the middle MB and write to it.
97 const uword commit_start = vm->start() + (1 * MB); 94 const uword commit_start = vm->start() + (1 * MB);
98 const intptr_t kCommitSize = 1 * MB; 95 const intptr_t kCommitSize = 1 * MB;
99 vm->Commit(commit_start, kCommitSize, false, NULL); 96 vm->Commit(commit_start, kCommitSize, false, NULL);
100 char* buf = reinterpret_cast<char*>(commit_start); 97 char* buf = reinterpret_cast<char*>(commit_start);
101 EXPECT(IsZero(buf, buf + kCommitSize)); 98 EXPECT(IsZero(buf, buf + kCommitSize));
102 buf[0] = 'f'; 99 buf[0] = 'f';
103 buf[1] = 'o'; 100 buf[1] = 'o';
104 buf[2] = 'o'; 101 buf[2] = 'o';
105 buf[3] = 0; 102 buf[3] = 0;
106 EXPECT_STREQ("foo", buf); 103 EXPECT_STREQ("foo", buf);
107 delete vm; 104 delete vm;
108 } 105 }
109 106
110 } // namespace dart 107 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/virtual_memory_macos.cc ('k') | runtime/vm/virtual_memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698