OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 | 657 |
658 // realloc(0, size) should be equivalent to malloc(). | 658 // realloc(0, size) should be equivalent to malloc(). |
659 void* ptr = partitionReallocGeneric(genericAllocator.root(), 0, kTestAllocSi ze); | 659 void* ptr = partitionReallocGeneric(genericAllocator.root(), 0, kTestAllocSi ze); |
660 memset(ptr, 'A', kTestAllocSize); | 660 memset(ptr, 'A', kTestAllocSize); |
661 WTF::PartitionPage* page = WTF::partitionPointerToPage(WTF::partitionCookieF reePointerAdjust(ptr)); | 661 WTF::PartitionPage* page = WTF::partitionPointerToPage(WTF::partitionCookieF reePointerAdjust(ptr)); |
662 // realloc(ptr, 0) should be equivalent to free(). | 662 // realloc(ptr, 0) should be equivalent to free(). |
663 void* ptr2 = partitionReallocGeneric(genericAllocator.root(), ptr, 0); | 663 void* ptr2 = partitionReallocGeneric(genericAllocator.root(), ptr, 0); |
664 EXPECT_EQ(0, ptr2); | 664 EXPECT_EQ(0, ptr2); |
665 EXPECT_EQ(WTF::partitionCookieFreePointerAdjust(ptr), page->freelistHead); | 665 EXPECT_EQ(WTF::partitionCookieFreePointerAdjust(ptr), page->freelistHead); |
666 | 666 |
667 // Test that growing an allocation with realloc() copies everything from the | |
668 // old allocation. | |
669 size_t size = WTF::kSystemPageSize - kExtraAllocSize; | |
670 EXPECT_EQ(size, partitionAllocActualSize(genericAllocator.root(), size)); | |
671 ptr = partitionAllocGeneric(genericAllocator.root(), size); | |
672 memset(ptr, 'A', size); | |
673 ptr2 = partitionReallocGeneric(genericAllocator.root(), ptr, size + 1); | |
674 EXPECT_NE(ptr, ptr2); | |
675 char* charPtr2 = static_cast<char*>(ptr2); | |
676 EXPECT_EQ('A', charPtr2[0]); | |
677 EXPECT_EQ('A', charPtr2[size - 1]); | |
678 #ifndef NDEBUG | |
679 EXPECT_EQ(WTF::kUninitializedByte, static_cast<unsigned char>(charPtr2[size] )); | |
680 #endif | |
681 | |
682 // Test that shrinking an allocation with realloc() also copies everything | |
683 // from the old allocation. | |
684 ptr = partitionReallocGeneric(genericAllocator.root(), ptr2, size - 1); | |
685 EXPECT_NE(ptr2, ptr); | |
686 char* charPtr = static_cast<char*>(ptr); | |
687 EXPECT_EQ('A', charPtr[0]); | |
688 EXPECT_EQ('A', charPtr[size - 2]); | |
689 #ifndef NDEBUG | |
690 EXPECT_EQ(WTF::kUninitializedByte, static_cast<unsigned char>(charPtr[size - 1])); | |
Chris Evans
2014/02/26 20:56:55
I think "size - 1" is technically out of bounds he
Jens Widell
2014/02/27 07:18:13
The test sets 'size' to be a "perfect fit" (and ch
| |
691 #endif | |
692 | |
693 partitionFreeGeneric(genericAllocator.root(), ptr); | |
694 | |
667 TestShutdown(); | 695 TestShutdown(); |
668 } | 696 } |
669 | 697 |
670 // Tests the handing out of freelists for partial pages. | 698 // Tests the handing out of freelists for partial pages. |
671 TEST(WTF_PartitionAlloc, PartialPageFreelists) | 699 TEST(WTF_PartitionAlloc, PartialPageFreelists) |
672 { | 700 { |
673 TestSetup(); | 701 TestSetup(); |
674 | 702 |
675 size_t bigSize = allocator.root()->maxAllocation - kExtraAllocSize; | 703 size_t bigSize = allocator.root()->maxAllocation - kExtraAllocSize; |
676 EXPECT_EQ(WTF::kSystemPageSize - WTF::kAllocationGranularity, bigSize + kExt raAllocSize); | 704 EXPECT_EQ(WTF::kSystemPageSize - WTF::kAllocationGranularity, bigSize + kExt raAllocSize); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1124 EXPECT_EQ(32u, WTF::countLeadingZerosSizet(0)); | 1152 EXPECT_EQ(32u, WTF::countLeadingZerosSizet(0)); |
1125 EXPECT_EQ(31u, WTF::countLeadingZerosSizet(1)); | 1153 EXPECT_EQ(31u, WTF::countLeadingZerosSizet(1)); |
1126 EXPECT_EQ(1u, WTF::countLeadingZerosSizet(1 << 30)); | 1154 EXPECT_EQ(1u, WTF::countLeadingZerosSizet(1 << 30)); |
1127 EXPECT_EQ(0u, WTF::countLeadingZerosSizet(1 << 31)); | 1155 EXPECT_EQ(0u, WTF::countLeadingZerosSizet(1 << 31)); |
1128 #endif | 1156 #endif |
1129 } | 1157 } |
1130 | 1158 |
1131 } // namespace | 1159 } // namespace |
1132 | 1160 |
1133 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 1161 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
OLD | NEW |