[sanitizer_common] Fix DenseMapCustomTest.DefaultMinReservedSizeTest on SPARC

As described in Issue #53523, the
`DenseMapCustomTest.DefaultMinReservedSizeTest` test FAILs on Solaris/SPARC
(both 32 and 64-bit):

  /vol/llvm/src/llvm-project/local/compiler-rt/lib/sanitizer_common/tests/sanitizer_dense_map_test.cpp:399:
Failure
  Expected: (MemorySize) != (Map.getMemorySize()), actual: 8192 vs 8192

This happens because SPARC, unlike many other CPUs, uses an 8 kB pagesize.

Fixed by incorporating the pagesize into the calculations of
`ExpectedInitialBucketCount` and derived values.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and
`x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D118771
This commit is contained in:
Rainer Orth 2022-02-09 09:12:02 +01:00
parent 7cca34acc4
commit 0d4b6f1f4b
1 changed files with 6 additions and 9 deletions

View File

@ -365,11 +365,10 @@ TEST(DenseMapCustomTest, EqualityComparison) {
EXPECT_NE(M1, M3);
}
const int ExpectedInitialBucketCount = GetPageSizeCached() / /* sizeof(KV) */ 8;
// Test for the default minimum size of a DenseMap
TEST(DenseMapCustomTest, DefaultMinReservedSizeTest) {
// IF THIS VALUE CHANGE, please update InitialSizeTest, InitFromIterator, and
// ReserveTest as well!
const int ExpectedInitialBucketCount = 512;
// Formula from DenseMap::getMinBucketToReserveForEntries()
const int ExpectedMaxInitialEntries = ExpectedInitialBucketCount * 3 / 4 - 1;
@ -410,9 +409,8 @@ TEST(DenseMapCustomTest, InitialSizeTest) {
// Test a few different size, 341 is *not* a random choice: we need a value
// that is 2/3 of a power of two to stress the grow() condition, and the power
// of two has to be at least 512 because of minimum size allocation in the
// DenseMap (see DefaultMinReservedSizeTest). 513 is a value just above the
// 512 default init.
for (auto Size : {1, 2, 48, 66, 341, 513}) {
// DenseMap (see DefaultMinReservedSizeTest).
for (auto Size : {1, 2, 48, 66, 341, ExpectedInitialBucketCount + 1}) {
DenseMap<int, CountCopyAndMove> Map(Size);
unsigned MemorySize = Map.getMemorySize();
CountCopyAndMove::Copy = 0;
@ -453,9 +451,8 @@ TEST(DenseMapCustomTest, ReserveTest) {
// Test a few different size, 341 is *not* a random choice: we need a value
// that is 2/3 of a power of two to stress the grow() condition, and the power
// of two has to be at least 512 because of minimum size allocation in the
// DenseMap (see DefaultMinReservedSizeTest). 513 is a value just above the
// 512 default init.
for (auto Size : {1, 2, 48, 66, 341, 513}) {
// DenseMap (see DefaultMinReservedSizeTest).
for (auto Size : {1, 2, 48, 66, 341, ExpectedInitialBucketCount + 1}) {
DenseMap<int, CountCopyAndMove> Map;
Map.reserve(Size);
unsigned MemorySize = Map.getMemorySize();