OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "courgette/third_party/paged_array.h" | 5 #include "courgette/third_party/paged_array.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 class PagedArrayTest : public testing::Test { | 9 class PagedArrayTest : public testing::Test { |
10 public: | 10 public: |
11 // Total allocation of 4GB will fail in 32 bit programs if allocations are | 11 // Total allocation of 4GB will fail in 32 bit programs if allocations are |
12 // leaked. | 12 // leaked. |
13 static const int kIterations = 20; | 13 static const int kIterations = 20; |
14 static const int kSize = 200 * 1024 * 1024 / sizeof(int); // 200MB | 14 static const int kSize = 200 * 1024 * 1024 / sizeof(int); // 200MB |
15 }; | 15 }; |
16 | 16 |
17 // Disable these tests under AddressSanitizer on Windows as it uses more memory | |
dgarrett
2015/01/13 22:16:11
Can you reword this comment a little? It confused
| |
18 // by itself and also has to keep some freed memory in a quarantine. | |
19 // As a result, these two tests fail on OOM under AddressSanitizer on Windows. | |
20 #if !defined(ADDRESS_SANITIZER) || !defined(OS_WIN) | |
17 TEST_F(PagedArrayTest, TestManyAllocationsDestructorFree) { | 21 TEST_F(PagedArrayTest, TestManyAllocationsDestructorFree) { |
18 for (int i = 0; i < kIterations; ++i) { | 22 for (int i = 0; i < kIterations; ++i) { |
19 courgette::PagedArray<int> a; | 23 courgette::PagedArray<int> a; |
20 EXPECT_TRUE(a.Allocate(kSize)); | 24 EXPECT_TRUE(a.Allocate(kSize)); |
21 } | 25 } |
22 } | 26 } |
23 | 27 |
24 TEST_F(PagedArrayTest, TestManyAllocationsManualFree) { | 28 TEST_F(PagedArrayTest, TestManyAllocationsManualFree) { |
25 courgette::PagedArray<int> a; | 29 courgette::PagedArray<int> a; |
26 for (int i = 0; i < kIterations; ++i) { | 30 for (int i = 0; i < kIterations; ++i) { |
27 EXPECT_TRUE(a.Allocate(kSize)); | 31 EXPECT_TRUE(a.Allocate(kSize)); |
28 a.clear(); | 32 a.clear(); |
29 } | 33 } |
30 } | 34 } |
35 #endif | |
31 | 36 |
32 TEST_F(PagedArrayTest, TestAccess) { | 37 TEST_F(PagedArrayTest, TestAccess) { |
33 const int kAccessSize = 3 * 1024 * 1024; | 38 const int kAccessSize = 3 * 1024 * 1024; |
34 courgette::PagedArray<int> a; | 39 courgette::PagedArray<int> a; |
35 a.Allocate(kAccessSize); | 40 a.Allocate(kAccessSize); |
36 for (int i = 0; i < kAccessSize; ++i) { | 41 for (int i = 0; i < kAccessSize; ++i) { |
37 a[i] = i; | 42 a[i] = i; |
38 } | 43 } |
39 for (int i = 0; i < kAccessSize; ++i) { | 44 for (int i = 0; i < kAccessSize; ++i) { |
40 EXPECT_EQ(i, a[i]); | 45 EXPECT_EQ(i, a[i]); |
41 } | 46 } |
42 } | 47 } |
OLD | NEW |