OLD | NEW |
1 // Copyright 2014 Google Inc. All Rights Reserved. | 1 // Copyright 2014 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 TEST(SimpleBlockHeapTest, EndToEnd) { | 49 TEST(SimpleBlockHeapTest, EndToEnd) { |
50 WinHeap win_heap; | 50 WinHeap win_heap; |
51 SimpleBlockHeap h(&win_heap); | 51 SimpleBlockHeap h(&win_heap); |
52 | 52 |
53 BlockLayout layout = {}; | 53 BlockLayout layout = {}; |
54 BlockInfo block = {}; | 54 BlockInfo block = {}; |
55 | 55 |
56 // Allocate and free a zero-sized allocation. This should succeed | 56 // Allocate and free a zero-sized allocation. This should succeed |
57 // by definition. | 57 // by definition. |
58 void* alloc = h.AllocateBlock(0, 0, 0, &layout); | 58 void* alloc = h.AllocateBlock(0, 0, 0, &layout); |
59 BlockInitialize(layout, alloc, false, &block); | 59 BlockInitialize(layout, alloc, &block); |
60 EXPECT_TRUE(h.FreeBlock(block)); | 60 EXPECT_TRUE(h.FreeBlock(block)); |
61 | 61 |
62 // Make a bunch of different sized allocations. | 62 // Make a bunch of different sized allocations. |
63 BlockInfoSet blocks; | 63 BlockInfoSet blocks; |
64 for (uint32_t i = 1; i < 1024 * 1024; i <<= 1) { | 64 for (uint32_t i = 1; i < 1024 * 1024; i <<= 1) { |
65 void* alloc = h.AllocateBlock(i, 0, 0, &layout); | 65 void* alloc = h.AllocateBlock(i, 0, 0, &layout); |
66 BlockInitialize(layout, alloc, false, &block); | 66 BlockInitialize(layout, alloc, &block); |
67 blocks.insert(block); | 67 blocks.insert(block); |
68 } | 68 } |
69 | 69 |
70 // Now free them. | 70 // Now free them. |
71 BlockInfoSet::const_iterator it = blocks.begin(); | 71 BlockInfoSet::const_iterator it = blocks.begin(); |
72 for (; it != blocks.end(); ++it) | 72 for (; it != blocks.end(); ++it) |
73 EXPECT_TRUE(h.FreeBlock(*it)); | 73 EXPECT_TRUE(h.FreeBlock(*it)); |
74 } | 74 } |
75 | 75 |
76 TEST(SimpleBlockHeap, IsAllocated) { | 76 TEST(SimpleBlockHeap, IsAllocated) { |
(...skipping 16 matching lines...) Expand all Loading... |
93 | 93 |
94 h.Lock(); | 94 h.Lock(); |
95 EXPECT_TRUE(h.TryLock()); | 95 EXPECT_TRUE(h.TryLock()); |
96 h.Unlock(); | 96 h.Unlock(); |
97 h.Unlock(); | 97 h.Unlock(); |
98 } | 98 } |
99 | 99 |
100 } // namespace heaps | 100 } // namespace heaps |
101 } // namespace asan | 101 } // namespace asan |
102 } // namespace agent | 102 } // namespace agent |
OLD | NEW |