Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdio.h> | 5 #include <stdio.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 #include <algorithm> // for min() | 7 #include <algorithm> // for min() |
| 8 #include "base/atomicops.h" | 8 #include "base/atomicops.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 unsigned char* dst = | 472 unsigned char* dst = |
| 473 reinterpret_cast<unsigned char*>(_recalloc(src, 1, dst_size)); | 473 reinterpret_cast<unsigned char*>(_recalloc(src, 1, dst_size)); |
| 474 EXPECT_TRUE(Valid(dst, min(src_size, dst_size))); | 474 EXPECT_TRUE(Valid(dst, min(src_size, dst_size))); |
| 475 Fill(dst, dst_size); | 475 Fill(dst, dst_size); |
| 476 EXPECT_TRUE(Valid(dst, dst_size)); | 476 EXPECT_TRUE(Valid(dst, dst_size)); |
| 477 if (dst != NULL) | 477 if (dst != NULL) |
| 478 free(dst); | 478 free(dst); |
| 479 } | 479 } |
| 480 } | 480 } |
| 481 } | 481 } |
| 482 | |
| 483 // Test windows specific _aligned_malloc() and _aligned_free() methods. | |
| 484 TEST(Allocators, AlignedMalloc) { | |
| 485 // Try allocating data with a bunch of alignments and sizes | |
| 486 static const int kTestAlignments[] = {8, 16, 256, 4096}; | |
| 487 for (int size = 1; size < 1048576; size *= 2) { | |
|
jar (doing other things)
2012/07/30 23:04:22
By accident, tcmalloc will tend(?) to pass this te
DaleCurtis
2012/07/31 00:44:22
Added 8192, 16384 alignments and allocate two per
| |
| 488 for (int i = 0; i < ARRAYSIZE(kTestAlignments); ++i) { | |
| 489 unsigned char* ptr = reinterpret_cast<unsigned char*>( | |
| 490 _aligned_malloc(size, kTestAlignments[i])); | |
|
jar (doing other things)
2012/07/30 23:04:22
I'd also suggest you allocate "size + 1" to avoid
DaleCurtis
2012/07/31 00:44:22
Switched to using NextSize() as many of the other
| |
| 491 CheckAlignment(ptr, kTestAlignments[i]); | |
| 492 Fill(ptr, size); | |
| 493 EXPECT_TRUE(Valid(ptr, size)); | |
| 494 _aligned_free(ptr); | |
| 495 } | |
| 496 } | |
| 497 } | |
| 498 | |
| 482 #endif | 499 #endif |
| 483 | 500 |
| 484 | 501 |
| 485 int main(int argc, char** argv) { | 502 int main(int argc, char** argv) { |
| 486 testing::InitGoogleTest(&argc, argv); | 503 testing::InitGoogleTest(&argc, argv); |
| 487 return RUN_ALL_TESTS(); | 504 return RUN_ALL_TESTS(); |
| 488 } | 505 } |
| OLD | NEW |