OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This file contains unit tests for InterceptionManager. | 5 // This file contains unit tests for InterceptionManager. |
6 // The tests require private information so the whole interception.cc file is | 6 // The tests require private information so the whole interception.cc file is |
7 // included from this file. | 7 // included from this file. |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <set> | 10 #include <set> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 TEST(InterceptionManagerTest, GetGranularAlignedRandomOffset) { | 86 TEST(InterceptionManagerTest, GetGranularAlignedRandomOffset) { |
87 std::set<size_t> sizes; | 87 std::set<size_t> sizes; |
88 | 88 |
89 // 544 is current value of interceptions_.size() * sizeof(ThunkData) + | 89 // 544 is current value of interceptions_.size() * sizeof(ThunkData) + |
90 // sizeof(DllInterceptionData). | 90 // sizeof(DllInterceptionData). |
91 const size_t kThunkBytes = 544; | 91 const size_t kThunkBytes = 544; |
92 | 92 |
93 // ciel(log2(544)) = 10. | 93 // ciel(log2(544)) = 10. |
94 // Alignment must be 2^10 = 1024. | 94 // Alignment must be 2^10 = 1024. |
95 const size_t kAlignmentBits = base::bits::Log2Ceiling(kThunkBytes); | 95 const size_t kAlignmentBits = base::bits::Log2Ceiling(kThunkBytes); |
96 const size_t kAlignment = 1 << kAlignmentBits; | 96 const size_t kAlignment = static_cast<size_t>(1) << kAlignmentBits; |
97 | 97 |
98 const size_t kAllocGranularity = 65536; | 98 const size_t kAllocGranularity = 65536; |
99 | 99 |
100 // Generate enough sample data to ensure there is at least one value in each | 100 // Generate enough sample data to ensure there is at least one value in each |
101 // potential bucket. | 101 // potential bucket. |
102 for (size_t i = 0; i < 1000000; i++) | 102 for (size_t i = 0; i < 1000000; i++) |
103 sizes.insert(internal::GetGranularAlignedRandomOffset(kThunkBytes)); | 103 sizes.insert(internal::GetGranularAlignedRandomOffset(kThunkBytes)); |
104 | 104 |
105 size_t prev_val = 0; | 105 size_t prev_val = 0; |
106 size_t min_val = kAllocGranularity; | 106 size_t min_val = kAllocGranularity; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 int num_dlls, num_functions, num_names; | 250 int num_dlls, num_functions, num_names; |
251 WalkBuffer(local_buffer.get(), buffer_size, &num_dlls, &num_functions, | 251 WalkBuffer(local_buffer.get(), buffer_size, &num_dlls, &num_functions, |
252 &num_names); | 252 &num_names); |
253 | 253 |
254 EXPECT_EQ(3, num_dlls); | 254 EXPECT_EQ(3, num_dlls); |
255 EXPECT_EQ(4, num_functions); | 255 EXPECT_EQ(4, num_functions); |
256 EXPECT_EQ(0, num_names); | 256 EXPECT_EQ(0, num_names); |
257 } | 257 } |
258 | 258 |
259 } // namespace sandbox | 259 } // namespace sandbox |
OLD | NEW |