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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 | 567 |
568 // Can we free null? | 568 // Can we free null? |
569 partitionFreeGeneric(genericAllocator.root(), 0); | 569 partitionFreeGeneric(genericAllocator.root(), 0); |
570 | 570 |
571 // Do we correctly get a null for a failed allocation? | 571 // Do we correctly get a null for a failed allocation? |
572 EXPECT_EQ(0, partitionAllocGenericFlags(genericAllocator.root(), WTF::Partit ionAllocReturnNull, 3u * 1024 * 1024 * 1024)); | 572 EXPECT_EQ(0, partitionAllocGenericFlags(genericAllocator.root(), WTF::Partit ionAllocReturnNull, 3u * 1024 * 1024 * 1024)); |
573 | 573 |
574 TestShutdown(); | 574 TestShutdown(); |
575 } | 575 } |
576 | 576 |
577 // Test that we can fetch the real allocated size after an allocation. | |
578 TEST(WTF_PartitionAlloc, GenericAllocGetSize) | |
579 { | |
580 TestSetup(); | |
581 | |
582 void* ptr; | |
583 size_t requestedSize, actualSize; | |
584 | |
585 EXPECT_TRUE(partitionAllocSupportsGetSize()); | |
586 | |
587 // Allocate something small. | |
588 requestedSize = 511 - kExtraAllocSize; | |
589 ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); | |
590 EXPECT_TRUE(ptr); | |
591 actualSize = partitionAllocGetSize(ptr); | |
592 EXPECT_LT(requestedSize, actualSize); | |
593 partitionFreeGeneric(genericAllocator.root(), ptr); | |
594 | |
595 // Allocate that should be a perfect match for a bucket. | |
Chris Evans
2014/02/19 07:15:52
Grammar: should be "allocation" or "allocate a siz
| |
596 requestedSize = (256 * 1024) - kExtraAllocSize; | |
597 ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); | |
598 EXPECT_TRUE(ptr); | |
599 actualSize = partitionAllocGetSize(ptr); | |
600 EXPECT_EQ(requestedSize, actualSize); | |
601 partitionFreeGeneric(genericAllocator.root(), ptr); | |
602 | |
603 // Allocate something slightly larger and uneven. GetSize() should return a | |
Chris Evans
2014/02/19 07:15:52
The size is not uneven as far as I can see? Maybe
| |
604 // larger size than we asked for now. | |
605 requestedSize = (256 * 1024) - WTF::kSystemPageSize - kExtraAllocSize; | |
606 ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); | |
607 EXPECT_TRUE(ptr); | |
608 actualSize = partitionAllocGetSize(ptr); | |
609 EXPECT_EQ(requestedSize + WTF::kSystemPageSize, actualSize); | |
610 // Check that we can write at the end of the reported size too. | |
611 char* charPtr = reinterpret_cast<char*>(ptr); | |
612 *(charPtr + (actualSize - 1)) = 'A'; | |
613 partitionFreeGeneric(genericAllocator.root(), ptr); | |
614 | |
615 // Allocate something very large. | |
616 requestedSize = 512 * 1024 * 1024; | |
Chris Evans
2014/02/19 07:15:52
Let's do (512 * 1024 * 1024) - 1, and then we can
| |
617 ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); | |
618 EXPECT_TRUE(ptr); | |
619 actualSize = partitionAllocGetSize(ptr); | |
620 EXPECT_LE(requestedSize, actualSize); | |
621 partitionFreeGeneric(genericAllocator.root(), ptr); | |
622 | |
623 TestShutdown(); | |
624 } | |
625 | |
577 // Test the realloc() contract. | 626 // Test the realloc() contract. |
578 TEST(WTF_PartitionAlloc, Realloc) | 627 TEST(WTF_PartitionAlloc, Realloc) |
579 { | 628 { |
580 TestSetup(); | 629 TestSetup(); |
581 | 630 |
582 // realloc(0, size) should be equivalent to malloc(). | 631 // realloc(0, size) should be equivalent to malloc(). |
583 void* ptr = partitionReallocGeneric(genericAllocator.root(), 0, kTestAllocSi ze); | 632 void* ptr = partitionReallocGeneric(genericAllocator.root(), 0, kTestAllocSi ze); |
584 memset(ptr, 'A', kTestAllocSize); | 633 memset(ptr, 'A', kTestAllocSize); |
585 WTF::PartitionPage* page = WTF::partitionPointerToPage(WTF::partitionCookieF reePointerAdjust(ptr)); | 634 WTF::PartitionPage* page = WTF::partitionPointerToPage(WTF::partitionCookieF reePointerAdjust(ptr)); |
586 // realloc(ptr, 0) should be equivalent to free(). | 635 // realloc(ptr, 0) should be equivalent to free(). |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
986 EXPECT_EQ(32u, WTF::countLeadingZerosSizet(0)); | 1035 EXPECT_EQ(32u, WTF::countLeadingZerosSizet(0)); |
987 EXPECT_EQ(31u, WTF::countLeadingZerosSizet(1)); | 1036 EXPECT_EQ(31u, WTF::countLeadingZerosSizet(1)); |
988 EXPECT_EQ(1u, WTF::countLeadingZerosSizet(1 << 30)); | 1037 EXPECT_EQ(1u, WTF::countLeadingZerosSizet(1 << 30)); |
989 EXPECT_EQ(0u, WTF::countLeadingZerosSizet(1 << 31)); | 1038 EXPECT_EQ(0u, WTF::countLeadingZerosSizet(1 << 31)); |
990 #endif | 1039 #endif |
991 } | 1040 } |
992 | 1041 |
993 } // namespace | 1042 } // namespace |
994 | 1043 |
995 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 1044 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
OLD | NEW |