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 |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #include "vm/heap/pages.h" |
6 | #include "platform/assert.h" |
7 | #include "vm/unit_test.h" |
8 | |
9 | namespace dart { |
10 | |
11 | TEST_CASE(Pages) { |
12 | PageSpace* space = new PageSpace(NULL, 4 * MBInWords); |
13 | EXPECT(!space->Contains(reinterpret_cast<uword>(&space))); |
14 | uword block = space->TryAllocate(8 * kWordSize); |
15 | EXPECT(block != 0); |
16 | uword total = 0; |
17 | while (total < 2 * MB) { |
18 | const intptr_t kBlockSize = 16 * kWordSize; |
19 | uword new_block = space->TryAllocate(kBlockSize); |
20 | EXPECT(block != 0); |
21 | EXPECT(block != new_block); |
22 | EXPECT(space->IsValidAddress(new_block)); |
23 | block = new_block; |
24 | total += kBlockSize; |
25 | } |
26 | // Allocate a large block. |
27 | uword large_block = space->TryAllocate(1 * MB); |
28 | EXPECT(large_block != 0); |
29 | EXPECT(block != large_block); |
30 | EXPECT(space->IsValidAddress(large_block)); |
31 | delete space; |
32 | } |
33 | |
34 | } // namespace dart |
35 |