[llvm] bca47ef - [LLVM][SupportTests] Ask the OS how large the page size is instead of guessing.

Michael Spencer via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 15 15:12:58 PDT 2020


Author: Michael Spencer
Date: 2020-04-15T15:12:28-07:00
New Revision: bca47ef80e3ec61e5e83bb6d755eee68d4b8f925

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

LOG: [LLVM][SupportTests] Ask the OS how large the page size is instead of guessing.

PPC64 had a larger than expected page size. Instead of guessing just
use the same API that `MemoryBuffer` does to determine the page size.

Added: 
    

Modified: 
    llvm/unittests/Support/MemoryBufferTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/Support/MemoryBufferTest.cpp b/llvm/unittests/Support/MemoryBufferTest.cpp
index ae0c5eab178c..e0f51db1d79f 100644
--- a/llvm/unittests/Support/MemoryBufferTest.cpp
+++ b/llvm/unittests/Support/MemoryBufferTest.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
@@ -395,8 +396,10 @@ TEST_F(MemoryBufferTest, mmapVolatileNoNull) {
       "MemoryBufferTest_mmapVolatileNoNull", "temp", FD, TestPath));
   FileRemover Cleanup(TestPath);
   raw_fd_ostream OF(FD, true);
-  // Create a file large enough to mmap. A 32KiB file should be enough.
-  for (unsigned i = 0; i < 0x1000; ++i)
+  // Create a file large enough to mmap. 4 pages should be enough.
+  unsigned PageSize = sys::Process::getPageSizeEstimate();
+  unsigned FileWrites = (PageSize * 4) / 8;
+  for (unsigned i = 0; i < FileWrites; ++i)
     OF << "01234567";
   OF.close();
 
@@ -410,7 +413,7 @@ TEST_F(MemoryBufferTest, mmapVolatileNoNull) {
   ASSERT_NO_ERROR(MBOrError.getError())
   OwningBuffer MB = std::move(*MBOrError);
   EXPECT_EQ(MB->getBufferKind(), MemoryBuffer::MemoryBuffer_MMap);
-  EXPECT_EQ(MB->getBufferSize(), std::size_t(0x8000));
+  EXPECT_EQ(MB->getBufferSize(), std::size_t(FileWrites * 8));
   EXPECT_TRUE(MB->getBuffer().startswith("01234567"));
 }
 }


        


More information about the llvm-commits mailing list