Chromium Code Reviews| 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 // Allocate something small. | |
| 586 requestedSize = 512; | |
|
Chris Evans
2014/02/18 22:19:59
I think you might need to adjust the size dependin
Chris Evans
2014/02/18 22:19:59
I have another idea. Can we make all the sizes odd
| |
| 587 ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); | |
| 588 EXPECT_TRUE(ptr); | |
| 589 actualSize = partitionAllocGetSize(genericAllocator.root(), ptr); | |
| 590 EXPECT_LE(requestedSize, actualSize); | |
| 591 partitionFreeGeneric(genericAllocator.root(), ptr); | |
| 592 | |
| 593 // Allocate something slightly larger. | |
| 594 requestedSize = 200 * 1024; | |
| 595 ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); | |
| 596 EXPECT_TRUE(ptr); | |
| 597 actualSize = partitionAllocGetSize(genericAllocator.root(), ptr); | |
| 598 EXPECT_LE(requestedSize, actualSize); | |
| 599 partitionFreeGeneric(genericAllocator.root(), ptr); | |
| 600 | |
| 601 // Allocate something slightly larger and uneven. GetSize() should return a | |
| 602 // larger size than we asked for now. | |
| 603 requestedSize = 200 * 1024 + 250; | |
|
Chris Evans
2014/02/18 22:19:59
A nicer size to test might be (256 * 1024) - kSyst
| |
| 604 ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); | |
| 605 EXPECT_TRUE(ptr); | |
| 606 actualSize = partitionAllocGetSize(genericAllocator.root(), ptr); | |
| 607 EXPECT_LT(requestedSize, actualSize); | |
| 608 // Check that we can write at the end of the reported size too. | |
| 609 char* charPtr = reinterpret_cast<char*>(ptr); | |
| 610 *(charPtr + (actualSize - 1)) = 'A'; | |
| 611 partitionFreeGeneric(genericAllocator.root(), ptr); | |
| 612 | |
| 613 // Allocate something very large. GetSize() should return zero. | |
|
Chris Evans
2014/02/18 22:19:59
Does this actually happen? I see that you're testi
| |
| 614 requestedSize = 512 * 1024 * 1024; | |
| 615 ptr = partitionAllocGeneric(genericAllocator.root(), requestedSize); | |
| 616 EXPECT_TRUE(ptr); | |
| 617 actualSize = partitionAllocGetSize(genericAllocator.root(), ptr); | |
| 618 EXPECT_LE(requestedSize, actualSize); | |
| 619 partitionFreeGeneric(genericAllocator.root(), ptr); | |
| 620 | |
| 621 TestShutdown(); | |
| 622 } | |
| 623 | |
| 577 // Test the realloc() contract. | 624 // Test the realloc() contract. |
| 578 TEST(WTF_PartitionAlloc, Realloc) | 625 TEST(WTF_PartitionAlloc, Realloc) |
| 579 { | 626 { |
| 580 TestSetup(); | 627 TestSetup(); |
| 581 | 628 |
| 582 // realloc(0, size) should be equivalent to malloc(). | 629 // realloc(0, size) should be equivalent to malloc(). |
| 583 void* ptr = partitionReallocGeneric(genericAllocator.root(), 0, kTestAllocSi ze); | 630 void* ptr = partitionReallocGeneric(genericAllocator.root(), 0, kTestAllocSi ze); |
| 584 memset(ptr, 'A', kTestAllocSize); | 631 memset(ptr, 'A', kTestAllocSize); |
| 585 WTF::PartitionPage* page = WTF::partitionPointerToPage(WTF::partitionCookieF reePointerAdjust(ptr)); | 632 WTF::PartitionPage* page = WTF::partitionPointerToPage(WTF::partitionCookieF reePointerAdjust(ptr)); |
| 586 // realloc(ptr, 0) should be equivalent to free(). | 633 // 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)); | 1033 EXPECT_EQ(32u, WTF::countLeadingZerosSizet(0)); |
| 987 EXPECT_EQ(31u, WTF::countLeadingZerosSizet(1)); | 1034 EXPECT_EQ(31u, WTF::countLeadingZerosSizet(1)); |
| 988 EXPECT_EQ(1u, WTF::countLeadingZerosSizet(1 << 30)); | 1035 EXPECT_EQ(1u, WTF::countLeadingZerosSizet(1 << 30)); |
| 989 EXPECT_EQ(0u, WTF::countLeadingZerosSizet(1 << 31)); | 1036 EXPECT_EQ(0u, WTF::countLeadingZerosSizet(1 << 31)); |
| 990 #endif | 1037 #endif |
| 991 } | 1038 } |
| 992 | 1039 |
| 993 } // namespace | 1040 } // namespace |
| 994 | 1041 |
| 995 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 1042 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
| OLD | NEW |