[compiler-rt] 0d4b6f1 - [sanitizer_common] Fix DenseMapCustomTest.DefaultMinReservedSizeTest on SPARC

Rainer Orth via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 9 00:12:22 PST 2022


Author: Rainer Orth
Date: 2022-02-09T09:12:02+01:00
New Revision: 0d4b6f1f4b7b5f20698aae42a616b1bb3e18ef85

URL: https://github.com/llvm/llvm-project/commit/0d4b6f1f4b7b5f20698aae42a616b1bb3e18ef85
DIFF: https://github.com/llvm/llvm-project/commit/0d4b6f1f4b7b5f20698aae42a616b1bb3e18ef85.diff

LOG: [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

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/tests/sanitizer_dense_map_test.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_dense_map_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_dense_map_test.cpp
index fcc905ea87b8d..1336f1d85eac7 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_dense_map_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_dense_map_test.cpp
@@ -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 
diff erent 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 
diff erent 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();


        


More information about the llvm-commits mailing list