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

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

Issue 792163003: Deletion barrier preparation: validate overwritten references. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/virtual_memory.h ('k') | no next file » | 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 "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/unit_test.h" 6 #include "vm/unit_test.h"
7 #include "vm/virtual_memory.h" 7 #include "vm/virtual_memory.h"
8 8
9 namespace dart { 9 namespace dart {
10 10
11 bool IsZero(char* begin, char* end) {
12 for (char* current = begin; current < end; ++current) {
13 if (*current != 0) {
14 return false;
15 }
16 }
17 return true;
18 }
19
20
11 UNIT_TEST_CASE(AllocateVirtualMemory) { 21 UNIT_TEST_CASE(AllocateVirtualMemory) {
12 const intptr_t kVirtualMemoryBlockSize = 64 * KB; 22 const intptr_t kVirtualMemoryBlockSize = 64 * KB;
13 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize); 23 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize);
14 EXPECT(vm != NULL); 24 EXPECT(vm != NULL);
15 EXPECT(vm->address() != NULL); 25 EXPECT(vm->address() != NULL);
16 EXPECT_EQ(kVirtualMemoryBlockSize, vm->size()); 26 EXPECT_EQ(kVirtualMemoryBlockSize, vm->size());
17 EXPECT_EQ(vm->start(), reinterpret_cast<uword>(vm->address())); 27 EXPECT_EQ(vm->start(), reinterpret_cast<uword>(vm->address()));
18 EXPECT_EQ(vm->start() + kVirtualMemoryBlockSize, vm->end()); 28 EXPECT_EQ(vm->start() + kVirtualMemoryBlockSize, vm->end());
19 EXPECT(vm->Contains(vm->start())); 29 EXPECT(vm->Contains(vm->start()));
20 EXPECT(vm->Contains(vm->start() + 1)); 30 EXPECT(vm->Contains(vm->start() + 1));
21 EXPECT(vm->Contains(vm->start() + kVirtualMemoryBlockSize - 1)); 31 EXPECT(vm->Contains(vm->start() + kVirtualMemoryBlockSize - 1));
22 EXPECT(vm->Contains(vm->start() + (kVirtualMemoryBlockSize / 2))); 32 EXPECT(vm->Contains(vm->start() + (kVirtualMemoryBlockSize / 2)));
23 EXPECT(!vm->Contains(vm->start() - 1)); 33 EXPECT(!vm->Contains(vm->start() - 1));
24 EXPECT(!vm->Contains(vm->end())); 34 EXPECT(!vm->Contains(vm->end()));
25 EXPECT(!vm->Contains(vm->end() + 1)); 35 EXPECT(!vm->Contains(vm->end() + 1));
26 EXPECT(!vm->Contains(0)); 36 EXPECT(!vm->Contains(0));
27 EXPECT(!vm->Contains(static_cast<uword>(-1))); 37 EXPECT(!vm->Contains(static_cast<uword>(-1)));
28 38
29 vm->Commit(false); 39 vm->Commit(false);
40
30 char* buf = reinterpret_cast<char*>(vm->address()); 41 char* buf = reinterpret_cast<char*>(vm->address());
42 EXPECT(IsZero(buf, buf + vm->size()));
31 buf[0] = 'a'; 43 buf[0] = 'a';
32 buf[1] = 'c'; 44 buf[1] = 'c';
33 buf[2] = '/'; 45 buf[2] = '/';
34 buf[3] = 'd'; 46 buf[3] = 'd';
35 buf[4] = 'c'; 47 buf[4] = 'c';
36 buf[5] = 0; 48 buf[5] = 0;
37 EXPECT_STREQ("ac/dc", buf); 49 EXPECT_STREQ("ac/dc", buf);
38 50
39 delete vm; 51 delete vm;
40 } 52 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 91
80 UNIT_TEST_CASE(VirtualMemoryCommitPartial) { 92 UNIT_TEST_CASE(VirtualMemoryCommitPartial) {
81 const intptr_t kVirtualMemoryBlockSize = 3 * MB; 93 const intptr_t kVirtualMemoryBlockSize = 3 * MB;
82 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize); 94 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize);
83 EXPECT(vm != NULL); 95 EXPECT(vm != NULL);
84 // Commit only the middle MB and write to it. 96 // Commit only the middle MB and write to it.
85 const uword commit_start = vm->start() + (1 * MB); 97 const uword commit_start = vm->start() + (1 * MB);
86 const intptr_t kCommitSize = 1 * MB; 98 const intptr_t kCommitSize = 1 * MB;
87 vm->Commit(commit_start, kCommitSize, false); 99 vm->Commit(commit_start, kCommitSize, false);
88 char* buf = reinterpret_cast<char*>(commit_start); 100 char* buf = reinterpret_cast<char*>(commit_start);
101 EXPECT(IsZero(buf, buf + kCommitSize));
89 buf[0] = 'f'; 102 buf[0] = 'f';
90 buf[1] = 'o'; 103 buf[1] = 'o';
91 buf[2] = 'o'; 104 buf[2] = 'o';
92 buf[3] = 0; 105 buf[3] = 0;
93 EXPECT_STREQ("foo", buf); 106 EXPECT_STREQ("foo", buf);
94 delete vm; 107 delete vm;
95 } 108 }
96 109
97 } // namespace dart 110 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/virtual_memory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698